From 05f5aaaeca5628197cd65c7da5f076bf594a490e Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 19 Feb 2020 15:53:42 +0100 Subject: [PATCH] Refactoring --- wled00/const.h | 26 ++++++++++++++++++++++++++ wled00/wled00.ino | 23 ++++++----------------- wled00/wled05_init.ino | 10 +++++----- 3 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 wled00/const.h diff --git a/wled00/const.h b/wled00/const.h new file mode 100644 index 000000000..15345c7ca --- /dev/null +++ b/wled00/const.h @@ -0,0 +1,26 @@ +#ifndef wled_const_h +#define wled_const_h + +//Access point behavior +#define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot +#define AP_BEHAVIOR_NO_CONN 1 //Open when no connection +#define AP_BEHAVIOR_ALWAYS 2 //Always open +#define AP_BEHAVIOR_BUTTON_ONLY 3 //Only when button pressed for 6 sec + +//realtime modes +#define REALTIME_MODE_INACTIVE 0 +#define REALTIME_MODE_GENERIC 1 +#define REALTIME_MODE_UDP 2 +#define REALTIME_MODE_HYPERION 3 +#define REALTIME_MODE_E131 4 +#define REALTIME_MODE_ADALIGHT 5 + +//E1.31 DMX modes +#define DMX_MODE_DISABLED 0 //not used +#define DMX_MODE_SINGLE_RGB 1 //all LEDs same RGB color (3 channels) +#define DMX_MODE_SINGLE_DRGB 2 //all LEDs same RGB color and master dimmer (4 channels) +#define DMX_MODE_EFFECT 3 //trigger standalone effects of WLED (11 channels) +#define DMX_MODE_MULTIPLE_RGB 4 //every LED is addressed with its own RGB (ledCount * 3 channels) +#define DMX_MODE_MULTIPLE_DRGB 5 //every LED is addressed with its own RGB and share a master dimmer (ledCount * 3 + 1 channels) + +#endif diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 89f08a5d2..6d0bae61b 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -75,6 +75,7 @@ #include "html_other.h" #include "FX.h" #include "ir_codes.h" +#include "const.h" #if IR_PIN < 0 @@ -90,7 +91,7 @@ #endif //version code in format yymmddb (b = daily build) -#define VERSION 2002181 +#define VERSION 2002191 char versionString[] = "0.9.1"; @@ -115,7 +116,7 @@ char cmDNS[33] = "x"; //mDNS address (placeholder, will char apSSID[33] = ""; //AP off by default (unless setup) byte apChannel = 1; //2.4GHz WiFi AP channel (1-13) byte apHide = 0; //hidden AP SSID -byte apBehavior = 0; //0: Open AP when no connection after boot 1: Open when no connection 2: Always open 3: Only when button pressed for 6 sec +byte apBehavior = AP_BEHAVIOR_BOOT_NO_CONN; //access point opens when no connection after boot by default IPAddress staticIP(0, 0, 0, 0); //static IP of ESP IPAddress staticGateway(0, 0, 0, 0); //gateway (router) IP IPAddress staticSubnet(255, 255, 255, 0); //most common subnet in home networks @@ -178,14 +179,8 @@ bool arlsDisableGammaCorrection = true; //activate if gamma correction is bool arlsForceMaxBri = false; //enable to force max brightness if source has very dark colors that would be black uint16_t e131Universe = 1; //settings for E1.31 (sACN) protocol (only DMX_MODE_MULTIPLE_* can span over consequtive universes) -#define DMX_MODE_DISABLED 0 //not used -#define DMX_MODE_SINGLE_RGB 1 //all LEDs same RGB color (3 channels) -#define DMX_MODE_SINGLE_DRGB 2 //all LEDs same RGB color and master dimmer (4 channels) -#define DMX_MODE_EFFECT 3 //trigger standalone effects of WLED (11 channels) -#define DMX_MODE_MULTIPLE_RGB 4 //every LED is addressed with its own RGB (ledCount * 3 channels) -#define DMX_MODE_MULTIPLE_DRGB 5 //every LED is addressed with its own RGB and share a master dimmer (ledCount * 3 + 1 channels) -uint8_t DMXMode; //DMX mode (s.a.) -uint16_t DMXAddress; //DMX start address of fixture, a.k.a. first Channel [for E1.31 (sACN) protocol] +uint8_t DMXMode = DMX_MODE_MULTIPLE_RGB; //DMX mode (s.a.) +uint16_t DMXAddress = 1; //DMX start address of fixture, a.k.a. first Channel [for E1.31 (sACN) protocol] uint8_t DMXOldDimmer = 0; //only update brightness on change uint8_t e131LastSequenceNumber = 0; //to detect packet loss bool e131Multicast = false; //multicast or unicast @@ -362,13 +357,7 @@ bool presetApplyBri = false, presetApplyCol = true, presetApplyFx = true; bool saveCurrPresetCycConf = false; //realtime -#define REALTIME_MODE_INACTIVE 0 -#define REALTIME_MODE_GENERIC 1 -#define REALTIME_MODE_UDP 2 -#define REALTIME_MODE_HYPERION 3 -#define REALTIME_MODE_E131 4 -#define REALTIME_MODE_ADALIGHT 5 -byte realtimeMode = 0; +byte realtimeMode = REALTIME_MODE_INACTIVE; IPAddress realtimeIP = (0,0,0,0); unsigned long realtimeTimeout = 0; diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index 0cc6ac7ec..b26358cb3 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -121,7 +121,7 @@ void beginStrip() void initAP(bool resetAP=false){ - if (apBehavior == 3 && !resetAP) return; + if (apBehavior == AP_BEHAVIOR_BUTTON_ONLY && !resetAP) return; if (!apSSID[0] || resetAP) strcpy(apSSID, "WLED-AP"); if (resetAP) strcpy(apPass,"wled1234"); @@ -172,7 +172,7 @@ void initConnection() if (!apActive) initAP(); //instantly go to ap mode return; } else if (!apActive) { - if (apBehavior == 2) + if (apBehavior == AP_BEHAVIOR_ALWAYS) { initAP(); } else @@ -246,7 +246,7 @@ uint32_t lastHeap; unsigned long heapTime = 0; void handleConnection() { - if (millis() < 2000 && (!WLED_WIFI_CONFIGURED || apBehavior == 2)) return; + if (millis() < 2000 && (!WLED_WIFI_CONFIGURED || apBehavior == AP_BEHAVIOR_ALWAYS)) return; if (lastReconnectAttempt == 0) initConnection(); //reconnect WiFi to clear stale allocations if heap gets too low @@ -297,7 +297,7 @@ void handleConnection() { initConnection(); } if (millis() - lastReconnectAttempt > ((stac) ? 300000 : 20000) && WLED_WIFI_CONFIGURED) initConnection(); - if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == 1)) initAP(); + if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) initAP(); } else if (!interfacesInited) { //newly connected DEBUG_PRINTLN(""); DEBUG_PRINT("Connected! IP address: "); @@ -306,7 +306,7 @@ void handleConnection() { userConnected(); //shut down AP - if (apBehavior != 2 && apActive) + if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive) { dnsServer.stop(); WiFi.softAPdisconnect(true);