stash the pinmap in the process

This commit is contained in:
Skylar Grant 2024-08-23 21:17:04 -04:00
parent a0a0804754
commit ae4f3c7507

View File

@ -3,10 +3,10 @@ const debug = process.env.DEBUG === "TRUE";
const config = require('./config.json'); const config = require('./config.json');
const { pins } = config; const { pins } = config;
const gpio = require('./VoidGPIO.js'); const gpio = require('./VoidGPIO.js');
const pinMap = new Map(); process.pinMap = new Map();
for (const pin of pins) { for (const pin of pins) {
pinMap.set(pin.key, pin); process.pinMap.set(pin.key, pin);
} }
module.exports = { module.exports = {
@ -64,45 +64,45 @@ module.exports = {
}).catch(e => console.error(e)); }).catch(e => console.error(e));
// Power on igniter // Power on igniter
gpio.setPin(pinMap.igniter.board, 1).then(async () => { gpio.setPin(process.pinMap.igniter.board, 1).then(async () => {
// Wait for igniter preheat // Wait for igniter preheat
await module.exports.sleep(config.power.start.exhaustDelay); await module.exports.sleep(config.power.start.exhaustDelay);
}).catch(e => console.error(e)); }).catch(e => console.error(e));
// Start exhaust // Start exhaust
gpio.setPin(pinMap.exhaust.board, 1).then(async () => { gpio.setPin(process.pinMap.exhaust.board, 1).then(async () => {
// Finish igniter preheat // Finish igniter preheat
await module.exports.sleep(config.power.start.augerDelay); await module.exports.sleep(config.power.start.augerDelay);
}).catch(e => console.error(e)); }).catch(e => console.error(e));
// Check for vacuum // Check for vacuum
gpio.readPin(pinMap.vacuum.board).then(state => { gpio.readPin(process.pinMap.vacuum.board).then(state => {
if (state === '0') { if (state === '0') {
// Power off exhaust // Power off exhaust
gpio.setPin(pinMap.exhaust.board, 0).then(() => { gpio.setPin(process.pinMap.exhaust.board, 0).then(() => {
// Report vacuum failure // Report vacuum failure
reject(new Error('Vacuum failure.')); reject(new Error('Vacuum failure.'));
return; return;
}).catch(e => console.error(e)); }).catch(e => console.error(e));
} else { } else {
// Start auger // Start auger
gpio.setPin(pinMap.auger.board, 1).then(async () => { gpio.setPin(process.pinMap.auger.board, 1).then(async () => {
// Wait for fire // Wait for fire
await module.exports.sleep(config.power.start.fireCheckDelay); await module.exports.sleep(config.power.start.fireCheckDelay);
// Power off igniter // Power off igniter
gpio.setPin(pinMap.igniter.board, 0).then(() => { gpio.setPin(process.pinMap.igniter.board, 0).then(() => {
// Check for fire on pof // Check for fire on pof
gpio.readPin(pinMap.pof.board).then(state => { gpio.readPin(process.pinMap.pof.board).then(state => {
if (state === '0') { if (state === '0') {
// Power off auger // Power off auger
gpio.setPin(pinMap.auger.board, 0).then(() => { gpio.setPin(process.pinMap.auger.board, 0).then(() => {
// Report failed ignition // Report failed ignition
reject(new Error('Failed ignition.')); reject(new Error('Failed ignition.'));
}).catch(e => console.error(e)); }).catch(e => console.error(e));
} else { } else {
// Power off auger // Power off auger
gpio.setPin(pinMap.auger.board, 0).then(() => { gpio.setPin(process.pinMap.auger.board, 0).then(() => {
// Report successful ignition // Report successful ignition
resolve('Successful ignition.'); resolve('Successful ignition.');
}).catch(e => console.error(e)); }).catch(e => console.error(e));
@ -119,11 +119,11 @@ module.exports = {
init() { init() {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
// Power off auger // Power off auger
gpio.setPin(pinMap.auger.board, 0).then(async () => { gpio.setPin(process.pinMap.auger.board, 0).then(async () => {
// Wait for exhaust shutdown delay // Wait for exhaust shutdown delay
await module.exports.sleep(config.power.stop.exhaustDelay); await module.exports.sleep(config.power.stop.exhaustDelay);
// Power off exhaust // Power off exhaust
gpio.setPin(pinMap.exhaust.board, 0).then(() => { gpio.setPin(process.pinMap.exhaust.board, 0).then(() => {
// Report successful shutdown // Report successful shutdown
resolve('Successful shutdown.'); resolve('Successful shutdown.');
}).catch(e => console.error(e)); }).catch(e => console.error(e));