From f3e2e0181ab291d53092bd8f5b0a33cd4ccc507f Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Sat, 29 Feb 2020 12:39:54 +0100 Subject: [PATCH] fix formula --- mini-beieli-node.ino | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mini-beieli-node.ino b/mini-beieli-node.ino index 6aaf43d..cefd109 100644 --- a/mini-beieli-node.ino +++ b/mini-beieli-node.ino @@ -598,6 +598,8 @@ long my_read_average(byte gain, byte times) { void ReadSensors(SENSOR_data &sensor_data) { SENSOR_data res; int32_t weight_current32; + long w1_0_real; + long w2_0_real; // vBat gCatena.poll(); @@ -608,6 +610,8 @@ void ReadSensors(SENSOR_data &sensor_data) { } // Read Scales + w1_0_real = config_data.cal_w1_0; + w2_0_real = config_data.cal_w2_0; if (setup_scales()) { if (config_data.debug_level > 0) { gCatena.SafePrintf("%010d - HX711 LoadCell is ready.\n", millis()); @@ -620,6 +624,7 @@ void ReadSensors(SENSOR_data &sensor_data) { } } else { res.weight1 = 0; + w1_0_real = 0; if (config_data.debug_level > 0) { gCatena.SafePrintf("%010d - Load_cell 1 is disabled\n", millis()); } @@ -632,6 +637,7 @@ void ReadSensors(SENSOR_data &sensor_data) { } } else { res.weight2 = 0; + w2_0_real = 0; if (config_data.debug_level > 0) { gCatena.SafePrintf("%010d - Load_cell 2 is disabled\n", millis()); } @@ -648,7 +654,8 @@ void ReadSensors(SENSOR_data &sensor_data) { digitalWrite(D10, LOW); // Gewicht berechnen - weight_current32 = (int32_t)((((res.weight1 - config_data.cal_w1_0) / config_data.cal_w1_factor) + ((res.weight2 - config_data.cal_w2_0) / config_data.cal_w2_factor)) / 5.0); + weight_current32 = (int32_t)((((res.weight1 - w1_0_real) / config_data.cal_w1_factor) + ((res.weight2 - w2_0_real) / config_data.cal_w2_factor)) / 5.0); + if (weight_current32 < 0) { weight_current32 = 0; } else if (weight_current32 > UINT16_MAX) {