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 failedHandler(String msg);
|
||||
static void configurationUpdateSchedule(void);
|
||||
static void executeCo2Calibration(void);
|
||||
static void appLedHandler(void);
|
||||
static void appDispHandler(void);
|
||||
static void oledDisplayLedBarSchedule(void);
|
||||
@ -104,7 +103,6 @@ static void updatePm(void);
|
||||
static void sendDataToServer(void);
|
||||
static void tempHumUpdate(void);
|
||||
static void co2Update(void);
|
||||
static void showNr(void);
|
||||
static void mdnsInit(void);
|
||||
static void createMqttTask(void);
|
||||
static void initMqtt(void);
|
||||
@ -478,6 +476,8 @@ static void oneIndoorInit(void) {
|
||||
ag->watchdog.begin();
|
||||
|
||||
/** Init sensor SGP41 */
|
||||
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
||||
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
||||
if (ag->sgp41.begin(Wire) == false) {
|
||||
Serial.println("SGP41 sensor not found");
|
||||
configuration.hasSensorSGP = false;
|
||||
@ -562,6 +562,8 @@ static void openAirInit(void) {
|
||||
serial1Available = false;
|
||||
}
|
||||
|
||||
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
||||
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
||||
if (ag->sgp41.begin(Wire) == false) {
|
||||
configuration.hasSensorSGP = false;
|
||||
Serial.println("SGP sensor not found");
|
||||
@ -669,6 +671,23 @@ static void configUpdateHandle() {
|
||||
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();
|
||||
appLedHandler();
|
||||
}
|
||||
|
@ -403,6 +403,7 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
int tvocLearningOffset = root["tvocLearningOffset"];
|
||||
if (tvocLearningOffset != config.tvocLearningOffset) {
|
||||
changed = true;
|
||||
_tvocLearningOffsetChanged = true;
|
||||
config.tvocLearningOffset = tvocLearningOffset;
|
||||
logInfo("Set tvocLearningOffset: " + String(tvocLearningOffset));
|
||||
}
|
||||
@ -418,6 +419,7 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
int noxLearningOffset = root["noxLearningOffset"];
|
||||
if (noxLearningOffset != config.noxLearningOffset) {
|
||||
changed = true;
|
||||
_noxLearnOffsetChanged = true;
|
||||
config.noxLearningOffset = noxLearningOffset;
|
||||
logInfo("Set noxLearningOffset: " + String(noxLearningOffset));
|
||||
}
|
||||
@ -518,11 +520,10 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
udpated = true;
|
||||
saveConfig();
|
||||
}
|
||||
printConfig();
|
||||
|
||||
udpated = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -740,3 +741,23 @@ void Configuration::setPostToAirGradient(bool 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 udpated;
|
||||
String failedMessage;
|
||||
bool _noxLearnOffsetChanged;
|
||||
bool _tvocLearningOffsetChanged;
|
||||
|
||||
String getLedBarModeName(LedBarMode mode);
|
||||
void saveConfig(void);
|
||||
@ -73,6 +75,10 @@ public:
|
||||
bool isUpdated(void);
|
||||
String getFailedMesage(void);
|
||||
void setPostToAirGradient(bool enable);
|
||||
bool noxLearnOffsetChanged(void);
|
||||
bool tvocLearnOffsetChanged(void);
|
||||
int getTvocLearningOffset(void);
|
||||
int getNoxLearningOffset(void);
|
||||
};
|
||||
|
||||
#endif /** _AG_CONFIG_H_ */
|
||||
|
@ -38,6 +38,20 @@ bool Sgp41::begin(TwoWire &wire) {
|
||||
_vocAlgorithm = new VOCGasIndexAlgorithm();
|
||||
_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 */
|
||||
this->_sensor = new SensirionI2CSgp41();
|
||||
sgpSensor()->begin(wire);
|
||||
@ -51,6 +65,7 @@ bool Sgp41::begin(TwoWire &wire) {
|
||||
return false;
|
||||
}
|
||||
|
||||
onConditioning = true;
|
||||
#ifdef ESP32
|
||||
/** Create task */
|
||||
xTaskCreate(
|
||||
@ -270,3 +285,11 @@ void Sgp41::setCompensationTemperatureHumidity(float temp, float hum) {
|
||||
defaultRh = static_cast<uint16_t>(hum * 65535 / 100);
|
||||
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 getNoxRaw(void);
|
||||
void setCompensationTemperatureHumidity(float temp, float hum);
|
||||
void setNoxLearningOffset(int offset);
|
||||
void setTvocLearningOffset(int offset);
|
||||
|
||||
private:
|
||||
bool onConditioning = true;
|
||||
@ -42,6 +44,10 @@ private:
|
||||
int tvocRaw;
|
||||
int nox = 0;
|
||||
int noxRaw;
|
||||
|
||||
int noxLearnOffset;
|
||||
int tvocLearnOffset;
|
||||
|
||||
#if defined(ESP8266)
|
||||
uint32_t conditioningPeriod;
|
||||
uint8_t conditioningCount;
|
||||
|
Reference in New Issue
Block a user