Browse Source

sensor/pmsx003: only delete object when it is managed by sensor

master
Maxim Prokhorov 5 years ago
parent
commit
cb9dba4bb6
1 changed files with 9 additions and 3 deletions
  1. +9
    -3
      code/espurna/sensors/PMSX003Sensor.h

+ 9
- 3
code/espurna/sensors/PMSX003Sensor.h View File

@ -158,14 +158,13 @@ class PMSX003Sensor : public BaseSensor, PMSX003 {
// ---------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------
PMSX003Sensor(): BaseSensor() {
_count = pms_specs[_type].slot_count;
_sensor_id = SENSOR_PMSX003_ID;
}
~PMSX003Sensor() {
if (_serial) delete _serial;
removeSerial();
}
void setRX(unsigned char pin_rx) {
@ -216,7 +215,7 @@ class PMSX003Sensor : public BaseSensor, PMSX003 {
if (!_dirty) return;
if (_soft) {
if (_serial) delete _serial;
if (_serial) removeSerial();
_serial = new SoftwareSerial(_pin_rx, _pin_tx, false, 64);
static_cast<SoftwareSerial*>(_serial)->enableIntTx(false);
}
@ -358,6 +357,13 @@ class PMSX003Sensor : public BaseSensor, PMSX003 {
return _slot_values[index];
}
private:
void removeSerial() {
if (_serial && _soft) {
delete static_cast<SoftwareSerial*>(_serial);
}
}
protected:
bool _soft = true;
unsigned int _pin_rx;


Loading…
Cancel
Save