Skip to content

Commit

Permalink
MH-Z19 auto-calibration setting (#1580 , #1592)
Browse files Browse the repository at this point in the history
  • Loading branch information
eschava authored and mcspr committed Mar 1, 2019
1 parent 3018b9f commit e62d0df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions code/espurna/sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,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
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 e62d0df

Please sign in to comment.