Handle consecutive invalid value update

Set measurements type average value to invalid when invalidCounter reached max period
This commit is contained in:
samuelbles07
2024-10-21 22:37:44 +07:00
parent c3068be6e9
commit 8a87b865e6
2 changed files with 22 additions and 8 deletions
+20 -6
View File
@@ -111,9 +111,16 @@ bool Measurements::update(MeasurementType type, int val, int ch) {
if (val == invalidValue) {
temporary->update.invalidCounter++;
// TODO: Need to check if its more than threshold, to create some indication. Maybe reference to
// max element?
return false;
if (temporary->update.invalidCounter >= temporary->update.max) {
Serial.printf("%s{%d} invalid value update counter reached (%dx)! Setting its average value "
"to invalid!",
measurementTypeStr(type), ch, temporary->update.max);
temporary->update.avg = invalidValue;
return false;
}
// Still consider updating value to valid
return true;
}
// Reset invalid counter when update new valid value
@@ -174,9 +181,16 @@ bool Measurements::update(MeasurementType type, float val, int ch) {
if (val == invalidValue) {
temporary->update.invalidCounter++;
// TODO: Need to check if its more than threshold, to create some indication. Maybe reference to
// max element?
return false;
if (temporary->update.invalidCounter >= temporary->update.max) {
Serial.printf("%s{%d} invalid value update counter reached (%dx)! Setting its average value "
"to invalid!",
measurementTypeStr(type), ch, temporary->update.max);
temporary->update.avg = invalidValue;
return false;
}
// Still consider updating value to valid
return true;
}
// Reset invalid counter when update new valid value