From f596ea1bdae98fe57048768d2ea48004a0321268 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 18 Aug 2024 13:14:28 -0400 Subject: [PATCH] 3 --- src/custom_modules/VoidGPIO.js | 102 ++++++++++++++++----------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/custom_modules/VoidGPIO.js b/src/custom_modules/VoidGPIO.js index b4452b6..b14311b 100644 --- a/src/custom_modules/VoidGPIO.js +++ b/src/custom_modules/VoidGPIO.js @@ -13,55 +13,55 @@ pins.forEach(pin => { }); -// Function to toggle a pin on-then-off -export function togglePin(pin, callback) { - exec(`python3 src/python/gpio_interface.py toggle ${pin}`, (error, stdout, stderr) => { - if (error) { - return callback(error); - } - if (stderr) { - return callback(new Error(stderr)); - } - console.log(`Successfully toggled pin ${pin}`); - }); -} - -// Function to sense a pin state -export function sensePin(pin, callback) { - exec(`python3 src/python/gpio_interface.py sense ${pin}`, (error, stdout, stderr) => { - if (error) { - console.error(`Error sensing pin ${pin}: ${error.message}`); - return callback(error); - } - if (stderr) { - console.error(`Stderr while sensing pin ${pin}: ${stderr}`); - return callback(new Error(stderr)); - } - console.log(`Pin ${pin} state: ${stdout.trim()}`); - callback(stdout.trim(), null); - }); -} - -// Toggle pins sequentially and then sense pin states -export function debugInit() { - pins.forEach(async (pin) => { - switch (pin.mode) { - case 'OUT': - togglePin(pin.board, err => { - if (err) throw err; - }); - // Wait 1000ms before toggling again. - setTimeout(togglePin(pin.board, err => { - if (err) throw err; - }), 1000); - break; - case 'IN': - sensePin(pin.board, (state, err) => { - if (err) throw err; - console.log(`${pin.key} state: ${state}`); - }); - default: - break; - } - }); +module.exports = { + // Function to toggle a pin on-then-off + togglePin(pin, callback) { + exec(`python3 src/python/gpio_interface.py toggle ${pin}`, (error, stdout, stderr) => { + if (error) { + return callback(error); + } + if (stderr) { + return callback(new Error(stderr)); + } + console.log(`Successfully toggled pin ${pin}`); + }); + }. + // Function to sense a pin state + sensePin(pin, callback) { + exec(`python3 src/python/gpio_interface.py sense ${pin}`, (error, stdout, stderr) => { + if (error) { + console.error(`Error sensing pin ${pin}: ${error.message}`); + return callback(error); + } + if (stderr) { + console.error(`Stderr while sensing pin ${pin}: ${stderr}`); + return callback(new Error(stderr)); + } + console.log(`Pin ${pin} state: ${stdout.trim()}`); + callback(stdout.trim(), null); + }); + }, + // Toggle pins sequentially and then sense pin states + debugInit() { + pins.forEach(async (pin) => { + switch (pin.mode) { + case 'OUT': + togglePin(pin.board, err => { + if (err) throw err; + }); + // Wait 1000ms before toggling again. + setTimeout(togglePin(pin.board, err => { + if (err) throw err; + }), 1000); + break; + case 'IN': + sensePin(pin.board, (state, err) => { + if (err) throw err; + console.log(`${pin.key} state: ${state}`); + }); + default: + break; + } + }); + } } \ No newline at end of file