Fixed breaking bug and server now responds with print status
This commit is contained in:
27
print.js
27
print.js
@@ -21,14 +21,18 @@ module.exports.printing = function() {
|
||||
module.exports.print = async function() {
|
||||
printing = true;
|
||||
while (printQueue.length > 0) {
|
||||
await currentprint(printQueue[0].name, printQueue[0].coords);
|
||||
await currentprint(printQueue[0].name, printQueue[0].coords, printQueue[0].req, printQueue[0].res);
|
||||
await Helper.sleep(200);
|
||||
printQueue.splice(0, 1);
|
||||
}
|
||||
printing = false;
|
||||
}
|
||||
|
||||
async function currentprint(name, coords) {
|
||||
async function currentprint(name, coords, req, res) {
|
||||
let currentWeather = await WeatherAPI.getWeather(1, coords);
|
||||
let todaysForcast = await WeatherAPI.getWeather(2, coords);
|
||||
if (currentWeather == -1 || todaysForcast == -1) res.end('400 BAD REQUEST: INVALID COORDINATES');
|
||||
|
||||
let text = Result.genCompilerSettings({
|
||||
padding: 2,
|
||||
lineBreaks: 1,
|
||||
@@ -44,22 +48,23 @@ async function currentprint(name, coords) {
|
||||
size: `small`
|
||||
},
|
||||
{
|
||||
content: `${await WeatherAPI.getWeather(1, coords)}`,
|
||||
content: `${currentWeather}`,
|
||||
align: `left`,
|
||||
size: `small`
|
||||
},
|
||||
{
|
||||
content: `The forcast for today is ${await WeatherAPI.getWeather(2, coords)}`,
|
||||
content: `The forcast for today is ${todaysForcast}`,
|
||||
align: `left`,
|
||||
size: `small`
|
||||
}
|
||||
]
|
||||
});
|
||||
try {
|
||||
await PythonShell.run('printer/write.py', text, function (err, results) {
|
||||
if (err) {
|
||||
console.log('Could not open serial connection for ' + name + '\'s print');
|
||||
}
|
||||
});
|
||||
} catch (err) {}
|
||||
await PythonShell.run('printer/write.py', text, async function (err, results) {
|
||||
if (err) {
|
||||
console.log('Could not open serial connection for ' + name + '\'s print');
|
||||
res.end('500 INTERNAL SERVER ERROR: PRINTER NOT RESPONDING');
|
||||
} else {
|
||||
res.end('200 OK');
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user