fix pumps

Took 11 minutes
This commit is contained in:
Tobias Hopp 2022-11-28 11:55:28 +01:00
parent c770c5cce8
commit 5d0bf48854
2 changed files with 34 additions and 8 deletions

28
src/MyGPIO.ts Normal file
View File

@ -0,0 +1,28 @@
import GPIO from "rpi-gpio";
export class MyGPIO {
static setup(pin: number, direction): Promise<void> {
return new Promise((resolve, reject) => {
GPIO.setup(pin, direction, (err) => {
if (err) {
reject();
return;
}
resolve();
});
})
}
static write(pin: number, state: boolean): Promise<void> {
return new Promise((resolve, reject) => {
GPIO.write(pin, state, (err) => {
if(err)
{
reject();
return;
}
resolve();
});
});
}
}

View File

@ -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);