From 5d0bf488544dc430b425d9f4f6ae5343a194e28d Mon Sep 17 00:00:00 2001 From: Tobias Hopp Date: Mon, 28 Nov 2022 11:55:28 +0100 Subject: [PATCH] fix pumps Took 11 minutes --- src/MyGPIO.ts | 28 ++++++++++++++++++++++++++++ src/iTender.ts | 14 ++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 src/MyGPIO.ts diff --git a/src/MyGPIO.ts b/src/MyGPIO.ts new file mode 100644 index 0000000..0991399 --- /dev/null +++ b/src/MyGPIO.ts @@ -0,0 +1,28 @@ +import GPIO from "rpi-gpio"; + +export class MyGPIO { + static setup(pin: number, direction): Promise { + return new Promise((resolve, reject) => { + GPIO.setup(pin, direction, (err) => { + if (err) { + reject(); + return; + } + resolve(); + }); + }) + } + + static write(pin: number, state: boolean): Promise { + return new Promise((resolve, reject) => { + GPIO.write(pin, state, (err) => { + if(err) + { + reject(); + return; + } + resolve(); + }); + }); + } +} \ No newline at end of file diff --git a/src/iTender.ts b/src/iTender.ts index 6ef0d5c..3f9f9be 100644 --- a/src/iTender.ts +++ b/src/iTender.ts @@ -20,6 +20,7 @@ import {RejectReason} from "./RejectReason"; import {Settings} from "./Settings"; import axios from "axios"; import GPIO from "rpi-gpio"; +import {MyGPIO} from "./MyGPIO"; const isPI = require("detect-rpi"); @@ -144,11 +145,9 @@ export class iTender { for (let x of job.amounts) { // Start pump here try { - console.log(x.container); - console.log("x1"); - await GPIO.setup(x.container.pumpPin, GPIO.DIR_OUT); - console.log("x2"); - await GPIO.write(x.container.pumpPin, true); + await MyGPIO.setup(x.container.pumpPin, GPIO.DIR_OUT) + + await MyGPIO.write(x.container.pumpPin, true ); } catch (e) { if (isPI()) { log("[ERROR] GPIO I/O Error " + e); @@ -176,7 +175,7 @@ export class iTender { mixLog(`Stopping output of pump ${x.container.pumpPin}`); // Stop pump here try { - GPIO.write(x.container.pumpPin, false); + await MyGPIO.write(x.container.pumpPin, false ); } catch (e) { if (isPI()) { log("[ERROR] GPIO I/O Error " + e); @@ -220,11 +219,10 @@ export class iTender { for (let x of this._currentJob.amounts) { // stop pump pin try { - await GPIO.write(x.container.pumpPin, false); + await MyGPIO.write(x.container.pumpPin, false ); } catch (e) { } - } iTender.setStatus(iTenderStatus.READY);