Took 38 minutes
This commit is contained in:
Tobias Hopp 2023-02-01 14:44:42 +01:00
parent 00691557cc
commit 59bb0437e1
6 changed files with 25 additions and 11 deletions

View File

@ -5,7 +5,7 @@
#include "HX711.h" #include "HX711.h"
// Define the size of the JSON buffer // Define the size of the JSON buffer
#define JSON_BUFFER_SIZE 256 // #define JSON_BUFFER_SIZE 256
// Create a JSON object for incoming messages // Create a JSON object for incoming messages
StaticJsonDocument<JSON_BUFFER_SIZE> incomingJson; StaticJsonDocument<JSON_BUFFER_SIZE> incomingJson;
@ -97,6 +97,7 @@ void loop() {
// Send the outgoing JSON message // Send the outgoing JSON message
serializeJson(outgoingJson, Serial); serializeJson(outgoingJson, Serial);
Serial.println();
} }
} }
} }

View File

@ -15,7 +15,7 @@ export class ArduinoProxy {
private static onData(data) { private static onData(data) {
data = data.toString().trim(); data = data.toString().trim();
try { try {
log("Receiving " + data); console.debug("Received ", data);
let json = JSON.parse(data) as ArduinoProxyPayload; let json = JSON.parse(data) as ArduinoProxyPayload;
if (this.callbacks[json.id]) { if (this.callbacks[json.id]) {
this.callbacks[json.id].resolve(json); this.callbacks[json.id].resolve(json);
@ -80,10 +80,17 @@ export class ArduinoProxy {
public static sendRequest(request: ArduinoProxyPayload, timeout: number = 1000) { public static sendRequest(request: ArduinoProxyPayload, timeout: number = 1000) {
return new Promise<ArduinoProxyPayload>((resolve, reject) => { return new Promise<ArduinoProxyPayload>((resolve, reject) => {
let id = Utils.generateRandomString(8); let id = Utils.generateRandomString(8);
request.id = id; request.id = id;
this.callbacks[id] = {resolve: resolve, reject: reject}; this.callbacks[id] = {resolve: resolve, reject: reject};
log("Sending " + request); let formatted = {
this.serialPort.write(JSON.stringify(request), ArduinoProxy.encoding, (err: Error | null | undefined) => { id: request.id,
type: request.type,
data: request.data
}
console.debug("Sending...", formatted);
this.serialPort.write(JSON.stringify(formatted), ArduinoProxy.encoding, (err: Error | null | undefined) => {
if (err) { if (err) {
reject("I/O error on request " + id); reject("I/O error on request " + id);
} }

View File

@ -61,20 +61,24 @@ export class Mixer {
// Start pump here // Start pump here
try { try {
if (x.container.useProxy) { if (x.container.useProxy) {
console.log("Using proxy as filler");
let payload = new ArduinoProxyPayload(ArduinoProxyPayloadType.SET_PIN, { let payload = new ArduinoProxyPayload(ArduinoProxyPayloadType.SET_PIN, {
pin: x.container.pumpPin, pin: x.container.pumpPin,
mode: "DIGITAL", mode: "DIGITAL",
value: 255 value: 255
}); });
await ArduinoProxy.sendRequest(payload); await payload.send();
} else { } else {
console.log("Using normal gpio rpi");
await MyGPIO.setup(x.container.pumpPin, GPIO.DIR_OUT) await MyGPIO.setup(x.container.pumpPin, GPIO.DIR_OUT)
await MyGPIO.write(x.container.pumpPin, true); await MyGPIO.write(x.container.pumpPin, true);
} }
} catch (e) { } catch (e) {
console.debug(e);
if (isPI()) { if (isPI()) {
log("[ERROR] GPIO I/O Error " + e); log("[ERROR] GPIO I/O Error " + e);
// Todo error handling to user // Todo error handling to user
await this.cancelFill(); await this.cancelFill();
return; return;
@ -99,7 +103,7 @@ export class Mixer {
mode: "DIGITAL", mode: "DIGITAL",
"value": 0 "value": 0
}); });
await ArduinoProxy.sendRequest(payload); await payload.send();
} else { } else {
await MyGPIO.write(x.container.pumpPin, false); await MyGPIO.write(x.container.pumpPin, false);
} }
@ -172,7 +176,7 @@ export class Mixer {
mode: "DIGITAL", mode: "DIGITAL",
"value": 0 "value": 0
}); });
await ArduinoProxy.sendRequest(payload); await payload.send();
} else { } else {
await MyGPIO.write(jobIngredient.container.pumpPin, false); await MyGPIO.write(jobIngredient.container.pumpPin, false);
} }

View File

@ -26,7 +26,7 @@ export class SensorHelper {
pin_data: container.sensorPin1, pin_data: container.sensorPin1,
pin_clock: container.sensorPin2 pin_clock: container.sensorPin2
}); });
let val = await ArduinoProxy.sendRequest(payload); let val = await payload.send();
if (!val.data.value) if (!val.data.value)
return reject(""); return reject("");

View File

@ -85,11 +85,11 @@ export class Utils {
} }
static generateRandomString(number: number) { static generateRandomString(len: number) {
let result = ''; let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length; const charactersLength = characters.length;
for (let i = 0; i < length; i++) { for (let i = 0; i < len; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength)); result += characters.charAt(Math.floor(Math.random() * charactersLength));
} }
return result; return result;

View File

@ -161,7 +161,7 @@ Dort werden die Behälter definiert, welche in den iTender gestellt werden.<br>D
return; return;
} }
setupSaveBtn.disabled = true;
const ledCheckbox = document.getElementById("ledCheckbox") as HTMLInputElement; const ledCheckbox = document.getElementById("ledCheckbox") as HTMLInputElement;
@ -210,6 +210,8 @@ Dort werden die Behälter definiert, welche in den iTender gestellt werden.<br>D
return; return;
} }
setupSaveBtn.disabled = true;
let saveModal = new Modal("setup", "Setup"); let saveModal = new Modal("setup", "Setup");
let txt = document.createElement("p"); let txt = document.createElement("p");
txt.innerHTML = `Die Einstellungen werden gespeichert...<br> txt.innerHTML = `Die Einstellungen werden gespeichert...<br>