Browse Source

Sensor type, value and slot methods should not set error values

softuart
Xose Pérez 7 years ago
parent
commit
feffc290cc
17 changed files with 63 additions and 169 deletions
  1. +0
    -4
      code/espurna/sensors/AnalogSensor.h
  2. +0
    -4
      code/espurna/sensors/BH1750Sensor.h
  3. +24
    -34
      code/espurna/sensors/BMX280Sensor.h
  4. +0
    -4
      code/espurna/sensors/DHTSensor.h
  5. +2
    -9
      code/espurna/sensors/DallasSensor.h
  6. +0
    -4
      code/espurna/sensors/DigitalSensor.h
  7. +0
    -4
      code/espurna/sensors/ECH1560Sensor.h
  8. +0
    -8
      code/espurna/sensors/EmonADC121Sensor.h
  9. +23
    -37
      code/espurna/sensors/EmonADS1X15Sensor.h
  10. +0
    -8
      code/espurna/sensors/EmonAnalogSensor.h
  11. +0
    -4
      code/espurna/sensors/EventSensor.h
  12. +0
    -4
      code/espurna/sensors/HLW8012Sensor.h
  13. +0
    -4
      code/espurna/sensors/MHZ19Sensor.h
  14. +11
    -24
      code/espurna/sensors/PMSX003Sensor.h
  15. +3
    -9
      code/espurna/sensors/SHT3XI2CSensor.h
  16. +0
    -4
      code/espurna/sensors/SI7021Sensor.h
  17. +0
    -4
      code/espurna/sensors/V9261FSensor.h

+ 0
- 4
code/espurna/sensors/AnalogSensor.h View File

@ -49,17 +49,13 @@ class AnalogSensor : public BaseSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_ANALOG;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return analogRead(0);
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


+ 0
- 4
code/espurna/sensors/BH1750Sensor.h View File

