diff --git a/src/_EMR/main.js b/src/_EMR/main.js index 1b485f4..1e345e7 100644 --- a/src/_EMR/main.js +++ b/src/_EMR/main.js @@ -2,32 +2,30 @@ const gpio = require('../custom_modules/VoidGPIO.js'); const config = require('../custom_modules/config.json'); const fn = require('../custom_modules/functions.js'); -const { State } = require('../custom_modules/HestiaClasses.js'); // Variables process.pinMap = new Map(); -fn.log('Initializing pinMap'); +fn.log('Initializing pinMap', 'DEBUG'); for (const pin of config.pins) { process.pinMap.set(pin.key, pin); } -// Initialize state -fn.log('Initializing state'); -process.psState = new State(config); - // Auger Loop -fn.log('Starting auger loop'); -setInterval(fn.routines.cycleAuger, 2000); +fn.log('Starting auger loop', 'DEBUG'); +setInterval(() => { + fn.log('Running auger', 'DEBUG'); + gpio.setPin(process.pinMap.get('auger').board, 1); + setTimeout(() => { + gpio.setPin(process.pinMap.get('auger').board, 0); + }, process.env.AUGER_CYCLE_TIME || 500); +}, 2000); -fn.log('Setting exhaust to low to keep NC relay closed and fan running'); +fn.log('Setting exhaust to low to keep NC relay closed and fan running', 'DEBUG'); gpio.setPin(process.pinMap.get('exhaust').board, 0); -fn.log('Enabling auger'); -process.psState.auger.on = true; - process.on('SIGINT', () => { - fn.log(`Exiting gracefully...`); + fn.log(`Exiting gracefully...`, 'INFO'); gpio.setPin(process.pinMap.get('auger').board, 0); process.exit(); }); \ No newline at end of file diff --git a/src/custom_modules/functions.js b/src/custom_modules/functions.js index 8224856..4799178 100644 --- a/src/custom_modules/functions.js +++ b/src/custom_modules/functions.js @@ -10,9 +10,24 @@ for (const pin of pins) { } module.exports = { - log(message) { - if (debug) { - console.log(message); + log(message, level) { + if (level) { + switch (level) { + case 'INFO': + console.log(`INFO: ${message}`); + break; + case 'DEBUG': + if (debug) { + console.log(`DEBUG: ${message}`); + } + break; + default: + break; + } + } else { + if (debug) { + console.log(`DEBUG: ${message}`); + } } }, sleep(ms) {