Compare commits

...

1 Commits
main ... web

Author SHA1 Message Date
Skylar Grant f4985ac11d Commenting 2023-09-21 19:46:50 -04:00
1 changed files with 18 additions and 1 deletions

19
main.js
View File

@ -14,31 +14,47 @@ const fn = require('./functions.js').functions;
// Config File
const config = require('./config.json');
// Set the time we started execution, for time-aware logging
config.timestamps.procStart = Date.now();
// Environment Variables Importing
const dotenv = require('dotenv').config();
// 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') {
// TODO adjustable logging
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');
// Run the initialization function
fn.init(gpio).then((res) => {
// TODO: adjustable logging
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);
}).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}`);
});
} 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.`);
// Create a dummy gpio placeholder
const gpio = 'gpio';
// Run the initialization function, passing the fake GPIO module
fn.init(gpio).then(res => {
// TODO: Adj. logging
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);
}).catch(rej => {
// TODO: This probably should end the process since we can't continue if the initialization fails.
console.error(rej);
});
} 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.`);
}
@ -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.
// TODO move these from environment variables to a config file, if possible.
async function main(fn, gpio) {
// Check for the existence of certain files
fn.files.check().then((res,rej) => {