diff --git a/wled00/wled.h b/wled00/wled.h index e5c4f493b..9e373216f 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -1,41 +1,39 @@ #ifndef WLED_H #define WLED_H - /* Main sketch, global variable declarations -*/ -/* - * @title WLED project sketch - * @version 0.9.1 - * @author Christian Schwinne + @title WLED project sketch + @version 0.9.1 + @author Christian Schwinne */ -//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). +// 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). -//ESP8266-01 (black) has 1MB flash and can thus fit the whole program. Use 1M(64K SPIFFS). -//Uncomment some of the following lines to disable features to compile for ESP8266-01 (max flash size 434kB): +// ESP8266-01 (black) has 1MB flash and can thus fit the whole program. Use 1M(64K SPIFFS). +// Uncomment some of the following lines to disable features to compile for ESP8266-01 (max flash size 434kB): +// Alternatively, with platformio pass your chosen flags to your custom build target in platformio.ini.override -//You are required to disable over-the-air updates: +// You are required to disable over-the-air updates: //#define WLED_DISABLE_OTA //saves 14kb -//You need to choose some of these features to disable: +// You need to choose some of these features to disable: //#define WLED_DISABLE_ALEXA //saves 11kb //#define WLED_DISABLE_BLYNK //saves 6kb //#define WLED_DISABLE_CRONIXIE //saves 3kb //#define WLED_DISABLE_HUESYNC //saves 4kb //#define WLED_DISABLE_INFRARED //there is no pin left for this on ESP8266-01, saves 12kb -#define WLED_ENABLE_MQTT //saves 12kb -#define WLED_ENABLE_ADALIGHT //saves 500b only +#define WLED_ENABLE_MQTT //saves 12kb +#define WLED_ENABLE_ADALIGHT //saves 500b only //#define WLED_ENABLE_DMX //uses 3.5kb #define WLED_DISABLE_FILESYSTEM //SPIFFS is not used by any WLED feature yet //#define WLED_ENABLE_FS_SERVING //Enable sending html file from SPIFFS before serving progmem version //#define WLED_ENABLE_FS_EDITOR //enable /edit page for editing SPIFFS content. Will also be disabled with OTA lock -//to toggle usb serial debug (un)comment the following line +// to toggle usb serial debug (un)comment the following line //#define WLED_DEBUG -//library inclusions +// Library inclusions. #include #ifdef ESP8266 #include @@ -116,225 +114,171 @@ extern "C" #endif #endif -//version code in format yymmddb (b = daily build) +// version code in format yymmddb (b = daily build) #define VERSION 2003222 +// Global external variable declaration. See wled.cpp for definitions and comments. extern char versionString[]; - -//AP and OTA default passwords (for maximum change them!) extern char apPass[65]; extern char otaPass[33]; - -//Hardware CONFIG (only changeble HERE, not at runtime) -//LED strip pin, button pin and IR pin changeable in NpbWrapper.h! - -extern byte auxDefaultState; //0: input 1: high 2: low -extern byte auxTriggeredState; //0: input 1: high 2: low -extern char ntpServerName[33]; //NTP server to use - -//WiFi CONFIG (all these can be changed via web UI, no need to set them here) +extern byte auxDefaultState; +extern byte auxTriggeredState; +extern char ntpServerName[33]; extern char clientSSID[33]; extern char clientPass[65]; -extern char cmDNS[33]; //mDNS address (placeholder, will be replaced by wledXXXXXXXXXXXX.local) -extern char apSSID[33]; //AP off by default (unless setup) -extern byte apChannel; //2.4GHz WiFi AP channel (1-13) -extern byte apHide; //hidden AP SSID -extern byte apBehavior; //access point opens when no connection after boot by default -extern IPAddress staticIP; //static IP of ESP -extern IPAddress staticGateway; //gateway (router) IP -extern IPAddress staticSubnet; //most common subnet in home networks -extern bool noWifiSleep; //disabling modem sleep modes will increase heat output and power usage, but may help with connection issues - -//LED CONFIG -extern uint16_t ledCount; //overcurrent prevented by ABL -extern bool useRGBW; //SK6812 strips can contain an extra White channel -#define ABL_MILLIAMPS_DEFAULT 850; //auto lower brightness to stay close to milliampere limit -extern bool turnOnAtBoot; //turn on LEDs at power-up -extern byte bootPreset; //save preset to load after power-up - -extern byte col[]; //current RGB(W) primary color. col[] should be updated if you want to change the color. -extern byte colSec[]; //current RGB(W) secondary color -extern byte briS; //default brightness - -extern byte nightlightTargetBri; //brightness after nightlight is over +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; +extern bool turnOnAtBoot; +extern byte bootPreset; +extern byte col[]; +extern byte colSec[]; +extern byte briS; +extern byte nightlightTargetBri; extern byte nightlightDelayMins; -extern bool nightlightFade; //if enabled, light will gradually dim towards the target bri. Otherwise, it will instantly set after delay over -extern bool nightlightColorFade; //if enabled, light will gradually fade color from primary to secondary color. -extern bool fadeTransition; //enable crossfading color transition -extern uint16_t transitionDelay; //default crossfade duration in ms - -extern bool skipFirstLed; //ignore first LED in strip (useful if you need the LED as signal repeater) -extern byte briMultiplier; //% 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 -extern char serverDescription[33]; //Name of module -extern bool syncToggleReceive; //UIs which only have a single button for sync should toggle send+receive if this is true, only send otherwise - -//Sync CONFIG +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; //Infrared receiver - -extern uint16_t udpPort; //WLED notifier default port -extern uint16_t udpRgbPort; //Hyperion port - -extern bool receiveNotificationBrightness; //apply brightness from incoming notifications -extern bool receiveNotificationColor; //apply color -extern bool receiveNotificationEffects; //apply effects setup -extern bool notifyDirect; //send notification if change via UI or HTTP API -extern bool notifyButton; //send if updated by button or infrared remote -extern bool notifyAlexa; //send notification if updated via Alexa -extern bool notifyMacro; //send notification for macro -extern bool notifyHue; //send notification if Hue light changes -extern bool notifyTwice; //notifications use UDP: enable if devices don't sync reliably - -extern bool alexaEnabled; //enable device discovery by Amazon Echo -extern char alexaInvocationName[33]; //speech control name of device. Choose something voice-to-text can understand - -extern char blynkApiKey[36]; //Auth token for Blynk server. If empty, no connection will be made - -extern uint16_t realtimeTimeoutMs; //ms timeout of realtime mode before returning to normal mode -extern int arlsOffset; //realtime LED offset -extern bool receiveDirect; //receive UDP realtime -extern bool arlsDisableGammaCorrection; //activate if gamma correction is handled by the source -extern bool arlsForceMaxBri; //enable to force max brightness if source has very dark colors that would be black - +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; //settings for E1.31 (sACN) protocol (only DMX_MODE_MULTIPLE_* can span over consequtive universes) -extern uint8_t DMXMode; //DMX mode (s.a.) -extern uint16_t DMXAddress; //DMX start address of fixture, a.k.a. first Channel [for E1.31 (sACN) protocol] -extern uint8_t DMXOldDimmer; //only update brightness on change -extern uint8_t e131LastSequenceNumber[E131_MAX_UNIVERSE_COUNT]; //to detect packet loss -extern bool e131Multicast; //multicast or unicast -extern bool e131SkipOutOfSequence; //freeze instead of flickering - +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]; //main MQTT topic (individual per device, default is wled/mac) -extern char mqttGroupTopic[33]; //second MQTT topic (for example to group devices) -extern char mqttServer[33]; //both domains and IPs should work (no SSL) -extern char mqttUser[41]; //optional: username for MQTT auth -extern char mqttPass[41]; //optional: password for MQTT auth -extern char mqttClientID[41]; //override the client ID +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; //poll hue bridge for light state -extern uint16_t huePollIntervalMs; //low values (< 1sec) may cause lag but offer quicker response -extern char hueApiKey[47]; //key token will be obtained from bridge -extern byte huePollLightId; //ID of hue lamp to sync to. Find the ID in the hue app ("about" section) -extern IPAddress hueIP; //IP address of the bridge +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; - -//Time CONFIG -extern bool ntpEnabled; //get internet time. Only required if you use clock overlays or time-activated macros -extern bool useAMPM; //12h/24h clock format -extern byte currentTimezone; //Timezone ID. Refer to timezones array in wled_ntp.cpp -extern int utcOffsetSecs; //Seconds to offset from UTC before timzone calculation - -extern byte overlayDefault; //0: no overlay 1: analog clock 2: single-digit clocl 3: cronixie -extern byte overlayMin; //boundaries of overlay mode +extern bool ntpEnabled; +extern bool useAMPM; +extern byte currentTimezone; +extern int utcOffsetSecs; +extern byte overlayDefault; +extern byte overlayMin; extern byte overlayMax; - -extern byte analogClock12pixel; //The pixel in your strip where "midnight" would be -extern bool analogClockSecondsTrail; //Display seconds as trail of LEDs instead of a single pixel -extern bool analogClock5MinuteMarks; //Light pixels at every 5-minute position - -extern char cronixieDisplay[7]; //Cronixie Display mask. See wled13_cronixie.ino -extern bool cronixieBacklight; //Allow digits to be back-illuminated - -extern bool countdownMode; //Clock will count down towards date -extern byte countdownYear, countdownMonth; //Countdown target date, year is last two digits +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; //macro loaded after startup -extern byte macroNl; //after nightlight delay over +extern byte macroBoot; +extern byte macroNl; extern byte macroCountdown; extern byte macroAlexaOn, macroAlexaOff; extern byte macroButton, macroLongPress, macroDoublePress; - -//Security CONFIG -extern bool otaLock; //prevents OTA firmware updates without password. ALWAYS enable if system exposed to any public networks -extern bool wifiLock; //prevents access to WiFi settings when OTA lock is enabled -extern bool aOtaEnabled; //ArduinoOTA allows easy updates directly from the IDE. Careful, it does not auto-disable when OTA lock is on - +extern bool otaLock; +extern bool wifiLock; +extern bool aOtaEnabled; extern uint16_t userVar0, userVar1; - #ifdef WLED_ENABLE_DMX -//dmx CONFIG -extern byte DMXChannels; // number of channels per fixture +extern byte DMXChannels; extern byte DMXFixtureMap[15]; -extern // assigns the different channels to different functions. See wled21_dmx.ino for more information. -extern uint16_t DMXGap; // gap between the fixtures. makes addressing easier because you don't have to memorize odd numbers when climbing up onto a rig. -extern uint16_t DMXStart; // start address of the first fixture +extern +extern uint16_t DMXGap; +extern uint16_t DMXStart; #endif - -//internal global variable declarations -//wifi extern bool apActive; extern bool forceReconnect; extern uint32_t lastReconnectAttempt; extern bool interfacesInited; extern bool wasConnected; - -//color -extern byte colOld[]; //color before transition -extern byte colT[]; //color that is currently displayed on the LEDs -extern byte colIT[]; //color that was last sent to LEDs +extern byte colOld[]; +extern byte colT[]; +extern byte colIT[]; extern byte colSecT[]; extern byte colSecOld[]; extern byte colSecIT[]; - -extern byte lastRandomIndex; //used to save last random color so the new one is not the same - -//transitions +extern byte lastRandomIndex; extern bool transitionActive; extern uint16_t transitionDelayDefault; extern uint16_t transitionDelayTemp; extern unsigned long transitionStartTime; -extern float tperLast; //crossfade transition progress, 0.0f - 1.0f +extern float tperLast; extern bool jsonTransitionOnce; - -//nightlight extern bool nightlightActive; extern bool nightlightActiveOld; extern uint32_t nightlightDelayMs; extern uint8_t nightlightDelayMinsDefault; extern unsigned long nightlightStartTime; -extern byte briNlT; //current nightlight brightness -extern byte colNlT[]; //current nightlight color - +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; //brightness before turned off. Used for toggle function -extern byte whiteLast; //white channel before turned off. Used for toggle function - +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; -//uint16_t hueFailCount; extern float hueXLast, hueYLast; extern uint16_t hueHueLast, hueCtLast; extern byte hueSatLast, hueBriLast; @@ -342,31 +286,20 @@ 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; - -//countdown extern unsigned long countdownTime; extern bool countdownOverTriggered; - -//timer extern byte lastTimerMinute; extern byte timerHours[]; extern byte timerMinutes[]; extern byte timerMacro[]; -extern byte timerWeekday[]; //weekdays to activate on -//bit pattern of arr elem: 0b11111111: sun,sat,fri,thu,wed,tue,mon,validity - -//blynk +extern byte timerWeekday[]; extern bool blynkEnabled; - -//preset cycling extern bool presetCyclingEnabled; extern byte presetCycleMin, presetCycleMax; extern uint16_t presetCycleTime; @@ -374,36 +307,24 @@ extern unsigned long presetCycledTime; extern byte presetCycCurr; extern bool presetApplyBri; extern bool saveCurrPresetCycConf; - -//realtime extern byte realtimeMode; extern IPAddress realtimeIP; extern unsigned long realtimeTimeout; - -//mqtt extern long lastMqttReconnectAttempt; extern long lastInterfaceUpdate; extern byte interfaceUpdateCallMode; -extern char mqttStatusTopic[40]; //this must be global because of async handlers - +extern char mqttStatusTopic[40]; #if AUXPIN >= 0 -//auxiliary debug pin extern byte auxTime; extern unsigned long auxStartTime; extern bool auxActive; #endif - -//alexa udp extern String escapedMac; #ifndef WLED_DISABLE_ALEXA extern Espalexa espalexa; extern EspalexaDevice *espalexaDevice; #endif - -//dns server extern DNSServer dnsServer; - -//network time extern bool ntpConnected; extern time_t local; extern unsigned long ntpLastSyncTime; @@ -411,51 +332,35 @@ extern unsigned long ntpPacketSentTime; extern IPAddress ntpServerIP; extern uint16_t ntpLocalPort; #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 extern char *obuf; extern uint16_t olen; - -//presets extern uint16_t savedPresets; extern int8_t currentPreset; extern bool isPreset; - extern byte errorFlag; - extern String messageHead, messageSub; extern byte optionType; - -extern bool doReboot; //flag to initiate reboot from async handlers +extern bool doReboot; extern bool doPublishMqtt; - -//server library objects 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; -//function prototypes +// Function prototypes extern void colorFromUint32(uint32_t, bool); extern void serveMessage(AsyncWebServerRequest *, uint16_t, String, String, byte); extern void handleE131Packet(e131_packet_t *, IPAddress); extern void arlsLock(uint32_t, byte); extern void handleOverlayDraw(); -//udp interface objects -extern WiFiUDP notifierUdp, rgbUdp; -extern WiFiUDP ntpUdp; -extern ESPAsyncE131 e131; -extern bool e131NewData; - -//led fx library object -extern WS2812FX strip; - - #define WLED_CONNECTED (WiFi.status() == WL_CONNECTED) #define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0) @@ -474,11 +379,9 @@ extern int loops; #define DEBUG_PRINTF(x) #endif - -// TODO: Inline? -//append new c string to temp buffer efficiently +// append new c string to temp buffer efficiently bool oappend(const char *txt); -//append new number to temp buffer efficiently +// append new number to temp buffer efficiently bool oappendi(int i); int getSignalQuality(int rssi);