From 4d6e058afb4af6e8230bc2750247964b92a89ac0 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 18 Aug 2024 14:11:32 -0400 Subject: [PATCH] Maybe fixed polling? --- src/custom_modules/VoidGPIO.js | 46 ++-------------------------------- src/custom_modules/config.json | 37 ++++++++++++++++++++++++++- src/main.js | 12 ++++++++- 3 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/custom_modules/VoidGPIO.js b/src/custom_modules/VoidGPIO.js index 3c4a8be..e01cbb1 100644 --- a/src/custom_modules/VoidGPIO.js +++ b/src/custom_modules/VoidGPIO.js @@ -1,40 +1,5 @@ const { exec } = require('child_process'); - -const pins = [ - { - key: 'igniter', - board: 13, - bcm: 27, - mode: 'OUT', - defaultState: 0 - }, - { - key: 'exhaust', - board: 15, - bcm: 22, - mode: 'OUT', - defaultState: 1 - }, - { - key: 'auger', - board: 7, - bcm: 4, - mode: 'OUT', - defaultState: 0 - }, - { - key: 'pof', - board: 16, - bcm: 23, - mode: 'IN' - }, - { - key: 'vacuum', - board: 22, - bcm: 25, - mode: 'IN' } -]; - +const { pins } = require('./config.json'); const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); pins.forEach(pin => { @@ -111,13 +76,6 @@ module.exports = { }; }, async poll() { - for (const pin of pins) { - if (pin.mode === 'IN') { - this.readPin(pin.board, (err, state) => { - if (err) throw err; - console.log(`${pin.key}: ${state} [def: ${pin.defaultState}]`); - }); - } - } + } } \ No newline at end of file diff --git a/src/custom_modules/config.json b/src/custom_modules/config.json index 129060e..b60525b 100644 --- a/src/custom_modules/config.json +++ b/src/custom_modules/config.json @@ -15,5 +15,40 @@ "topic": "hestia/status/auger" } ] - } + }, + "pins": [ + { + "key": "igniter", + "board": 13, + "bcm": 27, + "mode": "OUT", + "defaultState": 0 + }, + { + "key": "exhaust", + "board": 15, + "bcm": 22, + "mode": "OUT", + "defaultState": 1 + }, + { + "key": "auger", + "board": 7, + "bcm": 4, + "mode": "OUT", + "defaultState": 0 + }, + { + "key": "pof", + "board": 16, + "bcm": 23, + "mode": "IN" + }, + { + "key": "vacuum", + "board": 22, + "bcm": 25, + "mode": "IN" + } + ] } \ No newline at end of file diff --git a/src/main.js b/src/main.js index b80637b..eee611c 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,15 @@ // Import modules const gpio = require('./custom_modules/VoidGPIO.js'); +const { pins } = require('./custom_modules/config.json'); gpio.debugInit(); -// setInterval(gpio.poll, 1000); \ No newline at end of file +setInterval(() => { + for (const pin of pins) { + if (pin.mode === 'IN') { + gpio.readPin(pin.board, (err, state) => { + if (err) throw err; + console.log(`${pin.key}: ${state} [def: ${pin.defaultState}]`); + }); + } + } +}, 1000); \ No newline at end of file