Browse Source

Some clean-up

fastled
Xose Pérez 7 years ago
parent
commit
b70a5aaf8c
6 changed files with 100 additions and 65 deletions
  1. +17
    -4
      code/espurna/config/arduino.h
  2. +3
    -3
      code/espurna/config/hardware.h
  3. +1
    -1
      code/espurna/config/prototypes.h
  4. +33
    -37
      code/espurna/config/sensors.h
  5. +39
    -12
      code/espurna/espurna.ino
  6. +7
    -8
      code/espurna/sensor.ino

+ 17
- 4
code/espurna/config/arduino.h View File

@ -60,14 +60,10 @@
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
//#define ALEXA_SUPPORT 0 //#define ALEXA_SUPPORT 0
//#define ANALOG_SUPPORT 1
//#define COUNTER_SUPPORT 1
//#define DEBUG_SERIAL_SUPPORT 0 //#define DEBUG_SERIAL_SUPPORT 0
//#define DEBUG_TELNET_SUPPORT 0 //#define DEBUG_TELNET_SUPPORT 0
//#define DEBUG_UDP_SUPPORT 1 //#define DEBUG_UDP_SUPPORT 1
//#define DHT_SUPPORT 1
//#define DOMOTICZ_SUPPORT 0 //#define DOMOTICZ_SUPPORT 0
//#define DS18B20_SUPPORT 1
//#define HOMEASSISTANT_SUPPORT 0 //#define HOMEASSISTANT_SUPPORT 0
//#define I2C_SUPPORT 1 //#define I2C_SUPPORT 1
//#define INFLUXDB_SUPPORT 0 //#define INFLUXDB_SUPPORT 0
@ -81,3 +77,20 @@
//#define TELNET_SUPPORT 0 //#define TELNET_SUPPORT 0
//#define TERMINAL_SUPPORT 0 //#define TERMINAL_SUPPORT 0
//#define WEB_SUPPORT 0 //#define WEB_SUPPORT 0
//--------------------------------------------------------------------------------
// Sensors (values below are non-default values)
//--------------------------------------------------------------------------------
//#define ANALOG_SUPPORT 1
//#define BMX280_SUPPORT 1
//#define DALLAS_SUPPORT 1
//#define DHT_SUPPORT 1
//#define DIGITAL_SUPPORT 1
//#define EMON_ADC121_SUPPORT 1
//#define EMON_ADS1X15_SUPPORT 1
//#define EMON_ANALOG_SUPPORT 1
//#define EVENTS_SUPPORT 1
//#define MHZ19_SUPPORT 1
//#define PMSX003_SUPPORT 1
//#define SI7021_SUPPORT 1

+ 3
- 3
code/espurna/config/hardware.h View File

@ -1076,9 +1076,9 @@
#define RELAY2_TYPE RELAY_TYPE_NORMAL #define RELAY2_TYPE RELAY_TYPE_NORMAL
// DB18B20 // DB18B20
#define DS18B20_SUPPORT 1
#define DS18B20_PIN 2
#define DS18B20_UPDATE_INTERVAL 5000
#define DALLAS_SUPPORT 1
#define DALLAS_PIN 2
#define DALLAS_UPDATE_INTERVAL 5000
#define TEMPERATURE_MIN_CHANGE 1.0 #define TEMPERATURE_MIN_CHANGE 1.0
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


+ 1
- 1
code/espurna/config/prototypes.h View File

