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;
|
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,24 +588,29 @@ 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;
|
||||||
} else if (weight_current32 > UINT16_MAX) {
|
} else if (weight_current32 > UINT16_MAX) {
|
||||||
//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...
|
// we set the weight to 0, as such high values are not realistic and probably a sign for bad calibration...
|
||||||
weight_current32 = 0;
|
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
|
// when at least one load cell is disabled, we multiply the measured weight by 2
|
||||||
weight_current32 = weight_current32 * 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 */
|
/* warm up the BME280 by discarding a measurement */
|
||||||
(void)gBME280.readTemperature();
|
(void)gBME280.readTemperature();
|
||||||
|
|
||||||
Adafruit_BME280::Measurements m = gBME280.readTemperaturePressureHumidity();
|
Adafruit_BME280::Measurements m = gBME280.readTemperaturePressureHumidity();
|
||||||
// temperature is 2 bytes from -0x80.00 to +0x7F.FF degrees C
|
// temperature is 2 bytes from -0x80.00 to +0x7F.FF degrees C
|
||||||
|
|
@ -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
|
||||||
|
|
@ -733,7 +756,7 @@ void StartNewIteration() {
|
||||||
last_sensor_reading = current_sensor_reading;
|
last_sensor_reading = current_sensor_reading;
|
||||||
} else {
|
} else {
|
||||||
// we only copy the last weight
|
// we only copy the last weight
|
||||||
last_sensor_reading.weight = current_sensor_reading.weight;
|
last_sensor_reading.weight = current_sensor_reading.weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t sleep_time_sec;
|
uint32_t sleep_time_sec;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue