Skip to content

Commit

Permalink
MH-Z19 sensor has disabled auto-calibrating xoseperez#1580
Browse files Browse the repository at this point in the history
  • Loading branch information
eschava committed Mar 2, 2019
1 parent e715de3 commit 09a6942
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 2 additions & 9 deletions code/espurna/sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ void _sensorLoad() {
MHZ19Sensor * sensor = new MHZ19Sensor();
sensor->setRX(MHZ19_RX_PIN);
sensor->setTX(MHZ19_TX_PIN);
if (getSetting("mhz19CalibrateAuto", 0).toInt() == 1)
sensor->setCalibrateAuto(true);
_sensors.push_back(sensor);
}
#endif
Expand Down Expand Up @@ -1200,15 +1202,6 @@ void _sensorConfigure() {

#endif // PZEM004T_SUPPORT

#if MHZ19_SUPPORT
if (_sensors[i]->getID() == SENSOR_MHZ19_ID) {
MHZ19Sensor * sensor = (MHZ19Sensor *) _sensors[i];
if (getSetting("mhz19CalibrateAuto", 0).toInt() == 1) {
sensor->calibrateAuto(true);
}
}
#endif // MHZ19_SUPPORT

}

// Update filter sizes
Expand Down
10 changes: 9 additions & 1 deletion code/espurna/sensors/MHZ19Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class MHZ19Sensor : public BaseSensor {
_serial = new SoftwareSerial(_pin_rx, _pin_tx, false, 32);
_serial->enableIntTx(false);
_serial->begin(9600);
calibrateAuto(false);
calibrateAuto(_calibrateAuto);

_ready = true;
_dirty = false;
Expand Down Expand Up @@ -139,6 +139,13 @@ class MHZ19Sensor : public BaseSensor {
_write(buffer);
}

void setCalibrateAuto(boolean value) {
_calibrateAuto = value;
if (_ready) {
calibrateAuto(value);
}
}

protected:

// ---------------------------------------------------------------------
Expand Down Expand Up @@ -214,6 +221,7 @@ class MHZ19Sensor : public BaseSensor {
double _co2 = 0;
unsigned int _pin_rx;
unsigned int _pin_tx;
bool _calibrateAuto = false;
SoftwareSerial * _serial = NULL;

};
Expand Down

0 comments on commit 09a6942

Please sign in to comment.