mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-30 17:07:16 +02:00
validate measurement type channel
This commit is contained in:
@ -50,12 +50,8 @@ void Measurements::maxUpdate(AgValueType type, int max) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Measurements::updateValue(AgValueType type, int val, int ch) {
|
bool Measurements::updateValue(AgValueType type, int val, int ch) {
|
||||||
// Validate channel
|
// Sanity check to validate channel, assert if invalid
|
||||||
if (ch != 1 || ch != 2) {
|
validateChannel(ch);
|
||||||
Serial.printf(" Channel %d is undefined. Only channel 1 or 2 is the optional value!", ch);
|
|
||||||
// TODO: Perhaps just do assert
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Follow array indexing just for get address of the value type
|
// Follow array indexing just for get address of the value type
|
||||||
ch = ch - 1;
|
ch = ch - 1;
|
||||||
@ -150,12 +146,8 @@ bool Measurements::updateValue(AgValueType type, int val, int ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Measurements::updateValue(AgValueType type, float val, int ch) {
|
bool Measurements::updateValue(AgValueType type, float val, int ch) {
|
||||||
// Validate channel
|
// Sanity check to validate channel, assert if invalid
|
||||||
if (ch != 1 || ch != 2) {
|
validateChannel(ch);
|
||||||
Serial.printf(" Channel %d is undefined. Only channel 1 or 2 is the optional value!", ch);
|
|
||||||
// TODO: Perhaps just do assert
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Follow array indexing just for get address of the value type
|
// Follow array indexing just for get address of the value type
|
||||||
ch = ch - 1;
|
ch = ch - 1;
|
||||||
@ -222,6 +214,9 @@ bool Measurements::updateValue(AgValueType type, float val, int ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Measurements::getValue(AgValueType type, bool average, int ch) {
|
int Measurements::getValue(AgValueType type, bool average, int ch) {
|
||||||
|
// Sanity check to validate channel, assert if invalid
|
||||||
|
validateChannel(ch);
|
||||||
|
|
||||||
// Follow array indexing just for get address of the value type
|
// Follow array indexing just for get address of the value type
|
||||||
ch = ch - 1;
|
ch = ch - 1;
|
||||||
|
|
||||||
@ -275,6 +270,9 @@ int Measurements::getValue(AgValueType type, bool average, int ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float Measurements::getValueFloat(AgValueType type, bool average, int ch) {
|
float Measurements::getValueFloat(AgValueType type, bool average, int ch) {
|
||||||
|
// Sanity check to validate channel, assert if invalid
|
||||||
|
validateChannel(ch);
|
||||||
|
|
||||||
// Define data point source
|
// Define data point source
|
||||||
FloatValue *temporary = nullptr;
|
FloatValue *temporary = nullptr;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -208,6 +208,12 @@ private:
|
|||||||
* Convert AgValue Type to string representation of the value
|
* Convert AgValue Type to string representation of the value
|
||||||
*/
|
*/
|
||||||
String agValueTypeStr(AgValueType type);
|
String agValueTypeStr(AgValueType type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief check if provided channel is a valid channel or not
|
||||||
|
* abort program if invalid
|
||||||
|
*/
|
||||||
|
void validateChannel(int ch);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /** _AG_VALUE_H_ */
|
#endif /** _AG_VALUE_H_ */
|
||||||
|
Reference in New Issue
Block a user