2022-12-03 23:10:31 +00:00
|
|
|
// Custom functions module to keep main script clean
|
2022-12-04 00:42:47 +00:00
|
|
|
const fn = require('./functions.js').functions;
|
2022-11-27 01:50:20 +00:00
|
|
|
|
2022-12-03 23:10:31 +00:00
|
|
|
// Environment Variables Importing
|
|
|
|
const dotenv = require('dotenv').config();
|
|
|
|
|
2022-12-04 00:55:47 +00:00
|
|
|
// Setup for use with the Pi's GPIO pins
|
|
|
|
if (process.env.ONPI == 'true') {
|
|
|
|
console.log('Running on a Raspberry Pi.');
|
|
|
|
const gpio = require('rpi-gpio');
|
|
|
|
fn.init(gpio).then((res, rej) => {
|
|
|
|
if (res != undefined) {
|
|
|
|
console.log(res);
|
|
|
|
main(fn, gpio);
|
|
|
|
} else {
|
|
|
|
console.error(rej);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (process.env.ONPI == 'false') {
|
|
|
|
console.log('Not running on a Raspberry Pi.');
|
|
|
|
const gpio = 'gpio';
|
|
|
|
fn.init(gpio).then((res, rej) => {
|
|
|
|
if (res != undefined) {
|
|
|
|
console.log(res);
|
|
|
|
main(fn, gpio);
|
|
|
|
} else {
|
|
|
|
console.error(rej);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log('Problem with ENV file.');
|
|
|
|
}
|
|
|
|
|
2022-11-27 03:14:18 +00:00
|
|
|
// TODO Add logic for other sensors
|
|
|
|
|
2022-12-04 00:55:47 +00:00
|
|
|
|
2022-11-27 00:33:33 +00:00
|
|
|
|
2022-11-27 01:56:04 +00:00
|
|
|
// Main function, turns the auger on, sleeps for the time given in environment variables, then turns the auger off, sleeps, repeats.
|
2022-12-04 00:55:47 +00:00
|
|
|
async function main(fn, gpio) {
|
2022-12-04 00:42:47 +00:00
|
|
|
fn.files.check().then((res,rej) => {
|
|
|
|
console.log('File Check: ' + res);
|
|
|
|
switch (res) {
|
|
|
|
case "pause":
|
|
|
|
fn.commands.pause().then(() => {
|
|
|
|
main(fn);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "reload":
|
|
|
|
fn.commands.reload().then(() => {
|
|
|
|
main(fn);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "quit":
|
|
|
|
fn.commands.quit();
|
|
|
|
break;
|
|
|
|
case "none":
|
2022-12-04 00:55:47 +00:00
|
|
|
fn.auger.cycle(gpio).then(() => {
|
2022-12-04 00:42:47 +00:00
|
|
|
main(fn);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
main(fn);
|
2022-12-03 23:03:57 +00:00
|
|
|
break;
|
2022-12-04 00:42:47 +00:00
|
|
|
}
|
|
|
|
});
|
2022-11-27 00:49:07 +00:00
|
|
|
}
|