mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-04 19:56:31 +02:00
update handle noxLearningOffset
and tvocLearningOffset
configuration
This commit is contained in:
@ -95,7 +95,6 @@ static bool ledBarButtonTest = false;
|
|||||||
static void boardInit(void);
|
static void boardInit(void);
|
||||||
static void failedHandler(String msg);
|
static void failedHandler(String msg);
|
||||||
static void configurationUpdateSchedule(void);
|
static void configurationUpdateSchedule(void);
|
||||||
static void executeCo2Calibration(void);
|
|
||||||
static void appLedHandler(void);
|
static void appLedHandler(void);
|
||||||
static void appDispHandler(void);
|
static void appDispHandler(void);
|
||||||
static void oledDisplayLedBarSchedule(void);
|
static void oledDisplayLedBarSchedule(void);
|
||||||
@ -104,7 +103,6 @@ static void updatePm(void);
|
|||||||
static void sendDataToServer(void);
|
static void sendDataToServer(void);
|
||||||
static void tempHumUpdate(void);
|
static void tempHumUpdate(void);
|
||||||
static void co2Update(void);
|
static void co2Update(void);
|
||||||
static void showNr(void);
|
|
||||||
static void mdnsInit(void);
|
static void mdnsInit(void);
|
||||||
static void createMqttTask(void);
|
static void createMqttTask(void);
|
||||||
static void initMqtt(void);
|
static void initMqtt(void);
|
||||||
@ -478,6 +476,8 @@ static void oneIndoorInit(void) {
|
|||||||
ag->watchdog.begin();
|
ag->watchdog.begin();
|
||||||
|
|
||||||
/** Init sensor SGP41 */
|
/** Init sensor SGP41 */
|
||||||
|
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
||||||
|
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
||||||
if (ag->sgp41.begin(Wire) == false) {
|
if (ag->sgp41.begin(Wire) == false) {
|
||||||
Serial.println("SGP41 sensor not found");
|
Serial.println("SGP41 sensor not found");
|
||||||
configuration.hasSensorSGP = false;
|
configuration.hasSensorSGP = false;
|
||||||
@ -562,6 +562,8 @@ static void openAirInit(void) {
|
|||||||
serial1Available = false;
|
serial1Available = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
||||||
|
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
||||||
if (ag->sgp41.begin(Wire) == false) {
|
if (ag->sgp41.begin(Wire) == false) {
|
||||||
configuration.hasSensorSGP = false;
|
configuration.hasSensorSGP = false;
|
||||||
Serial.println("SGP sensor not found");
|
Serial.println("SGP sensor not found");
|
||||||
@ -669,6 +671,23 @@ static void configUpdateHandle() {
|
|||||||
initMqtt();
|
initMqtt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (configuration.noxLearnOffsetChanged() ||
|
||||||
|
configuration.tvocLearnOffsetChanged()) {
|
||||||
|
ag->sgp41.end();
|
||||||
|
Serial.println("nox/tvoc learning offset changed");
|
||||||
|
Serial.println("noxLearningOffset: " + String(configuration.getNoxLearningOffset()));
|
||||||
|
Serial.println("tvocLearningOffset: " + String(configuration.getTvocLearningOffset()));
|
||||||
|
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
||||||
|
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
||||||
|
if (ag->sgp41.begin(Wire)) {
|
||||||
|
Serial.println("Init SGP41 success");
|
||||||
|
configuration.hasSensorSGP = true;
|
||||||
|
} else {
|
||||||
|
Serial.println("Init SGP41 failuire");
|
||||||
|
configuration.hasSensorSGP = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
appDispHandler();
|
appDispHandler();
|
||||||
appLedHandler();
|
appLedHandler();
|
||||||
}
|
}
|
||||||
|
@ -403,6 +403,7 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
int tvocLearningOffset = root["tvocLearningOffset"];
|
int tvocLearningOffset = root["tvocLearningOffset"];
|
||||||
if (tvocLearningOffset != config.tvocLearningOffset) {
|
if (tvocLearningOffset != config.tvocLearningOffset) {
|
||||||
changed = true;
|
changed = true;
|
||||||
|
_tvocLearningOffsetChanged = true;
|
||||||
config.tvocLearningOffset = tvocLearningOffset;
|
config.tvocLearningOffset = tvocLearningOffset;
|
||||||
logInfo("Set tvocLearningOffset: " + String(tvocLearningOffset));
|
logInfo("Set tvocLearningOffset: " + String(tvocLearningOffset));
|
||||||
}
|
}
|
||||||
@ -418,6 +419,7 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
int noxLearningOffset = root["noxLearningOffset"];
|
int noxLearningOffset = root["noxLearningOffset"];
|
||||||
if (noxLearningOffset != config.noxLearningOffset) {
|
if (noxLearningOffset != config.noxLearningOffset) {
|
||||||
changed = true;
|
changed = true;
|
||||||
|
_noxLearnOffsetChanged = true;
|
||||||
config.noxLearningOffset = noxLearningOffset;
|
config.noxLearningOffset = noxLearningOffset;
|
||||||
logInfo("Set noxLearningOffset: " + String(noxLearningOffset));
|
logInfo("Set noxLearningOffset: " + String(noxLearningOffset));
|
||||||
}
|
}
|
||||||
@ -518,11 +520,10 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
|
udpated = true;
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
printConfig();
|
printConfig();
|
||||||
|
|
||||||
udpated = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -740,3 +741,23 @@ void Configuration::setPostToAirGradient(bool enable) {
|
|||||||
logInfo("postDataToAirGradient: Ignored set to " + String(enable));
|
logInfo("postDataToAirGradient: Ignored set to " + String(enable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Configuration::noxLearnOffsetChanged(void) {
|
||||||
|
bool changed = _noxLearnOffsetChanged;
|
||||||
|
_noxLearnOffsetChanged = false;
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Configuration::tvocLearnOffsetChanged(void) {
|
||||||
|
bool changed = _tvocLearningOffsetChanged;
|
||||||
|
_tvocLearningOffsetChanged = false;
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Configuration::getTvocLearningOffset(void) {
|
||||||
|
return config.tvocLearningOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Configuration::getNoxLearningOffset(void) {
|
||||||
|
return config.noxLearningOffset;
|
||||||
|
}
|
||||||
|
@ -33,6 +33,8 @@ private:
|
|||||||
bool ledBarTestRequested;
|
bool ledBarTestRequested;
|
||||||
bool udpated;
|
bool udpated;
|
||||||
String failedMessage;
|
String failedMessage;
|
||||||
|
bool _noxLearnOffsetChanged;
|
||||||
|
bool _tvocLearningOffsetChanged;
|
||||||
|
|
||||||
String getLedBarModeName(LedBarMode mode);
|
String getLedBarModeName(LedBarMode mode);
|
||||||
void saveConfig(void);
|
void saveConfig(void);
|
||||||
@ -73,6 +75,10 @@ public:
|
|||||||
bool isUpdated(void);
|
bool isUpdated(void);
|
||||||
String getFailedMesage(void);
|
String getFailedMesage(void);
|
||||||
void setPostToAirGradient(bool enable);
|
void setPostToAirGradient(bool enable);
|
||||||
|
bool noxLearnOffsetChanged(void);
|
||||||
|
bool tvocLearnOffsetChanged(void);
|
||||||
|
int getTvocLearningOffset(void);
|
||||||
|
int getNoxLearningOffset(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /** _AG_CONFIG_H_ */
|
#endif /** _AG_CONFIG_H_ */
|
||||||
|
@ -38,6 +38,20 @@ bool Sgp41::begin(TwoWire &wire) {
|
|||||||
_vocAlgorithm = new VOCGasIndexAlgorithm();
|
_vocAlgorithm = new VOCGasIndexAlgorithm();
|
||||||
_noxAlgorithm = new NOxGasIndexAlgorithm();
|
_noxAlgorithm = new NOxGasIndexAlgorithm();
|
||||||
|
|
||||||
|
int32_t indexOffset;
|
||||||
|
int32_t learningTimeOffsetHours;
|
||||||
|
int32_t learningTimeGainHours;
|
||||||
|
int32_t gatingMaxDurationMin;
|
||||||
|
int32_t stdInitial;
|
||||||
|
int32_t gainFactor;
|
||||||
|
noxAlgorithm()->get_tuning_parameters(indexOffset, learningTimeOffsetHours, learningTimeGainHours, gatingMaxDurationMin, stdInitial, gainFactor);
|
||||||
|
learningTimeOffsetHours = noxLearnOffset;
|
||||||
|
noxAlgorithm()->set_tuning_parameters(indexOffset, learningTimeOffsetHours, learningTimeGainHours, gatingMaxDurationMin, stdInitial, gainFactor);
|
||||||
|
|
||||||
|
vocAlgorithm()->get_tuning_parameters(indexOffset, learningTimeOffsetHours, learningTimeGainHours, gatingMaxDurationMin, stdInitial, gainFactor);
|
||||||
|
learningTimeOffsetHours = tvocLearnOffset;
|
||||||
|
vocAlgorithm()->set_tuning_parameters(indexOffset, learningTimeOffsetHours, learningTimeGainHours, gatingMaxDurationMin, stdInitial, gainFactor);
|
||||||
|
|
||||||
/** Init sensor */
|
/** Init sensor */
|
||||||
this->_sensor = new SensirionI2CSgp41();
|
this->_sensor = new SensirionI2CSgp41();
|
||||||
sgpSensor()->begin(wire);
|
sgpSensor()->begin(wire);
|
||||||
@ -51,6 +65,7 @@ bool Sgp41::begin(TwoWire &wire) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onConditioning = true;
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
/** Create task */
|
/** Create task */
|
||||||
xTaskCreate(
|
xTaskCreate(
|
||||||
@ -270,3 +285,11 @@ void Sgp41::setCompensationTemperatureHumidity(float temp, float hum) {
|
|||||||
defaultRh = static_cast<uint16_t>(hum * 65535 / 100);
|
defaultRh = static_cast<uint16_t>(hum * 65535 / 100);
|
||||||
AgLog("Update: defaultT: %d, defaultRh: %d", defaultT, defaultRh);
|
AgLog("Update: defaultT: %d, defaultRh: %d", defaultT, defaultRh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sgp41::setNoxLearningOffset(int offset) {
|
||||||
|
noxLearnOffset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sgp41::setTvocLearningOffset(int offset) {
|
||||||
|
tvocLearnOffset = offset;
|
||||||
|
}
|
||||||
|
@ -26,6 +26,8 @@ public:
|
|||||||
int getTvocRaw(void);
|
int getTvocRaw(void);
|
||||||
int getNoxRaw(void);
|
int getNoxRaw(void);
|
||||||
void setCompensationTemperatureHumidity(float temp, float hum);
|
void setCompensationTemperatureHumidity(float temp, float hum);
|
||||||
|
void setNoxLearningOffset(int offset);
|
||||||
|
void setTvocLearningOffset(int offset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool onConditioning = true;
|
bool onConditioning = true;
|
||||||
@ -42,6 +44,10 @@ private:
|
|||||||
int tvocRaw;
|
int tvocRaw;
|
||||||
int nox = 0;
|
int nox = 0;
|
||||||
int noxRaw;
|
int noxRaw;
|
||||||
|
|
||||||
|
int noxLearnOffset;
|
||||||
|
int tvocLearnOffset;
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
uint32_t conditioningPeriod;
|
uint32_t conditioningPeriod;
|
||||||
uint8_t conditioningCount;
|
uint8_t conditioningCount;
|
||||||
|
Reference in New Issue
Block a user