Not really tested
This commit is contained in:
parent
178bc1e115
commit
f0687e4c2b
@ -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) {
|
||||
setPin(pin, state) {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`python3 src/python/gpio_interface.py set ${pin} ${state}`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
callback(error);
|
||||
reject(error);
|
||||
}
|
||||
if (stderr) {
|
||||
callback(new Error(stderr));
|
||||
reject(new Error(stderr));
|
||||
}
|
||||
callback(null);
|
||||
resolve();
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
@ -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':
|
||||
|
Loading…
Reference in New Issue
Block a user