mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-16 02:02:11 +02:00
Merge branch 'develop' of https://github.com/airgradienthq/arduino into develop
This commit is contained in:
@ -90,6 +90,7 @@ void Configuration::loadConfig(void) {
|
||||
logError("Configure validate invalid");
|
||||
defaultConfig();
|
||||
} else {
|
||||
/** Correct configuration parameter value. */
|
||||
bool changed = false;
|
||||
if ((config.temperatureUnit != 'c') && (config.temperatureUnit != 'f')) {
|
||||
config.temperatureUnit = 'c';
|
||||
@ -126,7 +127,7 @@ void Configuration::defaultConfig(void) {
|
||||
config.postDataToAirGradient = true;
|
||||
config.displayMode = true;
|
||||
config.useRGBLedBar = LedBarMode::LedBarModeCO2;
|
||||
config.abcDays = 7;
|
||||
config.abcDays = 8;
|
||||
config.tvocLearningOffset = 12;
|
||||
config.noxLearningOffset = 12;
|
||||
config.temperatureUnit = 'c';
|
||||
@ -178,6 +179,8 @@ bool Configuration::begin(void) {
|
||||
* @return false Failure
|
||||
*/
|
||||
bool Configuration::parse(String data, bool isLocal) {
|
||||
logInfo("Parse configure: " + data);
|
||||
|
||||
JSONVar root = JSON.parse(data);
|
||||
failedMessage = "";
|
||||
if (JSON.typeof_(root) == "undefined") {
|
||||
@ -192,32 +195,37 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
|
||||
/** Get ConfigurationControl */
|
||||
if (isLocal) {
|
||||
uint8_t configurationControl = config.configurationControl;
|
||||
if (JSON.typeof_(root["configurationControl"]) == "string") {
|
||||
String configurationControl = root["configurationControl"];
|
||||
if (configurationControl ==
|
||||
String(CONFIGURATION_CONTROL_NAME
|
||||
[ConfigurationControl::ConfigurationControlLocal])) {
|
||||
config.configurationControl =
|
||||
(uint8_t)ConfigurationControl::ConfigurationControlLocal;
|
||||
changed = true;
|
||||
} else if (configurationControl ==
|
||||
String(
|
||||
CONFIGURATION_CONTROL_NAME
|
||||
[ConfigurationControl::ConfigurationControlCloud])) {
|
||||
config.configurationControl =
|
||||
(uint8_t)ConfigurationControl::ConfigurationControlCloud;
|
||||
changed = true;
|
||||
} else if (configurationControl ==
|
||||
String(CONFIGURATION_CONTROL_NAME
|
||||
[ConfigurationControl::ConfigurationControlBoth])) {
|
||||
config.configurationControl =
|
||||
(uint8_t)ConfigurationControl::ConfigurationControlBoth;
|
||||
changed = true;
|
||||
} else {
|
||||
failedMessage = jsonValueInvalidMessage("configurationControl",
|
||||
configurationControl);
|
||||
jsonInvalid();
|
||||
return false;
|
||||
if (configurationControl !=
|
||||
String(CONFIGURATION_CONTROL_NAME[config.configurationControl])) {
|
||||
if (configurationControl ==
|
||||
String(CONFIGURATION_CONTROL_NAME
|
||||
[ConfigurationControl::ConfigurationControlLocal])) {
|
||||
config.configurationControl =
|
||||
(uint8_t)ConfigurationControl::ConfigurationControlLocal;
|
||||
changed = true;
|
||||
} else if (configurationControl ==
|
||||
String(
|
||||
CONFIGURATION_CONTROL_NAME
|
||||
[ConfigurationControl::ConfigurationControlCloud])) {
|
||||
config.configurationControl =
|
||||
(uint8_t)ConfigurationControl::ConfigurationControlCloud;
|
||||
changed = true;
|
||||
} else if (configurationControl ==
|
||||
String(
|
||||
CONFIGURATION_CONTROL_NAME
|
||||
[ConfigurationControl::ConfigurationControlBoth])) {
|
||||
config.configurationControl =
|
||||
(uint8_t)ConfigurationControl::ConfigurationControlBoth;
|
||||
changed = true;
|
||||
} else {
|
||||
failedMessage = jsonValueInvalidMessage("configurationControl",
|
||||
configurationControl);
|
||||
jsonInvalid();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["configurationControl"], "string")) {
|
||||
@ -228,6 +236,15 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
changed = false;
|
||||
saveConfig();
|
||||
configLogInfo(
|
||||
"configurationControl",
|
||||
String(CONFIGURATION_CONTROL_NAME[configurationControl]),
|
||||
String(CONFIGURATION_CONTROL_NAME[config.configurationControl]));
|
||||
}
|
||||
|
||||
if ((config.configurationControl ==
|
||||
(byte)ConfigurationControl::ConfigurationControlCloud)) {
|
||||
failedMessage = "Local configure ignored";
|
||||
@ -249,17 +266,8 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
if (country.length() == 2) {
|
||||
if (country != String(config.country)) {
|
||||
changed = true;
|
||||
configLogInfo("country", String(config.country), country);
|
||||
snprintf(config.country, sizeof(config.country), country.c_str());
|
||||
logInfo(String("Set country: " + country).c_str());
|
||||
}
|
||||
|
||||
// Update temperature unit if get configuration from server
|
||||
if (isLocal == false) {
|
||||
if (country == "US") {
|
||||
temperatureUnit = 'f';
|
||||
} else {
|
||||
temperatureUnit = 'c';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
failedMessage = "Country name " + country +
|
||||
@ -279,9 +287,9 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
if (JSON.typeof_(root["pmStandard"]) == "string") {
|
||||
String pmStandard = root["pmStandard"];
|
||||
bool inUSAQI = true;
|
||||
if (pmStandard == "ugm3") {
|
||||
if (pmStandard == getPMStandardString(false)) {
|
||||
inUSAQI = false;
|
||||
} else if (pmStandard == "us-aqi") {
|
||||
} else if (pmStandard == getPMStandardString(true)) {
|
||||
inUSAQI = true;
|
||||
} else {
|
||||
failedMessage = jsonValueInvalidMessage("pmStandard", pmStandard);
|
||||
@ -290,9 +298,9 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
}
|
||||
|
||||
if (inUSAQI != config.inUSAQI) {
|
||||
configLogInfo("pmStandard", getPMStandardString(config.inUSAQI), pmStandard);
|
||||
config.inUSAQI = inUSAQI;
|
||||
changed = true;
|
||||
logInfo("Set PM standard: " + pmStandard);
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["pmStandard"], "string")) {
|
||||
@ -304,7 +312,10 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
|
||||
if (JSON.typeof_(root["co2CalibrationRequested"]) == "boolean") {
|
||||
co2CalibrationRequested = root["co2CalibrationRequested"];
|
||||
logInfo("Set co2CalibrationRequested: " + String(co2CalibrationRequested));
|
||||
if(co2CalibrationRequested) {
|
||||
logInfo("co2CalibrationRequested: " +
|
||||
String(co2CalibrationRequested ? "True" : "False"));
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["co2CalibrationRequested"], "boolean")) {
|
||||
failedMessage =
|
||||
@ -316,7 +327,10 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
|
||||
if (JSON.typeof_(root["ledBarTestRequested"]) == "boolean") {
|
||||
ledBarTestRequested = root["ledBarTestRequested"];
|
||||
logInfo("Set ledBarTestRequested: " + String(ledBarTestRequested));
|
||||
if(ledBarTestRequested){
|
||||
logInfo("ledBarTestRequested: " +
|
||||
String(ledBarTestRequested ? "True" : "False"));
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["ledBarTestRequested"], "boolean")) {
|
||||
failedMessage = jsonTypeInvalidMessage("ledBarTestRequested", "boolean");
|
||||
@ -341,9 +355,11 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
}
|
||||
|
||||
if (ledBarMode != config.useRGBLedBar) {
|
||||
configLogInfo("useRGBLedBar",
|
||||
String(LED_BAR_MODE_NAMES[config.useRGBLedBar]),
|
||||
String(LED_BAR_MODE_NAMES[ledBarMode]));
|
||||
config.useRGBLedBar = ledBarMode;
|
||||
changed = true;
|
||||
logInfo("Set ledBarMode: " + mode);
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["ledBarMode"], "string")) {
|
||||
@ -356,9 +372,9 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
if (JSON.typeof_(root["displayMode"]) == "string") {
|
||||
String mode = root["displayMode"];
|
||||
bool displayMode = false;
|
||||
if (mode == "on") {
|
||||
if (mode == getDisplayModeString(true)) {
|
||||
displayMode = true;
|
||||
} else if (mode == "off") {
|
||||
} else if (mode == getDisplayModeString(false)) {
|
||||
displayMode = false;
|
||||
} else {
|
||||
failedMessage = jsonTypeInvalidMessage("displayMode", mode);
|
||||
@ -368,8 +384,8 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
|
||||
if (displayMode != config.displayMode) {
|
||||
changed = true;
|
||||
configLogInfo("displayMode", getDisplayModeString(config.displayMode), mode);
|
||||
config.displayMode = displayMode;
|
||||
logInfo("Set displayMode: " + mode);
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["displayMode"], "string")) {
|
||||
@ -382,14 +398,14 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
if (JSON.typeof_(root["abcDays"]) == "number") {
|
||||
int abcDays = root["abcDays"];
|
||||
if (abcDays <= 0) {
|
||||
failedMessage = jsonTypeInvalidMessage("abcDaysabcDays", String(abcDays));
|
||||
jsonInvalid();
|
||||
return false;
|
||||
abcDays = 0;
|
||||
}
|
||||
if (abcDays != config.abcDays) {
|
||||
logInfo("Set abcDays: " + String(abcDays));
|
||||
configLogInfo("abcDays", getAbcDayString(config.abcDays),
|
||||
String(getAbcDayString(abcDays)));
|
||||
config.abcDays = abcDays;
|
||||
changed = true;
|
||||
logInfo("Set abcDays: " + String(abcDays));
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["abcDays"], "number")) {
|
||||
@ -399,13 +415,15 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
}
|
||||
}
|
||||
|
||||
_tvocLearningOffsetChanged = false;
|
||||
if (JSON.typeof_(root["tvocLearningOffset"]) == "number") {
|
||||
int tvocLearningOffset = root["tvocLearningOffset"];
|
||||
if (tvocLearningOffset != config.tvocLearningOffset) {
|
||||
changed = true;
|
||||
_tvocLearningOffsetChanged = true;
|
||||
configLogInfo("tvocLearningOffset", String(config.tvocLearningOffset),
|
||||
String(tvocLearningOffset));
|
||||
config.tvocLearningOffset = tvocLearningOffset;
|
||||
logInfo("Set tvocLearningOffset: " + String(tvocLearningOffset));
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["tvocLearningOffset"], "number")) {
|
||||
@ -415,13 +433,15 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
}
|
||||
}
|
||||
|
||||
_noxLearnOffsetChanged = false;
|
||||
if (JSON.typeof_(root["noxLearningOffset"]) == "number") {
|
||||
int noxLearningOffset = root["noxLearningOffset"];
|
||||
if (noxLearningOffset != config.noxLearningOffset) {
|
||||
changed = true;
|
||||
_noxLearnOffsetChanged = true;
|
||||
configLogInfo("noxLearningOffset", String(config.noxLearningOffset),
|
||||
String(noxLearningOffset));
|
||||
config.noxLearningOffset = noxLearningOffset;
|
||||
logInfo("Set noxLearningOffset: " + String(noxLearningOffset));
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["noxLearningOffset"], "number")) {
|
||||
@ -436,8 +456,8 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
if (broker.length() < sizeof(config.mqttBroker)) {
|
||||
if (broker != String(config.mqttBroker)) {
|
||||
changed = true;
|
||||
configLogInfo("mqttBrokerUrl", String(config.mqttBroker), broker);
|
||||
snprintf(config.mqttBroker, sizeof(config.mqttBroker), broker.c_str());
|
||||
logInfo("Set mqttBrokerUrl: " + broker);
|
||||
}
|
||||
} else {
|
||||
failedMessage =
|
||||
@ -456,9 +476,9 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
if (JSON.typeof_(root["temperatureUnit"]) == "string") {
|
||||
String unit = root["temperatureUnit"];
|
||||
unit.toLowerCase();
|
||||
if (unit == "c") {
|
||||
if ((unit == "c") || (unit == "celsius")) {
|
||||
temperatureUnit = 'c';
|
||||
} else if (unit == "f") {
|
||||
} else if ((unit == "f") || (unit == "fahrenheit")) {
|
||||
temperatureUnit = 'f';
|
||||
} else {
|
||||
failedMessage = "'temperatureUnit' value '" + unit + "' invalid";
|
||||
@ -475,23 +495,28 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
|
||||
if (temperatureUnit != 0 && temperatureUnit != config.temperatureUnit) {
|
||||
changed = true;
|
||||
configLogInfo("temperatureUnit", String(config.temperatureUnit),
|
||||
String(temperatureUnit));
|
||||
config.temperatureUnit = temperatureUnit;
|
||||
logInfo("set temperatureUnit: " + String(temperatureUnit));
|
||||
}
|
||||
|
||||
if (JSON.typeof_(root["postDataToAirGradient"]) == "boolean") {
|
||||
bool post = root["postDataToAirGradient"];
|
||||
if (post != config.postDataToAirGradient) {
|
||||
changed = true;
|
||||
config.postDataToAirGradient = post;
|
||||
logInfo("Set postDataToAirGradient: " + String(post));
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["postDataToAirGradient"], "boolean")) {
|
||||
failedMessage =
|
||||
jsonTypeInvalidMessage("postDataToAirGradient", "boolean");
|
||||
jsonInvalid();
|
||||
return false;
|
||||
if (isLocal) {
|
||||
if (JSON.typeof_(root["postDataToAirGradient"]) == "boolean") {
|
||||
bool post = root["postDataToAirGradient"];
|
||||
if (post != config.postDataToAirGradient) {
|
||||
changed = true;
|
||||
configLogInfo("postDataToAirGradient",
|
||||
String(config.postDataToAirGradient ? "true" : "false"),
|
||||
String(post ? "true" : "false"));
|
||||
config.postDataToAirGradient = post;
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["postDataToAirGradient"], "boolean")) {
|
||||
failedMessage =
|
||||
jsonTypeInvalidMessage("postDataToAirGradient", "boolean");
|
||||
jsonInvalid();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -502,6 +527,7 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
if (model.length() < sizeof(config.model)) {
|
||||
if (model != String(config.model)) {
|
||||
changed = true;
|
||||
configLogInfo("model", String(config.model), model);
|
||||
snprintf(config.model, sizeof(config.model), model.c_str());
|
||||
}
|
||||
} else {
|
||||
@ -522,8 +548,13 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
if (changed) {
|
||||
udpated = true;
|
||||
saveConfig();
|
||||
printConfig();
|
||||
} else {
|
||||
logInfo("Nothing changed ignore udpate");
|
||||
if (ledBarTestRequested || co2CalibrationRequested) {
|
||||
udpated = true;
|
||||
}
|
||||
}
|
||||
printConfig();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -539,11 +570,7 @@ String Configuration::toString(void) {
|
||||
root["country"] = String(config.country);
|
||||
|
||||
/** "pmStandard" */
|
||||
if (config.inUSAQI) {
|
||||
root["pmStandard"] = "us-aqi";
|
||||
} else {
|
||||
root["pmStandard"] = "ugm3";
|
||||
}
|
||||
root["pmStandard"] = getPMStandardString(config.inUSAQI);
|
||||
|
||||
/** co2CalibrationRequested */
|
||||
/** ledBarTestRequested */
|
||||
@ -730,6 +757,33 @@ void Configuration::jsonInvalid(void) {
|
||||
logError(failedMessage);
|
||||
}
|
||||
|
||||
void Configuration::configLogInfo(String name, String fromValue,
|
||||
String toValue) {
|
||||
logInfo(String("Setting '") + name + String("' from '") + fromValue +
|
||||
String("' to '") + toValue + String("'"));
|
||||
}
|
||||
|
||||
String Configuration::getPMStandardString(bool usaqi) {
|
||||
if (usaqi) {
|
||||
return "us-aqi";
|
||||
}
|
||||
return "ugm3";
|
||||
}
|
||||
|
||||
String Configuration::getDisplayModeString(bool dispMode) {
|
||||
if(dispMode){
|
||||
return String("on");
|
||||
}
|
||||
return String("off");
|
||||
}
|
||||
|
||||
String Configuration::getAbcDayString(int value) {
|
||||
if(value <= 0){
|
||||
return String("off");
|
||||
}
|
||||
return String(value);
|
||||
}
|
||||
|
||||
String Configuration::getFailedMesage(void) { return failedMessage; }
|
||||
|
||||
void Configuration::setPostToAirGradient(bool enable) {
|
||||
|
@ -44,6 +44,10 @@ private:
|
||||
String jsonTypeInvalidMessage(String name, String type);
|
||||
String jsonValueInvalidMessage(String name, String value);
|
||||
void jsonInvalid(void);
|
||||
void configLogInfo(String name, String fromValue, String toValue);
|
||||
String getPMStandardString(bool usaqi);
|
||||
String getDisplayModeString(bool dispMode);
|
||||
String getAbcDayString(int value);
|
||||
|
||||
public:
|
||||
Configuration(Stream &debugLog);
|
||||
|
@ -276,22 +276,24 @@ void StateMachine::co2Calibration(void) {
|
||||
}
|
||||
}
|
||||
|
||||
if (config.getCO2CalibrationAbcDays() > 0 && config.hasSensorS8) {
|
||||
if (config.getCO2CalibrationAbcDays() >= 0 && config.hasSensorS8) {
|
||||
int newHour = config.getCO2CalibrationAbcDays() * 24;
|
||||
logInfo("Requested abcDays setting: " +
|
||||
String(config.getCO2CalibrationAbcDays()) + "days (" +
|
||||
String(newHour) + "hours)");
|
||||
int curHour = ag->s8.getAbcPeriod();
|
||||
logInfo("Current S8 abcDays setting: " + String(curHour) + "(hours)");
|
||||
if (curHour == newHour) {
|
||||
logInfo("'abcDays' unchanged");
|
||||
} else {
|
||||
if (ag->s8.setAbcPeriod(config.getCO2CalibrationAbcDays() * 24) ==
|
||||
false) {
|
||||
logError("Set S8 abcDays period failed");
|
||||
} else {
|
||||
logInfo("Set S8 abcDays period success");
|
||||
if (curHour != newHour) {
|
||||
String resultStr = "failure";
|
||||
if (ag->s8.setAbcPeriod(config.getCO2CalibrationAbcDays() * 24)) {
|
||||
resultStr = "successful";
|
||||
}
|
||||
String fromStr = String(curHour/24) + " days";
|
||||
if(curHour == 0){
|
||||
fromStr = "off";
|
||||
}
|
||||
String toStr = String(config.getCO2CalibrationAbcDays()) + " days";
|
||||
if(config.getCO2CalibrationAbcDays() == 0) {
|
||||
toStr = "off";
|
||||
}
|
||||
String msg = "Setting S8 from " + fromStr + " to " + toStr + " " + resultStr;
|
||||
logInfo(msg);
|
||||
}
|
||||
} else {
|
||||
logWarning("CO2 S8 not available, set 'abcDays' ignored");
|
||||
|
@ -46,6 +46,7 @@ bool WifiConnector::connect(void) {
|
||||
}
|
||||
|
||||
WIFI()->setConfigPortalBlocking(false);
|
||||
WIFI()->setConnectTimeout(15);
|
||||
WIFI()->setTimeout(WIFI_CONNECT_COUNTDOWN_MAX);
|
||||
|
||||
#ifdef ESP32
|
||||
@ -148,9 +149,15 @@ bool WifiConnector::connect(void) {
|
||||
hasConfig = true;
|
||||
logInfo("WiFi Connected: " + WiFi.SSID() + " IP: " + localIpStr());
|
||||
|
||||
String result = String(postToAg.getValue());
|
||||
logInfo("Post to AirGradient Configure: " + result);
|
||||
config.setPostToAirGradient(result != "T");
|
||||
if (hasPortalConfig) {
|
||||
String result = String(postToAg.getValue());
|
||||
logInfo("Setting postToAirGradient set from " +
|
||||
String(config.isPostDataToAirGradient() ? "True" : "False") +
|
||||
String(" to ") + String(result != "T" ? "True" : "False") +
|
||||
String(" successful"));
|
||||
config.setPostToAirGradient(result != "T");
|
||||
}
|
||||
hasPortalConfig = false;
|
||||
}
|
||||
#else
|
||||
_wifiProcess();
|
||||
@ -226,6 +233,7 @@ void WifiConnector::_wifiSaveParamCallback(void) {
|
||||
sm.ledAnimationInit();
|
||||
sm.handleLeds(AgStateMachineWiFiManagerStaConnecting);
|
||||
sm.setDisplayState(AgStateMachineWiFiManagerStaConnecting);
|
||||
hasPortalConfig = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,6 +23,7 @@ private:
|
||||
void *wifi = NULL;
|
||||
bool hasConfig;
|
||||
uint32_t lastRetry;
|
||||
bool hasPortalConfig = false;
|
||||
|
||||
bool wifiClientConnected(void);
|
||||
|
||||
|
@ -202,18 +202,3 @@ void PMS5003T::handle(void) { pms.handle(); }
|
||||
*/
|
||||
bool PMS5003T::isFailed(void) { return pms.isFailed(); }
|
||||
|
||||
float PMS5003T::temperatureCompensated(float temp) {
|
||||
if (temp < 10.0f) {
|
||||
return temp * 1.327f - 6.738f;
|
||||
}
|
||||
return temp * 1.181f - 5.113f;
|
||||
}
|
||||
|
||||
float PMS5003T::humidityCompensated(float hum) {
|
||||
hum = hum * 1.259f + 7.34f;
|
||||
|
||||
if (hum > 100.0f) {
|
||||
hum = 100.0f;
|
||||
}
|
||||
return hum;
|
||||
}
|
||||
|
@ -3,13 +3,14 @@
|
||||
|
||||
#include "../Main/BoardDef.h"
|
||||
#include "PMS.h"
|
||||
#include "PMS5003TBase.h"
|
||||
#include "Stream.h"
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
/**
|
||||
* @brief The class define how to handle PMS5003T sensor bas on @ref PMS class
|
||||
*/
|
||||
class PMS5003T {
|
||||
class PMS5003T: public PMS5003TBase {
|
||||
public:
|
||||
PMS5003T(BoardType def);
|
||||
#if defined(ESP8266)
|
||||
@ -28,8 +29,6 @@ public:
|
||||
int convertPm25ToUsAqi(int pm25);
|
||||
float getTemperature(void);
|
||||
float getRelativeHumidity(void);
|
||||
float temperatureCompensated(float temp);
|
||||
float humidityCompensated(float hum);
|
||||
|
||||
private:
|
||||
bool _isBegin = false;
|
||||
|
21
src/PMS/PMS5003TBase.cpp
Normal file
21
src/PMS/PMS5003TBase.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "PMS5003TBase.h"
|
||||
|
||||
PMS5003TBase::PMS5003TBase() {}
|
||||
|
||||
PMS5003TBase::~PMS5003TBase() {}
|
||||
|
||||
float PMS5003TBase::temperatureCompensated(float temp) {
|
||||
if (temp < 10.0f) {
|
||||
return temp * 1.327f - 6.738f;
|
||||
}
|
||||
return temp * 1.181f - 5.113f;
|
||||
}
|
||||
|
||||
float PMS5003TBase::humidityCompensated(float hum) {
|
||||
hum = hum * 1.259f + 7.34f;
|
||||
|
||||
if (hum > 100.0f) {
|
||||
hum = 100.0f;
|
||||
}
|
||||
return hum;
|
||||
}
|
15
src/PMS/PMS5003TBase.h
Normal file
15
src/PMS/PMS5003TBase.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef _PMS5003T_BASE_H_
|
||||
#define _PMS5003T_BASE_H_
|
||||
|
||||
class PMS5003TBase
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
PMS5003TBase();
|
||||
~PMS5003TBase();
|
||||
float temperatureCompensated(float temp);
|
||||
float humidityCompensated(float hum);
|
||||
};
|
||||
|
||||
#endif
|
@ -293,3 +293,7 @@ void Sgp41::setNoxLearningOffset(int offset) {
|
||||
void Sgp41::setTvocLearningOffset(int offset) {
|
||||
tvocLearnOffset = offset;
|
||||
}
|
||||
|
||||
int Sgp41::getNoxLearningOffset(void) { return noxLearnOffset; }
|
||||
|
||||
int Sgp41::getTvocLearningOffset(void) { return tvocLearnOffset; }
|
||||
|
@ -28,6 +28,8 @@ public:
|
||||
void setCompensationTemperatureHumidity(float temp, float hum);
|
||||
void setNoxLearningOffset(int offset);
|
||||
void setTvocLearningOffset(int offset);
|
||||
int getNoxLearningOffset(void);
|
||||
int getTvocLearningOffset(void);
|
||||
|
||||
private:
|
||||
bool onConditioning = true;
|
||||
|
Reference in New Issue
Block a user