Apply pm correction to display and led bar

This commit is contained in:
samuelbles07
2024-11-02 14:44:32 +07:00
parent 5867d0f1d5
commit 7b0381dea3
4 changed files with 51 additions and 8 deletions
+33
View File
@@ -1,6 +1,7 @@
#include "AgValue.h"
#include "AgConfigure.h"
#include "AirGradient.h"
#include "App/AppDef.h"
#define json_prop_pmFirmware "firmware"
#define json_prop_pm01Ae "pm01"
@@ -482,6 +483,38 @@ void Measurements::validateChannel(int ch) {
}
}
float Measurements::getCorrectedPM25(AirGradient &ag, Configuration &config, bool useAvg, int ch) {
float pm25;
float humidity;
float pm003Count;
int channel = ch - 1; // Array index
if (useAvg) {
// Directly call from the index
pm25 = _pm_25[channel].update.avg;
humidity = _humidity[channel].update.avg;
pm003Count = _pm_03_pc[channel].update.avg;
} else {
pm25 = get(PM25, ch);
humidity = getFloat(Humidity, ch);
pm003Count = get(PM03_PC, ch);
}
Configuration::PMCorrection pmCorrection = config.getPMCorrection();
if (pmCorrection.algorithm == PMCorrectionAlgorithm::EPA_2021) {
// EPA correction directly applied
pm25 = ag.pms5003.compensate(pm25, humidity);
} else {
// SLR correction, this is assumes before calling this function, correction algorithm is not None
pm25 = ag.pms5003.slrCorrection(pm25, pm003Count, pmCorrection.scalingFactor, pmCorrection.intercept);
if (pmCorrection.useEPA) {
// Add EPA compensation on top of SLR
pm25 = ag.pms5003.compensate(pm25, humidity);
}
}
return pm25;
}
String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi, AirGradient &ag,
Configuration &config) {
JSONVar root;