Semi fixed...

This commit is contained in:
Skylar Grant 2024-08-18 14:34:23 -04:00
parent 1eb1dc8270
commit 768e9faae5
2 changed files with 11 additions and 7 deletions

View File

@ -11,5 +11,8 @@
"url": "https://git.vfsh.dev/voidf1sh/hestia" "url": "https://git.vfsh.dev/voidf1sh/hestia"
}, },
"author": "Skylar Grant", "author": "Skylar Grant",
"license": "MIT" "license": "MIT",
"dependencies": {
"dotenv": "^16.4.5"
}
} }

View File

@ -1,5 +1,6 @@
const dotenv = require('dotenv').config(); const dotenv = require('dotenv').config();
const debug = process.env.DEBUG === "TRUE"; const debug = process.env.DEBUG === "TRUE";
const { pins } = require('./config.json');
module.exports = { module.exports = {
log(message) { log(message) {
@ -10,12 +11,12 @@ module.exports = {
gpio: { gpio: {
// Boot up sanity check during debug mode // Boot up sanity check during debug mode
async debugInit() { async debugInit() {
exports.log('Resetting all output pins.'); module.exports.log('Resetting all output pins.');
pins.forEach(async (pin) => { pins.forEach(async (pin) => {
if (pin.mode === 'OUT') { if (pin.mode === 'OUT') {
this.setPin(pin.board, pin.defaultState, err => { this.setPin(pin.board, pin.defaultState, err => {
if (err) throw err; if (err) throw err;
exports.log(`Set ${pin.key} pin to ${pin.defaultState}.`); module.exports.log(`Set ${pin.key} pin to ${pin.defaultState}.`);
}); });
}; };
}); });
@ -24,19 +25,19 @@ module.exports = {
case 'OUT': case 'OUT':
this.togglePin(pin.board, err => { this.togglePin(pin.board, err => {
if (err) throw err; if (err) throw err;
exports.log(`Toggled ${pin.key}`); module.exports.log(`Toggled ${pin.key}`);
}); });
// Wait 1000ms before toggling again. // Wait 1000ms before toggling again.
await sleep(1000); await sleep(1000);
this.togglePin(pin.board, err => { this.togglePin(pin.board, err => {
if (err) throw err; if (err) throw err;
exports.log(`Toggled ${pin.key}`); module.exports.log(`Toggled ${pin.key}`);
}); });
break; break;
case 'IN': case 'IN':
this.readPin(pin.board, (err, state) => { this.readPin(pin.board, (err, state) => {
if (err) throw err; if (err) throw err;
exports.log(`${pin.key} state: ${state}`); module.exports.log(`${pin.key} state: ${state}`);
}); });
default: default:
break; break;
@ -44,4 +45,4 @@ module.exports = {
}; };
} }
} }
} }