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
readPin(pin, callback) {
exec(`python3 src/python/gpio_interface.py read ${pin}`, (error, stdout, stderr) => {
if (error) callback(error);
if (stderr) callback(new Error(stderr));
callback(null, stdout.trim());
readPin(pin) {
return new Promise((resolve, reject) => {
exec(`python3 src/python/gpio_interface.py read ${pin}`, (error, stdout, stderr) => {
if (error) reject(error);
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

View File

@ -1,5 +1,6 @@
const dotenv = require('dotenv').config();
const debug = process.env.DEBUG === "TRUE";
const config = require('./config.json');
const { pins } = require('./config.json');
const gpio = require('./VoidGPIO.js');
const pinMap = new Map();
@ -71,25 +72,29 @@ module.exports = {
power: {
start: {
init() {
return new Promise((resolve, reject) => {
// Check pin states
return new Promise(async (resolve, reject) => {
// TODO: Check pin states?
// Set pins to default states
// T_DONE: Set pins to default states
module.exports.gpio.setDefaults().then(changes => {
module.exports.log(changes);
}).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
// Start auger
// Wait for fire