@@ -25,12 +25,7 @@ const char *PM_CORRECTION_ALGORITHM_NAMES[] = {
25
25
[COR_ALGO_PM_UNKNOWN] = " -" , // This is only to pass "non-trivial designated initializers" error
26
26
[COR_ALGO_PM_NONE] = " none" ,
27
27
[COR_ALGO_PM_EPA_2021] = " epa_2021" ,
28
- [COR_ALGO_PM_PMS5003_20220802] = " slr_PMS5003_20220802" ,
29
- [COR_ALGO_PM_PMS5003_20220803] = " slr_PMS5003_20220803" ,
30
- [COR_ALGO_PM_PMS5003_20220824] = " slr_PMS5003_20220824" ,
31
- [COR_ALGO_PM_PMS5003_20231030] = " slr_PMS5003_20231030" ,
32
- [COR_ALGO_PM_PMS5003_20231218] = " slr_PMS5003_20231218" ,
33
- [COR_ALGO_PM_PMS5003_20240104] = " slr_PMS5003_20240104" ,
28
+ [COR_ALGO_PM_SLR_CUSTOM] = " custom" ,
34
29
};
35
30
36
31
const char *TEMP_HUM_CORRECTION_ALGORITHM_NAMES[] = {
@@ -115,7 +110,7 @@ PMCorrectionAlgorithm Configuration::matchPmAlgorithm(String algorithm) {
115
110
// If the input string matches an algorithm name, return the corresponding enum value
116
111
// Else return Unknown
117
112
118
- const size_t enumSize = COR_ALGO_PM_PMS5003_20240104 + 1 ; // Get the actual size of the enum
113
+ const size_t enumSize = COR_ALGO_PM_SLR_CUSTOM + 1 ; // Get the actual size of the enum
119
114
PMCorrectionAlgorithm result = COR_ALGO_PM_UNKNOWN;;
120
115
121
116
// Loop through enum values
@@ -125,6 +120,15 @@ PMCorrectionAlgorithm Configuration::matchPmAlgorithm(String algorithm) {
125
120
}
126
121
}
127
122
123
+ // If string not match from enum, check if correctionAlgorithm is one of the PM batch corrections
124
+ if (result == COR_ALGO_PM_UNKNOWN) {
125
+ // Check the substring "slr_PMS5003_xxxxxxxx"
126
+ if (algorithm.substring (0 , 11 ) == " slr_PMS5003" ) {
127
+ // If it is, then its a custom correction
128
+ result = COR_ALGO_PM_SLR_CUSTOM;
129
+ }
130
+ }
131
+
128
132
return result;
129
133
}
130
134
@@ -145,29 +149,27 @@ TempHumCorrectionAlgorithm Configuration::matchTempHumAlgorithm(String algorithm
145
149
146
150
bool Configuration::updatePmCorrection (JSONVar &json) {
147
151
if (!json.hasOwnProperty (" corrections" )) {
148
- Serial. println (" corrections not found" );
152
+ logInfo (" corrections not found" );
149
153
return false ;
150
154
}
151
155
152
156
JSONVar corrections = json[" corrections" ];
153
157
if (!corrections.hasOwnProperty (" pm02" )) {
154
- Serial. println (" pm02 not found" );
158
+ logWarning (" pm02 not found" );
155
159
return false ;
156
160
}
157
161
158
162
JSONVar pm02 = corrections[" pm02" ];
159
163
if (!pm02.hasOwnProperty (" correctionAlgorithm" )) {
160
- Serial. println ( " correctionAlgorithm not found" );
164
+ logWarning ( " pm02 correctionAlgorithm not found" );
161
165
return false ;
162
166
}
163
167
164
- // TODO: Need to have data type check, with error message response if invalid
165
-
166
168
// Check algorithm
167
169
String algorithm = pm02[" correctionAlgorithm" ];
168
170
PMCorrectionAlgorithm algo = matchPmAlgorithm (algorithm);
169
171
if (algo == COR_ALGO_PM_UNKNOWN) {
170
- logInfo (" Unknown algorithm" );
172
+ logWarning (" Unknown algorithm" );
171
173
return false ;
172
174
}
173
175
logInfo (" Correction algorithm: " + algorithm);
@@ -191,7 +193,7 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
191
193
192
194
// Check if pm02 has slr object
193
195
if (!pm02.hasOwnProperty (" slr" )) {
194
- Serial. println (" slr not found" );
196
+ logWarning (" slr not found" );
195
197
return false ;
196
198
}
197
199
@@ -200,7 +202,7 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
200
202
// Validate required slr properties exist
201
203
if (!slr.hasOwnProperty (" intercept" ) || !slr.hasOwnProperty (" scalingFactor" ) ||
202
204
!slr.hasOwnProperty (" useEpa2021" )) {
203
- Serial. println (" Missing required slr properties" );
205
+ logWarning (" Missing required slr properties" );
204
206
return false ;
205
207
}
206
208
0 commit comments