forked from airgradienthq/arduino
Apply pm correction to display and led bar
This commit is contained in:
@ -314,13 +314,11 @@ void OledDisplay::showDashboard(const char *status) {
|
||||
|
||||
/** Draw PM2.5 value */
|
||||
int pm25 = value.get(Measurements::PM25);
|
||||
if (utils::isValidPm(pm25)) {
|
||||
/** Compensate PM2.5 value. */
|
||||
if (config.hasSensorSHT && config.isMonitorDisplayCompensatedValues()) {
|
||||
pm25 = ag->pms5003.compensate(pm25, value.getFloat(Measurements::Humidity));
|
||||
logInfo("PM2.5 compensate: " + String(pm25));
|
||||
}
|
||||
if (config.hasSensorSHT && config.isPMCorrectionEnabled()) {
|
||||
pm25 = (int)value.getCorrectedPM25(*ag, config);
|
||||
}
|
||||
|
||||
if (utils::isValidPm(pm25)) {
|
||||
if (config.isPmStandardInUSAQI()) {
|
||||
sprintf(strBuf, "%d", ag->pms5003.convertPm25ToUsAqi(pm25));
|
||||
} else {
|
||||
|
@ -142,8 +142,8 @@ void StateMachine::co2handleLeds(void) {
|
||||
*/
|
||||
void StateMachine::pm25handleLeds(void) {
|
||||
int pm25Value = value.get(Measurements::PM25);
|
||||
if (config.isMonitorDisplayCompensatedValues() && config.hasSensorSHT) {
|
||||
pm25Value = ag->pms5003.compensate(pm25Value, value.getFloat(Measurements::Humidity));
|
||||
if (config.hasSensorSHT && config.isPMCorrectionEnabled()) {
|
||||
pm25Value = (int)value.getCorrectedPM25(*ag, config);
|
||||
}
|
||||
|
||||
if (pm25Value < 5) {
|
||||
|
@ -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;
|
||||
|
@ -114,6 +114,18 @@ public:
|
||||
*/
|
||||
float getFloat(MeasurementType type, int ch = 1);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the Corrected PM25 object based on the correction algorithm from configuration
|
||||
*
|
||||
* @param ag AirGradient instance
|
||||
* @param config Configuration instance
|
||||
* @param useAvg Use moving average value if true, otherwise use latest value
|
||||
* @param ch MeasurementType channel
|
||||
* @return float Corrected PM2.5 value
|
||||
*/
|
||||
float getCorrectedPM25(AirGradient &ag, Configuration &config, bool useAvg = false, int ch = 1);
|
||||
|
||||
/**
|
||||
* build json payload for every measurements
|
||||
*/
|
||||
|
Reference in New Issue
Block a user