fix pumps
Took 11 minutes
This commit is contained in:
parent
c770c5cce8
commit
5d0bf48854
28
src/MyGPIO.ts
Normal file
28
src/MyGPIO.ts
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ import {RejectReason} from "./RejectReason";
|
|||||||
import {Settings} from "./Settings";
|
import {Settings} from "./Settings";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import GPIO from "rpi-gpio";
|
import GPIO from "rpi-gpio";
|
||||||
|
import {MyGPIO} from "./MyGPIO";
|
||||||
|
|
||||||
const isPI = require("detect-rpi");
|
const isPI = require("detect-rpi");
|
||||||
|
|
||||||
@ -144,11 +145,9 @@ export class iTender {
|
|||||||
for (let x of job.amounts) {
|
for (let x of job.amounts) {
|
||||||
// Start pump here
|
// Start pump here
|
||||||
try {
|
try {
|
||||||
console.log(x.container);
|
await MyGPIO.setup(x.container.pumpPin, GPIO.DIR_OUT)
|
||||||
console.log("x1");
|
|
||||||
await GPIO.setup(x.container.pumpPin, GPIO.DIR_OUT);
|
await MyGPIO.write(x.container.pumpPin, true );
|
||||||
console.log("x2");
|
|
||||||
await GPIO.write(x.container.pumpPin, true);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isPI()) {
|
if (isPI()) {
|
||||||
log("[ERROR] GPIO I/O Error " + e);
|
log("[ERROR] GPIO I/O Error " + e);
|
||||||
@ -176,7 +175,7 @@ export class iTender {
|
|||||||
mixLog(`Stopping output of pump ${x.container.pumpPin}`);
|
mixLog(`Stopping output of pump ${x.container.pumpPin}`);
|
||||||
// Stop pump here
|
// Stop pump here
|
||||||
try {
|
try {
|
||||||
GPIO.write(x.container.pumpPin, false);
|
await MyGPIO.write(x.container.pumpPin, false );
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isPI()) {
|
if (isPI()) {
|
||||||
log("[ERROR] GPIO I/O Error " + e);
|
log("[ERROR] GPIO I/O Error " + e);
|
||||||
@ -220,11 +219,10 @@ export class iTender {
|
|||||||
for (let x of this._currentJob.amounts) {
|
for (let x of this._currentJob.amounts) {
|
||||||
// stop pump pin
|
// stop pump pin
|
||||||
try {
|
try {
|
||||||
await GPIO.write(x.container.pumpPin, false);
|
await MyGPIO.write(x.container.pumpPin, false );
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
iTender.setStatus(iTenderStatus.READY);
|
iTender.setStatus(iTenderStatus.READY);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user