i want to cry

This commit is contained in:
Skylar Grant 2022-12-16 22:30:12 -05:00
parent 8a35bb0328
commit 7a8b037e06
3 changed files with 52 additions and 1 deletions

View File

@ -12,5 +12,8 @@
"blower": 0,
"auger": 0,
"seenFire": false
},
"times": {
"blowerOff": 0
}
}

View File

@ -1,3 +1,5 @@
// TODOs: Add tests for PoF and Vacuum switches, add delays for shutting down blower, test logic for igniter
// Physical Pin numbers for GPIO
const augerPin = 26; // Pin for controlling the relay for the pellet auger motor.
const igniterPin = 13; // Pin for controlling the relay for the igniter.
@ -170,6 +172,7 @@ const functions = {
},
// Shutdown the script gracefully
quit() {
// TODO add quit file detection, not always going to be quitting from files
// Delete the quit file
fs.unlink('./quit', (err) => {
if (err) throw err;
@ -200,6 +203,27 @@ const functions = {
}
});
},
shutdown(gpio) {
// If the auger is enabled, disable it
if (config.status.auger == 1) {
config.status.auger = 0;
}
// If the igniter is on, shut it off.
if (config.status.igniter == 1) {
functions.power.igniter.off(gpio).then(res => {
if (config.debugMode) console.log(`[${(Date.now() - config.startTime)/1000}] I: Shut off igniter.`);
}); // TODO catch an error here
}
// TODO Change this so it gives a delay after shutting down so smoke doesn't enter the house
if (config.status.blower == 1) {
config.times.blowerOff = Date.now() + 600000; // 10 minutes, TODO move to config
// TODO Move this to another function, to run after tests pass
// functions.power.blower.off(gpio).then(res => {
// if (config.debugMode) console.log(`[${(Date.now() - config.startTime)/1000}] I: Shut off blower.`);
// });
}
},
},
tests: {
vacuum(gpio) {
@ -264,7 +288,16 @@ const functions = {
}
resolve(statusMsg);
});
}
},
blowerOffDelay() {
if (config.times.blowerOff == 0) return false;
// TODO Implement the blower shutdown delay as a test here
if (Date.now() > config.times.blowerOff) {
return true;
} else {
return false;
}
},
},
power: {
igniter: {

15
main.js
View File

@ -127,4 +127,19 @@ function statusCheck(fn, gpio) {
if (config.debugMode) console.log(`[${(Date.now() - config.startTime)/1000}] I: ${res}`);
main(fn, gpio);
});
fn.tests.vacuum(gpio).then(status => {
if (!status) {
fn.commands.shutdown(gpio);
}
})
// blowerOffDelay() returns true only if the blower shutdown has
// been initiated AND the specified cooldown time has passed
if(fn.tests.blowerOffDelay()) {
fn.power.blower.off(gpio).then(res => {
// Since the blower shutting off is the last step in the shutdown, we can quit.
fn.commands.quit();
});
}
}