From 7a8b037e06af02f65656c13d407355aea1b0fb48 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 16 Dec 2022 22:30:12 -0500 Subject: [PATCH] i want to cry --- config.json | 3 +++ functions.js | 35 ++++++++++++++++++++++++++++++++++- main.js | 15 +++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/config.json b/config.json index 30074e9..4f2d67f 100644 --- a/config.json +++ b/config.json @@ -12,5 +12,8 @@ "blower": 0, "auger": 0, "seenFire": false + }, + "times": { + "blowerOff": 0 } } \ No newline at end of file diff --git a/functions.js b/functions.js index 864b467..8b6bbff 100644 --- a/functions.js +++ b/functions.js @@ -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: { diff --git a/main.js b/main.js index 7be6804..b3d2c1e 100644 --- a/main.js +++ b/main.js @@ -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(); + }); + } } \ No newline at end of file