From 42374d094d92ae9c0eb9e290a386d3ae19b2b5c8 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 1 Dec 2024 17:55:38 -0500 Subject: [PATCH] v2 MQTT Ready to test --- src/main.js | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/main.js b/src/main.js index 984fc36..c9f9012 100644 --- a/src/main.js +++ b/src/main.js @@ -81,22 +81,58 @@ process.psState.on('announcement', msg => { process.comlink.on('igniter', (message) => { fn.log(`ComLink: V2 Igniter: ${message}`, 'INFO'); - // TODO: Implement Igniter toggle + // Toggle the state + process.psState.igniter.on = !process.psState.igniter.on; + // Run the corresponding action + if (process.psState.igniter.on) { + fn.power.igniter.on().then(res => fn.log(res, 'DEBUG')) + .catch(error => fn.log(`ComLink: Igniter: ${error}`, 'ERROR')); + } else { + fn.power.igniter.off().then(res => fn.log(res, 'DEBUG')) + .catch(error => fn.log(`ComLink: Igniter: ${error}`, 'ERROR')); + } }); process.comlink.on('exhaust', (message) => { fn.log(`ComLink: V2 Exhaust: ${message}`, 'INFO'); - // TODO: Implement Exhaust toggle + // Toggle the state + process.psState.exhaust.on = !process.psState.exhaust.on; + // Run the corresponding action + if (process.psState.exhaust.on) { + fn.power.exhaust.on().then(res => fn.log(res, 'DEBUG')) + .catch(error => fn.log(`ComLink: Exhaust: ${error}`, 'ERROR')); + } else { + fn.power.exhaust.off().then(res => fn.log(res, 'DEBUG')) + .catch(error => fn.log(`ComLink: Exhaust: ${error}`, 'ERROR')); + } }); process.comlink.on('auger', (message) => { fn.log(`ComLink: V2 Auger: ${message}`, 'INFO'); - // TODO: Implement Auger toggle + // Toggle the state + process.psState.auger.on = !process.psState.auger.on; + // Nothing else to do since the auger loop always runs and checks the state + fn.log(`ComLink: Auger: ${process.psState.auger.on}`, 'INFO'); }); -process.comlink.on('feed-rate', (message) => { +process.comlink.on('feedRate', (message) => { fn.log(`ComLink: V2 Feed Rate: ${message}`, 'INFO'); - // TODO: Implement Feed Rate toggle + // Check if the message is a number hiding in a string + if (!isNaN(message)) { + // Convert the message to a number + const feedRate = parseInt(message); + // Check if the feed rate is within the acceptable range + if (feedRate >= 350 && feedRate <= 1000) { + // Update the feed rate + process.psState.auger.feedRate = feedRate; + // Send the feed rate to the MQTT broker + fn.log(`ComLink: Feed Rate: ${feedRate}`, 'INFO'); + } else { + fn.log(`ComLink: Invalid Feed Rate: ${message}`, 'ERROR'); + } + } else { + fn.log(`ComLink: Invalid Feed Rate: ${message}`, 'ERROR'); + } }); /***************************************************************************************/