Fix pmcorrection member datatype

Log using printlog
Function to check if correction is not none
This commit is contained in:
samuelbles07
2024-11-02 14:40:35 +07:00
parent a98d77e0c3
commit 5867d0f1d5
2 changed files with 19 additions and 9 deletions

View File

@ -134,13 +134,13 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
} }
// Check algorithm // Check algorithm
const char *algorithm = (const char *)pm02["correctionAlgorithm"]; String algorithm = pm02["correctionAlgorithm"];
PMCorrectionAlgorithm algo = matchPmAlgorithm(algorithm); PMCorrectionAlgorithm algo = matchPmAlgorithm(algorithm);
if (algo == Unknown) { if (algo == Unknown) {
Serial.println("Unknown algorithm"); logInfo("Unknown algorithm");
return false; return false;
} }
Serial.printf("Correction algorithm: %s\n", algorithm); logInfo("Correction algorithm: " + algorithm);
// If algo is None or EPA_2021, no need to check slr // If algo is None or EPA_2021, no need to check slr
// But first check if pmCorrection different from algo // But first check if pmCorrection different from algo
@ -149,7 +149,7 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
jconfig[jprop_corrections]["pm02"]["correctionAlgorithm"] = algorithm; jconfig[jprop_corrections]["pm02"]["correctionAlgorithm"] = algorithm;
pmCorrection.algorithm = algo; pmCorrection.algorithm = algo;
pmCorrection.changed = true; pmCorrection.changed = true;
Serial.println("PM2.5 correction updated"); logInfo("PM2.5 correction updated");
return true; return true;
} }
@ -180,7 +180,6 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
// Deep copy corrections from root to jconfig, so it will be saved later // Deep copy corrections from root to jconfig, so it will be saved later
jconfig[jprop_corrections] = corrections; jconfig[jprop_corrections] = corrections;
Serial.println("Correction copied");
// Update pmCorrection with new values // Update pmCorrection with new values
pmCorrection.algorithm = algo; pmCorrection.algorithm = algo;
@ -190,7 +189,7 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
pmCorrection.changed = true; pmCorrection.changed = true;
// Correction values were updated // Correction values were updated
Serial.println("PM2.5 correction updated"); logInfo("PM2.5 correction updated");
return true; return true;
} }
@ -1351,6 +1350,16 @@ bool Configuration::isPMCorrectionChanged(void) {
return changed; return changed;
} }
PMCorrection Configuration::getPMCorrection(void) { /**
* @brief Check if PM correction is enabled
*
* @return true if PM correction algorithm is not None, otherwise false
*/
bool Configuration::isPMCorrectionEnabled(void) {
PMCorrection pmCorrection = getPMCorrection();
return pmCorrection.algorithm != PMCorrectionAlgorithm::None;
}
Configuration::PMCorrection Configuration::getPMCorrection(void) {
return pmCorrection; return pmCorrection;
} }

View File

@ -11,8 +11,8 @@ class Configuration : public PrintLog {
public: public:
struct PMCorrection { struct PMCorrection {
PMCorrectionAlgorithm algorithm; PMCorrectionAlgorithm algorithm;
int intercept; float intercept;
int scalingFactor; float scalingFactor;
bool useEPA; // EPA 2021 bool useEPA; // EPA 2021
bool changed; bool changed;
}; };
@ -97,6 +97,7 @@ public:
bool isLedBarModeChanged(void); bool isLedBarModeChanged(void);
bool isMonitorDisplayCompensatedValues(void); bool isMonitorDisplayCompensatedValues(void);
bool isPMCorrectionChanged(void); bool isPMCorrectionChanged(void);
bool isPMCorrectionEnabled(void);
PMCorrection getPMCorrection(void); PMCorrection getPMCorrection(void);
}; };