diff --git a/CHANGELOG.md b/CHANGELOG.md index a9804b1f4..8df63ff8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ### Development versions after 0.9.1 release +#### Build 2004060 + +- Consolidated global variables in wled.h + #### Build 2003300 - Major change of project structure from .ino to .cpp and func_declare.h diff --git a/wled00/const.h b/wled00/const.h index 535a59870..ef19e51be 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -75,4 +75,17 @@ //EEPROM size #define EEPSIZE 2560 //Maximum is 4096 +#define NTP_PACKET_SIZE 48 + +// maximum number of LEDs - MAX_LEDS is coming from the JSON response getting too big, MAX_LEDS_DMA will become a timing issue +#define MAX_LEDS 1500 +#define MAX_LEDS_DMA 500 + +// string temp buffer (now stored in stack locally) +#define OMAX 2048 + +#define E131_MAX_UNIVERSE_COUNT 9 + +#define ABL_MILLIAMPS_DEFAULT 850; // auto lower brightness to stay close to milliampere limit + #endif diff --git a/wled00/dmx.cpp b/wled00/dmx.cpp index 596624a6e..ea0871241 100644 --- a/wled00/dmx.cpp +++ b/wled00/dmx.cpp @@ -19,7 +19,7 @@ void handleDMX() for (int i = 0; i < ledCount; i++) { // uses the amount of LEDs as fixture count - uint32_t in = strip.getPixelColor(i); // time to get the colors for the individual fixtures as suggested by AirCookie at issue #462 + uint32_t in = strip.getPixelColor(i); // get the colors for the individual fixtures as suggested by Aircoookie in issue #462 byte w = in >> 24 & 0xFF; byte r = in >> 16 & 0xFF; byte g = in >> 8 & 0xFF; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 7579a9c5e..701b98e31 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -1,344 +1,7 @@ +#define WLED_DEFINE_GLOBAL_VARS //only in one source file, wled.cpp! #include "wled.h" #include -// Global Variable definitions -char versionString[] = "0.9.1n"; - -// AP and OTA default passwords (for maximum change them!) -char apPass[65] = DEFAULT_AP_PASS; -char otaPass[33] = DEFAULT_OTA_PASS; - -// Hardware CONFIG (only changeble HERE, not at runtime) -// LED strip pin, button pin and IR pin changeable in NpbWrapper.h! - -byte auxDefaultState = 0; // 0: input 1: high 2: low -byte auxTriggeredState = 0; // 0: input 1: high 2: low -char ntpServerName[33] = "0.wled.pool.ntp.org"; // NTP server to use - -// WiFi CONFIG (all these can be changed via web UI, no need to set them here) -char clientSSID[33] = CLIENT_SSID; -char clientPass[65] = CLIENT_PASS; -char cmDNS[33] = "x"; // mDNS address (placeholder, will be replaced by wledXXXXXXXXXXXX.local) -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 = 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 -bool noWifiSleep = false; // disabling modem sleep modes will increase heat output and power usage, but may help with connection issues - -// LED CONFIG -uint16_t ledCount = 30; // overcurrent prevented by ABL -bool useRGBW = false; // SK6812 strips can contain an extra White channel -bool turnOnAtBoot = true; // turn on LEDs at power-up -byte bootPreset = 0; // save preset to load after power-up - -byte col[] { 255, 160, 0, 0 }; // current RGB(W) primary color. col[] should be updated if you want to change the color. -byte colSec[] { 0, 0, 0, 0 }; // current RGB(W) secondary color -byte briS = 128; // default brightness - -byte nightlightTargetBri = 0; // brightness after nightlight is over -byte nightlightDelayMins = 60; -bool nightlightFade = true; // if enabled, light will gradually dim towards the target bri. Otherwise, it will instantly set after delay over -bool nightlightColorFade = false; // if enabled, light will gradually fade color from primary to secondary color. -bool fadeTransition = true; // enable crossfading color transition -uint16_t transitionDelay = 750; // default crossfade duration in ms - -bool skipFirstLed = false; // ignore first LED in strip (useful if you need the LED as signal repeater) -byte briMultiplier = 100; // % of brightness to set (to limit power, if you set it to 50 and set bri to 255, actual brightness will be 127) - -// User Interface CONFIG -char serverDescription[33] = "WLED"; // Name of module -bool syncToggleReceive = false; // UIs which only have a single button for sync should toggle send+receive if this is true, only send otherwise - -// Sync CONFIG -bool buttonEnabled = true; -byte irEnabled = 0; // Infrared receiver - -uint16_t udpPort = 21324; // WLED notifier default port -uint16_t udpRgbPort = 19446; // Hyperion port - -bool receiveNotificationBrightness = true; // apply brightness from incoming notifications -bool receiveNotificationColor = true; // apply color -bool receiveNotificationEffects = true; // apply effects setup -bool notifyDirect = false; // send notification if change via UI or HTTP API -bool notifyButton = false; // send if updated by button or infrared remote -bool notifyAlexa = false; // send notification if updated via Alexa -bool notifyMacro = false; // send notification for macro -bool notifyHue = true; // send notification if Hue light changes -bool notifyTwice = false; // notifications use UDP: enable if devices don't sync reliably - -bool alexaEnabled = true; // enable device discovery by Amazon Echo -char alexaInvocationName[33] = "Light"; // speech control name of device. Choose something voice-to-text can understand - -char blynkApiKey[36] = ""; // Auth token for Blynk server. If empty, no connection will be made - -uint16_t realtimeTimeoutMs = 2500; // ms timeout of realtime mode before returning to normal mode -int arlsOffset = 0; // realtime LED offset -bool receiveDirect = true; // receive UDP realtime -bool arlsDisableGammaCorrection = true; // activate if gamma correction is handled by the source -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) -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[E131_MAX_UNIVERSE_COUNT]; // to detect packet loss -bool e131Multicast = false; // multicast or unicast -bool e131SkipOutOfSequence = false; // freeze instead of flickering - -bool mqttEnabled = false; -char mqttDeviceTopic[33] = ""; // main MQTT topic (individual per device, default is wled/mac) -char mqttGroupTopic[33] = "wled/all"; // second MQTT topic (for example to group devices) -char mqttServer[33] = ""; // both domains and IPs should work (no SSL) -char mqttUser[41] = ""; // optional: username for MQTT auth -char mqttPass[41] = ""; // optional: password for MQTT auth -char mqttClientID[41] = ""; // override the client ID -uint16_t mqttPort = 1883; - -bool huePollingEnabled = false; // poll hue bridge for light state -uint16_t huePollIntervalMs = 2500; // low values (< 1sec) may cause lag but offer quicker response -char hueApiKey[47] = "api"; // key token will be obtained from bridge -byte huePollLightId = 1; // ID of hue lamp to sync to. Find the ID in the hue app ("about" section) -IPAddress hueIP = (0, 0, 0, 0); // IP address of the bridge -bool hueApplyOnOff = true; -bool hueApplyBri = true; -bool hueApplyColor = true; - -// Time CONFIG -bool ntpEnabled = false; // get internet time. Only required if you use clock overlays or time-activated macros -bool useAMPM = false; // 12h/24h clock format -byte currentTimezone = 0; // Timezone ID. Refer to timezones array in wled10_ntp.ino -int utcOffsetSecs = 0; // Seconds to offset from UTC before timzone calculation - -byte overlayDefault = 0; // 0: no overlay 1: analog clock 2: single-digit clocl 3: cronixie -byte overlayMin = 0, overlayMax = ledCount - 1; // boundaries of overlay mode - -byte analogClock12pixel = 0; // The pixel in your strip where "midnight" would be -bool analogClockSecondsTrail = false; // Display seconds as trail of LEDs instead of a single pixel -bool analogClock5MinuteMarks = false; // Light pixels at every 5-minute position - -char cronixieDisplay[7] = "HHMMSS"; // Cronixie Display mask. See wled13_cronixie.ino -bool cronixieBacklight = true; // Allow digits to be back-illuminated - -bool countdownMode = false; // Clock will count down towards date -byte countdownYear = 20, countdownMonth = 1; // Countdown target date, year is last two digits -byte countdownDay = 1, countdownHour = 0; -byte countdownMin = 0, countdownSec = 0; - -byte macroBoot = 0; // macro loaded after startup -byte macroNl = 0; // after nightlight delay over -byte macroCountdown = 0; -byte macroAlexaOn = 0, macroAlexaOff = 0; -byte macroButton = 0, macroLongPress = 0, macroDoublePress = 0; - -// Security CONFIG -bool otaLock = false; // prevents OTA firmware updates without password. ALWAYS enable if system exposed to any public networks -bool wifiLock = false; // prevents access to WiFi settings when OTA lock is enabled -bool aOtaEnabled = true; // ArduinoOTA allows easy updates directly from the IDE. Careful, it does not auto-disable when OTA lock is on - -uint16_t userVar0 = 0, userVar1 = 0; - -#ifdef WLED_ENABLE_DMX - // dmx CONFIG - byte DMXChannels = 7; // number of channels per fixture - byte DMXFixtureMap[15] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - // assigns the different channels to different functions. See wled21_dmx.ino for more information. - uint16_t DMXGap = 10; // gap between the fixtures. makes addressing easier because you don't have to memorize odd numbers when climbing up onto a rig. - uint16_t DMXStart = 10; // start address of the first fixture -#endif - -// internal global variable declarations -// wifi -bool apActive = false; -bool forceReconnect = false; -uint32_t lastReconnectAttempt = 0; -bool interfacesInited = false; -bool wasConnected = false; - -// color -byte colOld[] { 0, 0, 0, 0 }; // color before transition -byte colT[] { 0, 0, 0, 0 }; // color that is currently displayed on the LEDs -byte colIT[] { 0, 0, 0, 0 }; // color that was last sent to LEDs -byte colSecT[] { 0, 0, 0, 0 }; -byte colSecOld[] { 0, 0, 0, 0 }; -byte colSecIT[] { 0, 0, 0, 0 }; - -byte lastRandomIndex = 0; // used to save last random color so the new one is not the same - -// transitions -bool transitionActive = false; -uint16_t transitionDelayDefault = transitionDelay; -uint16_t transitionDelayTemp = transitionDelay; -unsigned long transitionStartTime; -float tperLast = 0; // crossfade transition progress, 0.0f - 1.0f -bool jsonTransitionOnce = false; - -// nightlight -bool nightlightActive = false; -bool nightlightActiveOld = false; -uint32_t nightlightDelayMs = 10; -uint8_t nightlightDelayMinsDefault = nightlightDelayMins; -unsigned long nightlightStartTime; -byte briNlT = 0; // current nightlight brightness -byte colNlT[] { 0, 0, 0, 0 }; // current nightlight color - -// brightness -unsigned long lastOnTime = 0; -bool offMode = !turnOnAtBoot; -byte bri = briS; -byte briOld = 0; -byte briT = 0; -byte briIT = 0; -byte briLast = 128; // brightness before turned off. Used for toggle function -byte whiteLast = 128; // white channel before turned off. Used for toggle function - -// button -bool buttonPressedBefore = false; -bool buttonLongPressed = false; -unsigned long buttonPressedTime = 0; -unsigned long buttonWaitTime = 0; - -// notifications -bool notifyDirectDefault = notifyDirect; -bool receiveNotifications = true; -unsigned long notificationSentTime = 0; -byte notificationSentCallMode = NOTIFIER_CALL_MODE_INIT; -bool notificationTwoRequired = false; - -// effects -byte effectCurrent = 0; -byte effectSpeed = 128; -byte effectIntensity = 128; -byte effectPalette = 0; - -// network -bool udpConnected = false, udpRgbConnected = false; - -// ui style -bool showWelcomePage = false; - -// hue -byte hueError = HUE_ERROR_INACTIVE; -// uint16_t hueFailCount = 0; -float hueXLast = 0, hueYLast = 0; -uint16_t hueHueLast = 0, hueCtLast = 0; -byte hueSatLast = 0, hueBriLast = 0; -unsigned long hueLastRequestSent = 0; -bool hueAuthRequired = false; -bool hueReceived = false; -bool hueStoreAllowed = false, hueNewKey = false; - -// overlays -byte overlayCurrent = overlayDefault; -byte overlaySpeed = 200; -unsigned long overlayRefreshMs = 200; -unsigned long overlayRefreshedTime; - -// cronixie -byte dP[] { 0, 0, 0, 0, 0, 0 }; -bool cronixieInit = false; - -// countdown -unsigned long countdownTime = 1514764800L; -bool countdownOverTriggered = true; - -// timer -byte lastTimerMinute = 0; -byte timerHours[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; -byte timerMinutes[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; -byte timerMacro[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; -byte timerWeekday[] = { 255, 255, 255, 255, 255, 255, 255, 255 }; // weekdays to activate on -// bit pattern of arr elem: 0b11111111: sun,sat,fri,thu,wed,tue,mon,validity - -// blynk -bool blynkEnabled = false; - -// preset cycling -bool presetCyclingEnabled = false; -byte presetCycleMin = 1, presetCycleMax = 5; -uint16_t presetCycleTime = 1250; -unsigned long presetCycledTime = 0; -byte presetCycCurr = presetCycleMin; -bool presetApplyBri = true; -bool saveCurrPresetCycConf = false; - -// realtime -byte realtimeMode = REALTIME_MODE_INACTIVE; -IPAddress realtimeIP = (0, 0, 0, 0); -unsigned long realtimeTimeout = 0; - -// mqtt -long lastMqttReconnectAttempt = 0; -long lastInterfaceUpdate = 0; -byte interfaceUpdateCallMode = NOTIFIER_CALL_MODE_INIT; -char mqttStatusTopic[40] = ""; // this must be global because of async handlers - -#if AUXPIN >= 0 - // auxiliary debug pin - byte auxTime = 0; - unsigned long auxStartTime = 0; - bool auxActive = false, auxActiveBefore = false; -#endif - -// alexa udp -String escapedMac; -#ifndef WLED_DISABLE_ALEXA - Espalexa espalexa; - EspalexaDevice* espalexaDevice; -#endif - -// dns server -DNSServer dnsServer; - -// network time -bool ntpConnected = false; -time_t local = 0; -unsigned long ntpLastSyncTime = 999000000L; -unsigned long ntpPacketSentTime = 999000000L; -IPAddress ntpServerIP; -uint16_t ntpLocalPort = 2390; - -// Temp buffer -char* obuf; -uint16_t olen = 0; - -// presets -uint16_t savedPresets = 0; -int8_t currentPreset = -1; -bool isPreset = false; - -byte errorFlag = 0; - -String messageHead, messageSub; -byte optionType; - -bool doReboot = false; // flag to initiate reboot from async handlers -bool doPublishMqtt = false; - -// server library objects -AsyncWebServer server(80); -AsyncClient* hueClient = NULL; -AsyncMqttClient* mqtt = NULL; - -// udp interface objects -WiFiUDP notifierUdp, rgbUdp; -WiFiUDP ntpUdp; -ESPAsyncE131 e131(handleE131Packet); -bool e131NewData = false; - -// led fx library object -WS2812FX strip = WS2812FX(); - -// debug macro variable definitions -#ifdef WLED_DEBUG - unsigned long debugTime = 0; - int lastWifiState = 3; - unsigned long wifiStateChangedTime = 0; - int loops = 0; -#endif - WLED::WLED() { } diff --git a/wled00/wled.h b/wled00/wled.h index 926fa0c81..0c6d31147 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2003300 +#define VERSION 2004060 // ESP8266-01 (blue) got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.4.2 and the setting 512K(No SPIFFS). @@ -119,268 +119,370 @@ #ifndef ESP8266 #include #endif -#endif - -// Global external variable declaration. See wled.cpp for definitions and comments. -extern char versionString[]; -extern char apPass[65]; -extern char otaPass[33]; -extern byte auxDefaultState; -extern byte auxTriggeredState; -extern char ntpServerName[33]; -extern char clientSSID[33]; -extern char clientPass[65]; -extern char cmDNS[33]; -extern char apSSID[33]; -extern byte apChannel; -extern byte apHide; -extern byte apBehavior; -extern IPAddress staticIP; -extern IPAddress staticGateway; -extern IPAddress staticSubnet; -extern bool noWifiSleep; -extern uint16_t ledCount; -extern bool useRGBW; -#define ABL_MILLIAMPS_DEFAULT 850; // auto lower brightness to stay close to milliampere limit -extern bool turnOnAtBoot; -extern byte bootPreset; -extern byte col[]; -extern byte colSec[]; -extern byte briS; -extern byte nightlightTargetBri; -extern byte nightlightDelayMins; -extern bool nightlightFade; -extern bool nightlightColorFade; -extern bool fadeTransition; -extern uint16_t transitionDelay; -extern bool skipFirstLed; -extern byte briMultiplier; -extern char serverDescription[33]; -extern bool syncToggleReceive; -extern bool buttonEnabled; -extern byte irEnabled; -extern uint16_t udpPort; -extern uint16_t udpRgbPort; -extern bool receiveNotificationBrightness; -extern bool receiveNotificationColor; -extern bool receiveNotificationEffects; -extern bool notifyDirect; -extern bool notifyButton; -extern bool notifyAlexa; -extern bool notifyMacro; -extern bool notifyHue; -extern bool notifyTwice; -extern bool alexaEnabled; -extern char alexaInvocationName[33]; -extern char blynkApiKey[36]; -extern uint16_t realtimeTimeoutMs; -extern int arlsOffset; -extern bool receiveDirect; -extern bool arlsDisableGammaCorrection; -extern bool arlsForceMaxBri; -#define E131_MAX_UNIVERSE_COUNT 9 -extern uint16_t e131Universe; -extern uint8_t DMXMode; -extern uint16_t DMXAddress; -extern uint8_t DMXOldDimmer; -extern uint8_t e131LastSequenceNumber[E131_MAX_UNIVERSE_COUNT]; -extern bool e131Multicast; -extern bool e131SkipOutOfSequence; -extern bool mqttEnabled; -extern char mqttDeviceTopic[33]; -extern char mqttGroupTopic[33]; -extern char mqttServer[33]; -extern char mqttUser[41]; -extern char mqttPass[41]; -extern char mqttClientID[41]; -extern uint16_t mqttPort; -extern bool huePollingEnabled; -extern uint16_t huePollIntervalMs; -extern char hueApiKey[47]; -extern byte huePollLightId; -extern IPAddress hueIP; -extern bool hueApplyOnOff; -extern bool hueApplyBri; -extern bool hueApplyColor; -extern bool ntpEnabled; -extern bool useAMPM; -extern byte currentTimezone; -extern int utcOffsetSecs; -extern byte overlayDefault; -extern byte overlayMin; -extern byte overlayMax; -extern byte analogClock12pixel; -extern bool analogClockSecondsTrail; -extern bool analogClock5MinuteMarks; -extern char cronixieDisplay[7]; -extern bool cronixieBacklight; -extern bool countdownMode; -extern byte countdownYear, countdownMonth; -extern byte countdownDay, countdownHour; -extern byte countdownMin, countdownSec; -extern byte macroBoot; -extern byte macroNl; -extern byte macroCountdown; -extern byte macroAlexaOn, macroAlexaOff; -extern byte macroButton, macroLongPress, macroDoublePress; -extern bool otaLock; -extern bool wifiLock; -extern bool aOtaEnabled; -extern uint16_t userVar0, userVar1; -#ifdef WLED_ENABLE_DMX - extern byte DMXChannels; - extern byte DMXFixtureMap[15]; - extern uint16_t DMXGap; - extern uint16_t DMXStart; -#endif -extern bool apActive; -extern bool forceReconnect; -extern uint32_t lastReconnectAttempt; -extern bool interfacesInited; -extern bool wasConnected; -extern byte colOld[]; -extern byte colT[]; -extern byte colIT[]; -extern byte colSecT[]; -extern byte colSecOld[]; -extern byte colSecIT[]; -extern byte lastRandomIndex; -extern bool transitionActive; -extern uint16_t transitionDelayDefault; -extern uint16_t transitionDelayTemp; -extern unsigned long transitionStartTime; -extern float tperLast; -extern bool jsonTransitionOnce; -extern bool nightlightActive; -extern bool nightlightActiveOld; -extern uint32_t nightlightDelayMs; -extern uint8_t nightlightDelayMinsDefault; -extern unsigned long nightlightStartTime; -extern byte briNlT; -extern byte colNlT[]; -extern unsigned long lastOnTime; -extern bool offMode; -extern byte bri; -extern byte briOld; -extern byte briT; -extern byte briIT; -extern byte briLast; -extern byte whiteLast; -extern bool buttonPressedBefore; -extern bool buttonLongPressed; -extern unsigned long buttonPressedTime; -extern unsigned long buttonWaitTime; -extern bool notifyDirectDefault; -extern bool receiveNotifications; -extern unsigned long notificationSentTime; -extern byte notificationSentCallMode; -extern bool notificationTwoRequired; -extern byte effectCurrent; -extern byte effectSpeed; -extern byte effectIntensity; -extern byte effectPalette; -extern bool udpConnected, udpRgbConnected; -extern bool showWelcomePage; -extern byte hueError; -extern float hueXLast, hueYLast; -extern uint16_t hueHueLast, hueCtLast; -extern byte hueSatLast, hueBriLast; -extern unsigned long hueLastRequestSent; -extern bool hueAuthRequired; -extern bool hueReceived; -extern bool hueStoreAllowed, hueNewKey; -extern byte overlayCurrent; -extern byte overlaySpeed; -extern unsigned long overlayRefreshMs; -extern unsigned long overlayRefreshedTime; -extern byte dP[]; -extern bool cronixieInit; -extern unsigned long countdownTime; -extern bool countdownOverTriggered; -extern byte lastTimerMinute; -extern byte timerHours[]; -extern byte timerMinutes[]; -extern byte timerMacro[]; -extern byte timerWeekday[]; -extern bool blynkEnabled; -extern bool presetCyclingEnabled; -extern byte presetCycleMin, presetCycleMax; -extern uint16_t presetCycleTime; -extern unsigned long presetCycledTime; -extern byte presetCycCurr; -extern bool presetApplyBri; -extern bool saveCurrPresetCycConf; -extern byte realtimeMode; -extern IPAddress realtimeIP; -extern unsigned long realtimeTimeout; -extern long lastMqttReconnectAttempt; -extern long lastInterfaceUpdate; -extern byte interfaceUpdateCallMode; -extern char mqttStatusTopic[40]; -#if AUXPIN >= 0 - extern byte auxTime; - extern unsigned long auxStartTime; - extern bool auxActive; -#endif -extern String escapedMac; -#ifndef WLED_DISABLE_ALEXA - extern Espalexa espalexa; - extern EspalexaDevice *espalexaDevice; -#endif - -#define NTP_PACKET_SIZE 48 -extern DNSServer dnsServer; -extern bool ntpConnected; -extern time_t local; -extern unsigned long ntpLastSyncTime; -extern unsigned long ntpPacketSentTime; -extern IPAddress ntpServerIP; -extern uint16_t ntpLocalPort; - -// maximum number of LEDs - MAX_LEDS is coming from the JSON response getting too big, MAX_LEDS_DMA will become a timing issue -#define MAX_LEDS 1500 -#define MAX_LEDS_DMA 500 - -// string temp buffer (now stored in stack locally) -#define OMAX 2048 -extern char* obuf; -extern uint16_t olen; - -extern uint16_t savedPresets; -extern int8_t currentPreset; -extern bool isPreset; -extern byte errorFlag; -extern String messageHead, messageSub; -extern byte optionType; -extern bool doReboot; -extern bool doPublishMqtt; -extern AsyncWebServer server; -extern AsyncClient* hueClient; -extern AsyncMqttClient* mqtt; -extern WiFiUDP notifierUdp, rgbUdp; -extern WiFiUDP ntpUdp; -extern ESPAsyncE131 e131; -extern bool e131NewData; -extern WS2812FX strip; - -#define WLED_CONNECTED (WiFi.status() == WL_CONNECTED) -#define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0) - -// debug macros -#ifdef WLED_DEBUG #define DEBUG_PRINT(x) Serial.print(x) #define DEBUG_PRINTLN(x) Serial.println(x) #define DEBUG_PRINTF(x) Serial.printf(x) - extern unsigned long debugTime; - extern int lastWifiState; - extern unsigned long wifiStateChangedTime; - extern int loops; #else #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) #define DEBUG_PRINTF(x) #endif +#ifndef WLED_DEFINE_GLOBAL_VARS +# define WLED_GLOBAL extern +# define _INIT(x) +# define _INIT_N(x) +#else +# define WLED_GLOBAL +# define _INIT(x) = x + +//needed to ignore commas in array definitions +#define UNPACK( ... ) __VA_ARGS__ +# define _INIT_N(x) UNPACK x +#endif + +// Global Variable definitions +WLED_GLOBAL char versionString[] _INIT("0.9.1n"); + +// AP and OTA default passwords (for maximum security change them!) +WLED_GLOBAL char apPass[65] _INIT(DEFAULT_AP_PASS); +WLED_GLOBAL char otaPass[33] _INIT(DEFAULT_OTA_PASS); + +// Hardware CONFIG (only changeble HERE, not at runtime) +// LED strip pin, button pin and IR pin changeable in NpbWrapper.h! + +WLED_GLOBAL byte auxDefaultState _INIT(0); // 0: input 1: high 2: low +WLED_GLOBAL byte auxTriggeredState _INIT(0); // 0: input 1: high 2: low +WLED_GLOBAL char ntpServerName[33] _INIT("0.wled.pool.ntp.org"); // NTP server to use + +// WiFi CONFIG (all these can be changed via web UI, no need to set them here) +WLED_GLOBAL char clientSSID[33] _INIT(CLIENT_SSID); +WLED_GLOBAL char clientPass[65] _INIT(CLIENT_PASS); +WLED_GLOBAL char cmDNS[33] _INIT("x"); // mDNS address (placeholder, is replaced by wledXXXXXX.local) +WLED_GLOBAL char apSSID[33] _INIT(""); // AP off by default (unless setup) +WLED_GLOBAL byte apChannel _INIT(1); // 2.4GHz WiFi AP channel (1-13) +WLED_GLOBAL byte apHide _INIT(0); // hidden AP SSID +WLED_GLOBAL byte apBehavior _INIT(AP_BEHAVIOR_BOOT_NO_CONN); // access point opens when no connection after boot by default +WLED_GLOBAL IPAddress staticIP _INIT_N((( 0, 0, 0, 0))); // static IP of ESP +WLED_GLOBAL IPAddress staticGateway _INIT_N((( 0, 0, 0, 0))); // gateway (router) IP +WLED_GLOBAL IPAddress staticSubnet _INIT_N(((255, 255, 255, 0))); // most common subnet in home networks +WLED_GLOBAL bool noWifiSleep _INIT(false); // disabling modem sleep modes will increase heat output and power usage, but may help with connection issues + +// LED CONFIG +WLED_GLOBAL uint16_t ledCount _INIT(30); // overcurrent prevented by ABL +WLED_GLOBAL bool useRGBW _INIT(false); // SK6812 strips can contain an extra White channel +WLED_GLOBAL bool turnOnAtBoot _INIT(true); // turn on LEDs at power-up +WLED_GLOBAL byte bootPreset _INIT(0); // save preset to load after power-up + +WLED_GLOBAL byte col[] _INIT_N(({ 255, 160, 0, 0 })); // current RGB(W) primary color. col[] should be updated if you want to change the color. +WLED_GLOBAL byte colSec[] _INIT_N(({ 0, 0, 0, 0 })); // current RGB(W) secondary color +WLED_GLOBAL byte briS _INIT(128); // default brightness + +WLED_GLOBAL byte nightlightTargetBri _INIT(0); // brightness after nightlight is over +WLED_GLOBAL byte nightlightDelayMins _INIT(60); +WLED_GLOBAL bool nightlightFade _INIT(true); // if enabled, light will gradually dim towards the target bri. Otherwise, it will instantly set after delay over +WLED_GLOBAL bool nightlightColorFade _INIT(false); // if enabled, light will gradually fade color from primary to secondary color. +WLED_GLOBAL bool fadeTransition _INIT(true); // enable crossfading color transition +WLED_GLOBAL uint16_t transitionDelay _INIT(750); // default crossfade duration in ms + +WLED_GLOBAL bool skipFirstLed _INIT(false); // ignore first LED in strip (useful if you need the LED as signal repeater) +WLED_GLOBAL byte briMultiplier _INIT(100); // % of brightness to set (to limit power, if you set it to 50 and set bri to 255, actual brightness will be 127) + +// User Interface CONFIG +WLED_GLOBAL char serverDescription[33] _INIT("WLED"); // Name of module +WLED_GLOBAL bool syncToggleReceive _INIT(false); // UIs which only have a single button for sync should toggle send+receive if this is true, only send otherwise + +// Sync CONFIG +WLED_GLOBAL bool buttonEnabled _INIT(true); +WLED_GLOBAL byte irEnabled _INIT(0); // Infrared receiver + +WLED_GLOBAL uint16_t udpPort _INIT(21324); // WLED notifier default port +WLED_GLOBAL uint16_t udpRgbPort _INIT(19446); // Hyperion port + +WLED_GLOBAL bool receiveNotificationBrightness _INIT(true); // apply brightness from incoming notifications +WLED_GLOBAL bool receiveNotificationColor _INIT(true); // apply color +WLED_GLOBAL bool receiveNotificationEffects _INIT(true); // apply effects setup +WLED_GLOBAL bool notifyDirect _INIT(false); // send notification if change via UI or HTTP API +WLED_GLOBAL bool notifyButton _INIT(false); // send if updated by button or infrared remote +WLED_GLOBAL bool notifyAlexa _INIT(false); // send notification if updated via Alexa +WLED_GLOBAL bool notifyMacro _INIT(false); // send notification for macro +WLED_GLOBAL bool notifyHue _INIT(true); // send notification if Hue light changes +WLED_GLOBAL bool notifyTwice _INIT(false); // notifications use UDP: enable if devices don't sync reliably + +WLED_GLOBAL bool alexaEnabled _INIT(true); // enable device discovery by Amazon Echo +WLED_GLOBAL char alexaInvocationName[33] _INIT("Light"); // speech control name of device. Choose something voice-to-text can understand + +WLED_GLOBAL char blynkApiKey[36] _INIT(""); // Auth token for Blynk server. If empty, no connection will be made + +WLED_GLOBAL uint16_t realtimeTimeoutMs _INIT(2500); // ms timeout of realtime mode before returning to normal mode +WLED_GLOBAL int arlsOffset _INIT(0); // realtime LED offset +WLED_GLOBAL bool receiveDirect _INIT(true); // receive UDP realtime +WLED_GLOBAL bool arlsDisableGammaCorrection _INIT(true); // activate if gamma correction is handled by the source +WLED_GLOBAL bool arlsForceMaxBri _INIT(false); // enable to force max brightness if source has very dark colors that would be black + +WLED_GLOBAL uint16_t e131Universe _INIT(1); // settings for E1.31 (sACN) protocol (only DMX_MODE_MULTIPLE_* can span over consequtive universes) +WLED_GLOBAL byte DMXMode _INIT(DMX_MODE_MULTIPLE_RGB); // DMX mode (s.a.) +WLED_GLOBAL uint16_t DMXAddress _INIT(1); // DMX start address of fixture, a.k.a. first Channel [for E1.31 (sACN) protocol] +WLED_GLOBAL byte DMXOldDimmer _INIT(0); // only update brightness on change +WLED_GLOBAL byte e131LastSequenceNumber[E131_MAX_UNIVERSE_COUNT]; // to detect packet loss +WLED_GLOBAL bool e131Multicast _INIT(false); // multicast or unicast +WLED_GLOBAL bool e131SkipOutOfSequence _INIT(false); // freeze instead of flickering + +WLED_GLOBAL bool mqttEnabled _INIT(false); +WLED_GLOBAL char mqttDeviceTopic[33] _INIT(""); // main MQTT topic (individual per device, default is wled/mac) +WLED_GLOBAL char mqttGroupTopic[33] _INIT("wled/all"); // second MQTT topic (for example to group devices) +WLED_GLOBAL char mqttServer[33] _INIT(""); // both domains and IPs should work (no SSL) +WLED_GLOBAL char mqttUser[41] _INIT(""); // optional: username for MQTT auth +WLED_GLOBAL char mqttPass[41] _INIT(""); // optional: password for MQTT auth +WLED_GLOBAL char mqttClientID[41] _INIT(""); // override the client ID +WLED_GLOBAL uint16_t mqttPort _INIT(1883); + +WLED_GLOBAL bool huePollingEnabled _INIT(false); // poll hue bridge for light state +WLED_GLOBAL uint16_t huePollIntervalMs _INIT(2500); // low values (< 1sec) may cause lag but offer quicker response +WLED_GLOBAL char hueApiKey[47] _INIT("api"); // key token will be obtained from bridge +WLED_GLOBAL byte huePollLightId _INIT(1); // ID of hue lamp to sync to. Find the ID in the hue app ("about" section) +WLED_GLOBAL IPAddress hueIP _INIT((0, 0, 0, 0)); // IP address of the bridge +WLED_GLOBAL bool hueApplyOnOff _INIT(true); +WLED_GLOBAL bool hueApplyBri _INIT(true); +WLED_GLOBAL bool hueApplyColor _INIT(true); + +// Time CONFIG +WLED_GLOBAL bool ntpEnabled _INIT(false); // get internet time. Only required if you use clock overlays or time-activated macros +WLED_GLOBAL bool useAMPM _INIT(false); // 12h/24h clock format +WLED_GLOBAL byte currentTimezone _INIT(0); // Timezone ID. Refer to timezones array in wled10_ntp.ino +WLED_GLOBAL int utcOffsetSecs _INIT(0); // Seconds to offset from UTC before timzone calculation + +WLED_GLOBAL byte overlayDefault _INIT(0); // 0: no overlay 1: analog clock 2: single-digit clocl 3: cronixie +WLED_GLOBAL byte overlayMin _INIT(0), overlayMax _INIT(ledCount - 1); // boundaries of overlay mode + +WLED_GLOBAL byte analogClock12pixel _INIT(0); // The pixel in your strip where "midnight" would be +WLED_GLOBAL bool analogClockSecondsTrail _INIT(false); // Display seconds as trail of LEDs instead of a single pixel +WLED_GLOBAL bool analogClock5MinuteMarks _INIT(false); // Light pixels at every 5-minute position + +WLED_GLOBAL char cronixieDisplay[7] _INIT("HHMMSS"); // Cronixie Display mask. See wled13_cronixie.ino +WLED_GLOBAL bool cronixieBacklight _INIT(true); // Allow digits to be back-illuminated + +WLED_GLOBAL bool countdownMode _INIT(false); // Clock will count down towards date +WLED_GLOBAL byte countdownYear _INIT(20), countdownMonth _INIT(1); // Countdown target date, year is last two digits +WLED_GLOBAL byte countdownDay _INIT(1), countdownHour _INIT(0); +WLED_GLOBAL byte countdownMin _INIT(0), countdownSec _INIT(0); + +WLED_GLOBAL byte macroBoot _INIT(0); // macro loaded after startup +WLED_GLOBAL byte macroNl _INIT(0); // after nightlight delay over +WLED_GLOBAL byte macroCountdown _INIT(0); +WLED_GLOBAL byte macroAlexaOn _INIT(0), macroAlexaOff _INIT(0); +WLED_GLOBAL byte macroButton _INIT(0), macroLongPress _INIT(0), macroDoublePress _INIT(0); + +// Security CONFIG +WLED_GLOBAL bool otaLock _INIT(false); // prevents OTA firmware updates without password. ALWAYS enable if system exposed to any public networks +WLED_GLOBAL bool wifiLock _INIT(false); // prevents access to WiFi settings when OTA lock is enabled +WLED_GLOBAL bool aOtaEnabled _INIT(true); // ArduinoOTA allows easy updates directly from the IDE. Careful, it does not auto-disable when OTA lock is on + +WLED_GLOBAL uint16_t userVar0 _INIT(0), userVar1 _INIT(0); + +#ifdef WLED_ENABLE_DMX + // dmx CONFIG + WLED_GLOBAL byte DMXChannels _INIT(7); // number of channels per fixture + WLED_GLOBAL byte DMXFixtureMap[15] _INIT_N(({ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 })); + // assigns the different channels to different functions. See wled21_dmx.ino for more information. + WLED_GLOBAL uint16_t DMXGap _INIT(10); // gap between the fixtures. makes addressing easier because you don't have to memorize odd numbers when climbing up onto a rig. + WLED_GLOBAL uint16_t DMXStart _INIT(10); // start address of the first fixture +#endif + +// internal global variable declarations +// wifi +WLED_GLOBAL bool apActive _INIT(false); +WLED_GLOBAL bool forceReconnect _INIT(false); +WLED_GLOBAL uint32_t lastReconnectAttempt _INIT(0); +WLED_GLOBAL bool interfacesInited _INIT(false); +WLED_GLOBAL bool wasConnected _INIT(false); + +// color +WLED_GLOBAL byte colOld[] _INIT_N(({ 0, 0, 0, 0 })); // color before transition +WLED_GLOBAL byte colT[] _INIT_N(({ 0, 0, 0, 0 })); // color that is currently displayed on the LEDs +WLED_GLOBAL byte colIT[] _INIT_N(({ 0, 0, 0, 0 })); // color that was last sent to LEDs +WLED_GLOBAL byte colSecT[] _INIT_N(({ 0, 0, 0, 0 })); +WLED_GLOBAL byte colSecOld[] _INIT_N(({ 0, 0, 0, 0 })); +WLED_GLOBAL byte colSecIT[] _INIT_N(({ 0, 0, 0, 0 })); + +WLED_GLOBAL byte lastRandomIndex _INIT(0); // used to save last random color so the new one is not the same + +// transitions +WLED_GLOBAL bool transitionActive _INIT(false); +WLED_GLOBAL uint16_t transitionDelayDefault _INIT(transitionDelay); +WLED_GLOBAL uint16_t transitionDelayTemp _INIT(transitionDelay); +WLED_GLOBAL unsigned long transitionStartTime; +WLED_GLOBAL float tperLast _INIT(0); // crossfade transition progress, 0.0f - 1.0f +WLED_GLOBAL bool jsonTransitionOnce _INIT(false); + +// nightlight +WLED_GLOBAL bool nightlightActive _INIT(false); +WLED_GLOBAL bool nightlightActiveOld _INIT(false); +WLED_GLOBAL uint32_t nightlightDelayMs _INIT(10); +WLED_GLOBAL byte nightlightDelayMinsDefault _INIT(nightlightDelayMins); +WLED_GLOBAL unsigned long nightlightStartTime; +WLED_GLOBAL byte briNlT _INIT(0); // current nightlight brightness +WLED_GLOBAL byte colNlT[] _INIT_N(({ 0, 0, 0, 0 })); // current nightlight color + +// brightness +WLED_GLOBAL unsigned long lastOnTime _INIT(0); +WLED_GLOBAL bool offMode _INIT(!turnOnAtBoot); +WLED_GLOBAL byte bri _INIT(briS); +WLED_GLOBAL byte briOld _INIT(0); +WLED_GLOBAL byte briT _INIT(0); +WLED_GLOBAL byte briIT _INIT(0); +WLED_GLOBAL byte briLast _INIT(128); // brightness before turned off. Used for toggle function +WLED_GLOBAL byte whiteLast _INIT(128); // white channel before turned off. Used for toggle function + +// button +WLED_GLOBAL bool buttonPressedBefore _INIT(false); +WLED_GLOBAL bool buttonLongPressed _INIT(false); +WLED_GLOBAL unsigned long buttonPressedTime _INIT(0); +WLED_GLOBAL unsigned long buttonWaitTime _INIT(0); + +// notifications +WLED_GLOBAL bool notifyDirectDefault _INIT(notifyDirect); +WLED_GLOBAL bool receiveNotifications _INIT(true); +WLED_GLOBAL unsigned long notificationSentTime _INIT(0); +WLED_GLOBAL byte notificationSentCallMode _INIT(NOTIFIER_CALL_MODE_INIT); +WLED_GLOBAL bool notificationTwoRequired _INIT(false); + +// effects +WLED_GLOBAL byte effectCurrent _INIT(0); +WLED_GLOBAL byte effectSpeed _INIT(128); +WLED_GLOBAL byte effectIntensity _INIT(128); +WLED_GLOBAL byte effectPalette _INIT(0); + +// network +WLED_GLOBAL bool udpConnected _INIT(false), udpRgbConnected _INIT(false); + +// ui style +WLED_GLOBAL bool showWelcomePage _INIT(false); + +// hue +WLED_GLOBAL byte hueError _INIT(HUE_ERROR_INACTIVE); +// WLED_GLOBAL uint16_t hueFailCount _INIT(0); +WLED_GLOBAL float hueXLast _INIT(0), hueYLast _INIT(0); +WLED_GLOBAL uint16_t hueHueLast _INIT(0), hueCtLast _INIT(0); +WLED_GLOBAL byte hueSatLast _INIT(0), hueBriLast _INIT(0); +WLED_GLOBAL unsigned long hueLastRequestSent _INIT(0); +WLED_GLOBAL bool hueAuthRequired _INIT(false); +WLED_GLOBAL bool hueReceived _INIT(false); +WLED_GLOBAL bool hueStoreAllowed _INIT(false), hueNewKey _INIT(false); + +// overlays +WLED_GLOBAL byte overlayCurrent _INIT(overlayDefault); +WLED_GLOBAL byte overlaySpeed _INIT(200); +WLED_GLOBAL unsigned long overlayRefreshMs _INIT(200); +WLED_GLOBAL unsigned long overlayRefreshedTime; + +// cronixie +WLED_GLOBAL byte dP[] _INIT_N(({ 0, 0, 0, 0, 0, 0 })); +WLED_GLOBAL bool cronixieInit _INIT(false); + +// countdown +WLED_GLOBAL unsigned long countdownTime _INIT(1514764800L); +WLED_GLOBAL bool countdownOverTriggered _INIT(true); + +// timer +WLED_GLOBAL byte lastTimerMinute _INIT(0); +WLED_GLOBAL byte timerHours[] _INIT_N(({ 0, 0, 0, 0, 0, 0, 0, 0 })); +WLED_GLOBAL byte timerMinutes[] _INIT_N(({ 0, 0, 0, 0, 0, 0, 0, 0 })); +WLED_GLOBAL byte timerMacro[] _INIT_N(({ 0, 0, 0, 0, 0, 0, 0, 0 })); +WLED_GLOBAL byte timerWeekday[] _INIT_N(({ 255, 255, 255, 255, 255, 255, 255, 255 })); // weekdays to activate on +// bit pattern of arr elem: 0b11111111: sun,sat,fri,thu,wed,tue,mon,validity + +// blynk +WLED_GLOBAL bool blynkEnabled _INIT(false); + +// preset cycling +WLED_GLOBAL bool presetCyclingEnabled _INIT(false); +WLED_GLOBAL byte presetCycleMin _INIT(1), presetCycleMax _INIT(5); +WLED_GLOBAL uint16_t presetCycleTime _INIT(1250); +WLED_GLOBAL unsigned long presetCycledTime _INIT(0); +WLED_GLOBAL byte presetCycCurr _INIT(presetCycleMin); +WLED_GLOBAL bool presetApplyBri _INIT(true); +WLED_GLOBAL bool saveCurrPresetCycConf _INIT(false); + +// realtime +WLED_GLOBAL byte realtimeMode _INIT(REALTIME_MODE_INACTIVE); +WLED_GLOBAL IPAddress realtimeIP _INIT((0, 0, 0, 0)); +WLED_GLOBAL unsigned long realtimeTimeout _INIT(0); + +// mqtt +WLED_GLOBAL long lastMqttReconnectAttempt _INIT(0); +WLED_GLOBAL long lastInterfaceUpdate _INIT(0); +WLED_GLOBAL byte interfaceUpdateCallMode _INIT(NOTIFIER_CALL_MODE_INIT); +WLED_GLOBAL char mqttStatusTopic[40] _INIT(""); // this must be global because of async handlers + +#if AUXPIN >= 0 + // auxiliary debug pin + WLED_GLOBAL byte auxTime _INIT(0); + WLED_GLOBAL unsigned long auxStartTime _INIT(0); + WLED_GLOBAL bool auxActive _INIT(false, auxActiveBefore _INIT(false); +#endif + +// alexa udp +WLED_GLOBAL String escapedMac; +#ifndef WLED_DISABLE_ALEXA + WLED_GLOBAL Espalexa espalexa; + WLED_GLOBAL EspalexaDevice* espalexaDevice; +#endif + +// dns server +WLED_GLOBAL DNSServer dnsServer; + +// network time +WLED_GLOBAL bool ntpConnected _INIT(false); +WLED_GLOBAL time_t local _INIT(0); +WLED_GLOBAL unsigned long ntpLastSyncTime _INIT(999000000L); +WLED_GLOBAL unsigned long ntpPacketSentTime _INIT(999000000L); +WLED_GLOBAL IPAddress ntpServerIP; +WLED_GLOBAL uint16_t ntpLocalPort _INIT(2390); + +// Temp buffer +WLED_GLOBAL char* obuf; +WLED_GLOBAL uint16_t olen _INIT(0); + +// presets +WLED_GLOBAL uint16_t savedPresets _INIT(0); +WLED_GLOBAL int8_t currentPreset _INIT(-1); +WLED_GLOBAL bool isPreset _INIT(false); + +WLED_GLOBAL byte errorFlag _INIT(0); + +WLED_GLOBAL String messageHead, messageSub; +WLED_GLOBAL byte optionType; + +WLED_GLOBAL bool doReboot _INIT(false); // flag to initiate reboot from async handlers +WLED_GLOBAL bool doPublishMqtt _INIT(false); + +// server library objects +WLED_GLOBAL AsyncWebServer server _INIT_N(((80))); +WLED_GLOBAL AsyncClient* hueClient _INIT(NULL); +WLED_GLOBAL AsyncMqttClient* mqtt _INIT(NULL); + +// udp interface objects +WLED_GLOBAL WiFiUDP notifierUdp, rgbUdp; +WLED_GLOBAL WiFiUDP ntpUdp; +WLED_GLOBAL ESPAsyncE131 e131 _INIT_N(((handleE131Packet))); +WLED_GLOBAL bool e131NewData _INIT(false); + +// led fx library object +WLED_GLOBAL WS2812FX strip _INIT(WS2812FX()); + +// debug macro variable definitions +#ifdef WLED_DEBUG + WLED_GLOBAL unsigned long debugTime _INIT(0); + WLED_GLOBAL int lastWifiState _INIT(3); + WLED_GLOBAL unsigned long wifiStateChangedTime _INIT(0); + WLED_GLOBAL int loops _INIT(0); +#endif + + +#define WLED_CONNECTED (WiFi.status() == WL_CONNECTED) +#define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0) + // append new c string to temp buffer efficiently bool oappend(const char* txt); // append new number to temp buffer efficiently