diff --git a/src/AgValue.cpp b/src/AgValue.cpp index 961c65b..0190852 100644 --- a/src/AgValue.cpp +++ b/src/AgValue.cpp @@ -5,7 +5,43 @@ #define json_prop_pmFirmware "firmware" -void Measurements::init() {} +void Measurements::maxUpdate(AgValueType type, int max) { + switch (type) { + case AgValueType::Temperature: + _temperature.update.max = max; + break; + case AgValueType::Humidity: + _humidity.update.max = max; + break; + case AgValueType::CO2: + _co2.update.max = max; + break; + case AgValueType::TVOC: + _tvoc.update.max = max; + break; + case AgValueType::TVOCRaw: + _tvoc_raw.update.max = max; + break; + case AgValueType::NOx: + _nox.update.max = max; + break; + case AgValueType::NOxRaw: + _nox_raw.update.max = max; + break; + case AgValueType::PM25: + _pm_25.update.max = max; + break; + case AgValueType::PM01: + _pm_01.update.max = max; + break; + case AgValueType::PM10: + _pm_10.update.max = max; + break; + case AgValueType::PM03_PC: + _pm_03_pc.update.max = max; + break; + }; +} bool Measurements::updateValue(AgValueType type, int val) { // Define data point source @@ -44,7 +80,7 @@ bool Measurements::updateValue(AgValueType type, int val) { temporary = &_pm_10; invalidValue = utils::getInvalidPmValue(); break; - case AgValueType::PM03: + case AgValueType::PM03_PC: temporary = &_pm_03_pc; invalidValue = utils::getInvalidPmValue(); break; @@ -568,7 +604,7 @@ String Measurements::agValueTypeStr(AgValueType type) { case AgValueType::PM10: str = "PM10"; break; - case AgValueType::PM03: + case AgValueType::PM03_PC: str = "PM03"; break; default: diff --git a/src/AgValue.h b/src/AgValue.h index 56fc38a..225c041 100644 --- a/src/AgValue.h +++ b/src/AgValue.h @@ -11,7 +11,7 @@ class Measurements { struct Update { int counter; // How many update attempts done int success; // How many update value that actually give valid value - int max; // Maximum update before calculating average + int max; // Maximum update counter before calculating average }; // Reading type for sensor value that outputs float @@ -68,15 +68,21 @@ class Measurements { PM25, PM01, PM10, - PM03, + PM03_PC, }; - void init(); + /** + * @brief Set each AgValueType maximum update for a value type before calculate the average + * + * @param type the target value type to set + * @param max the maximum counter + */ + void maxUpdate(AgValueType type, int max); /** * @brief update target type value with new value. * Each AgValueType has last raw value and last average that are calculated based on max number of - * set This function is for AgValueType that use INT as the data type + * update. This function is for AgValueType that use INT as the data type * * @param type (AgValueType) value type that will be updated * @param val (int) the new value @@ -88,7 +94,7 @@ class Measurements { /** * @brief update target type value with new value. * Each AgValueType has last raw value and last average that are calculated based on max number of - * set This function is for AgValueType that use FLOAT as the data type + * update. This function is for AgValueType that use FLOAT as the data type * * @param type (AgValueType) value type that will be updated * @param val (float) the new value