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

View File

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