From c39794493a3a5402f03545d2ce74d933e70958fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Wed, 20 Dec 2017 08:10:55 +0100 Subject: [PATCH] Load sensor classes outside the initSensor scope --- code/espurna/config/prototypes.h | 18 --------- code/espurna/config/sensors.h | 64 +++++++++++++++++++++++++++++++- code/espurna/sensor.ino | 12 ------ 3 files changed, 63 insertions(+), 31 deletions(-) diff --git a/code/espurna/config/prototypes.h b/code/espurna/config/prototypes.h index f56c4415..08e6befd 100644 --- a/code/espurna/config/prototypes.h +++ b/code/espurna/config/prototypes.h @@ -71,24 +71,6 @@ template bool idbSend(const char * topic, unsigned char id, T payloa #include #endif -// ----------------------------------------------------------------------------- -// Sensors -// ----------------------------------------------------------------------------- -#include "sensors/BaseSensor.h" -#if DALLAS_SUPPORT -#include -#endif -#if PMSX003_SUPPORT -#include -#include -#endif -#if MHZ19_SUPPORT -#include -#endif -#if BMX280_SUPPORT -#include -#endif - // ----------------------------------------------------------------------------- // Utils // ----------------------------------------------------------------------------- diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index b2341da6..4e6bf60c 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -266,7 +266,7 @@ //-------------------------------------------------------------------------------- #ifndef SI7021_SUPPORT -#define SI7021_SUPPORT 1 +#define SI7021_SUPPORT 0 #endif #ifndef SI7021_ADDRESS @@ -286,3 +286,65 @@ #if ADC_VCC_ENABLED ADC_MODE(ADC_VCC); #endif + +//-------------------------------------------------------------------------------- +// Class loading +//-------------------------------------------------------------------------------- + +// Embarrasing... +unsigned char i2cFindFirst(size_t size, unsigned char * addresses); + +#include "sensors/BaseSensor.h" + +#if ANALOG_SUPPORT + #include "sensors/AnalogSensor.h" +#endif + +#if BMX280_SUPPORT + #include + #include "sensors/BMX280Sensor.h" +#endif + +#if DALLAS_SUPPORT + #include + #include "sensors/DallasSensor.h" +#endif + +#if DHT_SUPPORT + #include "sensors/DHTSensor.h" +#endif + +#if DIGITAL_SUPPORT + #include "sensors/DigitalSensor.h" +#endif + +#if EMON_ADC121_SUPPORT + #include "sensors/EmonADC121Sensor.h" +#endif + +#if EMON_ADS1X15_SUPPORT + #include "sensors/EmonADS1X15Sensor.h" +#endif + +#if EMON_ANALOG_SUPPORT + #include "sensors/EmonAnalogSensor.h" +#endif + +#if EVENTS_SUPPORT + #include "sensors/EventSensor.h" +#endif + +#if MHZ19_SUPPORT + #include + #include "sensors/MHZ19Sensor.h" +#endif + +#if PMSX003_SUPPORT + #include + #include + #include "sensors/PMSX003Sensor.h" +#endif + +#if SI7021_SUPPORT + #include "sensors/SI7021Sensor.h" +#endif diff --git a/code/espurna/sensor.ino b/code/espurna/sensor.ino index 525f4c93..6b12bd6c 100644 --- a/code/espurna/sensor.ino +++ b/code/espurna/sensor.ino @@ -214,7 +214,6 @@ void _sensorInit() { #if ANALOG_SUPPORT { - #include "sensors/AnalogSensor.h" AnalogSensor * sensor = new AnalogSensor(); sensor->setGPIO(ANALOG_PIN, ANALOG_PIN_MODE); _sensorRegister(sensor); @@ -223,7 +222,6 @@ void _sensorInit() { #if BMX280_SUPPORT { - #include "sensors/BMX280Sensor.h" BMX280Sensor * sensor = new BMX280Sensor(); sensor->setAddress(BMX280_ADDRESS); _sensorRegister(sensor); @@ -232,7 +230,6 @@ void _sensorInit() { #if DALLAS_SUPPORT { - #include "sensors/DallasSensor.h" DallasSensor * sensor = new DallasSensor(); sensor->setGPIO(DALLAS_PIN, DALLAS_PULLUP); _sensorRegister(sensor); @@ -241,7 +238,6 @@ void _sensorInit() { #if DHT_SUPPORT { - #include "sensors/DHTSensor.h" DHTSensor * sensor = new DHTSensor(); sensor->setGPIO(DHT_PIN); sensor->setType(DHT_TYPE); @@ -251,7 +247,6 @@ void _sensorInit() { #if DIGITAL_SUPPORT { - #include "sensors/DigitalSensor.h" DigitalSensor * sensor = new DigitalSensor(); sensor->setGPIO(DIGITAL_PIN, DIGITAL_PIN_MODE); sensor->setDefault(DIGITAL_DEFAULT_STATE); @@ -261,7 +256,6 @@ void _sensorInit() { #if EMON_ADC121_SUPPORT { - #include "sensors/EmonADC121Sensor.h" EmonADC121Sensor * sensor = new EmonADC121Sensor(); sensor->setAddress(EMON_ADC121_I2C_ADDRESS); sensor->setVoltage(EMON_MAINS_VOLTAGE); @@ -273,7 +267,6 @@ void _sensorInit() { #if EMON_ADS1X15_SUPPORT { - #include "sensors/EmonADS1X15Sensor.h" EmonADS1X15Sensor * sensor = new EmonADS1X15Sensor(); sensor->setAddress(EMON_ADS1X15_I2C_ADDRESS); sensor->setType(EMON_ADS1X15_TYPE); @@ -287,7 +280,6 @@ void _sensorInit() { #if EMON_ANALOG_SUPPORT { - #include "sensors/EmonAnalogSensor.h" EmonAnalogSensor * sensor = new EmonAnalogSensor(); sensor->setVoltage(EMON_MAINS_VOLTAGE); sensor->setReference(EMON_REFERENCE_VOLTAGE); @@ -298,7 +290,6 @@ void _sensorInit() { #if EVENTS_SUPPORT { - #include "sensors/EventSensor.h" EventSensor * sensor = new EventSensor(); sensor->setGPIO(EVENTS_PIN, EVENTS_PIN_MODE); sensor->setDebounceTime(EVENTS_DEBOUNCE); @@ -310,7 +301,6 @@ void _sensorInit() { #if MHZ19_SUPPORT { - #include "sensors/MHZ19Sensor.h" MHZ19Sensor * sensor = new MHZ19Sensor(); sensor->setGPIO(MHZ19_RX_PIN, MHZ19_TX_PIN); _sensorRegister(sensor); @@ -319,7 +309,6 @@ void _sensorInit() { #if PMSX003_SUPPORT { - #include "sensors/PMSX003Sensor.h" PMSX003Sensor * sensor = new PMSX003Sensor(); sensor->setGPIO(PMS_RX_PIN, PMS_TX_PIN); _sensorRegister(sensor); @@ -328,7 +317,6 @@ void _sensorInit() { #if SI7021_SUPPORT { - #include "sensors/SI7021Sensor.h" SI7021Sensor * sensor = new SI7021Sensor(); sensor->setAddress(SI7021_ADDRESS); _sensorRegister(sensor);