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": {
"augerOn": 500,
"augerOff": 1500,
"pause": 10000,
"igniterStart": 10000,
"blowerStop": 10000
"pause": 3000,
"igniterStart": 30000,
"blowerStop": 30000
}
}

View File

@ -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);

22
main.js
View File

@ -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);