Update
Took 1 hour 43 minutes
This commit is contained in:
parent
8766961c7b
commit
d363b9eb1a
13
src/Mixer.ts
13
src/Mixer.ts
@ -10,6 +10,7 @@ import debug from "debug";
|
|||||||
import {ArduinoProxyPayload} from "./ArduinoProxyPayload";
|
import {ArduinoProxyPayload} from "./ArduinoProxyPayload";
|
||||||
import {ArduinoProxyPayloadType} from "./ArduinoProxyPayloadType";
|
import {ArduinoProxyPayloadType} from "./ArduinoProxyPayloadType";
|
||||||
import {ArduinoProxy} from "./ArduinoProxy";
|
import {ArduinoProxy} from "./ArduinoProxy";
|
||||||
|
import {ContainerHelper} from "./ContainerHelper";
|
||||||
|
|
||||||
const isPI = require("detect-rpi");
|
const isPI = require("detect-rpi");
|
||||||
|
|
||||||
@ -38,13 +39,14 @@ export class Mixer {
|
|||||||
*/
|
*/
|
||||||
private static _jobEndCheckInterval: NodeJS.Timer;
|
private static _jobEndCheckInterval: NodeJS.Timer;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the internal fill method, a sub-method of the onReceiveFill method
|
* 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
|
* This method only gets executed if REALLY all is okay, it is the internal function
|
||||||
* @param job
|
* @param job
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static async startFill(job: IJob) {
|
static async startFill(job: IJob) {
|
||||||
|
this._jobTimers = [];
|
||||||
job.startedAt = new Date();
|
job.startedAt = new Date();
|
||||||
await job.populate([{path: "amounts.ingredient"}, {path: "amounts.container"}, {path: "drink"}]);
|
await job.populate([{path: "amounts.ingredient"}, {path: "amounts.container"}, {path: "drink"}]);
|
||||||
log("New fill job " + job.drink.name + " will take " + job.estimatedTime + "s");
|
log("New fill job " + job.drink.name + " will take " + job.estimatedTime + "s");
|
||||||
@ -128,18 +130,22 @@ export class Mixer {
|
|||||||
this._jobTimers.push(timer);
|
this._jobTimers.push(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._jobEndCheckInterval = setInterval(async () => {
|
|
||||||
|
|
||||||
|
|
||||||
|
this._jobEndCheckInterval = setInterval(async () => {
|
||||||
if (this._jobTimers.length != 0)
|
if (this._jobTimers.length != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
clearInterval(this._jobEndCheckInterval);
|
clearInterval(this._jobEndCheckInterval);
|
||||||
job.endAt = new Date();
|
job.endAt = new Date();
|
||||||
job.successful = true;
|
job.successful = true;
|
||||||
|
|
||||||
await job.save();
|
await job.save();
|
||||||
log("Job successful");
|
log("Job successful");
|
||||||
setTimeout(() => iTender.setStatus(iTenderStatus.READY), 3000)
|
setTimeout(() => iTender.setStatus(iTenderStatus.READY), 2500);
|
||||||
|
|
||||||
|
await ContainerHelper.measureContainers();
|
||||||
|
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
@ -185,6 +191,7 @@ export class Mixer {
|
|||||||
|
|
||||||
// füllmenge - ( ( (stopp-start) / 1000 ) * ( sekunden100ml / 100 ) )
|
// 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.filled = container.filled - (deltaStartStop * (iTender.secondsPer100ml / 100)) // V2: Near the current fill value based on time values from delta start stop
|
||||||
|
|
||||||
container.save().then();
|
container.save().then();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,6 @@ export class iTender {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(amounts);
|
|
||||||
job.drink = drink
|
job.drink = drink
|
||||||
job.amounts = amounts as { ingredient: IIngredient, amount: number, container: IContainer }[];
|
job.amounts = amounts as { ingredient: IIngredient, amount: number, container: IContainer }[];
|
||||||
if (job.estimatedTime < 0.5) {
|
if (job.estimatedTime < 0.5) {
|
||||||
@ -170,6 +169,7 @@ export class iTender {
|
|||||||
resolve(job);
|
resolve(job);
|
||||||
|
|
||||||
await Mixer.startFill(job);
|
await Mixer.startFill(job);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ const wsApp = new WebsocketApp();
|
|||||||
log("Check OK, starting...");
|
log("Check OK, starting...");
|
||||||
await init();
|
await init();
|
||||||
log("Init OK");
|
log("Init OK");
|
||||||
setInterval(refresh, 1000 * 60);
|
setInterval(refresh, 1000 * 10);
|
||||||
iTender.setStatus(iTenderStatus.READY);
|
iTender.setStatus(iTenderStatus.READY);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -88,16 +88,17 @@ function init(): Promise<void> {
|
|||||||
|
|
||||||
function refresh(): Promise<void> {
|
function refresh(): Promise<void> {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
log("Refreshing...")
|
|
||||||
// Network
|
// Network
|
||||||
await iTender.checkNetwork();
|
await iTender.checkNetwork();
|
||||||
|
|
||||||
// Below are refreshments of containers / drinks
|
// Below are refreshments of containers / drinks
|
||||||
|
|
||||||
// If there is a current job, DO NOT REFRESH!
|
// If there is a current job, DO NOT REFRESH!
|
||||||
if (Mixer.currentJob)
|
if (iTender.status != iTenderStatus.READY)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
log("Refreshing...")
|
||||||
//await iTender.refreshContainers(); Not needed because there is no change in containers?
|
//await iTender.refreshContainers(); Not needed because there is no change in containers?
|
||||||
await ContainerHelper.measureContainers();
|
await ContainerHelper.measureContainers();
|
||||||
//await iTender.refreshDrinks(); Not needed because there is no change in drinks?
|
//await iTender.refreshDrinks(); Not needed because there is no change in drinks?
|
||||||
|
@ -128,6 +128,7 @@ router.ws('/', async (ws, req, next) => {
|
|||||||
|
|
||||||
case WebSocketEvent.CANCEL: {
|
case WebSocketEvent.CANCEL: {
|
||||||
await Mixer.cancelFill();
|
await Mixer.cancelFill();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WebSocketEvent.REQUEST: {
|
case WebSocketEvent.REQUEST: {
|
||||||
|
@ -46,7 +46,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
containerDiv.classList.add("container");
|
containerDiv.classList.add("container");
|
||||||
|
|
||||||
let span = document.createElement("span") as HTMLSpanElement;
|
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 )
|
if( !container.content )
|
||||||
span.innerText = "-";
|
span.innerText = "-";
|
||||||
else if( isNaN(pcnt) )
|
else if( isNaN(pcnt) )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user