Skip to content

Commit

Permalink
New function to set max update before averaging
Browse files Browse the repository at this point in the history
Rename enum member
  • Loading branch information
samuelbles07 committed Oct 11, 2024
1 parent 467b3e8 commit ea91cf9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
42 changes: 39 additions & 3 deletions src/AgValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 11 additions & 5 deletions src/AgValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ea91cf9

Please sign in to comment.