From 3bb5cc879f644b189a1dbbd233c0e5b99e92d3c3 Mon Sep 17 00:00:00 2001 From: Rui Caridade Date: Sat, 13 Jul 2019 00:54:53 +0100 Subject: [PATCH] Make compilation more flexible (#1816) * Make compilation more flexible allowing to define in custom.h your own variation to devices and define four wifi networks * Implement suggestion from Max Prokhorov, it's simpler and cleaner * Change a #elif by #else * Move ESPurna Core comment --- code/espurna/config/general.h | 48 +++++++++++++++++++++++++ code/espurna/config/hardware.h | 65 ++++++++++++++++++---------------- code/espurna/wifi.ino | 23 +++++++++++- 3 files changed, 105 insertions(+), 31 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 0b0e157a..a3f5f097 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -489,6 +489,54 @@ #define WIFI2_DNS "" #endif +#ifndef WIFI3_SSID +#define WIFI3_SSID "" +#endif + +#ifndef WIFI3_PASS +#define WIFI3_PASS "" +#endif + +#ifndef WIFI3_IP +#define WIFI3_IP "" +#endif + +#ifndef WIFI3_GW +#define WIFI3_GW "" +#endif + +#ifndef WIFI3_MASK +#define WIFI3_MASK "" +#endif + +#ifndef WIFI3_DNS +#define WIFI3_DNS "" +#endif + +#ifndef WIFI4_SSID +#define WIFI4_SSID "" +#endif + +#ifndef WIFI4_PASS +#define WIFI4_PASS "" +#endif + +#ifndef WIFI4_IP +#define WIFI4_IP "" +#endif + +#ifndef WIFI4_GW +#define WIFI4_GW "" +#endif + +#ifndef WIFI4_MASK +#define WIFI4_MASK "" +#endif + +#ifndef WIFI4_DNS +#define WIFI4_DNS "" +#endif + #ifndef WIFI_RSSI_1M #define WIFI_RSSI_1M -30 // Calibrate it with your router reading the RSSI at 1m #endif diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 5008f428..303dd215 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -20,11 +20,19 @@ // // Besides, other hardware specific information should be stated here +// ----------------------------------------------------------------------------- +// Custom hardware +// ----------------------------------------------------------------------------- + +#if defined(MANUFACTURER) and defined(DEVICE) + + // user has defined custom hardware, no need to check anything else + // ----------------------------------------------------------------------------- // ESPurna Core // ----------------------------------------------------------------------------- -#if defined(ESPURNA_CORE) +#elif defined(ESPURNA_CORE) // This is a special device targeted to generate a light-weight binary image // meant to be able to do two-step-updates: @@ -3326,7 +3334,7 @@ // Relays #define RELAY1_PIN 15 #define RELAY1_TYPE RELAY_TYPE_NORMAL - + // Light RGBW #define RELAY_PROVIDER RELAY_PROVIDER_LIGHT #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER @@ -3491,20 +3499,20 @@ #elif defined(TECKIN_SP20) - // Info + // Info #define MANUFACTURER "TECKIN" #define DEVICE "SP20" - // Buttons + // Buttons #define BUTTON1_PIN 13 #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH #define BUTTON1_RELAY 1 - // Relays + // Relays #define RELAY1_PIN 4 #define RELAY1_TYPE RELAY_TYPE_NORMAL - // LEDs + // LEDs #define LED1_PIN 2 #define LED1_PIN_INVERSE 1 #define LED2_PIN 0 @@ -3512,7 +3520,7 @@ #define LED2_MODE LED_MODE_FINDME #define LED2_RELAY 0 - // HJL01 / BL0937 + // HJL01 / BL0937 #ifndef HLW8012_SUPPORT #define HLW8012_SUPPORT 1 #endif @@ -3520,7 +3528,7 @@ #define HLW8012_CF1_PIN 14 #define HLW8012_CF_PIN 5 - #define HLW8012_SEL_CURRENT LOW + #define HLW8012_SEL_CURRENT LOW #define HLW8012_CURRENT_RATIO 25740 #define HLW8012_VOLTAGE_RATIO 313400 #define HLW8012_POWER_RATIO 3414290 @@ -3559,32 +3567,32 @@ // ----------------------------------------------------------------------------- #elif defined(PSH_WIFI_PLUG) - + // Info #define MANUFACTURER "PSH" #define DEVICE "WIFI_PLUG" - + // Relays #define RELAY1_PIN 2 #define RELAY1_TYPE RELAY_TYPE_NORMAL - + // LEDs #define LED1_PIN 0 #define LED1_PIN_INVERSE 0 - + #elif defined(PSH_RGBW_CONTROLLER) - + // Info #define MANUFACTURER "PSH" #define DEVICE "RGBW_CONTROLLER" #define RELAY_PROVIDER RELAY_PROVIDER_LIGHT #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define DUMMY_RELAY_COUNT 1 - + // LEDs #define LED1_PIN 13 #define LED1_PIN_INVERSE 1 - + // Light #define LIGHT_CHANNELS 4 #define LIGHT_CH1_PIN 5 // RED @@ -3595,9 +3603,9 @@ #define LIGHT_CH2_INVERSE 0 #define LIGHT_CH3_INVERSE 0 #define LIGHT_CH4_INVERSE 0 - + #elif defined(PSH_WIFI_SENSOR) - + // Info #define MANUFACTURER "PSH" #define DEVICE "WIFI_SENSOR" @@ -3726,13 +3734,13 @@ #define MICS2710_SUPPORT 1 #define MICS5525_SUPPORT 1 - // MAX6675 14 11 10 - #ifndef MAX6675_SUPPORT - #define MAX6675_SUPPORT 1 - #endif - #define MAX6675_CS_PIN 14 - #define MAX6675_SO_PIN 11 - #define MAX6675_SCK_PIN 10 +// MAX6675 14 11 10 +#ifndef MAX6675_SUPPORT +#define MAX6675_SUPPORT 1 +#endif +#define MAX6675_CS_PIN 14 +#define MAX6675_SO_PIN 11 +#define MAX6675_SCK_PIN 10 #elif defined(TRAVIS02) @@ -3848,12 +3856,9 @@ #define SSDP_SUPPORT 1 #define RF_SUPPORT 1 -#endif +#else -// ----------------------------------------------------------------------------- -// Check definitions -// ----------------------------------------------------------------------------- - -#if not defined(MANUFACTURER) || not defined(DEVICE) #error "UNSUPPORTED HARDWARE!!" + #endif + diff --git a/code/espurna/wifi.ino b/code/espurna/wifi.ino index 79878594..ce8fe96e 100644 --- a/code/espurna/wifi.ino +++ b/code/espurna/wifi.ino @@ -217,8 +217,29 @@ void _wifiInject() { setSetting("mask", 1, WIFI2_MASK); setSetting("dns", 1, WIFI2_DNS); } - } + if (strlen(WIFI3_SSID)) { + if (!hasSetting("ssid", 2)) { + setSetting("ssid", 2, WIFI3_SSID); + setSetting("pass", 2, WIFI3_PASS); + setSetting("ip", 2, WIFI3_IP); + setSetting("gw", 2, WIFI3_GW); + setSetting("mask", 2, WIFI3_MASK); + setSetting("dns", 2, WIFI3_DNS); + } + + if (strlen(WIFI4_SSID)) { + if (!hasSetting("ssid", 3)) { + setSetting("ssid", 3, WIFI4_SSID); + setSetting("pass", 3, WIFI4_PASS); + setSetting("ip", 3, WIFI4_IP); + setSetting("gw", 3, WIFI4_GW); + setSetting("mask", 3, WIFI4_MASK); + setSetting("dns", 3, WIFI4_DNS); + } + } + } + } } }