TODOs and documenting

This commit is contained in:
Skylar Grant 2022-11-26 20:56:04 -05:00
parent be54f6f769
commit 202472bfbb

10
main.js
View File

@ -1,8 +1,12 @@
// npm module for Raspberri Pi GPIO
var gpio = require('rpi-gpio'); var gpio = require('rpi-gpio');
// Module for importing environment variables
var dotenv = require('dotenv').config(); var dotenv = require('dotenv').config();
// Set up GPIO 4 (pysical pin 7) as output, then call cycleAuger()
gpio.setup(7, gpio.DIR_OUT, cycleAuger); gpio.setup(7, gpio.DIR_OUT, cycleAuger);
// Turns the auger on (Pin 7 high)
function augerOn(err) { function augerOn(err) {
if (err) throw err; if (err) throw err;
gpio.write(7, true, function(err) { gpio.write(7, true, function(err) {
@ -11,6 +15,7 @@ function augerOn(err) {
}); });
} }
// Turns the auger off (pin 7 low)
function augerOff(err) { function augerOff(err) {
if (err) throw err; if (err) throw err;
gpio.write(7, false, function(err) { gpio.write(7, false, function(err) {
@ -27,7 +32,8 @@ function augerOff(err) {
// function augerOn() { // function augerOn() {
// console.log('Auger turned on.'); // console.log('Auger turned on.');
// } // }
// Sleeps for any given milliseconds, call with await
function sleep(ms) { function sleep(ms) {
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout(resolve, ms); setTimeout(resolve, ms);
@ -35,8 +41,10 @@ function sleep(ms) {
}); });
} }
// Main function, turns the auger on, sleeps for the time given in environment variables, then turns the auger off, sleeps, repeats.
async function cycleAuger(err) { async function cycleAuger(err) {
if (err) throw err; if (err) throw err;
// TODO: Detect file 'pause', 'reload', 'quit'
augerOn(); augerOn();
await sleep(process.env.ONTIME); await sleep(process.env.ONTIME);
augerOff(); augerOff();