From e7c3e26b52070b3bc26d2e44b9e8ec072f4b90c2 Mon Sep 17 00:00:00 2001 From: Tobias Hopp Date: Mon, 28 Nov 2022 11:16:32 +0100 Subject: [PATCH] fix pumps Took 3 minutes --- src/iTender.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/iTender.ts b/src/iTender.ts index 646062f..5fdfcd8 100644 --- a/src/iTender.ts +++ b/src/iTender.ts @@ -19,6 +19,7 @@ import {clearInterval} from "timers"; import {RejectReason} from "./RejectReason"; import {Settings} from "./Settings"; import axios from "axios"; +import GPIO from "rpi-gpio"; const log = debug("itender:station"); const mixLog = debug("itender:mix"); @@ -135,15 +136,19 @@ export class iTender { let timers: NodeJS.Timeout[] = []; for (let x of job.amounts) { // Start pump here - //await GPIO.setup(x.container.pumpPin, GPIO.DIR_OUT); - //await GPIO.write(x.container.pumpPin, true); + try { + await GPIO.setup(x.container.pumpPin, GPIO.DIR_OUT); + await GPIO.write(x.container.pumpPin, true); + } catch (e) { + log("[ERROR] If iTender is running not on a pi, this is normal, if not this is an critical GPIO Error"); + } + let waitTime = (Settings.get("secondsPer100ml") as number) / 100 * x.amount * 1000; mixLog(`Starting output of pump ${x.container.pumpPin}`); //mixLog(x.ingredient + " takes " + (waitTime / 1000) + "s for " + x.amount + "ml"); - let timer = setTimeout(() => { - // Stop pump here - //GPIO.write(x.container.pumpPin, false); + let timer = setTimeout(async () => { + // Remove from list of timers let arr: NodeJS.Timer[] = []; @@ -151,7 +156,14 @@ export class iTender { if (timers[i] != timer) arr.push(timers[i]); } - mixLog(`Stopping output of pump ${x.container.pumpPin}`) + mixLog(`Stopping output of pump ${x.container.pumpPin}`); + // Stop pump here + try { + GPIO.write(x.container.pumpPin, false); + } catch (e) { + log("[ERROR] If iTender is running not on a pi, this is normal, if not this is an critical GPIO Error"); + } + timers = arr; }, waitTime);