mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-30 17:07:16 +02:00
Handle consecutive invalid value update
Set measurements type average value to invalid when invalidCounter reached max period
This commit is contained in:
@ -111,9 +111,16 @@ bool Measurements::update(MeasurementType type, int val, int ch) {
|
|||||||
|
|
||||||
if (val == invalidValue) {
|
if (val == invalidValue) {
|
||||||
temporary->update.invalidCounter++;
|
temporary->update.invalidCounter++;
|
||||||
// TODO: Need to check if its more than threshold, to create some indication. Maybe reference to
|
if (temporary->update.invalidCounter >= temporary->update.max) {
|
||||||
// max element?
|
Serial.printf("%s{%d} invalid value update counter reached (%dx)! Setting its average value "
|
||||||
return false;
|
"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
|
// Reset invalid counter when update new valid value
|
||||||
@ -174,9 +181,16 @@ bool Measurements::update(MeasurementType type, float val, int ch) {
|
|||||||
|
|
||||||
if (val == invalidValue) {
|
if (val == invalidValue) {
|
||||||
temporary->update.invalidCounter++;
|
temporary->update.invalidCounter++;
|
||||||
// TODO: Need to check if its more than threshold, to create some indication. Maybe reference to
|
if (temporary->update.invalidCounter >= temporary->update.max) {
|
||||||
// max element?
|
Serial.printf("%s{%d} invalid value update counter reached (%dx)! Setting its average value "
|
||||||
return false;
|
"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
|
// Reset invalid counter when update new valid value
|
||||||
|
@ -69,7 +69,7 @@ public:
|
|||||||
* @param val (int) the new value
|
* @param val (int) the new value
|
||||||
* @param ch (int) the MeasurementType channel, not every MeasurementType has more than 1 channel.
|
* @param ch (int) the MeasurementType channel, not every MeasurementType has more than 1 channel.
|
||||||
* Currently maximum channel is 2. Default: 1 (channel 1)
|
* Currently maximum channel is 2. Default: 1 (channel 1)
|
||||||
* @return false if new value invalid consecutively reach threshold
|
* @return false if new value invalid consecutively reach threshold (max period)
|
||||||
* @return true otherwise
|
* @return true otherwise
|
||||||
*/
|
*/
|
||||||
bool update(MeasurementType type, int val, int ch = 1);
|
bool update(MeasurementType type, int val, int ch = 1);
|
||||||
@ -83,7 +83,7 @@ public:
|
|||||||
* @param val (float) the new value
|
* @param val (float) the new value
|
||||||
* @param ch (int) the MeasurementType channel, not every MeasurementType has more than 1 channel.
|
* @param ch (int) the MeasurementType channel, not every MeasurementType has more than 1 channel.
|
||||||
* Currently maximum channel is 2. Default: 1 (channel 1)
|
* Currently maximum channel is 2. Default: 1 (channel 1)
|
||||||
* @return false if new value invalid consecutively reach threshold
|
* @return false if new value invalid consecutively reach threshold (max period)
|
||||||
* @return true otherwise
|
* @return true otherwise
|
||||||
*/
|
*/
|
||||||
bool update(MeasurementType type, float val, int ch = 1);
|
bool update(MeasurementType type, float val, int ch = 1);
|
||||||
|
Reference in New Issue
Block a user