Not really tested

This commit is contained in:
Skylar Grant 2024-08-19 20:56:39 -04:00
parent 178bc1e115
commit f0687e4c2b
2 changed files with 25 additions and 27 deletions

View File

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

View File

@ -21,32 +21,28 @@ module.exports = {
setDefaults() {
return new Promise((resolve, reject) => {
let stateChanges = [];
for (const pin of pins) {
const promises = pins.map(pin => {
if (pin.mode === 'OUT') {
gpio.setPin(pin.board, pin.defaultState, (err) => {
if (err) reject(err);
stateChanges.push( `Set ${pin.key} pin to ${pin.defaultState}.`);
})
return gpio.setPin(pin.board, pin.defaultState).then(() => {
stateChanges.push(`Set ${pin.key} pin to ${pin.defaultState}.`);
}).catch(e => console.error(e));
}
}
resolve(stateChanges.join('\n'));
});
Promise.all(promises).then(() => {
const changes = stateChanges.join('\n');
resolve(changes);
}).catch(reject);
});
},
// Boot up sanity check during debug mode
debugInit() {
async debugInit() {
module.exports.log('Resetting all output pins.');
module.exports.gpio.setDefaults().then(changes => {
module.exports.gpio.setDefaults().then((changes) => {
module.exports.log(changes);
}).catch(e => console.error(e));
pins.forEach(pin => {
if (pin.mode === 'OUT') {
gpio.setPin(pin.board, pin.defaultState, err => {
if (err) throw err;
module.exports.log();
});
};
});
for (const pin of pins) {
switch (pin.mode) {
case 'OUT':