MH-Z19 auto-calibration setting (#1580 , #1592)

This commit is contained in:
Eugene Schava
2019-03-01 21:35:36 +02:00
committed by Max Prokhorov
parent 3018b9ffe7
commit e62d0df9be
2 changed files with 11 additions and 1 deletions

View File

@@ -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

View File

@@ -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;
@@ -139,6 +139,13 @@ class MHZ19Sensor : public BaseSensor {
_write(buffer);
}
void setCalibrateAuto(boolean value) {
_calibrateAuto = value;
if (_ready) {
calibrateAuto(value);
}
}
protected:
// ---------------------------------------------------------------------
@@ -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;
};