From 9e96e0f21a1229cf21726100e7324e2103eb0d79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Tue, 22 Nov 2016 10:10:38 +0100 Subject: [PATCH] Split configuration file --- code/src/config/all.h | 5 + code/src/{ => config}/debug.h | 0 code/src/{defaults.h => config/general.h} | 110 ++-------------------- code/src/config/hardware.h | 76 +++++++++++++++ code/src/config/sensors.h | 56 +++++++++++ code/src/{ => config}/version.h | 2 +- code/src/main.ino | 4 +- 7 files changed, 149 insertions(+), 104 deletions(-) create mode 100644 code/src/config/all.h rename code/src/{ => config}/debug.h (100%) rename code/src/{defaults.h => config/general.h} (50%) create mode 100644 code/src/config/hardware.h create mode 100644 code/src/config/sensors.h rename code/src/{ => config}/version.h (79%) diff --git a/code/src/config/all.h b/code/src/config/all.h new file mode 100644 index 00000000..7c49a3e4 --- /dev/null +++ b/code/src/config/all.h @@ -0,0 +1,5 @@ +#include "version.h" +#include "debug.h" +#include "general.h" +#include "hardware.h" +#include "sensors.h" diff --git a/code/src/debug.h b/code/src/config/debug.h similarity index 100% rename from code/src/debug.h rename to code/src/config/debug.h diff --git a/code/src/defaults.h b/code/src/config/general.h similarity index 50% rename from code/src/defaults.h rename to code/src/config/general.h index 7bbfd7be..bf859923 100644 --- a/code/src/defaults.h +++ b/code/src/config/general.h @@ -1,72 +1,19 @@ //------------------------------------------------------------------------------ -// SET BY PLATFORMIO +// GENERAL //------------------------------------------------------------------------------ -//#define DEBUG_PORT Serial - -//#define ESPURNA -//#define SONOFF -//#define SLAMPHER -//#define S20 -//#define NODEMCUV2 - -//#define ENABLE_FAUXMO 1 -//#define ENABLE_NOFUSS 1 -//#define ENABLE_EMON 1 -//#define ENABLE_DHT 1 -//#define ENABLE_RF 1 -//#define ENABLE_POW 1 - -// ----------------------------------------------------------------------------- -// HARDWARE -// ----------------------------------------------------------------------------- - #define SERIAL_BAUDRATE 115200 -#define BUTTON_PIN 0 -#define RELAY_PIN 12 - -#ifdef ESPURNA - #define MANUFACTURER "TINKERMAN" - #define DEVICE "ESPURNA" - #define LED_PIN 13 -#endif - -#ifdef SONOFF - #define MANUFACTURER "ITEAD" - #define DEVICE "SONOFF" - #define LED_PIN 13 -#endif - -#ifdef SONOFF_POW - #define ENABLE_POW 1 - #define MANUFACTURER "ITEAD" - #define DEVICE "SONOFF_POW" - #define LED_PIN 13 -#endif - -#ifdef SLAMPHER - #define MANUFACTURER "ITEAD" - #define DEVICE "SLAMPHER" - #define LED_PIN 13 -#endif - -#ifdef S20 - #define MANUFACTURER "ITEAD" - #define DEVICE "S20" - #define LED_PIN 13 -#endif - -#ifdef NODEMCUV2 - #define MANUFACTURER "NODEMCU" - #define DEVICE "LOLIN" - #define LED_PIN 2 -#endif - #define HOSTNAME DEVICE #define BUFFER_SIZE 1024 #define HEARTBEAT_INTERVAL 300000 #define FS_VERSION_FILE "/fsversion" +//-------------------------------------------------------------------------------- +// RELAY +//-------------------------------------------------------------------------------- + +// 0 means OFF, 1 ON and 2 whatever was before +#define RELAY_MODE 1 // ----------------------------------------------------------------------------- // WIFI & WEB @@ -113,45 +60,8 @@ #define NTP_DAY_LIGHT true #define NTP_UPDATE_INTERVAL 1800 -//-------------------------------------------------------------------------------- -// DRIVERS -//-------------------------------------------------------------------------------- - -// 0 means OFF, 1 ON and 2 whatever was before -#define RELAY_MODE 1 - -#define RF_PIN 14 -#define RF_CHANNEL 31 -#define RF_DEVICE 1 - -#define DHT_PIN 14 -#define DHT_UPDATE_INTERVAL 300000 -#define DHT_TYPE DHT22 -#define DHT_TIMING 11 -#define DHT_TEMPERATURE_TOPIC "/temperature" -#define DHT_HUMIDITY_TOPIC "/humidity" - -#define EMON_CURRENT_PIN 0 -#define EMON_SAMPLES 1000 -#define EMON_INTERVAL 10000 -#define EMON_MEASUREMENTS 6 -#define EMON_ADC_BITS 10 -#define EMON_REFERENCE_VOLTAGE 1.0 -#define EMON_CURRENT_PRECISION 1 -#define EMON_CURRENT_OFFSET 0.25 -#define EMON_MAINS_VOLTAGE 230 -#define EMON_CURRENT_RATIO 180 -#define EMON_POWER_TOPIC "/power" - -#define POW_SEL_PIN 5 -#define POW_CF1_PIN 13 -#define POW_CF_PIN 14 -#define POW_SEL_CURRENT HIGH -#define POW_CURRENT_R 0.001 -#define POW_VOLTAGE_R_UP ( 5 * 470000 ) // Real: 2280k -#define POW_VOLTAGE_R_DOWN ( 1000 ) // Real 1.009k -#define POW_POWER_TOPIC "/power" -#define POW_UPDATE_INTERVAL 10000 -#define POW_REPORT_EVERY 6 +// ----------------------------------------------------------------------------- +// FAUXO +// ----------------------------------------------------------------------------- #define FAUXMO_ENABLED 0 diff --git a/code/src/config/hardware.h b/code/src/config/hardware.h new file mode 100644 index 00000000..1c0e173f --- /dev/null +++ b/code/src/config/hardware.h @@ -0,0 +1,76 @@ +// ----------------------------------------------------------------------------- +// NODEMCUv2 development board +// ----------------------------------------------------------------------------- + +#if defined(NODEMCUV2) + + #define MANUFACTURER "NODEMCU" + #define DEVICE "LOLIN" + #define BUTTON_PIN 0 + #define RELAY_PIN 12 + #define LED_PIN 2 + +// ----------------------------------------------------------------------------- +// Itead Studio boards +// ----------------------------------------------------------------------------- + +#elif defined(SONOFF) + + #define MANUFACTURER "ITEAD" + #define DEVICE "SONOFF" + #define BUTTON_PIN 0 + #define RELAY_PIN 12 + #define LED_PIN 13 + +#elif defined(SONOFF_TH) + + #define MANUFACTURER "ITEAD" + #define DEVICE "SONOFF_TH" + #define BUTTON_PIN 0 + #define RELAY_PIN 12 + #define LED_PIN 13 + +#elif defined(SONOFF_POW) + + #define MANUFACTURER "ITEAD" + #define DEVICE "SONOFF_POW" + #define BUTTON_PIN 0 + #define RELAY_PIN 12 + #define LED_PIN 15 + #define ENABLE_POW 1 + +#elif defined(SLAMPHER) + + #define MANUFACTURER "ITEAD" + #define DEVICE "SLAMPHER" + #define BUTTON_PIN 0 + #define RELAY_PIN 12 + #define LED_PIN 13 + +#elif defined(S20) + + #define MANUFACTURER "ITEAD" + #define DEVICE "S20" + #define BUTTON_PIN 0 + #define RELAY_PIN 12 + #define LED_PIN 13 + +// ----------------------------------------------------------------------------- +// ESPurna board (still beta) +// ----------------------------------------------------------------------------- + +#elif defined(ESPURNA) + + #define MANUFACTURER "TINKERMAN" + #define DEVICE "ESPURNA" + #define BUTTON_PIN 0 + #define RELAY_PIN 12 + #define LED_PIN 13 + +// ----------------------------------------------------------------------------- +// Unknown hardware +// ----------------------------------------------------------------------------- + +#else + #error "UNSUPPORTED HARDWARE!" +#endif diff --git a/code/src/config/sensors.h b/code/src/config/sensors.h new file mode 100644 index 00000000..4f11c0aa --- /dev/null +++ b/code/src/config/sensors.h @@ -0,0 +1,56 @@ +//-------------------------------------------------------------------------------- +// Custom RF module +// Check http://tinkerman.cat/adding-rf-to-a-non-rf-itead-sonoff/ +// Enable support by passing ENABLE_RF=1 build flag +//-------------------------------------------------------------------------------- + +#define RF_PIN 14 +#define RF_CHANNEL 31 +#define RF_DEVICE 1 + +//-------------------------------------------------------------------------------- +// DHTXX temperature/humidity sensor +// Enable support by passing ENABLE_DHT=1 build flag +//-------------------------------------------------------------------------------- + +#define DHT_PIN 14 +#define DHT_UPDATE_INTERVAL 300000 +#define DHT_TYPE DHT22 +#define DHT_TIMING 11 +#define DHT_TEMPERATURE_TOPIC "/temperature" +#define DHT_HUMIDITY_TOPIC "/humidity" + +//-------------------------------------------------------------------------------- +// Custom current sensor +// Check http://tinkerman.cat/your-laundry-is-done/ +// Enable support by passing ENABLE_EMON=1 build flag +//-------------------------------------------------------------------------------- + +#define EMON_CURRENT_PIN 0 +#define EMON_SAMPLES 1000 +#define EMON_INTERVAL 10000 +#define EMON_MEASUREMENTS 6 +#define EMON_ADC_BITS 10 +#define EMON_REFERENCE_VOLTAGE 1.0 +#define EMON_CURRENT_PRECISION 1 +#define EMON_CURRENT_OFFSET 0.25 +#define EMON_MAINS_VOLTAGE 230 +#define EMON_CURRENT_RATIO 180 +#define EMON_POWER_TOPIC "/power" + +//-------------------------------------------------------------------------------- +// HLW8012 power sensor (Sonoff POW) +// Enable support by passing ENABLE_POW=1 build flag +// Enabled by default when selecting SONOFF_POW hardware +//-------------------------------------------------------------------------------- + +#define POW_SEL_PIN 5 +#define POW_CF1_PIN 13 +#define POW_CF_PIN 14 +#define POW_SEL_CURRENT HIGH +#define POW_CURRENT_R 0.001 +#define POW_VOLTAGE_R_UP ( 5 * 470000 ) // Real: 2280k +#define POW_VOLTAGE_R_DOWN ( 1000 ) // Real 1.009k +#define POW_POWER_TOPIC "/power" +#define POW_UPDATE_INTERVAL 10000 +#define POW_REPORT_EVERY 6 diff --git a/code/src/version.h b/code/src/config/version.h similarity index 79% rename from code/src/version.h rename to code/src/config/version.h index 5e910f49..b434af89 100644 --- a/code/src/version.h +++ b/code/src/config/version.h @@ -1,4 +1,4 @@ #define APP_NAME "Espurna" -#define APP_VERSION "1.0.2" +#define APP_VERSION "1.0.3" #define APP_AUTHOR "xose.perez@gmail.com" #define APP_WEBSITE "http://tinkerman.cat" diff --git a/code/src/main.ino b/code/src/main.ino index be5a5d48..b8b6a066 100644 --- a/code/src/main.ino +++ b/code/src/main.ino @@ -19,9 +19,7 @@ along with this program. If not, see . */ #include -#include "defaults.h" -#include "version.h" -#include "debug.h" +#include "config/all.h" // ----------------------------------------------------------------------------- // PROTOTYPES