Browse Source

Homogeneize sensor error codes

fastled
Xose Pérez 7 years ago
parent
commit
7cc06d9892
4 changed files with 12 additions and 15 deletions
  1. +1
    -0
      code/espurna/sensors/BaseSensor.h
  2. +3
    -6
      code/espurna/sensors/DHTSensor.h
  3. +7
    -4
      code/espurna/sensors/DallasSensor.h
  4. +1
    -5
      code/espurna/sensors/SI7021Sensor.h

+ 1
- 0
code/espurna/sensors/BaseSensor.h View File

@ -42,6 +42,7 @@ typedef enum magnitude_t {
#define SENSOR_ERROR_WARM_UP 2 // Sensor is warming-up
#define SENSOR_ERROR_TIMEOUT 3 // Response from sensor timed out
#define SENSOR_ERROR_UNKNOWN_ID 4 // Sensor did not report a known ID
#define SENSOR_ERROR_CRC 5 // Sensor data corrupted
class BaseSensor {


+ 3
- 6
code/espurna/sensors/DHTSensor.h View File

@ -10,9 +10,6 @@
#define DHT_MAX_DATA 5
#define DHT_MAX_ERRORS 5
#define DHT_MIN_INTERVAL 2000
#define DHT_OK 0
#define DHT_CHECKSUM_ERROR -1
#define DHT_TIMEOUT_ERROR -2
#define DHT11 11
#define DHT22 22
@ -65,14 +62,14 @@ class DHTSensor : public BaseSensor {
// Starts new data transmission with >50us low signal
low = _signal(56, LOW);
if (low == 0) {
_error = DHT_TIMEOUT_ERROR;
_error = SENSOR_ERROR_TIMEOUT;
return;
}
// Check to see if after >70us rx data is a 0 or a 1
high = _signal(75, HIGH);
if (high == 0) {
_error = DHT_TIMEOUT_ERROR;
_error = SENSOR_ERROR_TIMEOUT;
return;
}
@ -98,7 +95,7 @@ class DHTSensor : public BaseSensor {
// Verify checksum
if (dhtData[4] != ((dhtData[0] + dhtData[1] + dhtData[2] + dhtData[3]) & 0xFF)) {
_error = DHT_CHECKSUM_ERROR;
_error = SENSOR_ERROR_CRC;
return;
}


+ 7
- 4
code/espurna/sensors/DallasSensor.h View File

@ -20,10 +20,8 @@
#define DS_CMD_START_CONVERSION 0x44
#define DS_CMD_READ_SCRATCHPAD 0xBE
#define DS_ERROR_NOT_FOUND -1
#define DS_ERROR_FAILED_RESET -2
#define DS_ERROR_FAILED_READ -3
#define DS_ERROR_CRC -4
class DallasSensor : public BaseSensor {
@ -96,7 +94,7 @@ class DallasSensor : public BaseSensor {
}
if (OneWire::crc8(data, 8) != data[8]) {
_error = DS_ERROR_CRC;
_error = SENSOR_ERROR_CRC;
return;
}
@ -182,8 +180,13 @@ class DallasSensor : public BaseSensor {
// 12 bit res, 750 ms
}
double value = (float) raw / 16.0;
if (value == DS_DISCONNECTED) {
_error = SENSOR_ERROR_CRC;
return 0;
}
_error = SENSOR_ERROR_OK;
return (float) raw / 16.0;
return value;
}


+ 1
- 5
code/espurna/sensors/SI7021Sensor.h View File

@ -22,10 +22,6 @@
#define SI7021_CMD_TMP_NOHOLD 0xF3
#define SI7021_CMD_HUM_NOHOLD 0xF5
#define SI7021_ERROR_UNKNOW_CHIP -1
#define SI7021_ERROR_TIMEOUT -2
#define SI7021_ERROR_CRC -3
class SI7021Sensor : public BaseSensor {
public:
@ -53,7 +49,7 @@ class SI7021Sensor : public BaseSensor {
#endif
if ((_chip != SI7021_CHIP_SI7021) & (_chip != SI7021_CHIP_HTU21D)) {
_error = SI7021_ERROR_UNKNOW_CHIP;
_error = SENSOR_ERROR_UNKNOWN_ID;
} else {
_count = 2;
}


Loading…
Cancel
Save