Maybe fixed polling?

This commit is contained in:
Skylar Grant 2024-08-18 14:11:32 -04:00
parent 38a110fa8f
commit 4d6e058afb
3 changed files with 49 additions and 46 deletions

View File

@ -1,40 +1,5 @@
const { exec } = require('child_process'); const { exec } = require('child_process');
const { pins } = require('./config.json');
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 sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
pins.forEach(pin => { pins.forEach(pin => {
@ -111,13 +76,6 @@ module.exports = {
}; };
}, },
async poll() { 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}]`);
});
}
}
} }
} }

View File

@ -15,5 +15,40 @@
"topic": "hestia/status/auger" "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"
}
]
} }

View File

@ -1,5 +1,15 @@
// Import modules // Import modules
const gpio = require('./custom_modules/VoidGPIO.js'); const gpio = require('./custom_modules/VoidGPIO.js');
const { pins } = require('./custom_modules/config.json');
gpio.debugInit(); gpio.debugInit();
// setInterval(gpio.poll, 1000); 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);