Browse Source

Check value range for PMSX005 and SenseAir CO2 sensor (#1865)

master
Yonsm 5 years ago
committed by Max Prokhorov
parent
commit
fa9ff7dee7
2 changed files with 27 additions and 11 deletions
  1. +25
    -9
      code/espurna/sensors/PMSX003Sensor.h
  2. +2
    -2
      code/espurna/sensors/SenseAirSensor.h

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

@ -276,8 +276,6 @@ class PMSX003Sensor : public BaseSensor, PMSX003 {
return; return;
} }
_error = SENSOR_ERROR_OK;
#if PMS_SMART_SLEEP #if PMS_SMART_SLEEP
unsigned int readCycle; unsigned int readCycle;
if (_readCount++ > 30) { if (_readCount++ > 30) {
@ -304,22 +302,40 @@ class PMSX003Sensor : public BaseSensor, PMSX003 {
uint16_t data[PMS_DATA_MAX]; uint16_t data[PMS_DATA_MAX];
if (readData(data, pms_specs[_type].data_count)) { if (readData(data, pms_specs[_type].data_count)) {
if (_type == PMS_TYPE_5003ST) { if (_type == PMS_TYPE_5003ST) {
_slot_values[0] = data[4];
_slot_values[1] = (double)data[13] / 10;
_slot_values[2] = (double)data[14] / 10;
_slot_values[3] = (double)data[12] / 1000;
if (data[14] > 10 && data[14] < 1000 && data[13] < 1000) {
_slot_values[0] = data[4];
_slot_values[1] = (double)data[13] / 10;
_slot_values[2] = (double)data[14] / 10;
_slot_values[3] = (double)data[12] / 1000;
_error = SENSOR_ERROR_OK;
} else {
_error = SENSOR_ERROR_OUT_OF_RANGE;
#if SENSOR_DEBUG
DEBUG_MSG("[SENSOR] %s: Invalid temperature=%d humidity=%d.\n", pms_specs[_type].name, (int)data[13], (int)data[14]);
#endif
}
} else if (_type == PMS_TYPE_5003S) { } else if (_type == PMS_TYPE_5003S) {
_slot_values[0] = data[4]; _slot_values[0] = data[4];
_slot_values[1] = data[5]; _slot_values[1] = data[5];
_slot_values[2] = (double)data[12] / 1000; _slot_values[2] = (double)data[12] / 1000;
_error = SENSOR_ERROR_OK;
} else if (_type == PMS_TYPE_5003T) { } else if (_type == PMS_TYPE_5003T) {
_slot_values[0] = data[4];
_slot_values[1] = (double)data[10] / 10;
_slot_values[2] = (double)data[11] / 10;
if (data[11] > 10 && data[11] < 1000 && data[10] < 1000) {
_slot_values[0] = data[4];
_slot_values[1] = (double)data[10] / 10;
_slot_values[2] = (double)data[11] / 10;
_error = SENSOR_ERROR_OK;
} else {
_error = SENSOR_ERROR_OUT_OF_RANGE;
#if SENSOR_DEBUG
DEBUG_MSG("[SENSOR] %s: Invalid temperature=%d humidity=%d.\n", pms_specs[_type].name, (int)data[10], (int)data[11]);
#endif
}
} else { } else {
_slot_values[0] = data[3]; _slot_values[0] = data[3];
_slot_values[1] = data[4]; _slot_values[1] = data[4];
_slot_values[2] = data[5]; _slot_values[2] = data[5];
_error = SENSOR_ERROR_OK;
} }
} }


+ 2
- 2
code/espurna/sensors/SenseAirSensor.h View File

@ -202,17 +202,17 @@ class SenseAirSensor : public BaseSensor, SenseAir {
return; return;
} }
_error = SENSOR_ERROR_OK;
unsigned int co2 = readCo2(); unsigned int co2 = readCo2();
if (co2 >= 5000 || co2 < 100) if (co2 >= 5000 || co2 < 100)
{ {
_co2 = _lastCo2; _co2 = _lastCo2;
_error = SENSOR_ERROR_OUT_OF_RANGE;
} }
else else
{ {
_co2 = (co2 > _lastCo2 + 2000) ? _lastCo2 : co2; _co2 = (co2 > _lastCo2 + 2000) ? _lastCo2 : co2;
_lastCo2 = co2; _lastCo2 = co2;
_error = SENSOR_ERROR_OK;
} }
} }


Loading…
Cancel
Save