Better logging, and resolving of promises

This commit is contained in:
Skylar Grant 2022-12-03 20:22:43 -05:00
parent 973816757e
commit 2444cbde4d
2 changed files with 14 additions and 10 deletions

View File

@ -19,7 +19,7 @@ const functions = {
if (process.env.ONPI == 'true') { if (process.env.ONPI == 'true') {
gpio.write(7, true, function(err) { gpio.write(7, true, function(err) {
if (err) throw err; if (err) throw err;
if (process.env.DEBUG == "true") console.log('Auger turned on.'); resolve('Auger turned on.');
}); });
} else { } else {
console.log('NOPI Auger turned on.'); console.log('NOPI Auger turned on.');
@ -34,7 +34,8 @@ const functions = {
if (process.env.ONPI == 'true') { if (process.env.ONPI == 'true') {
gpio.write(7, false, function(err) { gpio.write(7, false, function(err) {
if (err) throw err; if (err) throw err;
if (process.env.DEBUG == "true") console.log('Auger turned off.'); resolve('Auger turned on.');
}); });
} else { } else {
console.log('NOPI Auger turned off.'); console.log('NOPI Auger turned off.');
@ -47,10 +48,14 @@ const functions = {
// Sleeps in between cycles using functions.sleep() // Sleeps in between cycles using functions.sleep()
cycle(gpio) { cycle(gpio) {
return new Promise((resolve) => { return new Promise((resolve) => {
this.on(gpio).then(() => { this.on(gpio).then((res) => {
functions.sleep(process.env.ONTIME).then(() => { if (process.env.DEBUG == 'true') console.log(res);
this.off(gpio).then(() => { functions.sleep(process.env.ONTIME).then((res) => {
functions.sleep(process.env.OFFTIME).then(() => { if (process.env.DEBUG == 'true') console.log(res);
this.off(gpio).then((res) => {
if (process.env.DEBUG == 'true') console.log(res);
functions.sleep(process.env.OFFTIME).then((res) => {
if (process.env.DEBUG == 'true') console.log(res);
resolve("Cycle complete."); resolve("Cycle complete.");
}); });
}); });
@ -114,11 +119,9 @@ const functions = {
return new Promise((resolve) => { return new Promise((resolve) => {
if (process.env.DEBUG == "true") console.log(`Sleeping for ${ms}ms`); if (process.env.DEBUG == "true") console.log(`Sleeping for ${ms}ms`);
const finish = () => { const finish = () => {
if (process.env.DEBUG == "true") console.log(`Slept for ${ms}ms`); resolve(`Slept for ${ms}ms`);
resolve();
} }
setTimeout(finish, ms); setTimeout(finish, ms);
}); });
}, },
init(gpio) { init(gpio) {

View File

@ -54,7 +54,8 @@ async function main(fn, gpio) {
fn.commands.quit(); fn.commands.quit();
break; break;
case "none": case "none":
fn.auger.cycle(gpio).then(() => { fn.auger.cycle(gpio).then((res) => {
if (process.env.DEBUG == 'true') console.log(res);
main(fn); main(fn);
}); });
break; break;