mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-30 17:07:16 +02:00
get and getFloat function specific for latest value
Update functions comments
This commit is contained in:
@ -198,7 +198,7 @@ bool Measurements::update(MeasurementType type, float val, int ch) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Measurements::get(MeasurementType type, bool average, int ch) {
|
int Measurements::get(MeasurementType type, int ch) {
|
||||||
// Sanity check to validate channel, assert if invalid
|
// Sanity check to validate channel, assert if invalid
|
||||||
validateChannel(ch);
|
validateChannel(ch);
|
||||||
|
|
||||||
@ -252,15 +252,10 @@ int Measurements::get(MeasurementType type, bool average, int ch) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (average) {
|
|
||||||
// TODO: This now is average value, need to update this
|
|
||||||
return temporary->update.avg;
|
|
||||||
}
|
|
||||||
|
|
||||||
return temporary->listValues.back();
|
return temporary->listValues.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
float Measurements::getFloat(MeasurementType type, bool average, int ch) {
|
float Measurements::getFloat(MeasurementType type, int ch) {
|
||||||
// Sanity check to validate channel, assert if invalid
|
// Sanity check to validate channel, assert if invalid
|
||||||
validateChannel(ch);
|
validateChannel(ch);
|
||||||
|
|
||||||
@ -292,10 +287,6 @@ float Measurements::getFloat(MeasurementType type, bool average, int ch) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (average) {
|
|
||||||
return temporary->update.avg;
|
|
||||||
}
|
|
||||||
|
|
||||||
return temporary->listValues.back();
|
return temporary->listValues.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ private:
|
|||||||
// Generic struct for update indication for respective value
|
// Generic struct for update indication for respective value
|
||||||
struct Update {
|
struct Update {
|
||||||
int invalidCounter; // Counting on how many invalid value that are passed to update function
|
int invalidCounter; // Counting on how many invalid value that are passed to update function
|
||||||
int max; // Maximum elements on the list
|
int max; // Maximum length of the period of the moving average
|
||||||
float avg; // Moving average value, updated every update function called
|
float avg; // Moving average value, updated every update function called
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -53,60 +53,58 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set each MeasurementType maximum update before calculate the average
|
* @brief Set each MeasurementType maximum period length for moving average
|
||||||
*
|
*
|
||||||
* @param type the target measurement type to set
|
* @param type the target measurement type to set
|
||||||
* @param max the maximum counter
|
* @param max the maximum period length
|
||||||
*/
|
*/
|
||||||
void maxUpdate(MeasurementType, int max);
|
void maxUpdate(MeasurementType, int max);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief update target measurement type with new value.
|
* @brief update target measurement type with new value.
|
||||||
* Each MeasurementType has last raw value and last average that are calculated based on max
|
* Each MeasurementType has last raw value and moving average value based on max period
|
||||||
* number of update. This function is for MeasurementType that use INT as the data type
|
* This function is for MeasurementType that use INT as the data type
|
||||||
*
|
*
|
||||||
* @param type measurement type that will be updated
|
* @param type measurement type that will be updated
|
||||||
* @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 true if update counter reached and new average value is calculated
|
* @return false if new value invalid consecutively reach threshold
|
||||||
* @return false otherwise
|
* @return true otherwise
|
||||||
*/
|
*/
|
||||||
bool update(MeasurementType type, int val, int ch = 1);
|
bool update(MeasurementType type, int val, int ch = 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief update target measurement type with new value.
|
* @brief update target measurement type with new value.
|
||||||
* Each MeasurementType has last raw value and last average that are calculated based on max
|
* Each MeasurementType has last raw value and moving average value based on max period
|
||||||
* number of update. This function is for MeasurementType that use FLOAT as the data type
|
* This function is for MeasurementType that use FLOAT as the data type
|
||||||
*
|
*
|
||||||
* @param type measurement type that will be updated
|
* @param type measurement type that will be updated
|
||||||
* @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 true if update counter reached and new average value is calculated
|
* @return false if new value invalid consecutively reach threshold
|
||||||
* @return false otherwise
|
* @return true otherwise
|
||||||
*/
|
*/
|
||||||
bool update(MeasurementType type, float val, int ch = 1);
|
bool update(MeasurementType type, float val, int ch = 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the target measurement type value
|
* @brief Get the target measurement latest value
|
||||||
*
|
*
|
||||||
* @param type measurement type that will be retrieve
|
* @param type measurement type that will be retrieve
|
||||||
* @param average true if expect last average value, false if expect last update value
|
|
||||||
* @param ch target type value channel
|
* @param ch target type value channel
|
||||||
* @return int measurement type value
|
* @return int measurement type value
|
||||||
*/
|
*/
|
||||||
int get(MeasurementType type, bool average = true, int ch = 1);
|
int get(MeasurementType type, int ch = 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the target measurement type value
|
* @brief Get the target measurement latest value
|
||||||
*
|
*
|
||||||
* @param type measurement type that will be retrieve
|
* @param type measurement type that will be retrieve
|
||||||
* @param average true if expect last average value, false if expect last update value
|
|
||||||
* @param ch target type value channel
|
* @param ch target type value channel
|
||||||
* @return float measurement type value
|
* @return float measurement type value
|
||||||
*/
|
*/
|
||||||
float getFloat(MeasurementType type, bool average = true, int ch = 1);
|
float getFloat(MeasurementType type, int ch = 1);
|
||||||
|
|
||||||
// TODO: update this to using setter
|
// TODO: update this to using setter
|
||||||
int bootCount;
|
int bootCount;
|
||||||
|
Reference in New Issue
Block a user