Mostly working I think

This commit is contained in:
Skylar Grant 2024-11-30 17:24:50 -05:00
parent 5e20cfff6e
commit de2e9e00ec

View File

@ -102,22 +102,21 @@ module.exports = {
}, },
cycleAuger() { cycleAuger() {
const mod = module.exports; const mod = module.exports;
return new Promise(async (resolve, reject) => {
// Check if the auger is enabled // Check if the auger is enabled
if (process.psState.auger.on) { if (process.psState.auger.on) {
mod.power.auger.on().then((res) => { mod.power.auger.on().then((res) => {
// Sleep while auger is feeding // Sleep while auger is feeding
mod.log(`Auger feeding at ${process.psState.auger.feedRate}ms.`, 'DEBUG');
mod.sleep(process.psState.auger.feedRate).then(() => { mod.sleep(process.psState.auger.feedRate).then(() => {
// Turn off auger // Turn off auger
mod.power.auger.off().then((res) => { mod.power.auger.off().then((res) => {
resolve('Auger cycle complete.'); mod.log('Auger cycle complete.', 'DEBUG');
}).catch(e => reject(e)); }).catch(e => reject(e));
}); });
}).catch(e => reject(e)); }).catch(e => reject(e));
} else { } else {
resolve('Auger is disabled.'); mod.log('Auger is disabled.', 'DEBUG');
} }
});
} }
}, },
power: { power: {
@ -282,27 +281,48 @@ module.exports = {
if (oldState[pin.key].on !== state[pin.key].on) { if (oldState[pin.key].on !== state[pin.key].on) {
// Did it turn on or off? // Did it turn on or off?
if (state[pin.key].on) { if (state[pin.key].on) {
if (pin.key !== 'auger') { switch (pin.key) {
// Set the corresponding pin to the new state case 'exhaust':
return gpio.setPin(pin.board, 1).then(() => { module.exports.log('Exhaust powered on.', 'DEBUG');
console.log(`State Change Handler: ${pin.key} powered on.`); return module.exports.power.exhaust.on();
}).catch(e => console.error(`GPIO Set Pin: ${e}`)); case 'igniter':
module.exports.log('Igniter powered on.', 'DEBUG');
return module.exports.power.igniter.on();
case 'auger':
module.exports.log('Auger powered on.', 'DEBUG');
return module.exports.handlers.toggleAuger();
default:
module.exports.log('Invalid pin key.', 'ERROR');
throw new Error('Invalid pin key.');
} }
} else { } else {
if (pin.key !== 'auger') { switch (pin.key) {
// Set the corresponding pin to the new state case 'exhaust':
return gpio.setPin(pin.board, 0).then(() => { module.exports.log('Exhaust powered off.', 'DEBUG');
console.log(`State Change Handler: ${pin.key} powered off.`); return module.exports.power.exhaust.off();
}).catch(e => console.error(`GPIO Set Pin: ${e}`)); case 'igniter':
module.exports.log('Igniter powered off.', 'DEBUG');
return module.exports.power.igniter.off();
case 'auger':
module.exports.log('Auger powered off.', 'DEBUG');
return module.exports.handlers.toggleAuger();
default:
module.exports.log('Invalid pin key.', 'ERROR');
throw new Error('Invalid pin key.');
} }
} }
} }
}); });
// Wait for all promises to resolve // Wait for all promises to resolve
Promise.all(promises).then(() => { Promise.all(promises).catch(e => console.error(e));
console.log('State change complete.'); },
}).catch(e => console.error(e)); toggleAuger() {
return new Promise(async (resolve, reject) => {
// This is so stupid but I wanted to use promises.all so here we are (:
resolve();
});
} }
} }
} }