Added more logic flow stuff.

This commit is contained in:
Skylar Grant 2024-08-20 18:54:34 -04:00
parent f0687e4c2b
commit 459008d372
2 changed files with 23 additions and 16 deletions

View File

@ -14,11 +14,13 @@ module.exports = {
}); });
}, },
// Calls the GPIO Interface script to read a pin's state // Calls the GPIO Interface script to read a pin's state
readPin(pin, callback) { readPin(pin) {
exec(`python3 src/python/gpio_interface.py read ${pin}`, (error, stdout, stderr) => { return new Promise((resolve, reject) => {
if (error) callback(error); exec(`python3 src/python/gpio_interface.py read ${pin}`, (error, stdout, stderr) => {
if (stderr) callback(new Error(stderr)); if (error) reject(error);
callback(null, stdout.trim()); if (stderr) reject(new Error(stderr));
resolve(stdout.trim());
});
}); });
}, },
// Calls the GPIO Interface script to set a pin's state regardless of its current state // Calls the GPIO Interface script to set a pin's state regardless of its current state

View File

@ -1,5 +1,6 @@
const dotenv = require('dotenv').config(); const dotenv = require('dotenv').config();
const debug = process.env.DEBUG === "TRUE"; const debug = process.env.DEBUG === "TRUE";
const config = require('./config.json');
const { pins } = require('./config.json'); const { pins } = require('./config.json');
const gpio = require('./VoidGPIO.js'); const gpio = require('./VoidGPIO.js');
const pinMap = new Map(); const pinMap = new Map();
@ -71,25 +72,29 @@ module.exports = {
power: { power: {
start: { start: {
init() { init() {
return new Promise((resolve, reject) => { return new Promise(async (resolve, reject) => {
// Check pin states // TODO: Check pin states?
// Set pins to default states // T_DONE: Set pins to default states
module.exports.gpio.setDefaults().then(changes => { module.exports.gpio.setDefaults().then(changes => {
module.exports.log(changes); module.exports.log(changes);
}).catch(e => console.error(e)); }).catch(e => console.error(e));
// Power on igniter
gpio.setPin(pinMap.igniter.board, 1, (err) => {
if (err) reject(err);
})
// Wait for igniter preheat
// Start exhaust
// Finish igniter preheat // T_DONE: Power on igniter
gpio.setPin(pinMap.igniter.board, 1).then(async () => {
// T_DONE: Wait for igniter preheat
await module.exports.sleep(config.power.start.exhaustDelay);
}).catch(e => console.error(e));
// T_DONE: Start exhaust
gpio.setPin(pinMap.exhaust.board, 1).then(async () => {
// T_DONE: Finish igniter preheat
await module.exports.sleep(config.power.start.augerDelay);
}).catch(e => console.error(e));
// Check for vacuum // Check for vacuum
// Start auger // Start auger
// Wait for fire // Wait for fire