Commenting

This commit is contained in:
Skylar Grant 2023-09-21 19:46:50 -04:00
parent f66f705e58
commit f4985ac11d

19
main.js
View File

@ -14,31 +14,47 @@ const fn = require('./functions.js').functions;
// Config File // Config File
const config = require('./config.json'); const config = require('./config.json');
// Set the time we started execution, for time-aware logging
config.timestamps.procStart = Date.now(); config.timestamps.procStart = Date.now();
// Environment Variables Importing // Environment Variables Importing
const dotenv = require('dotenv').config(); const dotenv = require('dotenv').config();
// Setup for use with the Pi's GPIO pins // Setup for use with the Pi's GPIO pins
// TODO: ONPI should be DEV_ENV or DEBUG
// Include something like LOGGING = "DEBUG"|"PRODUCTION"|"ETC"
if (process.env.ONPI == 'true') { if (process.env.ONPI == 'true') {
// TODO adjustable logging
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] == Running on a Raspberry Pi.`); console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] == Running on a Raspberry Pi.`);
// Import the Node Raspberry Pi GPIO module
const gpio = require('rpi-gpio'); const gpio = require('rpi-gpio');
// Run the initialization function
fn.init(gpio).then((res) => { fn.init(gpio).then((res) => {
// TODO: adjustable logging
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`);
// Invoke the first cycle of main, passing along the Functions module and GPIO module
main(fn, gpio); main(fn, gpio);
}).catch(rej => { }).catch(rej => {
// TODO: This probably should end the process since we can't continue if the initialization fails
console.error(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${rej}`); console.error(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${rej}`);
}); });
} else if (process.env.ONPI == 'false') { } else if (process.env.ONPI == 'false') { // TODO ONPI change to DEV_ENV
// TODO: adjustable logging
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Not running on a Raspberry Pi.`); console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Not running on a Raspberry Pi.`);
// Create a dummy gpio placeholder
const gpio = 'gpio'; const gpio = 'gpio';
// Run the initialization function, passing the fake GPIO module
fn.init(gpio).then(res => { fn.init(gpio).then(res => {
// TODO: Adj. logging
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`);
// Invoke the first cycle of the main function, passing the Functions module and fake GPIO module
main(fn, gpio); main(fn, gpio);
}).catch(rej => { }).catch(rej => {
// TODO: This probably should end the process since we can't continue if the initialization fails.
console.error(rej); console.error(rej);
}); });
} else { } else {
// TODO: This probably should end the process since we can't continue if the initialization fails.
console.error(`[${Date.now() - config.timestamps.procStart}] E: Problem with ENV file.`); console.error(`[${Date.now() - config.timestamps.procStart}] E: Problem with ENV file.`);
} }
@ -47,6 +63,7 @@ if (process.env.ONPI == 'true') {
// Main function, turns the auger on, sleeps for the time given in environment variables, then turns the auger off, sleeps, repeats. // Main function, turns the auger on, sleeps for the time given in environment variables, then turns the auger off, sleeps, repeats.
// TODO move these from environment variables to a config file, if possible.
async function main(fn, gpio) { async function main(fn, gpio) {
// Check for the existence of certain files // Check for the existence of certain files
fn.files.check().then((res,rej) => { fn.files.check().then((res,rej) => {