Took 1 hour 43 minutes
This commit is contained in:
Tobias Hopp 2023-01-31 20:56:35 +01:00
parent 8766961c7b
commit d363b9eb1a
6 changed files with 17 additions and 8 deletions

View File

@ -10,6 +10,7 @@ import debug from "debug";
import {ArduinoProxyPayload} from "./ArduinoProxyPayload";
import {ArduinoProxyPayloadType} from "./ArduinoProxyPayloadType";
import {ArduinoProxy} from "./ArduinoProxy";
import {ContainerHelper} from "./ContainerHelper";
const isPI = require("detect-rpi");
@ -38,13 +39,14 @@ export class Mixer {
*/
private static _jobEndCheckInterval: NodeJS.Timer;
/**
* Start the internal fill method, a sub-method of the onReceiveFill method
* This method only gets executed if REALLY all is okay, it is the internal function
* @param job
*/
static async startFill(job: IJob) {
this._jobTimers = [];
job.startedAt = new Date();
await job.populate([{path: "amounts.ingredient"}, {path: "amounts.container"}, {path: "drink"}]);
log("New fill job " + job.drink.name + " will take " + job.estimatedTime + "s");
@ -128,18 +130,22 @@ export class Mixer {
this._jobTimers.push(timer);
}
this._jobEndCheckInterval = setInterval(async () => {
this._jobEndCheckInterval = setInterval(async () => {
if (this._jobTimers.length != 0)
return;
clearInterval(this._jobEndCheckInterval);
job.endAt = new Date();
job.successful = true;
await job.save();
log("Job successful");
setTimeout(() => iTender.setStatus(iTenderStatus.READY), 3000)
setTimeout(() => iTender.setStatus(iTenderStatus.READY), 2500);
await ContainerHelper.measureContainers();
}, 500);
}
@ -185,6 +191,7 @@ export class Mixer {
// füllmenge - ( ( (stopp-start) / 1000 ) * ( sekunden100ml / 100 ) )
container.filled = container.filled - (deltaStartStop * (iTender.secondsPer100ml / 100)) // V2: Near the current fill value based on time values from delta start stop
container.save().then();
}

View File

@ -160,7 +160,6 @@ export class iTender {
}
console.log(amounts);
job.drink = drink
job.amounts = amounts as { ingredient: IIngredient, amount: number, container: IContainer }[];
if (job.estimatedTime < 0.5) {
@ -170,6 +169,7 @@ export class iTender {
resolve(job);
await Mixer.startFill(job);
});

View File

@ -43,7 +43,7 @@ const wsApp = new WebsocketApp();
log("Check OK, starting...");
await init();
log("Init OK");
setInterval(refresh, 1000 * 60);
setInterval(refresh, 1000 * 10);
iTender.setStatus(iTenderStatus.READY);
} catch (e) {
@ -88,16 +88,17 @@ function init(): Promise<void> {
function refresh(): Promise<void> {
return new Promise(async resolve => {
log("Refreshing...")
// Network
await iTender.checkNetwork();
// Below are refreshments of containers / drinks
// If there is a current job, DO NOT REFRESH!
if (Mixer.currentJob)
if (iTender.status != iTenderStatus.READY)
return;
log("Refreshing...")
//await iTender.refreshContainers(); Not needed because there is no change in containers?
await ContainerHelper.measureContainers();
//await iTender.refreshDrinks(); Not needed because there is no change in drinks?

View File

@ -128,6 +128,7 @@ router.ws('/', async (ws, req, next) => {
case WebSocketEvent.CANCEL: {
await Mixer.cancelFill();
break;
}
case WebSocketEvent.REQUEST: {

View File

@ -46,7 +46,7 @@ document.addEventListener("DOMContentLoaded", async () => {
containerDiv.classList.add("container");
let span = document.createElement("span") as HTMLSpanElement;
let pcnt = container.filled * 100 / container.volume;
let pcnt = Math.round( container.filled * 100 / container.volume );
if( !container.content )
span.innerText = "-";
else if( isNaN(pcnt) )

0
update.sh Normal file → Executable file
View File