Took 28 minutes
This commit is contained in:
Tobias Hopp 2023-02-02 08:32:22 +01:00
parent 59bb0437e1
commit 02c335bc27
2 changed files with 20 additions and 15 deletions

View File

@ -50,12 +50,22 @@ router.ws('/', async (ws, req, next) => {
switch (msg.event) { switch (msg.event) {
case WebSocketEvent.CONTAINERS: { case WebSocketEvent.CONTAINERS: {
let data = msg.data as { pumpPin: number; sensorType: SensorType; sensor1: number; sensor2: number; useProxy: boolean }[]; let data = msg.data as { id?: string, pumpPin: number; sensorType: SensorType; sensor1: number; sensor2: number; useProxy: boolean }[];
await Container.deleteMany({}); // V2: Remove this and check every container based on id if changes occurs // await Container.deleteMany({}); // V2: Remove this and check every container based on id if changes occurs
let i = 0; let i = 0;
for (let c of data) { for (let c of data) {
let container = new Container(); let container : IContainer | null = null;
if( c.id )
{
container = await Container.findOne( {_id: c.id } );
}
if( !container )
container = new Container();
container.slot = i; container.slot = i;
//container.volume = c.volume; // V2: Removed //container.volume = c.volume; // V2: Removed
container.pumpPin = c.pumpPin; container.pumpPin = c.pumpPin;

View File

@ -12,13 +12,11 @@ import {RequestType} from "../RequestType";
export class Setup { export class Setup {
public static arduinoProxyCheckboxes: HTMLInputElement[] = [];
private static usingProxy = false; private static usingProxy = false;
private static pins_pi = [3, 7, 8, 10, 11, 12, 13, 15, 16, 18, 19, 21, 22, 23, 24, 26, 29, 31, 32, 33, 35, 36, 37, 38]; private static pins_pi = [3, 7, 8, 10, 11, 12, 13, 15, 16, 18, 19, 21, 22, 23, 24, 26, 29, 31, 32, 33, 35, 36, 37, 38];
private static pins_arduino = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53]; private static pins_arduino = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53];
public static arduinoProxyCheckboxes: HTMLInputElement[] = [];
public static onConfigUpdate(payload: WebSocketPayload) { public static onConfigUpdate(payload: WebSocketPayload) {
// Setup containers updated // Setup containers updated
const ledGPIO = document.getElementById("ledGPIO") as HTMLInputElement; const ledGPIO = document.getElementById("ledGPIO") as HTMLInputElement;
@ -34,8 +32,7 @@ export class Setup {
this.usingProxy = proxyCheckbox.checked; this.usingProxy = proxyCheckbox.checked;
for (let checkbox of this.arduinoProxyCheckboxes) { for (let checkbox of this.arduinoProxyCheckboxes) {
checkbox.disabled = !proxyCheckbox.checked; checkbox.disabled = !proxyCheckbox.checked;
if( !proxyCheckbox.checked ) if (!proxyCheckbox.checked) {
{
checkbox.checked = false; checkbox.checked = false;
let event = new Event('change', {bubbles: true}); let event = new Event('change', {bubbles: true});
checkbox.dispatchEvent(event); // Trigger virtual onChange event checkbox.dispatchEvent(event); // Trigger virtual onChange event
@ -162,8 +159,6 @@ Dort werden die Behälter definiert, welche in den iTender gestellt werden.<br>D
} }
const ledCheckbox = document.getElementById("ledCheckbox") as HTMLInputElement; const ledCheckbox = document.getElementById("ledCheckbox") as HTMLInputElement;
const ledGPIO = document.getElementById("ledGPIO") as HTMLInputElement; const ledGPIO = document.getElementById("ledGPIO") as HTMLInputElement;
const ambientColor = document.getElementById("ambientColor") as HTMLInputElement; const ambientColor = document.getElementById("ambientColor") as HTMLInputElement;
@ -173,7 +168,7 @@ Dort werden die Behälter definiert, welche in den iTender gestellt werden.<br>D
// Containers // Containers
let cons: { pumpPin: number; sensorType: SensorType; sensor1: number; sensor2: number; useProxy: boolean }[] = []; let cons: { id: string, pumpPin: number; sensorType: SensorType; sensor1: number; sensor2: number; useProxy: boolean }[] = [];
for (let c of (document.getElementById("setupContainers") as HTMLDivElement).getElementsByTagName("div")) { for (let c of (document.getElementById("setupContainers") as HTMLDivElement).getElementsByTagName("div")) {
let sensorType = c.getElementsByTagName("select")[1].value; let sensorType = c.getElementsByTagName("select")[1].value;
let type; let type;
@ -189,7 +184,8 @@ Dort werden die Behälter definiert, welche in den iTender gestellt werden.<br>D
"pumpPin": parseInt(c.getElementsByTagName("select")[0].value), "pumpPin": parseInt(c.getElementsByTagName("select")[0].value),
"sensorType": type, "sensorType": type,
"sensor1": parseInt(c.getElementsByTagName("select")[2].value), "sensor1": parseInt(c.getElementsByTagName("select")[2].value),
"sensor2": parseInt(c.getElementsByTagName("select")[3].value) "sensor2": parseInt(c.getElementsByTagName("select")[3].value),
"id": c.id,
}); });
} }
let newConf = { let newConf = {
@ -231,7 +227,6 @@ Dort werden die Behälter definiert, welche in den iTender gestellt werden.<br>D
setTimeout(() => { setTimeout(() => {
saveModal.close(); saveModal.close();
this.startTare(); this.startTare();
}, 1000); }, 1000);
@ -255,7 +250,7 @@ Dort werden die Behälter definiert, welche in den iTender gestellt werden.<br>D
// Needs to be after selectPin.append because noSel-Pin should always be at pos 0 // Needs to be after selectPin.append because noSel-Pin should always be at pos 0
let event = new Event('click', {bubbles: true}); let event = new Event('click', {bubbles: true});
let btn = document.getElementById("setup_cancelBtn"); let btn = document.getElementById("setup_cancelBtn");
if(btn ) if (btn)
btn.dispatchEvent(event); btn.dispatchEvent(event);
}); });
@ -299,7 +294,7 @@ Alle Sensoren wurden erfolgreich kalibriert.<br>`;
clearInterval(tareInterval); clearInterval(tareInterval);
let event = new Event('click', {bubbles: true}); let event = new Event('click', {bubbles: true});
let btn = document.getElementById("setup_cancelBtn"); let btn = document.getElementById("setup_cancelBtn");
if(btn ) if (btn)
btn.dispatchEvent(event); btn.dispatchEvent(event);
}; };
} else { } else {