@ -75,7 +75,7 @@ template<typename T> bool idbSend(const char * topic, unsigned char id, T payloa
// Sensors // Sensors
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include "sensors/BaseSensor.h" #include "sensors/BaseSensor.h"
#if DS18B20_SUPPORT
#if DALLAS_SUPPORT
#include <OneWire.h> #include <OneWire.h>
#endif #endif
#if PMSX003_SUPPORT #if PMSX003_SUPPORT


+ 33
- 37
code/espurna/config/sensors.h View File

@ -7,10 +7,21 @@
#define SENSOR_USE_INDEX 0 // Use the index in topic (i.e. temperature/0) #define SENSOR_USE_INDEX 0 // Use the index in topic (i.e. temperature/0)
// even if just one sensor (0 for backwards compatibility) // even if just one sensor (0 for backwards compatibility)
#ifndef SENSOR_TEMPERATURE_UNITS
#define SENSOR_TEMPERATURE_UNITS TMP_CELSIUS // Temperature units (TMP_CELSIUS | TMP_FAHRENHEIT) #define SENSOR_TEMPERATURE_UNITS TMP_CELSIUS // Temperature units (TMP_CELSIUS | TMP_FAHRENHEIT)
#endif
#ifndef SENSOR_TEMPERATURE_CORRECTION
#define SENSOR_TEMPERATURE_CORRECTION 0.0 // Offset correction #define SENSOR_TEMPERATURE_CORRECTION 0.0 // Offset correction
#endif
#ifndef TEMPERATURE_MIN_CHANGE
#define TEMPERATURE_MIN_CHANGE 0.0 // Minimum temperature change to report #define TEMPERATURE_MIN_CHANGE 0.0 // Minimum temperature change to report
#endif
#ifndef HUMIDITY_MIN_CHANGE
#define HUMIDITY_MIN_CHANGE 0 // Minimum humidity change to report #define HUMIDITY_MIN_CHANGE 0 // Minimum humidity change to report
#endif
#define SENSOR_TEMPERATURE_DECIMALS 1 #define SENSOR_TEMPERATURE_DECIMALS 1
#define SENSOR_HUMIDITY_DECIMALS 0 #define SENSOR_HUMIDITY_DECIMALS 0
@ -68,13 +79,6 @@
#define DHT_PULLUP 0 #define DHT_PULLUP 0
#endif #endif
#ifndef DHT_UPDATE_INTERVAL
#define DHT_UPDATE_INTERVAL 60000
#endif
#define DHT_TEMPERATURE_TOPIC "temperature"
#define DHT_HUMIDITY_TOPIC "humidity"
#define HUMIDITY_NORMAL 0 #define HUMIDITY_NORMAL 0
#define HUMIDITY_COMFORTABLE 1 #define HUMIDITY_COMFORTABLE 1
#define HUMIDITY_DRY 2 #define HUMIDITY_DRY 2
@ -113,30 +117,22 @@
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// DS18B20 temperature sensor // DS18B20 temperature sensor
// Enable support by passing DS18B20_SUPPORT=1 build flag
// Enable support by passing DALLAS_SUPPORT=1 build flag
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
#ifndef DS18B20_SUPPORT
#define DS18B20_SUPPORT 0
#endif
#ifndef DS18B20_PIN
#define DS18B20_PIN 13
#endif
#ifndef DS18B20_PULLUP
#define DS18B20_PULLUP 1
#ifndef DALLAS_SUPPORT
#define DALLAS_SUPPORT 0
#endif #endif
#ifndef DS18B20_UPDATE_INTERVAL
#define DS18B20_UPDATE_INTERVAL 60000
#ifndef DALLAS_PIN
#define DALLAS_PIN 13
#endif #endif
#ifndef DS18B20_TEMPERATURE_TOPIC
#define DS18B20_TEMPERATURE_TOPIC "temperature"
#ifndef DALLAS_PULLUP
#define DALLAS_PULLUP 1
#endif #endif
#define DS18B20_RESOLUTION 9
#define DALLAS_RESOLUTION 9 // Not used atm
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Digital sensor // Digital sensor
@ -184,38 +180,38 @@
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Counter sensor // Counter sensor
// Enable support by passing COUNTER_SUPPORT=1 build flag
// Enable support by passing EVENTS_SUPPORT=1 build flag
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
#ifndef COUNTER_SUPPORT
#define COUNTER_SUPPORT 0 // Do not build with counter support by default
#ifndef EVENTS_SUPPORT
#define EVENTS_SUPPORT 0 // Do not build with counter support by default
#endif #endif
#ifndef COUNTER_PIN
#define COUNTER_PIN 2 // GPIO to monitor
#ifndef EVENTS_PIN
#define EVENTS_PIN 2 // GPIO to monitor
#endif #endif
#ifndef COUNTER_PIN_MODE
#define COUNTER_PIN_MODE INPUT // INPUT, INPUT_PULLUP
#ifndef EVENTS_PIN_MODE
#define EVENTS_PIN_MODE INPUT // INPUT, INPUT_PULLUP
#endif #endif
#ifndef COUNTER_INTERRUPT_MODE
#define COUNTER_INTERRUPT_MODE RISING // RISING, FALLING, BOTH
#ifndef EVENTS_INTERRUPT_MODE
#define EVENTS_INTERRUPT_MODE RISING // RISING, FALLING, BOTH
#endif #endif
#define COUNTER_DEBOUNCE 50 // Do not register events within less than 10 millis
#define EVENTS_DEBOUNCE 50 // Do not register events within less than 10 millis
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Energy Monitor
// Energy Monitor general settings
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
#define EMON_MAX_SAMPLES 1000 // Max number of samples to get #define EMON_MAX_SAMPLES 1000 // Max number of samples to get
#define EMON_MAX_TIME 250 // Max time in ms to sample #define EMON_MAX_TIME 250 // Max time in ms to sample
#define EMON_FILTER_SPEED 512 // Mobile average filter speed #define EMON_FILTER_SPEED 512 // Mobile average filter speed
#define EMON_MAINS_VOLTAGE 230 // Mains voltage #define EMON_MAINS_VOLTAGE 230 // Mains voltage
#define EMON_REPORT_CURRENT 0 // Calculate current
#define EMON_REPORT_POWER 1 // Calculate power
#define EMON_REPORT_ENERGY 1 // Calculate energy
#define EMON_REPORT_CURRENT 0 // Report current
#define EMON_REPORT_POWER 1 // Report power
#define EMON_REPORT_ENERGY 1 // Report energy
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Energy Monitor based on interval analog GPIO // Energy Monitor based on interval analog GPIO


+ 39
- 12
code/espurna/espurna.ino View File

@ -146,12 +146,6 @@ void welcome() {
#if ALEXA_SUPPORT #if ALEXA_SUPPORT
DEBUG_MSG_P(PSTR(" ALEXA")); DEBUG_MSG_P(PSTR(" ALEXA"));
#endif #endif
#if ANALOG_SUPPORT
DEBUG_MSG_P(PSTR(" ANALOG"));
#endif
#if COUNTER_SUPPORT
DEBUG_MSG_P(PSTR(" COUNTER"));
#endif
#if DEBUG_SERIAL_SUPPORT #if DEBUG_SERIAL_SUPPORT
DEBUG_MSG_P(PSTR(" DEBUG_SERIAL")); DEBUG_MSG_P(PSTR(" DEBUG_SERIAL"));
#endif #endif
@ -161,15 +155,9 @@ void welcome() {
#if DEBUG_UDP_SUPPORT #if DEBUG_UDP_SUPPORT
DEBUG_MSG_P(PSTR(" DEBUG_UDP")); DEBUG_MSG_P(PSTR(" DEBUG_UDP"));
#endif #endif
#if DHT_SUPPORT
DEBUG_MSG_P(PSTR(" DHT"));
#endif
#if DOMOTICZ_SUPPORT #if DOMOTICZ_SUPPORT
DEBUG_MSG_P(PSTR(" DOMOTICZ")); DEBUG_MSG_P(PSTR(" DOMOTICZ"));
#endif #endif
#if DS18B20_SUPPORT
DEBUG_MSG_P(PSTR(" DS18B20"));
#endif
#if HOMEASSISTANT_SUPPORT #if HOMEASSISTANT_SUPPORT
DEBUG_MSG_P(PSTR(" HOMEASSISTANT")); DEBUG_MSG_P(PSTR(" HOMEASSISTANT"));
#endif #endif
@ -210,6 +198,45 @@ void welcome() {
DEBUG_MSG_P(PSTR(" WEB")); DEBUG_MSG_P(PSTR(" WEB"));
#endif #endif
DEBUG_MSG_P(PSTR("\n[INIT] SENSORS:"));
#if ANALOG_SUPPORT
DEBUG_MSG_P(PSTR(" ANALOG"));
#endif
#if BMX280_SUPPORT
DEBUG_MSG_P(PSTR(" BMX280"));
#endif
#if DALLAS_SUPPORT
DEBUG_MSG_P(PSTR(" DALLAS"));
#endif
#if DHT_SUPPORT
DEBUG_MSG_P(PSTR(" DHTXX"));
#endif
#if DIGITAL_SUPPORT
DEBUG_MSG_P(PSTR(" DIGITAL"));
#endif
#if EMON_ADC121_SUPPORT
DEBUG_MSG_P(PSTR(" EMON_ADC121"));
#endif
#if EMON_ADS1X15_SUPPORT
DEBUG_MSG_P(PSTR(" EMON_ADX1X15"));
#endif
#if EMON_ANALOG_SUPPORT
DEBUG_MSG_P(PSTR(" EMON_ANALOG"));
#endif
#if EVENTS_SUPPORT
DEBUG_MSG_P(PSTR(" EVENTS"));
#endif
#if MHZ19_SUPPORT
DEBUG_MSG_P(PSTR(" MHZ19"));
#endif
#if PMSX003_SUPPORT
DEBUG_MSG_P(PSTR(" PMSX003"));
#endif
#if SI7021_SUPPORT
DEBUG_MSG_P(PSTR(" SI7021"));
#endif
DEBUG_MSG_P(PSTR("\n\n")); DEBUG_MSG_P(PSTR("\n\n"));
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------


+ 7
- 8
code/espurna/sensor.ino View File

@ -31,7 +31,6 @@ unsigned char _counts[MAGNITUDE_MAX];
bool _sensor_realtime = API_REAL_TIME_VALUES; bool _sensor_realtime = API_REAL_TIME_VALUES;
unsigned char _sensor_temperature_units = SENSOR_TEMPERATURE_UNITS; unsigned char _sensor_temperature_units = SENSOR_TEMPERATURE_UNITS;
double _sensor_temperature_correction = SENSOR_TEMPERATURE_CORRECTION; double _sensor_temperature_correction = SENSOR_TEMPERATURE_CORRECTION;
unsigned char _sensor_isr = 0xFF;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Private // Private
@ -193,14 +192,14 @@ void _sensorPost() {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Interrupts // Interrupts
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if COUNTER_SUPPORT
#if EVENTS_SUPPORT
unsigned char _event_sensor_id = 0; unsigned char _event_sensor_id = 0;
void isrEventSensor() { void isrEventSensor() {
_sensors[_event_sensor_id]->InterruptHandler(); _sensors[_event_sensor_id]->InterruptHandler();
} }
#endif // COUNTER_SUPPORT
#endif // EVENTS_SUPPORT
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Values // Values
@ -240,9 +239,9 @@ void sensorInit() {
sensorRegister(new DHTSensor(DHT_PIN, DHT_TYPE, DHT_PULLUP)); sensorRegister(new DHTSensor(DHT_PIN, DHT_TYPE, DHT_PULLUP));
#endif #endif
#if DS18B20_SUPPORT
#if DALLAS_SUPPORT
#include "sensors/DallasSensor.h" #include "sensors/DallasSensor.h"
sensorRegister(new DallasSensor(DS18B20_PIN, SENSOR_READ_INTERVAL, DS18B20_PULLUP));
sensorRegister(new DallasSensor(DALLAS_PIN, SENSOR_READ_INTERVAL, DALLAS_PULLUP));
#endif #endif
#if SI7021_SUPPORT #if SI7021_SUPPORT
@ -290,11 +289,11 @@ void sensorInit() {
sensorRegister(new MHZ19Sensor(MHZ19_RX_PIN, MHZ19_TX_PIN)); sensorRegister(new MHZ19Sensor(MHZ19_RX_PIN, MHZ19_TX_PIN));
#endif #endif
#if COUNTER_SUPPORT
#if EVENTS_SUPPORT
#include "sensors/EventSensor.h" #include "sensors/EventSensor.h"
sensorRegister(new EventSensor(COUNTER_PIN, COUNTER_PIN_MODE, COUNTER_DEBOUNCE));
sensorRegister(new EventSensor(EVENTS_PIN, EVENTS_PIN_MODE, EVENTS_DEBOUNCE));
_event_sensor_id = sensorCount() - 1; _event_sensor_id = sensorCount() - 1;
attachInterrupt(COUNTER_PIN, isrEventSensor, COUNTER_INTERRUPT_MODE);
attachInterrupt(EVENTS_PIN, isrEventSensor, EVENTS_INTERRUPT_MODE);
#endif #endif
} }


Loading…
Cancel
Save