diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index 2dac4306..039fbfbc 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -2,6 +2,7 @@ // SENSORS - General data // ============================================================================= +#define SENSOR_SUPPORT 0 // Sensor support #define SENSOR_DEBUG 0 // Debug sensors #define SENSOR_READ_INTERVAL 6 // Read data from sensors every 6 seconds @@ -40,36 +41,29 @@ // Magnitudes //-------------------------------------------------------------------------------- -typedef enum magnitude_t { - - MAGNITUDE_NONE = 0, - - MAGNITUDE_TEMPERATURE, - MAGNITUDE_HUMIDITY, - MAGNITUDE_PRESSURE, - - MAGNITUDE_CURRENT, - MAGNITUDE_VOLTAGE, - MAGNITUDE_POWER_ACTIVE, - MAGNITUDE_POWER_APPARENT, - MAGNITUDE_POWER_REACTIVE, - MAGNITUDE_ENERGY, - MAGNITUDE_ENERGY_DELTA, - MAGNITUDE_POWER_FACTOR, - - MAGNITUDE_ANALOG, - MAGNITUDE_DIGITAL, - MAGNITUDE_EVENTS, - - MAGNITUDE_PM1dot0, - MAGNITUDE_PM2dot5, - MAGNITUDE_PM10, - - MAGNITUDE_CO2, - - MAGNITUDE_MAX, - -} magnitude_t; +#define MAGNITUDE_NONE 0 +#define MAGNITUDE_TEMPERATURE 1 +#define MAGNITUDE_HUMIDITY 2 +#define MAGNITUDE_PRESSURE 3 +#define MAGNITUDE_CURRENT 4 +#define MAGNITUDE_VOLTAGE 5 +#define MAGNITUDE_POWER_ACTIVE 6 +#define MAGNITUDE_POWER_APPARENT 7 +#define MAGNITUDE_POWER_REACTIVE 8 +#define MAGNITUDE_ENERGY 9 +#define MAGNITUDE_ENERGY_DELTA 10 +#define MAGNITUDE_POWER_FACTOR 11 +#define MAGNITUDE_ANALOG 12 +#define MAGNITUDE_DIGITAL 13 +#define MAGNITUDE_EVENTS 14 +#define MAGNITUDE_PM1dot0 15 +#define MAGNITUDE_PM2dot5 16 +#define MAGNITUDE_PM10 17 +#define MAGNITUDE_CO2 18 + +#define MAGNITUDE_MAX 19 + +#if SENSOR_SUPPORT PROGMEM const unsigned char magnitude_decimals[] = { 0, @@ -132,6 +126,8 @@ PROGMEM const char* const magnitude_units[] = { magnitude_ppm }; +#endif // SENSOR_SUPPORT + //-------------------------------------------------------------------------------- // Sensor ID // These should remain over time, do not modify them, only add new ones at the end @@ -178,7 +174,7 @@ PROGMEM const char* const magnitude_units[] = { //------------------------------------------------------------------------------ #ifndef BMX280_SUPPORT -#define BMX280_SUPPORT 1 +#define BMX280_SUPPORT 0 #endif #ifndef BMX280_ADDRESS @@ -513,6 +509,8 @@ PROGMEM const char* const magnitude_units[] = { // Class loading //-------------------------------------------------------------------------------- +#if SENSOR_SUPPORT + #include "../sensors/BaseSensor.h" #if ANALOG_SUPPORT @@ -585,3 +583,5 @@ PROGMEM const char* const magnitude_units[] = { #include #include "../sensors/V9261FSensor.h" #endif + +#endif // SENSOR_SUPPORT diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index 771f7aa9..8b242467 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -91,22 +91,15 @@ void _domoticzWebSocketOnSend(JsonObject& root) { relays.add(domoticzIdx(i)); } - JsonArray& list = root.createNestedArray("dczMagnitudes"); - for (byte i=0; i */ +#if SENSOR_SUPPORT + #include #include "filters/MaxFilter.h" #include "filters/MedianFilter.h" @@ -15,7 +17,7 @@ Copyright (C) 2016-2017 by Xose Pérez typedef struct { BaseSensor * sensor; unsigned char local; // Local index in its provider - magnitude_t type; // Type of measurement + unsigned char type; // Type of measurement unsigned char global; // Global index in its type double current; // Current (last) value, unfiltered double filtered; // Filtered (averaged) value @@ -38,18 +40,18 @@ double _sensor_temperature_correction = SENSOR_TEMPERATURE_CORRECTION; // Private // ----------------------------------------------------------------------------- -String _magnitudeTopic(magnitude_t type) { +String _magnitudeTopic(unsigned char type) { char buffer[16] = {0}; if (type < MAGNITUDE_MAX) strncpy_P(buffer, magnitude_topics[type], sizeof(buffer)); return String(buffer); } -unsigned char _magnitudeDecimals(magnitude_t type) { +unsigned char _magnitudeDecimals(unsigned char type) { if (type < MAGNITUDE_MAX) return pgm_read_byte(magnitude_decimals + type); return 0; } -String _magnitudeUnits(magnitude_t type) { +String _magnitudeUnits(unsigned char type) { char buffer[8] = {0}; if (type < MAGNITUDE_MAX) { if ((type == MAGNITUDE_TEMPERATURE) && (_sensor_temperature_units == TMP_FAHRENHEIT)) { @@ -61,7 +63,7 @@ String _magnitudeUnits(magnitude_t type) { return String(buffer); } -double _magnitudeProcess(magnitude_t type, double value) { +double _magnitudeProcess(unsigned char type, double value) { if (type == MAGNITUDE_TEMPERATURE) { if (_sensor_temperature_units == TMP_FAHRENHEIT) value = value * 1.8 + 32; value = value + _sensor_temperature_correction; @@ -457,7 +459,7 @@ void _magnitudesInit() { for (unsigned char k=0; kcount(); k++) { - magnitude_t type = sensor->type(k); + unsigned char type = sensor->type(k); sensor_magnitude_t new_magnitude; new_magnitude.sensor = sensor; @@ -671,3 +673,5 @@ void sensorLoop() { } } + +#endif // SENSOR_SUPPORT diff --git a/code/espurna/sensors/AnalogSensor.h b/code/espurna/sensors/AnalogSensor.h index 126fb3f9..12d76923 100644 --- a/code/espurna/sensors/AnalogSensor.h +++ b/code/espurna/sensors/AnalogSensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && ANALOG_SUPPORT + #pragma once #include "Arduino.h" @@ -36,7 +38,7 @@ class AnalogSensor : public BaseSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { _error = SENSOR_ERROR_OK; if (index == 0) return MAGNITUDE_ANALOG; _error = SENSOR_ERROR_OUT_OF_RANGE; @@ -53,3 +55,5 @@ class AnalogSensor : public BaseSensor { }; + +#endif // SENSOR_SUPPORT && ANALOG_SUPPORT diff --git a/code/espurna/sensors/BMX280Sensor.h b/code/espurna/sensors/BMX280Sensor.h index 7bcd7713..840b45d6 100644 --- a/code/espurna/sensors/BMX280Sensor.h +++ b/code/espurna/sensors/BMX280Sensor.h @@ -4,6 +4,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && BMX280_SUPPORT + #pragma once #include "Arduino.h" @@ -60,7 +62,7 @@ class BMX280Sensor : public I2CSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { if (index < _count) { _error = SENSOR_ERROR_OK; unsigned char i = 0; @@ -245,3 +247,5 @@ class BMX280Sensor : public I2CSensor { // Static inizializations unsigned char BMX280Sensor::addresses[2] = {0x76, 0x77}; + +// SENSOR_SUPPORT && BMX280_SUPPORT diff --git a/code/espurna/sensors/BaseSensor.h b/code/espurna/sensors/BaseSensor.h index d7380a72..394e2418 100644 --- a/code/espurna/sensors/BaseSensor.h +++ b/code/espurna/sensors/BaseSensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT + #pragma once #include @@ -45,7 +47,7 @@ class BaseSensor { virtual String description() {} // Type for slot # index - virtual magnitude_t type(unsigned char index) {} + virtual unsigned char type(unsigned char index) {} // Current value for slot # index virtual double value(unsigned char index) {} @@ -82,3 +84,5 @@ class BaseSensor { unsigned char _count = 0; }; + +#endif diff --git a/code/espurna/sensors/DHTSensor.h b/code/espurna/sensors/DHTSensor.h index d2c7e8cd..524e93ab 100644 --- a/code/espurna/sensors/DHTSensor.h +++ b/code/espurna/sensors/DHTSensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && DHT_SUPPORT + #pragma once #include "Arduino.h" @@ -89,7 +91,7 @@ class DHTSensor : public BaseSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { _error = SENSOR_ERROR_OK; if (index == 0) return MAGNITUDE_TEMPERATURE; if (index == 1) return MAGNITUDE_HUMIDITY; @@ -226,3 +228,5 @@ class DHTSensor : public BaseSensor { unsigned int _humidity; }; + +#endif // SENSOR_SUPPORT && DHT_SUPPORT diff --git a/code/espurna/sensors/DallasSensor.h b/code/espurna/sensors/DallasSensor.h index e01a86cf..dadd0f1e 100644 --- a/code/espurna/sensors/DallasSensor.h +++ b/code/espurna/sensors/DallasSensor.h @@ -4,6 +4,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && DALLAS_SUPPORT + #pragma once #include "Arduino.h" @@ -187,7 +189,7 @@ class DallasSensor : public BaseSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { _error = SENSOR_ERROR_OK; if (index < _count) return MAGNITUDE_TEMPERATURE; _error = SENSOR_ERROR_OUT_OF_RANGE; @@ -301,3 +303,5 @@ class DallasSensor : public BaseSensor { OneWire * _wire = NULL; }; + +#endif // SENSOR_SUPPORT && DALLAS_SUPPORT diff --git a/code/espurna/sensors/DigitalSensor.h b/code/espurna/sensors/DigitalSensor.h index 0d9487c9..e72607da 100644 --- a/code/espurna/sensors/DigitalSensor.h +++ b/code/espurna/sensors/DigitalSensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && DIGITAL_SUPPORT + #pragma once #include "Arduino.h" @@ -66,7 +68,7 @@ class DigitalSensor : public BaseSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { _error = SENSOR_ERROR_OK; if (index == 0) return MAGNITUDE_DIGITAL; _error = SENSOR_ERROR_OUT_OF_RANGE; @@ -93,3 +95,5 @@ class DigitalSensor : public BaseSensor { bool _default = false; }; + +#endif // SENSOR_SUPPORT && DIGITAL_SUPPORT diff --git a/code/espurna/sensors/ECH1560Sensor.h b/code/espurna/sensors/ECH1560Sensor.h index cf95d550..67a97ea3 100644 --- a/code/espurna/sensors/ECH1560Sensor.h +++ b/code/espurna/sensors/ECH1560Sensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && ECH1560_SUPPORT + #pragma once #include "Arduino.h" @@ -81,7 +83,7 @@ class ECH1560Sensor : public BaseSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { _error = SENSOR_ERROR_OK; if (index == 0) return MAGNITUDE_CURRENT; if (index == 1) return MAGNITUDE_VOLTAGE; @@ -324,3 +326,5 @@ void ECH1560Sensor::_detach(unsigned char gpio) { _ech1560_sensor_instance[index] = NULL; } } + +#endif // SENSOR_SUPPORT && ECH1560_SUPPORT diff --git a/code/espurna/sensors/EmonADC121Sensor.h b/code/espurna/sensors/EmonADC121Sensor.h index 1d0a5133..4bf9deaf 100644 --- a/code/espurna/sensors/EmonADC121Sensor.h +++ b/code/espurna/sensors/EmonADC121Sensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && EMON_ADC121_SUPPORT + #pragma once #include "Arduino.h" @@ -139,3 +141,5 @@ class EmonADC121Sensor : public EmonAnalogSensor { } }; + +#endif // SENSOR_SUPPORT && EMON_ADC121_SUPPORT diff --git a/code/espurna/sensors/EmonADS1X15Sensor.h b/code/espurna/sensors/EmonADS1X15Sensor.h index c156b320..2691da9e 100644 --- a/code/espurna/sensors/EmonADS1X15Sensor.h +++ b/code/espurna/sensors/EmonADS1X15Sensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && EMON_ADS1X15_SUPPORT + #pragma once #include "Arduino.h" @@ -202,7 +204,7 @@ class EmonADS1X15Sensor : public EmonSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { if (index < _count) { _error = SENSOR_ERROR_OK; unsigned char magnitude = index / _ports; @@ -392,3 +394,5 @@ class EmonADS1X15Sensor : public EmonSensor { }; + +#endif // SENSOR_SUPPORT && EMON_ADS1X15_SUPPORT diff --git a/code/espurna/sensors/EmonAnalogSensor.h b/code/espurna/sensors/EmonAnalogSensor.h index 88cb9b67..767825a3 100644 --- a/code/espurna/sensors/EmonAnalogSensor.h +++ b/code/espurna/sensors/EmonAnalogSensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && EMON_ANALOG_SUPPORT + #pragma once #include "Arduino.h" @@ -58,7 +60,7 @@ class EmonAnalogSensor : public EmonSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { _error = SENSOR_ERROR_OK; unsigned char i=0; #if EMON_REPORT_CURRENT @@ -119,3 +121,5 @@ class EmonAnalogSensor : public EmonSensor { } }; + +#endif // SENSOR_SUPPORT && EMON_ANALOG_SUPPORT diff --git a/code/espurna/sensors/EmonSensor.h b/code/espurna/sensors/EmonSensor.h index a2e6d4fb..8bb6eed4 100644 --- a/code/espurna/sensors/EmonSensor.h +++ b/code/espurna/sensors/EmonSensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT + #pragma once #include "Arduino.h" @@ -225,3 +227,5 @@ class EmonSensor : public I2CSensor { }; + +#endif // SENSOR_SUPPORT diff --git a/code/espurna/sensors/EventSensor.h b/code/espurna/sensors/EventSensor.h index 985d07e3..6af9270d 100644 --- a/code/espurna/sensors/EventSensor.h +++ b/code/espurna/sensors/EventSensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && EVENTS_SUPPORT + #pragma once #include "Arduino.h" @@ -80,7 +82,7 @@ class EventSensor : public BaseSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { _error = SENSOR_ERROR_OK; if (index == 0) return MAGNITUDE_EVENTS; _error = SENSOR_ERROR_OUT_OF_RANGE; @@ -198,3 +200,5 @@ void EventSensor::_detach(unsigned char gpio) { _event_sensor_instance[index] = NULL; } } + +#endif // SENSOR_SUPPORT && EVENTS_SUPPORT diff --git a/code/espurna/sensors/HLW8012Sensor.h b/code/espurna/sensors/HLW8012Sensor.h index 34729bd8..59bebc6c 100644 --- a/code/espurna/sensors/HLW8012Sensor.h +++ b/code/espurna/sensors/HLW8012Sensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && HLW8012_SUPPORT + #pragma once #include "Arduino.h" @@ -161,7 +163,7 @@ class HLW8012Sensor : public BaseSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { _error = SENSOR_ERROR_OK; if (index == 0) return MAGNITUDE_CURRENT; if (index == 1) return MAGNITUDE_VOLTAGE; @@ -308,3 +310,5 @@ void HLW8012Sensor::_detach(unsigned char gpio) { _hlw8012_sensor_instance[index] = NULL; } } + +#endif // SENSOR_SUPPORT && HLW8012_SUPPORT diff --git a/code/espurna/sensors/I2CSensor.h b/code/espurna/sensors/I2CSensor.h index a3c18a9c..44057ee6 100644 --- a/code/espurna/sensors/I2CSensor.h +++ b/code/espurna/sensors/I2CSensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && I2C_SUPPORT + #pragma once #include "BaseSensor.h" @@ -55,3 +57,5 @@ class I2CSensor : public BaseSensor { unsigned char _address = 0; }; + +#endif // SENSOR_SUPPORT && I2C_SUPPORT diff --git a/code/espurna/sensors/MHZ19Sensor.h b/code/espurna/sensors/MHZ19Sensor.h index 63d9dd12..576d649b 100644 --- a/code/espurna/sensors/MHZ19Sensor.h +++ b/code/espurna/sensors/MHZ19Sensor.h @@ -6,6 +6,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && MHZ19_SUPPORT + #pragma once #include "Arduino.h" @@ -88,7 +90,7 @@ class MHZ19Sensor : public BaseSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { _error = SENSOR_ERROR_OK; if (index == 0) return MAGNITUDE_CO2; _error = SENSOR_ERROR_OUT_OF_RANGE; @@ -202,3 +204,5 @@ class MHZ19Sensor : public BaseSensor { SoftwareSerial * _serial = NULL; }; + +#endif // SENSOR_SUPPORT && MHZ19_SUPPORT diff --git a/code/espurna/sensors/PMSX003Sensor.h b/code/espurna/sensors/PMSX003Sensor.h index 4ab49e40..e6a3aada 100644 --- a/code/espurna/sensors/PMSX003Sensor.h +++ b/code/espurna/sensors/PMSX003Sensor.h @@ -4,6 +4,8 @@ // Contribution by Òscar Rovira López // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && PMSX003_SUPPORT + #pragma once #include "Arduino.h" @@ -96,7 +98,7 @@ class PMSX003Sensor : public BaseSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { if (index < _count) { _error = SENSOR_ERROR_OK; if (index == 0) return MAGNITUDE_PM1dot0; @@ -150,3 +152,5 @@ class PMSX003Sensor : public BaseSensor { PMS::DATA _data; }; + +#endif // SENSOR_SUPPORT && PMSX003_SUPPORT diff --git a/code/espurna/sensors/SHT3XI2CSensor.h b/code/espurna/sensors/SHT3XI2CSensor.h index 24fdf867..7639c830 100644 --- a/code/espurna/sensors/SHT3XI2CSensor.h +++ b/code/espurna/sensors/SHT3XI2CSensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && SHT3X_I2C_SUPPORT + #pragma once #include "Arduino.h" @@ -50,7 +52,7 @@ class SHT3XI2CSensor : public I2CSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { if (index < _count) { _error = SENSOR_ERROR_OK; if (index == 0) return MAGNITUDE_TEMPERATURE; @@ -116,3 +118,5 @@ class SHT3XI2CSensor : public I2CSensor { unsigned char _humidity = 0; }; + +#endif // SENSOR_SUPPORT && SHT3X_I2C_SUPPORT diff --git a/code/espurna/sensors/SI7021Sensor.h b/code/espurna/sensors/SI7021Sensor.h index f0da7b66..6dbfb457 100644 --- a/code/espurna/sensors/SI7021Sensor.h +++ b/code/espurna/sensors/SI7021Sensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && SI7021_SUPPORT + #pragma once #include "Arduino.h" @@ -84,7 +86,7 @@ class SI7021Sensor : public I2CSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { if (index < _count) { _error = SENSOR_ERROR_OK; if (index == 0) return MAGNITUDE_TEMPERATURE; @@ -175,3 +177,5 @@ class SI7021Sensor : public I2CSensor { unsigned char _chip; }; + +#endif // SENSOR_SUPPORT && SI7021_SUPPORT diff --git a/code/espurna/sensors/V9261FSensor.h b/code/espurna/sensors/V9261FSensor.h index 5249ff6c..4ffdeb20 100644 --- a/code/espurna/sensors/V9261FSensor.h +++ b/code/espurna/sensors/V9261FSensor.h @@ -3,6 +3,8 @@ // Copyright (C) 2017 by Xose Pérez // ----------------------------------------------------------------------------- +#if SENSOR_SUPPORT && V9261F_SUPPORT + #pragma once #include "Arduino.h" @@ -81,7 +83,7 @@ class V9261FSensor : public BaseSensor { } // Type for slot # index - magnitude_t type(unsigned char index) { + unsigned char type(unsigned char index) { _error = SENSOR_ERROR_OK; if (index == 0) return MAGNITUDE_CURRENT; if (index == 1) return MAGNITUDE_VOLTAGE; @@ -244,3 +246,5 @@ class V9261FSensor : public BaseSensor { unsigned char _data[24]; }; + +#endif // SENSOR_SUPPORT && V9261F_SUPPORT