update
Took 38 minutes
This commit is contained in:
parent
00691557cc
commit
59bb0437e1
@ -5,7 +5,7 @@
|
||||
#include "HX711.h"
|
||||
|
||||
// Define the size of the JSON buffer
|
||||
#define JSON_BUFFER_SIZE 256
|
||||
// #define JSON_BUFFER_SIZE 256
|
||||
|
||||
// Create a JSON object for incoming messages
|
||||
StaticJsonDocument<JSON_BUFFER_SIZE> incomingJson;
|
||||
@ -97,6 +97,7 @@ void loop() {
|
||||
|
||||
// Send the outgoing JSON message
|
||||
serializeJson(outgoingJson, Serial);
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ export class ArduinoProxy {
|
||||
private static onData(data) {
|
||||
data = data.toString().trim();
|
||||
try {
|
||||
log("Receiving " + data);
|
||||
console.debug("Received ", data);
|
||||
let json = JSON.parse(data) as ArduinoProxyPayload;
|
||||
if (this.callbacks[json.id]) {
|
||||
this.callbacks[json.id].resolve(json);
|
||||
@ -80,10 +80,17 @@ export class ArduinoProxy {
|
||||
public static sendRequest(request: ArduinoProxyPayload, timeout: number = 1000) {
|
||||
return new Promise<ArduinoProxyPayload>((resolve, reject) => {
|
||||
let id = Utils.generateRandomString(8);
|
||||
|
||||
request.id = id;
|
||||
this.callbacks[id] = {resolve: resolve, reject: reject};
|
||||
log("Sending " + request);
|
||||
this.serialPort.write(JSON.stringify(request), ArduinoProxy.encoding, (err: Error | null | undefined) => {
|
||||
let formatted = {
|
||||
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) {
|
||||
reject("I/O error on request " + id);
|
||||
}
|
||||
|
10
src/Mixer.ts
10
src/Mixer.ts
@ -61,20 +61,24 @@ export class Mixer {
|
||||
// Start pump here
|
||||
try {
|
||||
if (x.container.useProxy) {
|
||||
console.log("Using proxy as filler");
|
||||
let payload = new ArduinoProxyPayload(ArduinoProxyPayloadType.SET_PIN, {
|
||||
pin: x.container.pumpPin,
|
||||
mode: "DIGITAL",
|
||||
value: 255
|
||||
});
|
||||
await ArduinoProxy.sendRequest(payload);
|
||||
await payload.send();
|
||||
} else {
|
||||
console.log("Using normal gpio rpi");
|
||||
await MyGPIO.setup(x.container.pumpPin, GPIO.DIR_OUT)
|
||||
await MyGPIO.write(x.container.pumpPin, true);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.debug(e);
|
||||
if (isPI()) {
|
||||
log("[ERROR] GPIO I/O Error " + e);
|
||||
|
||||
// Todo error handling to user
|
||||
await this.cancelFill();
|
||||
return;
|
||||
@ -99,7 +103,7 @@ export class Mixer {
|
||||
mode: "DIGITAL",
|
||||
"value": 0
|
||||
});
|
||||
await ArduinoProxy.sendRequest(payload);
|
||||
await payload.send();
|
||||
} else {
|
||||
await MyGPIO.write(x.container.pumpPin, false);
|
||||
}
|
||||
@ -172,7 +176,7 @@ export class Mixer {
|
||||
mode: "DIGITAL",
|
||||
"value": 0
|
||||
});
|
||||
await ArduinoProxy.sendRequest(payload);
|
||||
await payload.send();
|
||||
} else {
|
||||
await MyGPIO.write(jobIngredient.container.pumpPin, false);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ export class SensorHelper {
|
||||
pin_data: container.sensorPin1,
|
||||
pin_clock: container.sensorPin2
|
||||
});
|
||||
let val = await ArduinoProxy.sendRequest(payload);
|
||||
let val = await payload.send();
|
||||
if (!val.data.value)
|
||||
return reject("");
|
||||
|
||||
|
@ -85,11 +85,11 @@ export class Utils {
|
||||
|
||||
}
|
||||
|
||||
static generateRandomString(number: number) {
|
||||
static generateRandomString(len: number) {
|
||||
let result = '';
|
||||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
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));
|
||||
}
|
||||
return result;
|
||||
|
@ -161,7 +161,7 @@ Dort werden die Behälter definiert, welche in den iTender gestellt werden.<br>D
|
||||
return;
|
||||
}
|
||||
|
||||
setupSaveBtn.disabled = true;
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
setupSaveBtn.disabled = true;
|
||||
|
||||
let saveModal = new Modal("setup", "Setup");
|
||||
let txt = document.createElement("p");
|
||||
txt.innerHTML = `Die Einstellungen werden gespeichert...<br>
|
||||
|
Loading…
x
Reference in New Issue
Block a user