From feffc290cc679b3bb382b452e66cac9f47bc0c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sun, 21 Jan 2018 19:35:35 +0100 Subject: [PATCH] Sensor type, value and slot methods should not set error values --- code/espurna/sensors/AnalogSensor.h | 4 -- code/espurna/sensors/BH1750Sensor.h | 4 -- code/espurna/sensors/BMX280Sensor.h | 58 ++++++++++------------- code/espurna/sensors/DHTSensor.h | 4 -- code/espurna/sensors/DallasSensor.h | 11 +---- code/espurna/sensors/DigitalSensor.h | 4 -- code/espurna/sensors/ECH1560Sensor.h | 4 -- code/espurna/sensors/EmonADC121Sensor.h | 8 ---- code/espurna/sensors/EmonADS1X15Sensor.h | 60 +++++++++--------------- code/espurna/sensors/EmonAnalogSensor.h | 8 ---- code/espurna/sensors/EventSensor.h | 4 -- code/espurna/sensors/HLW8012Sensor.h | 4 -- code/espurna/sensors/MHZ19Sensor.h | 4 -- code/espurna/sensors/PMSX003Sensor.h | 35 +++++--------- code/espurna/sensors/SHT3XI2CSensor.h | 12 ++--- code/espurna/sensors/SI7021Sensor.h | 4 -- code/espurna/sensors/V9261FSensor.h | 4 -- 17 files changed, 63 insertions(+), 169 deletions(-) diff --git a/code/espurna/sensors/AnalogSensor.h b/code/espurna/sensors/AnalogSensor.h index 0742e2bb..cf72519a 100644 --- a/code/espurna/sensors/AnalogSensor.h +++ b/code/espurna/sensors/AnalogSensor.h @@ -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; } diff --git a/code/espurna/sensors/BH1750Sensor.h b/code/espurna/sensors/BH1750Sensor.h index cf2125bc..c29ab2de 100644 --- a/code/espurna/sensors/BH1750Sensor.h +++ b/code/espurna/sensors/BH1750Sensor.h @@ -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; } diff --git a/code/espurna/sensors/BMX280Sensor.h b/code/espurna/sensors/BMX280Sensor.h index 6e028e8a..0abcc771 100644 --- a/code/espurna/sensors/BMX280Sensor.h +++ b/code/espurna/sensors/BMX280Sensor.h @@ -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 diff --git a/code/espurna/sensors/DHTSensor.h b/code/espurna/sensors/DHTSensor.h index 77bd5fc5..1cb3f3e1 100644 --- a/code/espurna/sensors/DHTSensor.h +++ b/code/espurna/sensors/DHTSensor.h @@ -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; } diff --git a/code/espurna/sensors/DallasSensor.h b/code/espurna/sensors/DallasSensor.h index def41ec4..7b3bc4d4 100644 --- a/code/espurna/sensors/DallasSensor.h +++ b/code/espurna/sensors/DallasSensor.h @@ -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; } diff --git a/code/espurna/sensors/DigitalSensor.h b/code/espurna/sensors/DigitalSensor.h index 0ec848b9..a0e725ae 100644 --- a/code/espurna/sensors/DigitalSensor.h +++ b/code/espurna/sensors/DigitalSensor.h @@ -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; } diff --git a/code/espurna/sensors/ECH1560Sensor.h b/code/espurna/sensors/ECH1560Sensor.h index 3cdd5fbd..0de3efc3 100644 --- a/code/espurna/sensors/ECH1560Sensor.h +++ b/code/espurna/sensors/ECH1560Sensor.h @@ -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; } diff --git a/code/espurna/sensors/EmonADC121Sensor.h b/code/espurna/sensors/EmonADC121Sensor.h index 5b5b853b..293b5c95 100644 --- a/code/espurna/sensors/EmonADC121Sensor.h +++ b/code/espurna/sensors/EmonADC121Sensor.h @@ -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: diff --git a/code/espurna/sensors/EmonADS1X15Sensor.h b/code/espurna/sensors/EmonADS1X15Sensor.h index 2a7dd6aa..36c9b045 100644 --- a/code/espurna/sensors/EmonADS1X15Sensor.h +++ b/code/espurna/sensors/EmonADS1X15Sensor.h @@ -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: diff --git a/code/espurna/sensors/EmonAnalogSensor.h b/code/espurna/sensors/EmonAnalogSensor.h index cf96e693..bfc5a2f0 100644 --- a/code/espurna/sensors/EmonAnalogSensor.h +++ b/code/espurna/sensors/EmonAnalogSensor.h @@ -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: diff --git a/code/espurna/sensors/EventSensor.h b/code/espurna/sensors/EventSensor.h index c83c2091..70288a1f 100644 --- a/code/espurna/sensors/EventSensor.h +++ b/code/espurna/sensors/EventSensor.h @@ -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; } diff --git a/code/espurna/sensors/HLW8012Sensor.h b/code/espurna/sensors/HLW8012Sensor.h index 0e4410af..9a43c938 100644 --- a/code/espurna/sensors/HLW8012Sensor.h +++ b/code/espurna/sensors/HLW8012Sensor.h @@ -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; } diff --git a/code/espurna/sensors/MHZ19Sensor.h b/code/espurna/sensors/MHZ19Sensor.h index 7e8fa9bc..923620c8 100644 --- a/code/espurna/sensors/MHZ19Sensor.h +++ b/code/espurna/sensors/MHZ19Sensor.h @@ -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; } diff --git a/code/espurna/sensors/PMSX003Sensor.h b/code/espurna/sensors/PMSX003Sensor.h index 6a08157e..c7203511 100644 --- a/code/espurna/sensors/PMSX003Sensor.h +++ b/code/espurna/sensors/PMSX003Sensor.h @@ -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; } diff --git a/code/espurna/sensors/SHT3XI2CSensor.h b/code/espurna/sensors/SHT3XI2CSensor.h index e652ec23..ded19529 100644 --- a/code/espurna/sensors/SHT3XI2CSensor.h +++ b/code/espurna/sensors/SHT3XI2CSensor.h @@ -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; } diff --git a/code/espurna/sensors/SI7021Sensor.h b/code/espurna/sensors/SI7021Sensor.h index f09d689c..971990fb 100644 --- a/code/espurna/sensors/SI7021Sensor.h +++ b/code/espurna/sensors/SI7021Sensor.h @@ -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; } diff --git a/code/espurna/sensors/V9261FSensor.h b/code/espurna/sensors/V9261FSensor.h index 6d846d58..85c9fce1 100644 --- a/code/espurna/sensors/V9261FSensor.h +++ b/code/espurna/sensors/V9261FSensor.h @@ -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; }