Safeties, Startup, Shutdown

This commit is contained in:
Skylar Grant 2022-12-20 15:04:37 -05:00
parent 096d1739ac
commit 3e0a78b905
3 changed files with 25 additions and 16 deletions

View File

@ -20,8 +20,8 @@
"intervals": { "intervals": {
"augerOn": 500, "augerOn": 500,
"augerOff": 1500, "augerOff": 1500,
"pause": 10000, "pause": 3000,
"igniterStart": 10000, "igniterStart": 30000,
"blowerStop": 10000 "blowerStop": 30000
} }
} }

View File

@ -224,6 +224,7 @@ const functions = {
// If the auger is enabled, disable it // If the auger is enabled, disable it
if (config.status.auger == 1) { if (config.status.auger == 1) {
config.status.auger = 0; 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 the igniter is on, shut it off.
if (config.status.igniter == 1) { if (config.status.igniter == 1) {
@ -235,20 +236,17 @@ const functions = {
if (config.status.blower == 1) { if (config.status.blower == 1) {
// Set the timestamp to turn the blower off at // Set the timestamp to turn the blower off at
config.timestamps.blowerOff = Date.now() + config.intervals.blowerStop; 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."; return "Shutdown has been initiated.";
} else { } 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 // 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.`); 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. // 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 // TODO eventually we don't want to ever quit the program, so it can be restarted remotely
fn.commands.quit(); functions.commands.quit();
}); });
} else { } else {
return "A shutdown has already been initiated and the blower is preventing shutdown."; return "A shutdown has already been initiated and the blower is preventing shutdown.";
@ -379,6 +377,7 @@ const functions = {
off(gpio) { off(gpio) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
config.timestamps.igniterOff = Date.now(); config.timestamps.igniterOff = Date.now();
config.status.igniterFinished = true;
if (process.env.ONPI == 'true') { if (process.env.ONPI == 'true') {
gpio.write(igniterPin, false, (err) => { gpio.write(igniterPin, false, (err) => {
if (err) reject(err); if (err) reject(err);

16
main.js
View File

@ -70,7 +70,8 @@ async function main(fn, gpio) {
break; break;
case "quit": case "quit":
// Quit the script // Quit the script
fn.commands.shutdown(gpio); console.log(fn.commands.shutdown(gpio));
statusCheck(fn, gpio);
break; break;
case "ignite": case "ignite":
// Start the ignite sequence // Start the ignite sequence
@ -121,9 +122,16 @@ async function main(fn, gpio) {
} }
function statusCheck(fn, gpio) { function statusCheck(fn, gpio) {
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) => { fn.tests.igniter(gpio).then((res) => {
if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${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 // Check the vacuum switch, if the test returns true, the vacuum is sensed
// if it returns false, we will initiate a shutdown // if it returns false, we will initiate a shutdown
@ -131,14 +139,16 @@ function statusCheck(fn, gpio) {
fn.tests.vacuum(gpio).then(vacStatus => { fn.tests.vacuum(gpio).then(vacStatus => {
if (!vacStatus) { if (!vacStatus) {
console.error('No vacuum detected, beginning shutdown procedure.'); console.error('No vacuum detected, beginning shutdown procedure.');
fn.commands.shutdown(gpio); console.log(fn.commands.shutdown(gpio));
main(fn, gpio);
} else { } else {
// Check the Proof of Fire Switch // Check the Proof of Fire Switch
fn.tests.pof(gpio).then(pofStatus => { fn.tests.pof(gpio).then(pofStatus => {
// If the igniter has finished running and no proof of fire is seen, shutdown the stove // If the igniter has finished running and no proof of fire is seen, shutdown the stove
if (config.status.igniterFinished && (!pofStatus)) { if (config.status.igniterFinished && (!pofStatus)) {
console.error('No Proof of Fire after the igniter shut off, beginning shutdown procedure.'); 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 { } else {
if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Vacuum and Proof of Fire OK.`); if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Vacuum and Proof of Fire OK.`);
main(fn, gpio); main(fn, gpio);