From 3e0a78b905b1910fc7a80461d383640f2b3720c9 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Tue, 20 Dec 2022 15:04:37 -0500 Subject: [PATCH] Safeties, Startup, Shutdown --- config.json | 6 +++--- functions.js | 13 ++++++------- main.js | 22 ++++++++++++++++------ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/config.json b/config.json index 78483ef..fdb8676 100644 --- a/config.json +++ b/config.json @@ -20,8 +20,8 @@ "intervals": { "augerOn": 500, "augerOff": 1500, - "pause": 10000, - "igniterStart": 10000, - "blowerStop": 10000 + "pause": 3000, + "igniterStart": 30000, + "blowerStop": 30000 } } \ No newline at end of file diff --git a/functions.js b/functions.js index df7f9f9..cce97ae 100644 --- a/functions.js +++ b/functions.js @@ -224,6 +224,7 @@ const functions = { // If the auger is enabled, disable it if (config.status.auger == 1) { config.status.auger = 0; + if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Auger disabled.`); } // If the igniter is on, shut it off. if (config.status.igniter == 1) { @@ -235,20 +236,17 @@ const functions = { if (config.status.blower == 1) { // Set the timestamp to turn the blower off at config.timestamps.blowerOff = Date.now() + config.intervals.blowerStop; - functions.power.blower.off(gpio).then(res => { - if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); - }); } return "Shutdown has been initiated."; } else { - // blower.canShutdown() returns true only if the blower shutdown has + // blower.blocksShutdown() returns false only if the blower shutdown has // been initiated AND the specified cooldown time has passed - if(functions.blower.blocksShutdown()) { + if(!(functions.blower.blocksShutdown())) { if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Blower can be turned off.`); - fn.power.blower.off(gpio).then(res => { + functions.power.blower.off(gpio).then(res => { // Since the blower shutting off is the last step in the shutdown, we can quit. // TODO eventually we don't want to ever quit the program, so it can be restarted remotely - fn.commands.quit(); + functions.commands.quit(); }); } else { return "A shutdown has already been initiated and the blower is preventing shutdown."; @@ -379,6 +377,7 @@ const functions = { off(gpio) { return new Promise((resolve, reject) => { config.timestamps.igniterOff = Date.now(); + config.status.igniterFinished = true; if (process.env.ONPI == 'true') { gpio.write(igniterPin, false, (err) => { if (err) reject(err); diff --git a/main.js b/main.js index b24d0da..7f3cf25 100644 --- a/main.js +++ b/main.js @@ -70,7 +70,8 @@ async function main(fn, gpio) { break; case "quit": // Quit the script - fn.commands.shutdown(gpio); + console.log(fn.commands.shutdown(gpio)); + statusCheck(fn, gpio); break; case "ignite": // Start the ignite sequence @@ -121,9 +122,16 @@ async function main(fn, gpio) { } function statusCheck(fn, gpio) { - fn.tests.igniter(gpio).then((res) => { - if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); - }); + if (config.status.shutdown == 1) { + console.log(fn.commands.shutdown(gpio) || 'Shutting down...'); + main(fn, gpio); + return; + } + if (config.status.igniter == 1) { + fn.tests.igniter(gpio).then((res) => { + if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); + }); + } // Check the vacuum switch, if the test returns true, the vacuum is sensed // if it returns false, we will initiate a shutdown @@ -131,14 +139,16 @@ function statusCheck(fn, gpio) { fn.tests.vacuum(gpio).then(vacStatus => { if (!vacStatus) { console.error('No vacuum detected, beginning shutdown procedure.'); - fn.commands.shutdown(gpio); + console.log(fn.commands.shutdown(gpio)); + main(fn, gpio); } else { // Check the Proof of Fire Switch fn.tests.pof(gpio).then(pofStatus => { // If the igniter has finished running and no proof of fire is seen, shutdown the stove if (config.status.igniterFinished && (!pofStatus)) { console.error('No Proof of Fire after the igniter shut off, beginning shutdown procedure.'); - fn.commands.shutdown(gpio); + console.log(fn.commands.shutdown(gpio)); + main(fn, gpio); } else { if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Vacuum and Proof of Fire OK.`); main(fn, gpio);