From 2a756065e726b7a904d67285a59e0537500c297a Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 2 Sep 2024 13:16:21 -0400 Subject: [PATCH] Try new startup init --- src/custom_modules/config.json | 6 +-- src/custom_modules/functions.js | 95 +++++++++++++++++++-------------- 2 files changed, 58 insertions(+), 43 deletions(-) diff --git a/src/custom_modules/config.json b/src/custom_modules/config.json index 58e42c9..9aa2ef5 100644 --- a/src/custom_modules/config.json +++ b/src/custom_modules/config.json @@ -61,9 +61,9 @@ ], "power": { "start": { - "exhaustDelay": 30000, - "augerDelay": 60000, - "fireCheckDelay": 420000 + "exhaustDelay": 5000, + "igniterPreheat": 60000, + "igniterDelay": 420000 }, "stop": { "exhaustDelay": 600000 diff --git a/src/custom_modules/functions.js b/src/custom_modules/functions.js index a0ef260..1713f62 100644 --- a/src/custom_modules/functions.js +++ b/src/custom_modules/functions.js @@ -63,53 +63,68 @@ module.exports = { module.exports.log(changes); }).catch(e => console.error(e)); - // Power on igniter - gpio.setPin(process.pinMap.get('igniter').board, 1).then(async () => { - // Wait for igniter preheat - await module.exports.sleep(config.power.start.exhaustDelay); + // Start the exhaust + this.exhaust().then(() => { + // Check for vacuum + this.vacuum().then(() => { + // Start the auger + this.auger().then(() => { + resolve('Startup sequence complete.'); + }).catch(e => console.error(e)); + // Preheat the igniter + this.igniter().then(() => { + module.exports.sleep(config.power.start.igniterDelay).then(() => { + // Check for fire + this.fire().then(() => { + }).catch(e => console.error(e)); + }); + }).catch(e => console.error(e)); + }).catch(e => console.error(e)); }).catch(e => console.error(e)); - + }); + }, + exhaust() { + return new Promise(async (resolve, reject) => { // Start exhaust - gpio.setPin(process.pinMap.get('exhaust').board, 1).then(async () => { - // Finish igniter preheat - await module.exports.sleep(config.power.start.augerDelay); + gpio.setPin(process.pinMap.get('exhaust').board, 1).then(() => { + // Wait to resolve + module.exports.sleep(config.power.start.exhaustDelay).then(() => { + resolve('Exhaust started.'); + } }).catch(e => console.error(e)); - + }); + }, + vacuum() { + return new Promise(async (resolve, reject) => { // Check for vacuum gpio.readPin(process.pinMap.get('vacuum').board).then(state => { if (state === '0') { - // Power off exhaust - gpio.setPin(process.pinMap.get('exhaust').board, 0).then(() => { - // Report vacuum failure - reject(new Error('Vacuum failure.')); - return; - }).catch(e => console.error(e)); + reject(new Error('Vacuum failure.')); } else { - // Start auger - gpio.setPin(process.pinMap.get('auger').board, 1).then(async () => { - // Wait for fire - await module.exports.sleep(config.power.start.fireCheckDelay); - - // Power off igniter - gpio.setPin(process.pinMap.get('igniter').board, 0).then(() => { - // Check for fire on pof - gpio.readPin(process.pinMap.get('pof').board).then(state => { - if (state === '0') { - // Power off auger - gpio.setPin(process.pinMap.get('auger').board, 0).then(() => { - // Report failed ignition - reject(new Error('Failed ignition.')); - }).catch(e => console.error(e)); - } else { - // Power off auger - gpio.setPin(process.pinMap.get('auger').board, 0).then(() => { - // Report successful ignition - resolve('Successful ignition.'); - }).catch(e => console.error(e)); - } - }).catch(e => console.error(e)); - }).catch(e => console.error(e)); - }).catch(e => console.error(e)); + resolve('Vacuum established.'); + } + }).catch(e => console.error(e)); + }); + }, + igniter() { + return new Promise(async (resolve, reject) => { + // Start igniter + gpio.setPin(process.pinMap.get('igniter').board, 1).then(() => { + // Wait to resolve + module.exports.sleep(config.power.start.igniterPreheat).then(() => { + resolve('Igniter preheated.'); + }); + }).catch(e => console.error(e)); + }); + }, + fire() { + return new Promise(async (resolve, reject) => { + // Check for fire + gpio.readPin(process.pinMap.get('pof').board).then(state => { + if (state === '0') { + reject(new Error('Failed ignition.')); + } else { + resolve('Successful ignition.'); } }).catch(e => console.error(e)); });