read sensors a second time if values do not seem plausible

This commit is contained in:
Joerg Lehmann 2020-07-01 11:05:25 +02:00
parent 924ec0719f
commit 363e8ecc23
2 changed files with 42 additions and 19 deletions

View File

@ -527,12 +527,18 @@ void DoDeepSleep(uint32_t sleep_time)
} }
} }
void ReadSensors(SENSOR_data &sensor_data) { // Returns true if measurements are plausible, otherwise false
bool ReadSensors(SENSOR_data &sensor_data) {
bool plausible;
SENSOR_data res; SENSOR_data res;
int32_t weight_current32; int32_t weight_current32;
int32_t weight_current32_a;
int32_t weight_current32_b;
long w1_0_real; long w1_0_real;
long w2_0_real; long w2_0_real;
plausible = true;
// vBat // vBat
int vbat_mv = (int)(gCatena.ReadVbat() * 1000.0f); int vbat_mv = (int)(gCatena.ReadVbat() * 1000.0f);
res.vbat = GetVBatValue(vbat_mv); res.vbat = GetVBatValue(vbat_mv);
@ -582,7 +588,12 @@ void ReadSensors(SENSOR_data &sensor_data) {
PowerdownScale(); PowerdownScale();
// Gewicht berechnen // Gewicht berechnen
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); weight_current32_a = (int32_t)((res.weight1 - w1_0_real) / config_data.cal_w1_factor);
weight_current32_b = (int32_t)((res.weight2 - w2_0_real) / config_data.cal_w2_factor);
weight_current32 = (int32_t)((weight_current32_a + weight_current32_b) / 5.0);
// we check if weights are plausible
plausible = (weight_current32_a > -10000) && (weight_current32_b > -10000) && (weight_current32_a < -150000) && (weight_current32_b < -150000);
if (weight_current32 < 0) { if (weight_current32 < 0) {
weight_current32 = 0; weight_current32 = 0;
@ -621,6 +632,7 @@ void ReadSensors(SENSOR_data &sensor_data) {
} }
sensor_data = res; sensor_data = res;
return plausible;
} }
void StartNewIteration() { void StartNewIteration() {
@ -632,7 +644,18 @@ void StartNewIteration() {
iteration++; iteration++;
SENSOR_data current_sensor_reading; SENSOR_data current_sensor_reading;
ReadSensors(current_sensor_reading); if (!ReadSensors(current_sensor_reading)) {
// we try a second time if Readings do not seem plausible
if (config_data.debug_level > 0) {
gCatena.SafePrintf("Readings do not seem plausible, try a second time\n");
}
delay(500);
if (!ReadSensors(current_sensor_reading)) {
if (config_data.debug_level > 0) {
gCatena.SafePrintf("Readings do not seem plausible for a second time, we give up!\n");
}
}
}
int16_t temp_change; int16_t temp_change;
// vBus // vBus

View File

@ -56,7 +56,7 @@ enum {
| |
\****************************************************************************/ \****************************************************************************/
static const int32_t fwVersion = 20200630; static const int32_t fwVersion = 20200701;
static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages; static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages;
static const byte MAX_VALUES_TO_SEND = 8; static const byte MAX_VALUES_TO_SEND = 8;