read sensors a second time if values do not seem plausible
This commit is contained in:
parent
924ec0719f
commit
363e8ecc23
|
|
@ -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;
|
||||
int32_t weight_current32;
|
||||
int32_t weight_current32_a;
|
||||
int32_t weight_current32_b;
|
||||
long w1_0_real;
|
||||
long w2_0_real;
|
||||
|
||||
plausible = true;
|
||||
|
||||
// vBat
|
||||
int vbat_mv = (int)(gCatena.ReadVbat() * 1000.0f);
|
||||
res.vbat = GetVBatValue(vbat_mv);
|
||||
|
|
@ -582,22 +588,27 @@ void ReadSensors(SENSOR_data &sensor_data) {
|
|||
PowerdownScale();
|
||||
|
||||
// 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) {
|
||||
weight_current32 = 0;
|
||||
} else if (weight_current32 > UINT16_MAX) {
|
||||
} else if (weight_current32 > UINT16_MAX) {
|
||||
//weight_current32 = UINT16_MAX;
|
||||
// we set the weight to 0, as such high values are not realistic and probably a sign for bad calibration...
|
||||
weight_current32 = 0;
|
||||
}
|
||||
if (config_data.cal_w1_0 == NOT_ATTACHED || config_data.cal_w2_0 == NOT_ATTACHED) {
|
||||
}
|
||||
if (config_data.cal_w1_0 == NOT_ATTACHED || config_data.cal_w2_0 == NOT_ATTACHED) {
|
||||
// when at least one load cell is disabled, we multiply the measured weight by 2
|
||||
weight_current32 = weight_current32 * 2;
|
||||
}
|
||||
res.weight = (uint16_t)weight_current32;
|
||||
}
|
||||
res.weight = (uint16_t)weight_current32;
|
||||
|
||||
if (fBme) {
|
||||
if (fBme) {
|
||||
/* warm up the BME280 by discarding a measurement */
|
||||
(void)gBME280.readTemperature();
|
||||
|
||||
|
|
@ -621,6 +632,7 @@ void ReadSensors(SENSOR_data &sensor_data) {
|
|||
}
|
||||
|
||||
sensor_data = res;
|
||||
return plausible;
|
||||
}
|
||||
|
||||
void StartNewIteration() {
|
||||
|
|
@ -632,7 +644,18 @@ void StartNewIteration() {
|
|||
iteration++;
|
||||
|
||||
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;
|
||||
|
||||
// vBus
|
||||
|
|
|
|||
|
|
@ -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 MAX_VALUES_TO_SEND = 8;
|
||||
|
|
|
|||
Loading…
Reference in New Issue