@ -76,9 +76,7 @@ class BH1750Sensor : public I2CSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_LUX;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
@ -90,9 +88,7 @@ class BH1750Sensor : public I2CSensor {
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return _lux;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


+ 24
- 34
code/espurna/sensors/BMX280Sensor.h View File

@ -90,22 +90,18 @@ class BMX280Sensor : public I2CSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
if (index < _count) {
_error = SENSOR_ERROR_OK;
unsigned char i = 0;
#if BMX280_TEMPERATURE > 0
if (index == i++) return MAGNITUDE_TEMPERATURE;
#endif
#if BMX280_PRESSURE > 0
if (index == i++) return MAGNITUDE_PRESSURE;
#endif
#if BMX280_HUMIDITY > 0
if (_chip == BMX280_CHIP_BME280) {
if (index == i) return MAGNITUDE_HUMIDITY;
}
#endif
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
unsigned char i = 0;
#if BMX280_TEMPERATURE > 0
if (index == i++) return MAGNITUDE_TEMPERATURE;
#endif
#if BMX280_PRESSURE > 0
if (index == i++) return MAGNITUDE_PRESSURE;
#endif
#if BMX280_HUMIDITY > 0
if (_chip == BMX280_CHIP_BME280) {
if (index == i) return MAGNITUDE_HUMIDITY;
}
#endif
return MAGNITUDE_NONE;
}
@ -127,25 +123,19 @@ class BMX280Sensor : public I2CSensor {
// Current value for slot # index
double value(unsigned char index) {
if (index < _count) {
_error = SENSOR_ERROR_OK;
unsigned char i = 0;
#if BMX280_TEMPERATURE > 0
if (index == i++) return _temperature;
#endif
#if BMX280_PRESSURE > 0
if (index == i++) return _pressure / 100;
#endif
#if BMX280_HUMIDITY > 0
if (_chip == BMX280_CHIP_BME280) {
if (index == i) return _humidity;
}
#endif
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
unsigned char i = 0;
#if BMX280_TEMPERATURE > 0
if (index == i++) return _temperature;
#endif
#if BMX280_PRESSURE > 0
if (index == i++) return _pressure / 100;
#endif
#if BMX280_HUMIDITY > 0
if (_chip == BMX280_CHIP_BME280) {
if (index == i) return _humidity;
}
#endif
return 0;
}
// Load the configuration manifest


+ 0
- 4
code/espurna/sensors/DHTSensor.h View File

@ -103,19 +103,15 @@ class DHTSensor : public BaseSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_TEMPERATURE;
if (index == 1) return MAGNITUDE_HUMIDITY;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return _temperature;
if (index == 1) return _humidity;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


+ 2
- 9
code/espurna/sensors/DallasSensor.h View File

@ -185,7 +185,6 @@ class DallasSensor : public BaseSensor {
// Descriptive name of the slot # index
String slot(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index < _count) {
char buffer[40];
uint8_t * address = _devices[index].address;
@ -197,15 +196,12 @@ class DallasSensor : public BaseSensor {
);
return String(buffer);
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
return String();
}
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index < _count) return MAGNITUDE_TEMPERATURE;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
@ -217,10 +213,7 @@ class DallasSensor : public BaseSensor {
// Current value for slot # index
double value(unsigned char index) {
if (index >= _count) {
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}
if (index >= _count) return 0;
uint8_t * data = _devices[index].data;
@ -257,7 +250,7 @@ class DallasSensor : public BaseSensor {
_error = SENSOR_ERROR_CRC;
return 0;
}
_error = SENSOR_ERROR_OK;
return value;
}


+ 0
- 4
code/espurna/sensors/DigitalSensor.h View File

@ -79,17 +79,13 @@ class DigitalSensor : public BaseSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_DIGITAL;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return (digitalRead(_gpio) == _default) ? 0 : 1;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


+ 0
- 4
code/espurna/sensors/ECH1560Sensor.h View File

@ -96,21 +96,17 @@ class ECH1560Sensor : public BaseSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_CURRENT;
if (index == 1) return MAGNITUDE_VOLTAGE;
if (index == 2) return MAGNITUDE_POWER_APPARENT;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return _current;
if (index == 1) return _voltage;
if (index == 2) return _apparent;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


+ 0
- 8
code/espurna/sensors/EmonADC121Sensor.h View File

@ -100,7 +100,6 @@ class EmonADC121Sensor : public EmonSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
unsigned char i=0;
#if EMON_REPORT_CURRENT
if (index == i++) return MAGNITUDE_CURRENT;
@ -111,16 +110,12 @@ class EmonADC121Sensor : public EmonSensor {
#if EMON_REPORT_ENERGY
if (index == i) return MAGNITUDE_ENERGY;
#endif
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
unsigned char channel = index / _magnitudes;
unsigned char i=0;
#if EMON_REPORT_CURRENT
if (index == i++) return _current[channel];
@ -131,10 +126,7 @@ class EmonADC121Sensor : public EmonSensor {
#if EMON_REPORT_ENERGY
if (index == i) return _energy[channel];
#endif
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}
protected:


+ 23
- 37
code/espurna/sensors/EmonADS1X15Sensor.h View File

@ -207,21 +207,17 @@ class EmonADS1X15Sensor : public EmonSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
if (index < _count) {
_error = SENSOR_ERROR_OK;
unsigned char magnitude = index / _ports;
unsigned char i=0;
#if EMON_REPORT_CURRENT
if (magnitude == i++) return MAGNITUDE_CURRENT;
#endif
#if EMON_REPORT_POWER
if (magnitude == i++) return MAGNITUDE_POWER_APPARENT;
#endif
#if EMON_REPORT_ENERGY
if (magnitude == i) return MAGNITUDE_ENERGY;
#endif
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
unsigned char magnitude = index / _ports;
unsigned char i=0;
#if EMON_REPORT_CURRENT
if (magnitude == i++) return MAGNITUDE_CURRENT;
#endif
#if EMON_REPORT_POWER
if (magnitude == i++) return MAGNITUDE_POWER_APPARENT;
#endif
#if EMON_REPORT_ENERGY
if (magnitude == i) return MAGNITUDE_ENERGY;
#endif
return MAGNITUDE_NONE;
}
@ -240,29 +236,19 @@ class EmonADS1X15Sensor : public EmonSensor {
// Current value for slot # index
double value(unsigned char index) {
if (index < _count) {
_error = SENSOR_ERROR_OK;
unsigned char port = index % _ports;
unsigned char magnitude = index / _ports;
unsigned char i=0;
#if EMON_REPORT_CURRENT
if (magnitude == i++) return _current[port];
#endif
#if EMON_REPORT_POWER
if (magnitude == i++) return _current[port] * _voltage;
#endif
#if EMON_REPORT_ENERGY
if (magnitude == i) return _energy[port];
#endif
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
unsigned char port = index % _ports;
unsigned char magnitude = index / _ports;
unsigned char i=0;
#if EMON_REPORT_CURRENT
if (magnitude == i++) return _current[port];
#endif
#if EMON_REPORT_POWER
if (magnitude == i++) return _current[port] * _voltage;
#endif
#if EMON_REPORT_ENERGY
if (magnitude == i) return _energy[port];
#endif
return 0;
}
protected:


+ 0
- 8
code/espurna/sensors/EmonAnalogSensor.h View File

@ -66,7 +66,6 @@ class EmonAnalogSensor : public EmonSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
unsigned char i=0;
#if EMON_REPORT_CURRENT
if (index == i++) return MAGNITUDE_CURRENT;
@ -77,7 +76,6 @@ class EmonAnalogSensor : public EmonSensor {
#if EMON_REPORT_ENERGY
if (index == i) return MAGNITUDE_ENERGY;
#endif
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
@ -100,10 +98,7 @@ class EmonAnalogSensor : public EmonSensor {
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
unsigned char channel = index / _magnitudes;
unsigned char i=0;
#if EMON_REPORT_CURRENT
if (index == i++) return _current[channel];
@ -114,10 +109,7 @@ class EmonAnalogSensor : public EmonSensor {
#if EMON_REPORT_ENERGY
if (index == i) return _energy[channel];
#endif
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}
protected:


+ 0
- 4
code/espurna/sensors/EventSensor.h View File

@ -93,21 +93,17 @@ class EventSensor : public BaseSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_EVENTS;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) {
double value = _events;
_events = 0;
return value;
};
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


+ 0
- 4
code/espurna/sensors/HLW8012Sensor.h View File

@ -176,7 +176,6 @@ class HLW8012Sensor : public BaseSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_CURRENT;
if (index == 1) return MAGNITUDE_VOLTAGE;
if (index == 2) return MAGNITUDE_POWER_ACTIVE;
@ -184,13 +183,11 @@ class HLW8012Sensor : public BaseSensor {
if (index == 4) return MAGNITUDE_POWER_APPARENT;
if (index == 5) return MAGNITUDE_POWER_FACTOR;
if (index == 6) return MAGNITUDE_ENERGY;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return _hlw8012->getCurrent();
if (index == 1) return _hlw8012->getVoltage();
if (index == 2) return _hlw8012->getActivePower();
@ -198,7 +195,6 @@ class HLW8012Sensor : public BaseSensor {
if (index == 4) return _hlw8012->getApparentPower();
if (index == 5) return 100 * _hlw8012->getPowerFactor();
if (index == 6) return _hlw8012->getEnergy();
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


+ 0
- 4
code/espurna/sensors/MHZ19Sensor.h View File

@ -103,9 +103,7 @@ class MHZ19Sensor : public BaseSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_CO2;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
@ -115,9 +113,7 @@ class MHZ19Sensor : public BaseSensor {
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return _co2;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


+ 11
- 24
code/espurna/sensors/PMSX003Sensor.h View File

@ -85,16 +85,11 @@ class PMSX003Sensor : public BaseSensor {
// Descriptive name of the slot # index
String slot(unsigned char index) {
if (index < _count) {
_error = SENSOR_ERROR_OK;
char buffer[36];
if (index == 0) snprintf(buffer, sizeof(buffer), "PM1.0 @ PMSX003 @ SwSerial(%u,%u)", _pin_rx, _pin_tx);
if (index == 1) snprintf(buffer, sizeof(buffer), "PM2.5 @ PMSX003 @ SwSerial(%u,%u)", _pin_rx, _pin_tx);
if (index == 2) snprintf(buffer, sizeof(buffer), "PM10 @ PMSX003 @ SwSerial(%u,%u)", _pin_rx, _pin_tx);
return String(buffer);
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
return String();
char buffer[36] = {0};
if (index == 0) snprintf(buffer, sizeof(buffer), "PM1.0 @ PMSX003 @ SwSerial(%u,%u)", _pin_rx, _pin_tx);
if (index == 1) snprintf(buffer, sizeof(buffer), "PM2.5 @ PMSX003 @ SwSerial(%u,%u)", _pin_rx, _pin_tx);
if (index == 2) snprintf(buffer, sizeof(buffer), "PM10 @ PMSX003 @ SwSerial(%u,%u)", _pin_rx, _pin_tx);
return String(buffer);
}
// Address of the sensor (it could be the GPIO or I2C address)
@ -106,13 +101,9 @@ class PMSX003Sensor : public BaseSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
if (index < _count) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_PM1dot0;
if (index == 1) return MAGNITUDE_PM2dot5;
if (index == 2) return MAGNITUDE_PM10;
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
if (index == 0) return MAGNITUDE_PM1dot0;
if (index == 1) return MAGNITUDE_PM2dot5;
if (index == 2) return MAGNITUDE_PM10;
return MAGNITUDE_NONE;
}
@ -137,13 +128,9 @@ class PMSX003Sensor : public BaseSensor {
// Current value for slot # index
double value(unsigned char index) {
if (index < _count) {
_error = SENSOR_ERROR_OK;
if(index == 0) return _pm1dot0;
if(index == 1) return _pm2dot5;
if(index == 2) return _pm10;
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
if(index == 0) return _pm1dot0;
if(index == 1) return _pm2dot5;
if(index == 2) return _pm10;
return 0;
}


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

@ -49,12 +49,8 @@ class SHT3XI2CSensor : public I2CSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
if (index < _count) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_TEMPERATURE;
if (index == 1) return MAGNITUDE_HUMIDITY;
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
if (index == 0) return MAGNITUDE_TEMPERATURE;
if (index == 1) return MAGNITUDE_HUMIDITY;
return MAGNITUDE_NONE;
}
@ -62,7 +58,7 @@ class SHT3XI2CSensor : public I2CSensor {
void pre() {
_error = SENSOR_ERROR_OK;
unsigned char buffer[6];
i2c_write_uint8(_address, 0x2C, 0x06);
delay(500);
@ -76,10 +72,8 @@ class SHT3XI2CSensor : public I2CSensor {
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return _temperature;
if (index == 1) return _humidity;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


+ 0
- 4
code/espurna/sensors/SI7021Sensor.h View File

@ -76,10 +76,8 @@ class SI7021Sensor : public I2CSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_TEMPERATURE;
if (index == 1) return MAGNITUDE_HUMIDITY;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
@ -105,10 +103,8 @@ class SI7021Sensor : public I2CSensor {
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return _temperature;
if (index == 1) return _humidity;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


+ 0
- 4
code/espurna/sensors/V9261FSensor.h View File

@ -94,27 +94,23 @@ class V9261FSensor : public BaseSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_CURRENT;
if (index == 1) return MAGNITUDE_VOLTAGE;
if (index == 2) return MAGNITUDE_POWER_ACTIVE;
if (index == 3) return MAGNITUDE_POWER_REACTIVE;
if (index == 4) return MAGNITUDE_POWER_APPARENT;
if (index == 5) return MAGNITUDE_POWER_FACTOR;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return _current;
if (index == 1) return _voltage;
if (index == 2) return _active;
if (index == 3) return _reactive;
if (index == 4) return _apparent;
if (index == 5) return _apparent > 0 ? 100 * _active / _apparent : 100;
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}


Loading…
Cancel
Save