mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-08-02 18:34:28 +02:00
Fix casting enum issue
Previously if algo is slr, it's always consider new update
This commit is contained in:
@@ -103,15 +103,18 @@ PMCorrectionAlgorithm Configuration::matchPmAlgorithm(String algorithm) {
|
|||||||
// Loop through all algorithm names in the PM_CORRECTION_ALGORITHM_NAMES array
|
// Loop through all algorithm names in the PM_CORRECTION_ALGORITHM_NAMES array
|
||||||
// If the input string matches an algorithm name, return the corresponding enum value
|
// If the input string matches an algorithm name, return the corresponding enum value
|
||||||
// Else return Unknown
|
// Else return Unknown
|
||||||
for (int idx = 0;
|
|
||||||
idx < sizeof(PM_CORRECTION_ALGORITHM_NAMES) / sizeof(PM_CORRECTION_ALGORITHM_NAMES[0]);
|
const size_t enumSize = SLR_PMS5003_20240104 + 1; // Get the actual size of the enum
|
||||||
idx++) {
|
PMCorrectionAlgorithm result = PMCorrectionAlgorithm::Unknown;
|
||||||
if (algorithm == PM_CORRECTION_ALGORITHM_NAMES[idx]) {
|
|
||||||
return (PMCorrectionAlgorithm)idx;
|
// Loop through enum values
|
||||||
|
for (size_t enumVal = 0; enumVal < enumSize; enumVal++) {
|
||||||
|
if (algorithm == PM_CORRECTION_ALGORITHM_NAMES[enumVal]) {
|
||||||
|
result = static_cast<PMCorrectionAlgorithm>(enumVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Unknown;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Configuration::updatePmCorrection(JSONVar &json) {
|
bool Configuration::updatePmCorrection(JSONVar &json) {
|
||||||
@@ -171,9 +174,13 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// arduino_json doesn't support float type, need to cast to double first
|
||||||
|
float intercept = (float)((double)slr["intercept"]);
|
||||||
|
float scalingFactor = (float)((double)slr["scalingFactor"]);
|
||||||
|
|
||||||
// Compare with current pmCorrection
|
// Compare with current pmCorrection
|
||||||
if (pmCorrection.algorithm == algo && pmCorrection.intercept == (double)slr["intercept"] &&
|
if (pmCorrection.algorithm == algo && pmCorrection.intercept == intercept &&
|
||||||
pmCorrection.scalingFactor == (double)slr["scalingFactor"] &&
|
pmCorrection.scalingFactor == scalingFactor &&
|
||||||
pmCorrection.useEPA == (bool)slr["useEpa2021"]) {
|
pmCorrection.useEPA == (bool)slr["useEpa2021"]) {
|
||||||
return false; // No changes needed
|
return false; // No changes needed
|
||||||
}
|
}
|
||||||
@@ -183,8 +190,8 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
|
|||||||
|
|
||||||
// Update pmCorrection with new values
|
// Update pmCorrection with new values
|
||||||
pmCorrection.algorithm = algo;
|
pmCorrection.algorithm = algo;
|
||||||
pmCorrection.intercept = (double)slr["intercept"];
|
pmCorrection.intercept = intercept;
|
||||||
pmCorrection.scalingFactor = (double)slr["scalingFactor"];
|
pmCorrection.scalingFactor = scalingFactor;
|
||||||
pmCorrection.useEPA = (bool)slr["useEpa2021"];
|
pmCorrection.useEPA = (bool)slr["useEpa2021"];
|
||||||
pmCorrection.changed = true;
|
pmCorrection.changed = true;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user