From 594c0b85507ec7e5ae29cfa72102d6a2aa58ba08 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Wed, 25 Mar 2020 04:00:55 -0400 Subject: [PATCH 01/32] Transform ino to h/cpp. Class WLED created. --- wled00/wled.cpp | 503 ++++++++++++++ wled00/wled.h | 529 +++++++++++++++ wled00/wled00.ino | 612 +----------------- wled00/wled05_init.ino | 339 ---------- ...{wled06_usermod.ino => wled06_usermod.cpp} | 1 + wled00/{wled12_alexa.ino => wled_alexa.cpp} | 10 +- wled00/wled_alexa.h | 16 + wled00/{wled16_blynk.ino => wled_blynk.cpp} | 6 +- wled00/wled_blynk.h | 13 + wled00/{wled09_button.ino => wled_button.cpp} | 2 + wled00/wled_button.h | 12 + wled00/{wled14_colors.ino => wled_colors.cpp} | 12 +- wled00/wled_colors.h | 20 + ...{wled13_cronixie.ino => wled_cronixie.cpp} | 20 +- wled00/wled_cronixie.h | 13 + wled00/{wled21_dmx.ino => wled_dmx.cpp} | 9 +- wled00/wled_dmx.h | 11 + wled00/{wled01_eeprom.ino => wled_eeprom.cpp} | 6 +- wled00/wled_eeprom.h | 22 + wled00/{wled04_file.ino => wled_file.cpp} | 14 +- wled00/wled_file.h | 12 + wled00/{wled15_hue.ino => wled_hue.cpp} | 7 +- wled00/wled_hue.h | 10 + wled00/{wled20_ir.ino => wled_ir.cpp} | 5 +- wled00/wled_ir.h | 9 + wled00/{wled19_json.ino => wled_json.cpp} | 5 +- wled00/wled_json.h | 15 + wled00/{wled08_led.ino => wled_led.cpp} | 8 +- wled00/wled_led.h | 19 + wled00/{wled17_mqtt.ino => wled_mqtt.cpp} | 5 +- wled00/wled_mqtt.h | 9 + wled00/{wled07_notify.ino => wled_notify.cpp} | 6 +- wled00/wled_notify.h | 17 + wled00/{wled10_ntp.ino => wled_ntp.cpp} | 62 +- wled00/wled_ntp.h | 76 +++ wled00/{wled11_ol.ino => wled_overlay.cpp} | 5 +- wled00/wled_overlay.h | 12 + wled00/{wled18_server.ino => wled_server.cpp} | 7 +- wled00/wled_server.h | 18 + wled00/{wled03_set.ino => wled_set.cpp} | 4 + wled00/wled_set.h | 12 + wled00/{wled02_xml.ino => wled_xml.cpp} | 7 +- wled00/wled_xml.h | 15 + 43 files changed, 1441 insertions(+), 1074 deletions(-) create mode 100644 wled00/wled.cpp create mode 100644 wled00/wled.h delete mode 100644 wled00/wled05_init.ino rename wled00/{wled06_usermod.ino => wled06_usermod.cpp} (97%) rename wled00/{wled12_alexa.ino => wled_alexa.cpp} (89%) create mode 100644 wled00/wled_alexa.h rename wled00/{wled16_blynk.ino => wled_blynk.cpp} (94%) create mode 100644 wled00/wled_blynk.h rename wled00/{wled09_button.ino => wled_button.cpp} (98%) create mode 100644 wled00/wled_button.h rename wled00/{wled14_colors.ino => wled_colors.cpp} (96%) create mode 100644 wled00/wled_colors.h rename wled00/{wled13_cronixie.ino => wled_cronixie.cpp} (97%) create mode 100644 wled00/wled_cronixie.h rename wled00/{wled21_dmx.ino => wled_dmx.cpp} (89%) create mode 100644 wled00/wled_dmx.h rename wled00/{wled01_eeprom.ino => wled_eeprom.cpp} (99%) create mode 100644 wled00/wled_eeprom.h rename wled00/{wled04_file.ino => wled_file.cpp} (95%) create mode 100644 wled00/wled_file.h rename wled00/{wled15_hue.ino => wled_hue.cpp} (99%) create mode 100644 wled00/wled_hue.h rename wled00/{wled20_ir.ino => wled_ir.cpp} (99%) create mode 100644 wled00/wled_ir.h rename wled00/{wled19_json.ino => wled_json.cpp} (99%) create mode 100644 wled00/wled_json.h rename wled00/{wled08_led.ino => wled_led.cpp} (98%) create mode 100644 wled00/wled_led.h rename wled00/{wled17_mqtt.ino => wled_mqtt.cpp} (98%) create mode 100644 wled00/wled_mqtt.h rename wled00/{wled07_notify.ino => wled_notify.cpp} (99%) create mode 100644 wled00/wled_notify.h rename wled00/{wled10_ntp.ino => wled_ntp.cpp} (58%) create mode 100644 wled00/wled_ntp.h rename wled00/{wled11_ol.ino => wled_overlay.cpp} (98%) create mode 100644 wled00/wled_overlay.h rename wled00/{wled18_server.ino => wled_server.cpp} (99%) create mode 100644 wled00/wled_server.h rename wled00/{wled03_set.ino => wled_set.cpp} (99%) create mode 100644 wled00/wled_set.h rename wled00/{wled02_xml.ino => wled_xml.cpp} (99%) create mode 100644 wled00/wled_xml.h diff --git a/wled00/wled.cpp b/wled00/wled.cpp new file mode 100644 index 00000000..50a83f27 --- /dev/null +++ b/wled00/wled.cpp @@ -0,0 +1,503 @@ +#include "wled.h" + +WLED::WLED() { + +} + +//turns all LEDs off and restarts ESP +void WLED::reset() +{ + briT = 0; + long dly = millis(); + while (millis() - dly < 250) + { + yield(); //enough time to send response to client + } + setAllLeds(); + DEBUG_PRINTLN("MODULE RESET"); + ESP.restart(); +} + +bool oappendi(int i) +{ + char s[11]; + sprintf(s, "%ld", i); + return oappend(s); +} + +bool oappend(const char *txt) +{ + uint16_t len = strlen(txt); + if (olen + len >= OMAX) + return false; //buffer full + strcpy(obuf + olen, txt); + olen += len; + return true; +} + +void WLED::loop() +{ + handleIR(); //2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too + handleConnection(); + handleSerial(); + handleNotifications(); + handleTransitions(); +#ifdef WLED_ENABLE_DMX + handleDMX(); +#endif + userLoop(); + + yield(); + handleIO(); + handleIR(); + handleNetworkTime(); + handleAlexa(); + + handleOverlays(); + yield(); +#ifdef WLED_USE_ANALOG_LEDS + strip.setRgbwPwm(); +#endif + + if (doReboot) + reset(); + + if (!realtimeMode) //block stuff if WARLS/Adalight is enabled + { + if (apActive) + dnsServer.processNextRequest(); +#ifndef WLED_DISABLE_OTA + if (WLED_CONNECTED && aOtaEnabled) + ArduinoOTA.handle(); +#endif + handleNightlight(); + yield(); + + handleHue(); + handleBlynk(); + + yield(); + if (!offMode) + strip.service(); + } + yield(); +#ifdef ESP8266 + MDNS.update(); +#endif + if (millis() - lastMqttReconnectAttempt > 30000) + initMqtt(); + +//DEBUG serial logging +#ifdef WLED_DEBUG + if (millis() - debugTime > 9999) + { + DEBUG_PRINTLN("---DEBUG INFO---"); + DEBUG_PRINT("Runtime: "); + DEBUG_PRINTLN(millis()); + DEBUG_PRINT("Unix time: "); + DEBUG_PRINTLN(now()); + DEBUG_PRINT("Free heap: "); + DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINT("Wifi state: "); + DEBUG_PRINTLN(WiFi.status()); + if (WiFi.status() != lastWifiState) + { + wifiStateChangedTime = millis(); + } + lastWifiState = WiFi.status(); + DEBUG_PRINT("State time: "); + DEBUG_PRINTLN(wifiStateChangedTime); + DEBUG_PRINT("NTP last sync: "); + DEBUG_PRINTLN(ntpLastSyncTime); + DEBUG_PRINT("Client IP: "); + DEBUG_PRINTLN(WiFi.localIP()); + DEBUG_PRINT("Loops/sec: "); + DEBUG_PRINTLN(loops / 10); + loops = 0; + debugTime = millis(); + } + loops++; +#endif // WLED_DEBU +} + +void WLED::wledInit() +{ + EEPROM.begin(EEPSIZE); + ledCount = EEPROM.read(229) + ((EEPROM.read(398) << 8) & 0xFF00); + if (ledCount > MAX_LEDS || ledCount == 0) + ledCount = 30; + +#ifdef ESP8266 +#if LEDPIN == 3 + if (ledCount > MAX_LEDS_DMA) + ledCount = MAX_LEDS_DMA; //DMA method uses too much ram +#endif +#endif + Serial.begin(115200); + Serial.setTimeout(50); + DEBUG_PRINTLN(); + DEBUG_PRINT("---WLED "); + DEBUG_PRINT(versionString); + DEBUG_PRINT(" "); + DEBUG_PRINT(VERSION); + DEBUG_PRINTLN(" INIT---"); +#ifdef ARDUINO_ARCH_ESP32 + DEBUG_PRINT("esp32 "); + DEBUG_PRINTLN(ESP.getSdkVersion()); +#else + DEBUG_PRINT("esp8266 "); + DEBUG_PRINTLN(ESP.getCoreVersion()); +#endif + int heapPreAlloc = ESP.getFreeHeap(); + DEBUG_PRINT("heap "); + DEBUG_PRINTLN(ESP.getFreeHeap()); + + strip.init(EEPROM.read(372), ledCount, EEPROM.read(2204)); //init LEDs quickly + strip.setBrightness(0); + + DEBUG_PRINT("LEDs inited. heap usage ~"); + DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap()); + +#ifndef WLED_DISABLE_FILESYSTEM +#ifdef ARDUINO_ARCH_ESP32 + SPIFFS.begin(true); +#endif + SPIFFS.begin(); +#endif + + DEBUG_PRINTLN("Load EEPROM"); + loadSettingsFromEEPROM(true); + beginStrip(); + userSetup(); + if (strcmp(clientSSID, DEFAULT_CLIENT_SSID) == 0) + showWelcomePage = true; + WiFi.persistent(false); + + if (macroBoot > 0) + applyMacro(macroBoot); + Serial.println("Ada"); + + //generate module IDs + escapedMac = WiFi.macAddress(); + escapedMac.replace(":", ""); + escapedMac.toLowerCase(); + if (strcmp(cmDNS, "x") == 0) //fill in unique mdns default + { + strcpy(cmDNS, "wled-"); + sprintf(cmDNS + 5, "%*s", 6, escapedMac.c_str() + 6); + } + if (mqttDeviceTopic[0] == 0) + { + strcpy(mqttDeviceTopic, "wled/"); + sprintf(mqttDeviceTopic + 5, "%*s", 6, escapedMac.c_str() + 6); + } + if (mqttClientID[0] == 0) + { + strcpy(mqttClientID, "WLED-"); + sprintf(mqttClientID + 5, "%*s", 6, escapedMac.c_str() + 6); + } + + strip.service(); + +#ifndef WLED_DISABLE_OTA + if (aOtaEnabled) + { + ArduinoOTA.onStart([]() { +#ifdef ESP8266 + wifi_set_sleep_type(NONE_SLEEP_T); +#endif + DEBUG_PRINTLN("Start ArduinoOTA"); + }); + if (strlen(cmDNS) > 0) + ArduinoOTA.setHostname(cmDNS); + } +#endif +#ifdef WLED_ENABLE_DMX + dmx.init(512); // initialize with bus length +#endif + //HTTP server page init + initServer(); +} + +void WLED::beginStrip() +{ + // Initialize NeoPixel Strip and button + strip.setShowCallback(handleOverlayDraw); + +#ifdef BTNPIN + pinMode(BTNPIN, INPUT_PULLUP); +#endif + + if (bootPreset > 0) + applyPreset(bootPreset, turnOnAtBoot); + colorUpdated(NOTIFIER_CALL_MODE_INIT); + +//init relay pin +#if RLYPIN >= 0 + pinMode(RLYPIN, OUTPUT); +#if RLYMDE + digitalWrite(RLYPIN, bri); +#else + digitalWrite(RLYPIN, !bri); +#endif +#endif + + //disable button if it is "pressed" unintentionally +#ifdef BTNPIN + if (digitalRead(BTNPIN) == LOW) + buttonEnabled = false; +#else + buttonEnabled = false; +#endif +} + +void WLED::initAP(bool resetAP = false) +{ + if (apBehavior == AP_BEHAVIOR_BUTTON_ONLY && !resetAP) + return; + + if (!apSSID[0] || resetAP) + strcpy(apSSID, "WLED-AP"); + if (resetAP) + strcpy(apPass, DEFAULT_AP_PASS); + DEBUG_PRINT("Opening access point "); + DEBUG_PRINTLN(apSSID); + WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255, 255, 255, 0)); + WiFi.softAP(apSSID, apPass, apChannel, apHide); + + if (!apActive) //start captive portal if AP active + { + DEBUG_PRINTLN("Init AP interfaces"); + server.begin(); + if (udpPort > 0 && udpPort != ntpLocalPort) + { + udpConnected = notifierUdp.begin(udpPort); + } + if (udpRgbPort > 0 && udpRgbPort != ntpLocalPort && udpRgbPort != udpPort) + { + udpRgbConnected = rgbUdp.begin(udpRgbPort); + } + + dnsServer.setErrorReplyCode(DNSReplyCode::NoError); + dnsServer.start(53, "*", WiFi.softAPIP()); + } + apActive = true; +} + +void WLED::initConnection() +{ + WiFi.disconnect(); //close old connections +#ifdef ESP8266 + WiFi.setPhyMode(WIFI_PHY_MODE_11N); +#endif + + if (staticIP[0] != 0 && staticGateway[0] != 0) + { + WiFi.config(staticIP, staticGateway, staticSubnet, IPAddress(8, 8, 8, 8)); + } + else + { + WiFi.config(0U, 0U, 0U); + } + + lastReconnectAttempt = millis(); + + if (!WLED_WIFI_CONFIGURED) + { + DEBUG_PRINT("No connection configured. "); + if (!apActive) + initAP(); //instantly go to ap mode + return; + } + else if (!apActive) + { + if (apBehavior == AP_BEHAVIOR_ALWAYS) + { + initAP(); + } + else + { + DEBUG_PRINTLN("Access point disabled."); + WiFi.softAPdisconnect(true); + } + } + showWelcomePage = false; + + DEBUG_PRINT("Connecting to "); + DEBUG_PRINT(clientSSID); + DEBUG_PRINTLN("..."); + +#ifdef ESP8266 + WiFi.hostname(serverDescription); +#endif + + WiFi.begin(clientSSID, clientPass); + +#ifdef ARDUINO_ARCH_ESP32 + WiFi.setSleep(!noWifiSleep); + WiFi.setHostname(serverDescription); +#else + wifi_set_sleep_type((noWifiSleep) ? NONE_SLEEP_T : MODEM_SLEEP_T); +#endif +} + +void WLED::initInterfaces() +{ + DEBUG_PRINTLN("Init STA interfaces"); + + if (hueIP[0] == 0) + { + hueIP[0] = WiFi.localIP()[0]; + hueIP[1] = WiFi.localIP()[1]; + hueIP[2] = WiFi.localIP()[2]; + } + + //init Alexa hue emulation + if (alexaEnabled) + alexaInit(); + +#ifndef WLED_DISABLE_OTA + if (aOtaEnabled) + ArduinoOTA.begin(); +#endif + + strip.service(); + // Set up mDNS responder: + if (strlen(cmDNS) > 0) + { + if (!aOtaEnabled) + MDNS.begin(cmDNS); + + DEBUG_PRINTLN("mDNS started"); + MDNS.addService("http", "tcp", 80); + MDNS.addService("wled", "tcp", 80); + MDNS.addServiceTxt("wled", "tcp", "mac", escapedMac.c_str()); + } + server.begin(); + + if (udpPort > 0 && udpPort != ntpLocalPort) + { + udpConnected = notifierUdp.begin(udpPort); + if (udpConnected && udpRgbPort != udpPort) + udpRgbConnected = rgbUdp.begin(udpRgbPort); + } + if (ntpEnabled) + ntpConnected = ntpUdp.begin(ntpLocalPort); + + initBlynk(blynkApiKey); + e131.begin((e131Multicast) ? E131_MULTICAST : E131_UNICAST, e131Universe, E131_MAX_UNIVERSE_COUNT); + reconnectHue(); + initMqtt(); + interfacesInited = true; + wasConnected = true; +} + +byte stacO = 0; +uint32_t lastHeap; +unsigned long heapTime = 0; + +void WLED::handleConnection() +{ + 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 + if (millis() - heapTime > 5000) + { + uint32_t heap = ESP.getFreeHeap(); + if (heap < 9000 && lastHeap < 9000) + { + DEBUG_PRINT("Heap too low! "); + DEBUG_PRINTLN(heap); + forceReconnect = true; + } + lastHeap = heap; + heapTime = millis(); + } + + byte stac = 0; + if (apActive) + { +#ifdef ESP8266 + stac = wifi_softap_get_station_num(); +#else + wifi_sta_list_t stationList; + esp_wifi_ap_get_sta_list(&stationList); + stac = stationList.num; +#endif + if (stac != stacO) + { + stacO = stac; + DEBUG_PRINT("Connected AP clients: "); + DEBUG_PRINTLN(stac); + if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) + { //trying to connect, but not connected + if (stac) + WiFi.disconnect(); //disable search so that AP can work + else + initConnection(); //restart search + } + } + } + if (forceReconnect) + { + DEBUG_PRINTLN("Forcing reconnect."); + initConnection(); + interfacesInited = false; + forceReconnect = false; + wasConnected = false; + return; + } + if (!WLED_CONNECTED) + { + if (interfacesInited) + { + DEBUG_PRINTLN("Disconnected!"); + interfacesInited = false; + initConnection(); + } + if (millis() - lastReconnectAttempt > ((stac) ? 300000 : 20000) && WLED_WIFI_CONFIGURED) + initConnection(); + if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) + initAP(); + } + else if (!interfacesInited) + { //newly connected + DEBUG_PRINTLN(""); + DEBUG_PRINT("Connected! IP address: "); + DEBUG_PRINTLN(WiFi.localIP()); + initInterfaces(); + userConnected(); + + //shut down AP + if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive) + { + dnsServer.stop(); + WiFi.softAPdisconnect(true); + apActive = false; + DEBUG_PRINTLN("Access point disabled."); + } + } +} + +//by https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp +int WLED::getSignalQuality(int rssi) +{ + int quality = 0; + + if (rssi <= -100) + { + quality = 0; + } + else if (rssi >= -50) + { + quality = 100; + } + else + { + quality = 2 * (rssi + 100); + } + return quality; +} \ No newline at end of file diff --git a/wled00/wled.h b/wled00/wled.h new file mode 100644 index 00000000..4f9b79af --- /dev/null +++ b/wled00/wled.h @@ -0,0 +1,529 @@ +#ifndef WLED_H +#define WLED_H + +/* + Main sketch, global variable declarations +*/ +/* + * @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 (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): + +//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: +//#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_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 +//#define WLED_DEBUG + +//library inclusions +#include +#ifdef WLED_ENABLE_DMX +#include +DMXESPSerial dmx; +#endif +#ifdef ESP8266 +#include +#include +#include +extern "C" +{ +#include +} +#else //ESP32 +#include +#include "esp_wifi.h" +#include +#include +#include "SPIFFS.h" +#endif + +#include +#include +#include +#include +#ifndef WLED_DISABLE_OTA +#include +#endif +#include +#include "src/dependencies/time/TimeLib.h" +#include "src/dependencies/timezone/Timezone.h" +#ifndef WLED_DISABLE_ALEXA +#define ESPALEXA_ASYNC +#define ESPALEXA_NO_SUBPAGE +#define ESPALEXA_MAXDEVICES 1 +// #define ESPALEXA_DEBUG +#include "src/dependencies/espalexa/Espalexa.h" +#endif +#ifndef WLED_DISABLE_BLYNK +#include "src/dependencies/blynk/BlynkSimpleEsp.h" +#endif +#include "src/dependencies/e131/ESPAsyncE131.h" +#include "src/dependencies/async-mqtt-client/AsyncMqttClient.h" +#include "src/dependencies/json/AsyncJson-v6.h" +#include "src/dependencies/json/ArduinoJson-v6.h" +#include "html_ui.h" +#include "html_settings.h" +#include "html_other.h" +#include "FX.h" +#include "ir_codes.h" +#include "const.h" + +#ifndef CLIENT_SSID +#define CLIENT_SSID DEFAULT_CLIENT_SSID +#endif + +#ifndef CLIENT_PASS +#define CLIENT_PASS "" +#endif + +#if IR_PIN < 0 +#ifndef WLED_DISABLE_INFRARED +#define WLED_DISABLE_INFRARED +#endif +#endif + +#ifndef WLED_DISABLE_INFRARED +#include +#include +#include +#endif + +// remove flicker because PWM signal of RGB channels can become out of phase +#if defined(WLED_USE_ANALOG_LEDS) && defined(ESP8266) +#include "src/dependencies/arduino/core_esp8266_waveform.h" +#endif + +// enable additional debug output +#ifdef WLED_DEBUG +#ifndef ESP8266 +#include +#endif +#endif + +//version code in format yymmddb (b = daily build) +#define VERSION 2003222 + +char versionString[] = "0.9.1"; + +//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 +#define ABL_MILLIAMPS_DEFAULT 850; //auto lower brightness to stay close to milliampere limit +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 + +#define E131_MAX_UNIVERSE_COUNT 9 +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; +#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 +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; + +//function prototypes +void colorFromUint32(uint32_t, bool = false); +void serveMessage(AsyncWebServerRequest *, uint16_t, String, String, byte); +void handleE131Packet(e131_packet_t *, IPAddress); +void arlsLock(uint32_t, byte); +void handleOverlayDraw(); + +//udp interface objects +WiFiUDP notifierUdp, rgbUdp; +WiFiUDP ntpUdp; +ESPAsyncE131 e131(handleE131Packet); +bool e131NewData = false; + +//led fx library object +WS2812FX strip = WS2812FX(); + +#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) +unsigned long debugTime = 0; +int lastWifiState = 3; +unsigned long wifiStateChangedTime = 0; +int loops = 0; +#else +#define DEBUG_PRINT(x) +#define DEBUG_PRINTLN(x) +#define DEBUG_PRINTF(x) +#endif + + +// TODO: Inline? +//append new c string to temp buffer efficiently +bool oappend(const char *txt); +//append new number to temp buffer efficiently +bool oappendi(int i); + +class WLED +{ +public: + static WLED &instance() + { + static WLED instance; + return instance; + } + + WLED(); + + void wledInit(); + + void reset(); + void loop(); + + + //boot starts here + void setup() + { + wledInit(); + } + + void loop(); + +private: + void wledInit(); + void beginStrip(); + + void handleConnection(); + void initAP(bool resetAP = false); + void initConnection(); + void initInterfaces(); +}; +#endif // WLED_H diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 7c64796d..fc06f211 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -1,617 +1,13 @@ /* - Main sketch, global variable declarations + Arduino Studio support file. */ -/* - * @title WLED project sketch - * @version 0.9.1 - * @author Christian Schwinne - */ +#include "wled.h" -//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): - -//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: -//#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_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 -//#define WLED_DEBUG - -//library inclusions -#include -#ifdef WLED_ENABLE_DMX - #include - DMXESPSerial dmx; -#endif -#ifdef ESP8266 - #include - #include - #include - extern "C" { - #include - } -#else //ESP32 - #include - #include "esp_wifi.h" - #include - #include - #include "SPIFFS.h" -#endif - -#include -#include -#include -#include -#ifndef WLED_DISABLE_OTA - #include -#endif -#include -#include "src/dependencies/time/TimeLib.h" -#include "src/dependencies/timezone/Timezone.h" -#ifndef WLED_DISABLE_ALEXA - #define ESPALEXA_ASYNC - #define ESPALEXA_NO_SUBPAGE - #define ESPALEXA_MAXDEVICES 1 - // #define ESPALEXA_DEBUG - #include "src/dependencies/espalexa/Espalexa.h" -#endif -#ifndef WLED_DISABLE_BLYNK - #include "src/dependencies/blynk/BlynkSimpleEsp.h" -#endif -#include "src/dependencies/e131/ESPAsyncE131.h" -#include "src/dependencies/async-mqtt-client/AsyncMqttClient.h" -#include "src/dependencies/json/AsyncJson-v6.h" -#include "src/dependencies/json/ArduinoJson-v6.h" -#include "html_ui.h" -#include "html_settings.h" -#include "html_other.h" -#include "FX.h" -#include "ir_codes.h" -#include "const.h" - -#ifndef CLIENT_SSID -#define CLIENT_SSID DEFAULT_CLIENT_SSID -#endif - -#ifndef CLIENT_PASS -#define CLIENT_PASS "" -#endif - - -#if IR_PIN < 0 - #ifndef WLED_DISABLE_INFRARED - #define WLED_DISABLE_INFRARED - #endif -#endif - -#ifndef WLED_DISABLE_INFRARED - #include - #include - #include -#endif - -// remove flicker because PWM signal of RGB channels can become out of phase -#if defined(WLED_USE_ANALOG_LEDS) && defined(ESP8266) - #include "src/dependencies/arduino/core_esp8266_waveform.h" -#endif - -// enable additional debug output -#ifdef WLED_DEBUG - #ifndef ESP8266 - #include - #endif -#endif - -//version code in format yymmddb (b = daily build) -#define VERSION 2003222 - -char versionString[] = "0.9.1"; - - -//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 -#define ABL_MILLIAMPS_DEFAULT 850; //auto lower brightness to stay close to milliampere limit -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 - -#define E131_MAX_UNIVERSE_COUNT 9 -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; -#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 -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; - -//function prototypes -void colorFromUint32(uint32_t, bool = false); -void serveMessage(AsyncWebServerRequest*, uint16_t, String, String, byte); -void handleE131Packet(e131_packet_t*, IPAddress); -void arlsLock(uint32_t,byte); -void handleOverlayDraw(); - -//udp interface objects -WiFiUDP notifierUdp, rgbUdp; -WiFiUDP ntpUdp; -ESPAsyncE131 e131(handleE131Packet); -bool e131NewData = false; - -//led fx library object -WS2812FX strip = WS2812FX(); - -#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) - unsigned long debugTime = 0; - int lastWifiState = 3; - unsigned long wifiStateChangedTime = 0; - int loops = 0; -#else - #define DEBUG_PRINT(x) - #define DEBUG_PRINTLN(x) - #define DEBUG_PRINTF(x) -#endif - -//filesystem -#ifndef WLED_DISABLE_FILESYSTEM - #include - #ifdef ARDUINO_ARCH_ESP32 - #include "SPIFFS.h" - #endif - #include "SPIFFSEditor.h" -#endif - - - -//turns all LEDs off and restarts ESP -void reset() -{ - briT = 0; - long dly = millis(); - while (millis() - dly < 250) - { - yield(); //enough time to send response to client - } - setAllLeds(); - DEBUG_PRINTLN("MODULE RESET"); - ESP.restart(); -} - - -//append new c string to temp buffer efficiently -bool oappend(const char* txt) -{ - uint16_t len = strlen(txt); - if (olen + len >= OMAX) return false; //buffer full - strcpy(obuf + olen, txt); - olen += len; - return true; -} - - -//append new number to temp buffer efficiently -bool oappendi(int i) -{ - char s[11]; - sprintf(s, "%ld", i); - return oappend(s); -} - - -//boot starts here void setup() { - wledInit(); + //auto& wled = Wled(); } - -//main program loop void loop() { - handleIR(); //2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too - handleConnection(); - handleSerial(); - handleNotifications(); - handleTransitions(); -#ifdef WLED_ENABLE_DMX - handleDMX(); -#endif - userLoop(); - yield(); - handleIO(); - handleIR(); - handleNetworkTime(); - handleAlexa(); - handleOverlays(); - yield(); -#ifdef WLED_USE_ANALOG_LEDS - strip.setRgbwPwm(); -#endif - - if (doReboot) reset(); - - if (!realtimeMode) //block stuff if WARLS/Adalight is enabled - { - if (apActive) dnsServer.processNextRequest(); -#ifndef WLED_DISABLE_OTA - if (WLED_CONNECTED && aOtaEnabled) ArduinoOTA.handle(); -#endif - handleNightlight(); - yield(); - - handleHue(); - handleBlynk(); - - yield(); - if (!offMode) strip.service(); - } - yield(); -#ifdef ESP8266 - MDNS.update(); -#endif - if (millis() - lastMqttReconnectAttempt > 30000) initMqtt(); - - //DEBUG serial logging -#ifdef WLED_DEBUG - if (millis() - debugTime > 9999) - { - DEBUG_PRINTLN("---DEBUG INFO---"); - DEBUG_PRINT("Runtime: "); DEBUG_PRINTLN(millis()); - DEBUG_PRINT("Unix time: "); DEBUG_PRINTLN(now()); - DEBUG_PRINT("Free heap: "); DEBUG_PRINTLN(ESP.getFreeHeap()); - DEBUG_PRINT("Wifi state: "); DEBUG_PRINTLN(WiFi.status()); - if (WiFi.status() != lastWifiState) - { - wifiStateChangedTime = millis(); - } - lastWifiState = WiFi.status(); - DEBUG_PRINT("State time: "); DEBUG_PRINTLN(wifiStateChangedTime); - DEBUG_PRINT("NTP last sync: "); DEBUG_PRINTLN(ntpLastSyncTime); - DEBUG_PRINT("Client IP: "); DEBUG_PRINTLN(WiFi.localIP()); - DEBUG_PRINT("Loops/sec: "); DEBUG_PRINTLN(loops / 10); - loops = 0; - debugTime = millis(); - } - loops++; -#endif -} +} \ No newline at end of file diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino deleted file mode 100644 index 29ae0e7a..00000000 --- a/wled00/wled05_init.ino +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Setup code - */ - -void wledInit() -{ - EEPROM.begin(EEPSIZE); - ledCount = EEPROM.read(229) + ((EEPROM.read(398) << 8) & 0xFF00); - if (ledCount > MAX_LEDS || ledCount == 0) ledCount = 30; - - #ifdef ESP8266 - #if LEDPIN == 3 - if (ledCount > MAX_LEDS_DMA) ledCount = MAX_LEDS_DMA; //DMA method uses too much ram - #endif - #endif - Serial.begin(115200); - Serial.setTimeout(50); - DEBUG_PRINTLN(); - DEBUG_PRINT("---WLED "); DEBUG_PRINT(versionString); DEBUG_PRINT(" "); DEBUG_PRINT(VERSION); DEBUG_PRINTLN(" INIT---"); - #ifdef ARDUINO_ARCH_ESP32 - DEBUG_PRINT("esp32 "); DEBUG_PRINTLN(ESP.getSdkVersion()); - #else - DEBUG_PRINT("esp8266 "); DEBUG_PRINTLN(ESP.getCoreVersion()); - #endif - int heapPreAlloc = ESP.getFreeHeap(); - DEBUG_PRINT("heap "); - DEBUG_PRINTLN(ESP.getFreeHeap()); - - strip.init(EEPROM.read(372),ledCount,EEPROM.read(2204)); //init LEDs quickly - strip.setBrightness(0); - - DEBUG_PRINT("LEDs inited. heap usage ~"); - DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap()); - - #ifndef WLED_DISABLE_FILESYSTEM - #ifdef ARDUINO_ARCH_ESP32 - SPIFFS.begin(true); - #endif - SPIFFS.begin(); - #endif - - DEBUG_PRINTLN("Load EEPROM"); - loadSettingsFromEEPROM(true); - beginStrip(); - userSetup(); - if (strcmp(clientSSID,DEFAULT_CLIENT_SSID) == 0) showWelcomePage = true; - WiFi.persistent(false); - - if (macroBoot>0) applyMacro(macroBoot); - Serial.println("Ada"); - - //generate module IDs - escapedMac = WiFi.macAddress(); - escapedMac.replace(":", ""); - escapedMac.toLowerCase(); - if (strcmp(cmDNS,"x") == 0) //fill in unique mdns default - { - strcpy(cmDNS, "wled-"); - sprintf(cmDNS+5, "%*s", 6, escapedMac.c_str()+6); - } - if (mqttDeviceTopic[0] == 0) - { - strcpy(mqttDeviceTopic, "wled/"); - sprintf(mqttDeviceTopic+5, "%*s", 6, escapedMac.c_str()+6); - } - if (mqttClientID[0] == 0) - { - strcpy(mqttClientID, "WLED-"); - sprintf(mqttClientID+5, "%*s", 6, escapedMac.c_str()+6); - } - - strip.service(); - - #ifndef WLED_DISABLE_OTA - if (aOtaEnabled) - { - ArduinoOTA.onStart([]() { - #ifdef ESP8266 - wifi_set_sleep_type(NONE_SLEEP_T); - #endif - DEBUG_PRINTLN("Start ArduinoOTA"); - }); - if (strlen(cmDNS) > 0) ArduinoOTA.setHostname(cmDNS); - } - #endif - #ifdef WLED_ENABLE_DMX - dmx.init(512); // initialize with bus length - #endif - //HTTP server page init - initServer(); -} - - -void beginStrip() -{ - // Initialize NeoPixel Strip and button - strip.setShowCallback(handleOverlayDraw); - -#ifdef BTNPIN - pinMode(BTNPIN, INPUT_PULLUP); -#endif - - if (bootPreset > 0) applyPreset(bootPreset, turnOnAtBoot); - colorUpdated(NOTIFIER_CALL_MODE_INIT); - - //init relay pin - #if RLYPIN >= 0 - pinMode(RLYPIN, OUTPUT); - #if RLYMDE - digitalWrite(RLYPIN, bri); - #else - digitalWrite(RLYPIN, !bri); - #endif - #endif - - //disable button if it is "pressed" unintentionally -#ifdef BTNPIN - if(digitalRead(BTNPIN) == LOW) buttonEnabled = false; -#else - buttonEnabled = false; -#endif -} - - -void initAP(bool resetAP=false){ - if (apBehavior == AP_BEHAVIOR_BUTTON_ONLY && !resetAP) return; - - if (!apSSID[0] || resetAP) strcpy(apSSID, "WLED-AP"); - if (resetAP) strcpy(apPass,DEFAULT_AP_PASS); - DEBUG_PRINT("Opening access point "); - DEBUG_PRINTLN(apSSID); - WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255,255,255,0)); - WiFi.softAP(apSSID, apPass, apChannel, apHide); - - if (!apActive) //start captive portal if AP active - { - DEBUG_PRINTLN("Init AP interfaces"); - server.begin(); - if (udpPort > 0 && udpPort != ntpLocalPort) - { - udpConnected = notifierUdp.begin(udpPort); - } - if (udpRgbPort > 0 && udpRgbPort != ntpLocalPort && udpRgbPort != udpPort) - { - udpRgbConnected = rgbUdp.begin(udpRgbPort); - } - - dnsServer.setErrorReplyCode(DNSReplyCode::NoError); - dnsServer.start(53, "*", WiFi.softAPIP()); - } - apActive = true; -} - -void initConnection() -{ - WiFi.disconnect(); //close old connections - #ifdef ESP8266 - WiFi.setPhyMode(WIFI_PHY_MODE_11N); - #endif - - if (staticIP[0] != 0 && staticGateway[0] != 0) - { - WiFi.config(staticIP, staticGateway, staticSubnet, IPAddress(8,8,8,8)); - } else - { - WiFi.config(0U, 0U, 0U); - } - - lastReconnectAttempt = millis(); - - if (!WLED_WIFI_CONFIGURED) - { - DEBUG_PRINT("No connection configured. "); - if (!apActive) initAP(); //instantly go to ap mode - return; - } else if (!apActive) { - if (apBehavior == AP_BEHAVIOR_ALWAYS) - { - initAP(); - } else - { - DEBUG_PRINTLN("Access point disabled."); - WiFi.softAPdisconnect(true); - } - } - showWelcomePage = false; - - DEBUG_PRINT("Connecting to "); - DEBUG_PRINT(clientSSID); - DEBUG_PRINTLN("..."); - - #ifdef ESP8266 - WiFi.hostname(serverDescription); - #endif - - WiFi.begin(clientSSID, clientPass); - - #ifdef ARDUINO_ARCH_ESP32 - WiFi.setSleep(!noWifiSleep); - WiFi.setHostname(serverDescription); - #else - wifi_set_sleep_type((noWifiSleep) ? NONE_SLEEP_T : MODEM_SLEEP_T); - #endif -} - -void initInterfaces() { - DEBUG_PRINTLN("Init STA interfaces"); - - if (hueIP[0] == 0) - { - hueIP[0] = WiFi.localIP()[0]; - hueIP[1] = WiFi.localIP()[1]; - hueIP[2] = WiFi.localIP()[2]; - } - - //init Alexa hue emulation - if (alexaEnabled) alexaInit(); - - #ifndef WLED_DISABLE_OTA - if (aOtaEnabled) ArduinoOTA.begin(); - #endif - - strip.service(); - // Set up mDNS responder: - if (strlen(cmDNS) > 0) - { - if (!aOtaEnabled) MDNS.begin(cmDNS); - - DEBUG_PRINTLN("mDNS started"); - MDNS.addService("http", "tcp", 80); - MDNS.addService("wled", "tcp", 80); - MDNS.addServiceTxt("wled", "tcp", "mac", escapedMac.c_str()); - } - server.begin(); - - if (udpPort > 0 && udpPort != ntpLocalPort) - { - udpConnected = notifierUdp.begin(udpPort); - if (udpConnected && udpRgbPort != udpPort) udpRgbConnected = rgbUdp.begin(udpRgbPort); - } - if (ntpEnabled) ntpConnected = ntpUdp.begin(ntpLocalPort); - - initBlynk(blynkApiKey); - e131.begin((e131Multicast) ? E131_MULTICAST : E131_UNICAST , e131Universe, E131_MAX_UNIVERSE_COUNT); - reconnectHue(); - initMqtt(); - interfacesInited = true; - wasConnected = true; -} - -byte stacO = 0; -uint32_t lastHeap; -unsigned long heapTime = 0; - -void handleConnection() { - 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 - if (millis() - heapTime > 5000) - { - uint32_t heap = ESP.getFreeHeap(); - if (heap < 9000 && lastHeap < 9000) { - DEBUG_PRINT("Heap too low! "); - DEBUG_PRINTLN(heap); - forceReconnect = true; - } - lastHeap = heap; - heapTime = millis(); - } - - byte stac = 0; - if (apActive) { - #ifdef ESP8266 - stac = wifi_softap_get_station_num(); - #else - wifi_sta_list_t stationList; - esp_wifi_ap_get_sta_list(&stationList); - stac = stationList.num; - #endif - if (stac != stacO) - { - stacO = stac; - DEBUG_PRINT("Connected AP clients: "); - DEBUG_PRINTLN(stac); - if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) { //trying to connect, but not connected - if (stac) WiFi.disconnect(); //disable search so that AP can work - else initConnection(); //restart search - } - } - } - if (forceReconnect) { - DEBUG_PRINTLN("Forcing reconnect."); - initConnection(); - interfacesInited = false; - forceReconnect = false; - wasConnected = false; - return; - } - if (!WLED_CONNECTED) { - if (interfacesInited) { - DEBUG_PRINTLN("Disconnected!"); - interfacesInited = false; - initConnection(); - } - if (millis() - lastReconnectAttempt > ((stac) ? 300000 : 20000) && WLED_WIFI_CONFIGURED) initConnection(); - if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) initAP(); - } else if (!interfacesInited) { //newly connected - DEBUG_PRINTLN(""); - DEBUG_PRINT("Connected! IP address: "); - DEBUG_PRINTLN(WiFi.localIP()); - initInterfaces(); - userConnected(); - - //shut down AP - if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive) - { - dnsServer.stop(); - WiFi.softAPdisconnect(true); - apActive = false; - DEBUG_PRINTLN("Access point disabled."); - } - } -} - -//by https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp -int getSignalQuality(int rssi) -{ - int quality = 0; - - if (rssi <= -100) { - quality = 0; - } else if (rssi >= -50) { - quality = 100; - } else { - quality = 2 * (rssi + 100); - } - return quality; -} diff --git a/wled00/wled06_usermod.ino b/wled00/wled06_usermod.cpp similarity index 97% rename from wled00/wled06_usermod.ino rename to wled00/wled06_usermod.cpp index 010d0f38..c780ffee 100644 --- a/wled00/wled06_usermod.ino +++ b/wled00/wled06_usermod.cpp @@ -1,3 +1,4 @@ +#include "wled.h" /* * This file allows you to add own functionality to WLED more easily * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality diff --git a/wled00/wled12_alexa.ino b/wled00/wled_alexa.cpp similarity index 89% rename from wled00/wled12_alexa.ino rename to wled00/wled_alexa.cpp index 5163640e..b68843cb 100644 --- a/wled00/wled12_alexa.ino +++ b/wled00/wled_alexa.cpp @@ -1,10 +1,6 @@ -/* - * Alexa Voice On/Off/Brightness Control. Emulates a Philips Hue bridge to Alexa. - * - * This was put together from these two excellent projects: - * https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch - * https://github.com/probonopd/ESP8266HueEmulator - */ +#include "wled_alexa.h" +#include "wled.h" +#include "src/dependencies/espalexa/EspalexaDevice.h" #ifndef WLED_DISABLE_ALEXA void onAlexaChange(EspalexaDevice* dev); diff --git a/wled00/wled_alexa.h b/wled00/wled_alexa.h new file mode 100644 index 00000000..4bf7bd12 --- /dev/null +++ b/wled00/wled_alexa.h @@ -0,0 +1,16 @@ +#ifndef WLED_ALEXA_H +#define WLED_ALEXA_H +/* + * Alexa Voice On/Off/Brightness Control. Emulates a Philips Hue bridge to Alexa. + * + * This was put together from these two excellent projects: + * https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch + * https://github.com/probonopd/ESP8266HueEmulator + */ +class EspalexaDevice; +void onAlexaChange(EspalexaDevice* dev); +void alexaInit(); +void handleAlexa(); +void onAlexaChange(EspalexaDevice* dev); + +#define WLED_ALEXA_H \ No newline at end of file diff --git a/wled00/wled16_blynk.ino b/wled00/wled_blynk.cpp similarity index 94% rename from wled00/wled16_blynk.ino rename to wled00/wled_blynk.cpp index ea4d6877..c6754a23 100644 --- a/wled00/wled16_blynk.ino +++ b/wled00/wled_blynk.cpp @@ -1,6 +1,6 @@ -/* - * Remote light control with the free Blynk app - */ +#include "wled_blynk.h" +#include "wled.h" +#include "src/dependencies/blynk/Blynk/BlynkHandlers.h" uint16_t blHue = 0; byte blSat = 255; diff --git a/wled00/wled_blynk.h b/wled00/wled_blynk.h new file mode 100644 index 00000000..e8c8341b --- /dev/null +++ b/wled00/wled_blynk.h @@ -0,0 +1,13 @@ +#ifndef WLED_BLYNK_H +#define WLED_BLYNK_H +#include +/* + * Remote light control with the free Blynk app + */ + +void initBlynk(const char* auth); +void handleBlynk(); +void updateBlynk(); +// Unsure if the macro expansions need to accessed through the declaration... TODO + +#endif //WLED_BLYNK_H \ No newline at end of file diff --git a/wled00/wled09_button.ino b/wled00/wled_button.cpp similarity index 98% rename from wled00/wled09_button.ino rename to wled00/wled_button.cpp index 1cd868be..12fe5b49 100644 --- a/wled00/wled09_button.ino +++ b/wled00/wled_button.cpp @@ -1,3 +1,5 @@ +#include "wled_button.h" +#include "wled.h" /* * Physical IO */ diff --git a/wled00/wled_button.h b/wled00/wled_button.h new file mode 100644 index 00000000..5f894477 --- /dev/null +++ b/wled00/wled_button.h @@ -0,0 +1,12 @@ +#ifndef WLED_BUTTON_H +#define WLED_BUTTON_H +#include +/* + * Physical IO + */ + +void shortPressAction(); +void handleButton(); +void handleIO(); + +#endif // WLED_BUTTON_H \ No newline at end of file diff --git a/wled00/wled14_colors.ino b/wled00/wled_colors.cpp similarity index 96% rename from wled00/wled14_colors.ino rename to wled00/wled_colors.cpp index a1db307a..dcd32e57 100644 --- a/wled00/wled14_colors.ino +++ b/wled00/wled_colors.cpp @@ -1,6 +1,5 @@ -/* - * Color conversion methods - */ +#include "wled_colors.h" +#include "wled.h" void colorFromUint32(uint32_t in, bool secondary) { @@ -18,7 +17,7 @@ void colorFromUint32(uint32_t in, bool secondary) } //load a color without affecting the white channel -void colorFromUint24(uint32_t in, bool secondary = false) +void colorFromUint24(uint32_t in, bool secondary) { if (secondary) { colSec[0] = in >> 16 & 0xFF; @@ -32,7 +31,7 @@ void colorFromUint24(uint32_t in, bool secondary = false) } //relatively change white brightness, minumum A=5 -void relativeChangeWhite(int8_t amount, byte lowerBoundary =0) +void relativeChangeWhite(int8_t amount, byte lowerBoundary) { int16_t new_val = (int16_t) col[3] + amount; if (new_val > 0xFF) new_val = 0xFF; @@ -149,7 +148,8 @@ void colorRGBtoXY(byte* rgb, float* xy) //rgb to coordinates (https://www.develo xy[0] = X / (X + Y + Z); xy[1] = Y / (X + Y + Z); } -#endif +#endif // WLED_DISABLE_HUESYNC + void colorFromDecOrHexString(byte* rgb, char* in) { diff --git a/wled00/wled_colors.h b/wled00/wled_colors.h new file mode 100644 index 00000000..2b3ff32c --- /dev/null +++ b/wled00/wled_colors.h @@ -0,0 +1,20 @@ +#ifndef WLED_COLORS_H +#define WLED_COLORS_H +#include +/* + * Color conversion methods + */ + +void colorFromUint32(uint32_t in, bool secondary); +void colorFromUint24(uint32_t in, bool secondary = false); +void relativeChangeWhite(int8_t amount, byte lowerBoundary = 0); +void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb +void colorCTtoRGB(uint16_t mired, byte* rgb); //white spectrum to rgb + +void colorXYtoRGB(float x, float y, byte* rgb); // only defined if huesync disabled TODO +void colorRGBtoXY(byte* rgb, float* xy); // only defined if huesync disabled TODO + +void colorFromDecOrHexString(byte* rgb, char* in); +void colorRGBtoRGBW(byte* rgb); //rgb to rgbw (http://codewelt.com/rgbw). (RGBW_MODE_LEGACY) + +#endif //WLED_COLORS_H \ No newline at end of file diff --git a/wled00/wled13_cronixie.ino b/wled00/wled_cronixie.cpp similarity index 97% rename from wled00/wled13_cronixie.ino rename to wled00/wled_cronixie.cpp index dd687ca1..107af752 100644 --- a/wled00/wled13_cronixie.ino +++ b/wled00/wled_cronixie.cpp @@ -1,9 +1,8 @@ -/* - * Support for the Cronixie clock - */ +#include "wled_cronixie.h" +#include "wled.h" + #ifndef WLED_DISABLE_CRONIXIE byte _digitOut[6] = {10,10,10,10,10,10}; -#endif byte getSameCodeLength(char code, int index, char const cronixieDisplay[]) { @@ -23,7 +22,6 @@ byte getSameCodeLength(char code, int index, char const cronixieDisplay[]) void setCronixie() { - #ifndef WLED_DISABLE_CRONIXIE /* * digit purpose index * 0-9 | 0-9 (incl. random) @@ -144,12 +142,10 @@ void setCronixie() DEBUG_PRINTLN((int)dP[5]); _overlayCronixie(); //refresh - #endif } void _overlayCronixie() { - #ifndef WLED_DISABLE_CRONIXIE byte h = hour(local); byte h0 = h; byte m = minute(local); @@ -211,12 +207,10 @@ void _overlayCronixie() } } } - #endif } void _drawOverlayCronixie() { - #ifndef WLED_DISABLE_CRONIXIE byte offsets[] = {5, 0, 6, 1, 7, 2, 8, 3, 9, 4}; for (uint16_t i = 0; i < 6; i++) @@ -239,5 +233,11 @@ void _drawOverlayCronixie() } } } - #endif } + +#else // WLED_DISABLE_CRONIXIE +byte getSameCodeLength(char code, int index, char const cronixieDisplay[]) {} +void setCronixie() {} +void _overlayCronixie() {} +void _drawOverlayCronixie() {} +#endif diff --git a/wled00/wled_cronixie.h b/wled00/wled_cronixie.h new file mode 100644 index 00000000..9dea69b3 --- /dev/null +++ b/wled00/wled_cronixie.h @@ -0,0 +1,13 @@ +#ifndef WLED_CRONIXIE_H +#define WLED_CRONIXIE_H +#include +/* + * Support for the Cronixie clock + */ + +byte getSameCodeLength(char code, int index, char const cronixieDisplay[]); +void setCronixie(); +void _overlayCronixie(); +void _drawOverlayCronixie(); + +#endif // WLED_CRONIXIE_H \ No newline at end of file diff --git a/wled00/wled21_dmx.ino b/wled00/wled_dmx.cpp similarity index 89% rename from wled00/wled21_dmx.ino rename to wled00/wled_dmx.cpp index 4230f07d..f620f777 100644 --- a/wled00/wled21_dmx.ino +++ b/wled00/wled_dmx.cpp @@ -1,10 +1,7 @@ -/* - * Support for DMX via MAX485. - * Needs the espdmx library. You might have to change the output pin within the library. Sketchy, i know. - * https://github.com/Rickgg/ESP-Dmx - */ -#ifdef WLED_ENABLE_DMX +#include "wled_dmx.h" +#include "wled.h" +#ifdef WLED_ENABLE_DMX void handleDMX() { // TODO: calculate brightness manually if no shutter channel is set diff --git a/wled00/wled_dmx.h b/wled00/wled_dmx.h new file mode 100644 index 00000000..94cbb0d2 --- /dev/null +++ b/wled00/wled_dmx.h @@ -0,0 +1,11 @@ +#ifndef WLED_DMX_H +#define WLED_DMX_H +/* + * Support for DMX via MAX485. + * Needs the espdmx library. You might have to change the output pin within the library. Sketchy, i know. + * https://github.com/Rickgg/ESP-Dmx + */ + +void handleDMX(); + +#endif //WLED_DMX_H \ No newline at end of file diff --git a/wled00/wled01_eeprom.ino b/wled00/wled_eeprom.cpp similarity index 99% rename from wled00/wled01_eeprom.ino rename to wled00/wled_eeprom.cpp index 1f0e8426..0ddbf57f 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled_eeprom.cpp @@ -1,7 +1,5 @@ -/* - * Methods to handle saving and loading to non-volatile memory - * EEPROM Map: https://github.com/Aircoookie/WLED/wiki/EEPROM-Map - */ +#include "wled_eeprom.h" +#include "wled.h" #define EEPSIZE 2560 //Maximum is 4096 diff --git a/wled00/wled_eeprom.h b/wled00/wled_eeprom.h new file mode 100644 index 00000000..fe5c2cbf --- /dev/null +++ b/wled00/wled_eeprom.h @@ -0,0 +1,22 @@ +#ifndef WLED_EPPROM_H +#define WLED_EPPROM_H +#include +/* + * Methods to handle saving and loading to non-volatile memory + * EEPROM Map: https://github.com/Aircoookie/WLED/wiki/EEPROM-Map + */ + +void commit(); +void clearEEPROM(); +void writeStringToEEPROM(uint16_t pos, char* str, uint16_t len); +void readStringFromEEPROM(uint16_t pos, char* str, uint16_t len); +void saveSettingsToEEPROM(); +void loadSettingsFromEEPROM(bool first); +void savedToPresets(); +bool applyPreset(byte index, bool loadBri = true); +void savePreset(byte index, bool persist = true); +void loadMacro(byte index, char* m); +void applyMacro(byte index); +void saveMacro(byte index, String mc, bool persist = true); //only commit on single save, not in settings + +#endif //WLED_EPPROM_H diff --git a/wled00/wled04_file.ino b/wled00/wled_file.cpp similarity index 95% rename from wled00/wled04_file.ino rename to wled00/wled_file.cpp index de752328..700d66ee 100644 --- a/wled00/wled04_file.ino +++ b/wled00/wled_file.cpp @@ -1,6 +1,14 @@ -/* - * Utility for SPIFFS filesystem & Serial console - */ +#include "wled_file.h" +#include "wled.h" +//filesystem +#ifndef WLED_DISABLE_FILESYSTEM +#include +#ifdef ARDUINO_ARCH_ESP32 +#include "SPIFFS.h" +#endif +#include "SPIFFSEditor.h" +#endif + enum class AdaState { Header_A, Header_d, diff --git a/wled00/wled_file.h b/wled00/wled_file.h new file mode 100644 index 00000000..7457ec4c --- /dev/null +++ b/wled00/wled_file.h @@ -0,0 +1,12 @@ +#ifndef WLED_FILE_H +#define WLED_FILE_H +#include +#include +/* + * Utility for SPIFFS filesystem & Serial console + */ + +void handleSerial(); +bool handleFileRead(AsyncWebServerRequest*, String path); + +#endif // WLED_FILE_H \ No newline at end of file diff --git a/wled00/wled15_hue.ino b/wled00/wled_hue.cpp similarity index 99% rename from wled00/wled15_hue.ino rename to wled00/wled_hue.cpp index 5f6b8f5b..082685d7 100644 --- a/wled00/wled15_hue.ino +++ b/wled00/wled_hue.cpp @@ -1,7 +1,8 @@ -/* - * Sync to Philips hue lights - */ +#include "wled_hue.h" +#include "wled.h" + #ifndef WLED_DISABLE_HUESYNC + void handleHue() { if (hueReceived) diff --git a/wled00/wled_hue.h b/wled00/wled_hue.h new file mode 100644 index 00000000..dcf39729 --- /dev/null +++ b/wled00/wled_hue.h @@ -0,0 +1,10 @@ +#ifndef WLED_HUE_H +#define WLED_HUE_H +/* + * Sync to Philips hue lights + */ + +void handleHue(); +void reconnectHue(); + +#endif //WLED_HUE_H \ No newline at end of file diff --git a/wled00/wled20_ir.ino b/wled00/wled_ir.cpp similarity index 99% rename from wled00/wled20_ir.ino rename to wled00/wled_ir.cpp index 64c131c2..53f0d23f 100644 --- a/wled00/wled20_ir.ino +++ b/wled00/wled_ir.cpp @@ -1,6 +1,5 @@ -/* - * Infrared sensor support for generic 24/40/44 key RGB remotes - */ +#include "wled_ir.h" +#include "wled.h" #if defined(WLED_DISABLE_INFRARED) void handleIR(){} diff --git a/wled00/wled_ir.h b/wled00/wled_ir.h new file mode 100644 index 00000000..3479f410 --- /dev/null +++ b/wled00/wled_ir.h @@ -0,0 +1,9 @@ +#ifndef WLED_IR_H +#define WLED_IR_H +/* + * Infrared sensor support for generic 24/40/44 key RGB remotes + */ + +void handleIR(); + +#endif //WLED_IR_H \ No newline at end of file diff --git a/wled00/wled19_json.ino b/wled00/wled_json.cpp similarity index 99% rename from wled00/wled19_json.ino rename to wled00/wled_json.cpp index df9bcead..43d3136d 100644 --- a/wled00/wled19_json.ino +++ b/wled00/wled_json.cpp @@ -1,6 +1,5 @@ -/* - * JSON API (De)serialization - */ +#include "wled_json.h" +#include "wled.h" void deserializeSegment(JsonObject elem, byte it) { diff --git a/wled00/wled_json.h b/wled00/wled_json.h new file mode 100644 index 00000000..83830faf --- /dev/null +++ b/wled00/wled_json.h @@ -0,0 +1,15 @@ +#ifndef WLED_JSON_H +#define WLED_JSON_H +/* + * JSON API (De)serialization + */ + +void deserializeSegment(JsonObject elem, byte it); +bool deserializeState(JsonObject root); +void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id); +void serializeState(JsonObject root); +void serializeInfo(JsonObject root); +void serveJson(AsyncWebServerRequest* request); +void serveLiveLeds(AsyncWebServerRequest* request); + +#endif //WLED_JSON_H \ No newline at end of file diff --git a/wled00/wled08_led.ino b/wled00/wled_led.cpp similarity index 98% rename from wled00/wled08_led.ino rename to wled00/wled_led.cpp index 63009f98..aefb004a 100644 --- a/wled00/wled08_led.ino +++ b/wled00/wled_led.cpp @@ -1,6 +1,6 @@ -/* - * LED methods - */ +#include "wled_led.h" +#include "wled.h" + void setValuesFromMainSeg() { WS2812FX::Segment& seg = strip.getSegment(strip.getMainSegmentId()); @@ -50,7 +50,7 @@ void setAllLeds() { } -void setLedsStandard(bool justColors = false) +void setLedsStandard(bool justColors) { for (byte i=0; i<4; i++) { diff --git a/wled00/wled_led.h b/wled00/wled_led.h new file mode 100644 index 00000000..aebe95e4 --- /dev/null +++ b/wled00/wled_led.h @@ -0,0 +1,19 @@ +#ifndef WLED_LED_H +#define WLED_LED_H +#include +/* + * LED methods + */ + +void setValuesFromMainSeg(); +void resetTimebase(); +void toggleOnOff(); +void setAllLeds(); +void setLedsStandard(bool justColors = false); +bool colorChanged(); +void colorUpdated(int callMode); +void updateInterfaces(uint8_t callMode); +void handleTransitions(); +void handleNightlight(); + +#endif \ No newline at end of file diff --git a/wled00/wled17_mqtt.ino b/wled00/wled_mqtt.cpp similarity index 98% rename from wled00/wled17_mqtt.ino rename to wled00/wled_mqtt.cpp index 741c807f..d4fc80c0 100644 --- a/wled00/wled17_mqtt.ino +++ b/wled00/wled_mqtt.cpp @@ -1,6 +1,5 @@ -/* - * MQTT communication protocol for home automation - */ +#include "wled_mqtt.h" +#include "wled.h" #ifdef WLED_ENABLE_MQTT #define MQTT_KEEP_ALIVE_TIME 60 // contact the MQTT broker every 60 seconds diff --git a/wled00/wled_mqtt.h b/wled00/wled_mqtt.h new file mode 100644 index 00000000..f1c7160e --- /dev/null +++ b/wled00/wled_mqtt.h @@ -0,0 +1,9 @@ +#ifndef WLED_MQTT_H +#define WLED_MQTT_H +/* + * MQTT communication protocol for home automation + */ +bool initMqtt(); +void publishMqtt(); + +#endif //WLED_MQTT_H \ No newline at end of file diff --git a/wled00/wled07_notify.ino b/wled00/wled_notify.cpp similarity index 99% rename from wled00/wled07_notify.ino rename to wled00/wled_notify.cpp index 8fcbdbe8..7827aba9 100644 --- a/wled00/wled07_notify.ino +++ b/wled00/wled_notify.cpp @@ -1,6 +1,6 @@ -/* - * UDP notifier - */ +#include "wled_notify.h" +#include "wled.h" +#include "src/dependencies/e131/ESPAsyncE131.h" #define WLEDPACKETSIZE 29 #define UDP_IN_MAXSIZE 1472 diff --git a/wled00/wled_notify.h b/wled00/wled_notify.h new file mode 100644 index 00000000..63d01142 --- /dev/null +++ b/wled00/wled_notify.h @@ -0,0 +1,17 @@ +#ifndef WLED_NOTIFY_H +#define WLED_NOTIFY_H +#include +#include "const.h" +/* + * UDP notifier + */ +union e131_packet_t; // Will this compile? +class IPAddress; + +void notify(byte callMode, bool followUp=false); +void arlsLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC); +void handleE131Packet(e131_packet_t* p, IPAddress clientIP); +void handleNotifications(); +void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w); + +#endif // WLED_NOTIFY_H \ No newline at end of file diff --git a/wled00/wled10_ntp.ino b/wled00/wled_ntp.cpp similarity index 58% rename from wled00/wled10_ntp.ino rename to wled00/wled_ntp.cpp index 2c5a64c4..82b99f96 100644 --- a/wled00/wled10_ntp.ino +++ b/wled00/wled_ntp.cpp @@ -1,63 +1,7 @@ -/* - * Acquires time from NTP server - */ +#include "wled_ntp.h" +#include "wled.h" +#include "wled_eeprom.h" -TimeChangeRule UTCr = {Last, Sun, Mar, 1, 0}; // UTC -Timezone tzUTC(UTCr, UTCr); - -TimeChangeRule BST = {Last, Sun, Mar, 1, 60}; // British Summer Time -TimeChangeRule GMT = {Last, Sun, Oct, 2, 0}; // Standard Time -Timezone tzUK(BST, GMT); - -TimeChangeRule CEST = {Last, Sun, Mar, 2, 120}; //Central European Summer Time -TimeChangeRule CET = {Last, Sun, Oct, 3, 60}; //Central European Standard Time -Timezone tzEUCentral(CEST, CET); - -TimeChangeRule EEST = {Last, Sun, Mar, 3, 180}; //Central European Summer Time -TimeChangeRule EET = {Last, Sun, Oct, 4, 120}; //Central European Standard Time -Timezone tzEUEastern(EEST, EET); - -TimeChangeRule EDT = {Second, Sun, Mar, 2, -240 }; //Daylight time = UTC - 4 hours -TimeChangeRule EST = {First, Sun, Nov, 2, -300 }; //Standard time = UTC - 5 hours -Timezone tzUSEastern(EDT, EST); - -TimeChangeRule CDT = {Second, Sun, Mar, 2, -300 }; //Daylight time = UTC - 5 hours -TimeChangeRule CST = {First, Sun, Nov, 2, -360 }; //Standard time = UTC - 6 hours -Timezone tzUSCentral(CDT, CST); - -Timezone tzCASaskatchewan(CST, CST); //Central without DST - -TimeChangeRule MDT = {Second, Sun, Mar, 2, -360 }; //Daylight time = UTC - 6 hours -TimeChangeRule MST = {First, Sun, Nov, 2, -420 }; //Standard time = UTC - 7 hours -Timezone tzUSMountain(MDT, MST); - -Timezone tzUSArizona(MST, MST); //Mountain without DST - -TimeChangeRule PDT = {Second, Sun, Mar, 2, -420 }; //Daylight time = UTC - 7 hours -TimeChangeRule PST = {First, Sun, Nov, 2, -480 }; //Standard time = UTC - 8 hours -Timezone tzUSPacific(PDT, PST); - -TimeChangeRule ChST = {Last, Sun, Mar, 1, 480}; // China Standard Time = UTC + 8 hours -Timezone tzChina(ChST, ChST); - -TimeChangeRule JST = {Last, Sun, Mar, 1, 540}; // Japan Standard Time = UTC + 9 hours -Timezone tzJapan(JST, JST); - -TimeChangeRule AEDT = {Second, Sun, Oct, 2, 660 }; //Daylight time = UTC + 11 hours -TimeChangeRule AEST = {First, Sun, Apr, 3, 600 }; //Standard time = UTC + 10 hours -Timezone tzAUEastern(AEDT, AEST); - -TimeChangeRule NZDT = {Second, Sun, Sep, 2, 780 }; //Daylight time = UTC + 13 hours -TimeChangeRule NZST = {First, Sun, Apr, 3, 720 }; //Standard time = UTC + 12 hours -Timezone tzNZ(NZDT, NZST); - -TimeChangeRule NKST = {Last, Sun, Mar, 1, 510}; //Pyongyang Time = UTC + 8.5 hours -Timezone tzNK(NKST, NKST); - -TimeChangeRule IST = {Last, Sun, Mar, 1, 330}; // India Standard Time = UTC + 5.5 hours -Timezone tzIndia(IST, IST); - -Timezone* timezones[] = {&tzUTC, &tzUK, &tzEUCentral, &tzEUEastern, &tzUSEastern, &tzUSCentral, &tzUSMountain, &tzUSArizona, &tzUSPacific, &tzChina, &tzJapan, &tzAUEastern, &tzNZ, &tzNK, &tzIndia, &tzCASaskatchewan}; void handleNetworkTime() { diff --git a/wled00/wled_ntp.h b/wled00/wled_ntp.h new file mode 100644 index 00000000..14293342 --- /dev/null +++ b/wled00/wled_ntp.h @@ -0,0 +1,76 @@ +#ifndef WLED_NTP_H +#define WLED_NTP_H +#include +#include "timezone/Timezone.h" + +/* + * Acquires time from NTP server + */ +TimeChangeRule UTCr = {Last, Sun, Mar, 1, 0}; // UTC +Timezone tzUTC(UTCr, UTCr); + +TimeChangeRule BST = {Last, Sun, Mar, 1, 60}; // British Summer Time +TimeChangeRule GMT = {Last, Sun, Oct, 2, 0}; // Standard Time +Timezone tzUK(BST, GMT); + +TimeChangeRule CEST = {Last, Sun, Mar, 2, 120}; //Central European Summer Time +TimeChangeRule CET = {Last, Sun, Oct, 3, 60}; //Central European Standard Time +Timezone tzEUCentral(CEST, CET); + +TimeChangeRule EEST = {Last, Sun, Mar, 3, 180}; //Central European Summer Time +TimeChangeRule EET = {Last, Sun, Oct, 4, 120}; //Central European Standard Time +Timezone tzEUEastern(EEST, EET); + +TimeChangeRule EDT = {Second, Sun, Mar, 2, -240 }; //Daylight time = UTC - 4 hours +TimeChangeRule EST = {First, Sun, Nov, 2, -300 }; //Standard time = UTC - 5 hours +Timezone tzUSEastern(EDT, EST); + +TimeChangeRule CDT = {Second, Sun, Mar, 2, -300 }; //Daylight time = UTC - 5 hours +TimeChangeRule CST = {First, Sun, Nov, 2, -360 }; //Standard time = UTC - 6 hours +Timezone tzUSCentral(CDT, CST); + +Timezone tzCASaskatchewan(CST, CST); //Central without DST + +TimeChangeRule MDT = {Second, Sun, Mar, 2, -360 }; //Daylight time = UTC - 6 hours +TimeChangeRule MST = {First, Sun, Nov, 2, -420 }; //Standard time = UTC - 7 hours +Timezone tzUSMountain(MDT, MST); + +Timezone tzUSArizona(MST, MST); //Mountain without DST + +TimeChangeRule PDT = {Second, Sun, Mar, 2, -420 }; //Daylight time = UTC - 7 hours +TimeChangeRule PST = {First, Sun, Nov, 2, -480 }; //Standard time = UTC - 8 hours +Timezone tzUSPacific(PDT, PST); + +TimeChangeRule ChST = {Last, Sun, Mar, 1, 480}; // China Standard Time = UTC + 8 hours +Timezone tzChina(ChST, ChST); + +TimeChangeRule JST = {Last, Sun, Mar, 1, 540}; // Japan Standard Time = UTC + 9 hours +Timezone tzJapan(JST, JST); + +TimeChangeRule AEDT = {Second, Sun, Oct, 2, 660 }; //Daylight time = UTC + 11 hours +TimeChangeRule AEST = {First, Sun, Apr, 3, 600 }; //Standard time = UTC + 10 hours +Timezone tzAUEastern(AEDT, AEST); + +TimeChangeRule NZDT = {Second, Sun, Sep, 2, 780 }; //Daylight time = UTC + 13 hours +TimeChangeRule NZST = {First, Sun, Apr, 3, 720 }; //Standard time = UTC + 12 hours +Timezone tzNZ(NZDT, NZST); + +TimeChangeRule NKST = {Last, Sun, Mar, 1, 510}; //Pyongyang Time = UTC + 8.5 hours +Timezone tzNK(NKST, NKST); + +TimeChangeRule IST = {Last, Sun, Mar, 1, 330}; // India Standard Time = UTC + 5.5 hours +Timezone tzIndia(IST, IST); + +Timezone* timezones[] = {&tzUTC, &tzUK, &tzEUCentral, &tzEUEastern, &tzUSEastern, &tzUSCentral, &tzUSMountain, &tzUSArizona, &tzUSPacific, &tzChina, &tzJapan, &tzAUEastern, &tzNZ, &tzNK, &tzIndia, &tzCASaskatchewan}; + +void handleNetworkTime(); +void sendNTPPacket(); +bool checkNTPResponse(); +void updateLocalTime(); +void getTimeString(char* out); +bool checkCountdown(); +void setCountdown(); +byte weekdayMondayFirst(); +void checkTimers(); + +#endif // WLED_NTP_H \ No newline at end of file diff --git a/wled00/wled11_ol.ino b/wled00/wled_overlay.cpp similarity index 98% rename from wled00/wled11_ol.ino rename to wled00/wled_overlay.cpp index 93f7b96d..93348e79 100644 --- a/wled00/wled11_ol.ino +++ b/wled00/wled_overlay.cpp @@ -1,6 +1,5 @@ -/* - * Used to draw clock overlays over the strip - */ +#include "wled_overlay.h" +#include "wled.h" void initCronixie() { diff --git a/wled00/wled_overlay.h b/wled00/wled_overlay.h new file mode 100644 index 00000000..47573978 --- /dev/null +++ b/wled00/wled_overlay.h @@ -0,0 +1,12 @@ +#ifndef WLED_OVERLAYS_H +#define WLED_OVERLAYS_H +#include +/* + * Used to draw clock overlays over the strip + */ + +void initCronixie(); +void handleOverlays(); +void handleOverlayDraw(); + +#endif // WLED_OVERLAY_H \ No newline at end of file diff --git a/wled00/wled18_server.ino b/wled00/wled_server.cpp similarity index 99% rename from wled00/wled18_server.ino rename to wled00/wled_server.cpp index f11a64be..c73e027f 100644 --- a/wled00/wled18_server.ino +++ b/wled00/wled_server.cpp @@ -1,6 +1,5 @@ -/* - * Server page definitions - */ +#include "wled_server.h" +#include "wled.h" //Is this an IP? bool isIp(String str) { @@ -303,7 +302,7 @@ String msgProcessor(const String& var) } -void serveMessage(AsyncWebServerRequest* request, uint16_t code, String headl, String subl="", byte optionT=255) +void serveMessage(AsyncWebServerRequest* request, uint16_t code, String headl, String subl, byte optionT) { messageHead = headl; messageSub = subl; diff --git a/wled00/wled_server.h b/wled00/wled_server.h new file mode 100644 index 00000000..08679e17 --- /dev/null +++ b/wled00/wled_server.h @@ -0,0 +1,18 @@ +#ifndef WLED_SERVER_H +#define WLED_SERVER_H +/* + * Server page declarations + */ + +bool isIp(String str); +bool captivePortal(AsyncWebServerRequest *request); +void initServer(); +void serveIndexOrWelcome(AsyncWebServerRequest *request); +void serveIndex(AsyncWebServerRequest* request); +String msgProcessor(const String& var); +void serveMessage(AsyncWebServerRequest* request, uint16_t code, String headl, String subl="", byte optionT=255); +String settingsProcessor(const String& var); +String dmxProcessor(const String& var); +void serveSettings(AsyncWebServerRequest* request); + +#endif //WLED_SERVER_H \ No newline at end of file diff --git a/wled00/wled03_set.ino b/wled00/wled_set.cpp similarity index 99% rename from wled00/wled03_set.ino rename to wled00/wled_set.cpp index fc82256d..d81cac91 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled_set.cpp @@ -1,3 +1,7 @@ +#include "wled_set.h" +#include "wled.h" +#include "wled_hue.h" +#include "wled_colors.h" /* * Receives client input */ diff --git a/wled00/wled_set.h b/wled00/wled_set.h new file mode 100644 index 00000000..7efde0d7 --- /dev/null +++ b/wled00/wled_set.h @@ -0,0 +1,12 @@ +#ifndef WLED_SET_H +#define WLED_SET_H +#include +#include + +void _setRandomColor(bool _sec,bool fromButton=false); +bool isAsterisksOnly(const char* str, byte maxLen); +void handleSettingsSet(AsyncWebServerRequest *request, byte subPage); +int getNumVal(const String* req, uint16_t pos); +bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte maxv=255); + +#endif // WLED_SET_H \ No newline at end of file diff --git a/wled00/wled02_xml.ino b/wled00/wled_xml.cpp similarity index 99% rename from wled00/wled02_xml.ino rename to wled00/wled_xml.cpp index 100be482..07009cf3 100644 --- a/wled00/wled02_xml.ino +++ b/wled00/wled_xml.cpp @@ -1,6 +1,7 @@ -/* - * Sending XML status files to client - */ +#include "wled_xml.h" +#include "wled.h" +#include "wled_eeprom.h" + //build XML response to HTTP /win API request char* XML_response(AsyncWebServerRequest *request, char* dest = nullptr) diff --git a/wled00/wled_xml.h b/wled00/wled_xml.h new file mode 100644 index 00000000..5cfb1dbb --- /dev/null +++ b/wled00/wled_xml.h @@ -0,0 +1,15 @@ +#ifndef WLED_XML_H +#define WLED_XML_H +#include +#include + +/* + * Sending XML status files to client + */ +char* XML_response(AsyncWebServerRequest *request, char* dest = nullptr); +char* URL_response(AsyncWebServerRequest *request); +void sappend(char stype, const char* key, int val); +void sappends(char stype, const char* key, char* val); +void getSettingsJS(byte subPage, char* dest); + +#endif // WLED_XML_H \ No newline at end of file From 12131764d1e7ce305063021b6b4f581593eabfb3 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Wed, 25 Mar 2020 04:36:55 -0400 Subject: [PATCH 02/32] Prior to refactoring includes and forward definitions. --- .../src/dependencies/espalexa/EspalexaDevice.h | 2 +- wled00/wled.cpp | 18 ++++++++++++++++-- wled00/wled.h | 5 +---- wled00/wled00.ino | 6 +++--- wled00/wled_alexa.cpp | 1 + wled00/wled_alexa.h | 5 +++-- wled00/wled_eeprom.cpp | 5 ++++- wled00/wled_eeprom.h | 1 + wled00/wled_file.cpp | 4 ++++ wled00/wled_server.cpp | 5 +++++ wled00/wled_server.h | 1 + wled00/wled_set.cpp | 11 +++++++---- wled00/wled_set.h | 4 ++++ .../{wled06_usermod.cpp => wled_usermod.cpp} | 0 wled00/wled_usermod.h | 8 ++++++++ 15 files changed, 59 insertions(+), 17 deletions(-) rename wled00/{wled06_usermod.cpp => wled_usermod.cpp} (100%) create mode 100644 wled00/wled_usermod.h diff --git a/wled00/src/dependencies/espalexa/EspalexaDevice.h b/wled00/src/dependencies/espalexa/EspalexaDevice.h index 4785591f..b964e0e3 100644 --- a/wled00/src/dependencies/espalexa/EspalexaDevice.h +++ b/wled00/src/dependencies/espalexa/EspalexaDevice.h @@ -1,6 +1,6 @@ #ifndef EspalexaDevice_h #define EspalexaDevice_h - +#include #include "Arduino.h" typedef class EspalexaDevice; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 50a83f27..97ed3878 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -1,4 +1,18 @@ #include "wled.h" +#include "wled_led.h" +#include "wled_ir.h" +#include "wled_notify.h" +#include "wled_alexa.h" +#include "wled_overlay.h" +#include "wled_file.h" +#include "wled_button.h" +#include "wled_ntp.h" +#include "wled_usermod.h" +#include "wled_blynk.h" +#include "wled_hue.h" +#include "wled_mqtt.h" +#include "wled_eeprom.h" +#include "wled_server.h" WLED::WLED() { @@ -251,7 +265,7 @@ void WLED::beginStrip() #endif } -void WLED::initAP(bool resetAP = false) +void WLED::initAP(bool resetAP) { if (apBehavior == AP_BEHAVIOR_BUTTON_ONLY && !resetAP) return; @@ -483,7 +497,7 @@ void WLED::handleConnection() } //by https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp -int WLED::getSignalQuality(int rssi) +int getSignalQuality(int rssi) { int quality = 0; diff --git a/wled00/wled.h b/wled00/wled.h index 4f9b79af..8ef30cbf 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -491,6 +491,7 @@ int loops = 0; bool oappend(const char *txt); //append new number to temp buffer efficiently bool oappendi(int i); +int getSignalQuality(int rssi); class WLED { @@ -503,8 +504,6 @@ public: WLED(); - void wledInit(); - void reset(); void loop(); @@ -515,8 +514,6 @@ public: wledInit(); } - void loop(); - private: void wledInit(); void beginStrip(); diff --git a/wled00/wled00.ino b/wled00/wled00.ino index fc06f211..ac993bf6 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -3,11 +3,11 @@ */ #include "wled.h" +WLED wled; void setup() { - //auto& wled = Wled(); + wled.instance(); // Force creation of static instance } void loop() { - - + wled.loop(); } \ No newline at end of file diff --git a/wled00/wled_alexa.cpp b/wled00/wled_alexa.cpp index b68843cb..ce63a019 100644 --- a/wled00/wled_alexa.cpp +++ b/wled00/wled_alexa.cpp @@ -1,6 +1,7 @@ #include "wled_alexa.h" #include "wled.h" #include "src/dependencies/espalexa/EspalexaDevice.h" +#include "const.h" #ifndef WLED_DISABLE_ALEXA void onAlexaChange(EspalexaDevice* dev); diff --git a/wled00/wled_alexa.h b/wled00/wled_alexa.h index 4bf7bd12..94ad0342 100644 --- a/wled00/wled_alexa.h +++ b/wled00/wled_alexa.h @@ -7,10 +7,11 @@ * https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch * https://github.com/probonopd/ESP8266HueEmulator */ -class EspalexaDevice; +#include "src/dependencies/espalexa/EspalexaDevice.h" + void onAlexaChange(EspalexaDevice* dev); void alexaInit(); void handleAlexa(); void onAlexaChange(EspalexaDevice* dev); -#define WLED_ALEXA_H \ No newline at end of file +#endif // WLED_ALEXA_H \ No newline at end of file diff --git a/wled00/wled_eeprom.cpp b/wled00/wled_eeprom.cpp index 0ddbf57f..1e2b0e62 100644 --- a/wled00/wled_eeprom.cpp +++ b/wled00/wled_eeprom.cpp @@ -1,7 +1,10 @@ #include "wled_eeprom.h" #include "wled.h" +#include "wled_cronixie.h" +#include "wled_ntp.h" +#include "wled_set.h" +#include "wled_led.h" -#define EEPSIZE 2560 //Maximum is 4096 //eeprom Version code, enables default settings instead of 0 init on update #define EEPVER 18 diff --git a/wled00/wled_eeprom.h b/wled00/wled_eeprom.h index fe5c2cbf..19f61925 100644 --- a/wled00/wled_eeprom.h +++ b/wled00/wled_eeprom.h @@ -5,6 +5,7 @@ * Methods to handle saving and loading to non-volatile memory * EEPROM Map: https://github.com/Aircoookie/WLED/wiki/EEPROM-Map */ +#define EEPSIZE 2560 //Maximum is 4096 void commit(); void clearEEPROM(); diff --git a/wled00/wled_file.cpp b/wled00/wled_file.cpp index 700d66ee..81b86d6d 100644 --- a/wled00/wled_file.cpp +++ b/wled00/wled_file.cpp @@ -1,5 +1,8 @@ #include "wled_file.h" #include "wled.h" +#include "wled_led.h" +#include "wled_notify.h" + //filesystem #ifndef WLED_DISABLE_FILESYSTEM #include @@ -21,6 +24,7 @@ enum class AdaState { Data_Blue }; +// Maybe Adalight should not be in filehandling? TODO void handleSerial() { #ifdef WLED_ENABLE_ADALIGHT diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index c73e027f..542abea4 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -1,5 +1,10 @@ #include "wled_server.h" #include "wled.h" +#include "wled_file.h" +#include "wled_set.h" +#include "wled_json.h" +#include "wled_xml.h" + //Is this an IP? bool isIp(String str) { diff --git a/wled00/wled_server.h b/wled00/wled_server.h index 08679e17..a03f83e1 100644 --- a/wled00/wled_server.h +++ b/wled00/wled_server.h @@ -1,5 +1,6 @@ #ifndef WLED_SERVER_H #define WLED_SERVER_H +#include /* * Server page declarations */ diff --git a/wled00/wled_set.cpp b/wled00/wled_set.cpp index d81cac91..aff3f0cd 100644 --- a/wled00/wled_set.cpp +++ b/wled00/wled_set.cpp @@ -1,10 +1,13 @@ #include "wled_set.h" #include "wled.h" -#include "wled_hue.h" #include "wled_colors.h" -/* - * Receives client input - */ +#include "wled_hue.h" +#include "wled_led.h" +#include "wled_blynk.h" +#include "wled_eeprom.h" +#include "wled_alexa.h" +#include "wled_cronixie.h" +#include "wled_xml.h" void _setRandomColor(bool _sec,bool fromButton=false) { diff --git a/wled00/wled_set.h b/wled00/wled_set.h index 7efde0d7..ebee8c92 100644 --- a/wled00/wled_set.h +++ b/wled00/wled_set.h @@ -2,10 +2,14 @@ #define WLED_SET_H #include #include +/* + * Receives client input + */ void _setRandomColor(bool _sec,bool fromButton=false); bool isAsterisksOnly(const char* str, byte maxLen); void handleSettingsSet(AsyncWebServerRequest *request, byte subPage); +bool handleSet(AsyncWebServerRequest *request, const String& req); int getNumVal(const String* req, uint16_t pos); bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte maxv=255); diff --git a/wled00/wled06_usermod.cpp b/wled00/wled_usermod.cpp similarity index 100% rename from wled00/wled06_usermod.cpp rename to wled00/wled_usermod.cpp diff --git a/wled00/wled_usermod.h b/wled00/wled_usermod.h new file mode 100644 index 00000000..61ef6b78 --- /dev/null +++ b/wled00/wled_usermod.h @@ -0,0 +1,8 @@ +#ifndef WLED_USERMOD_H +#define WLED_USERMOD_H + +void userSetup(); +void userConnected(); +void userLoop(); + +#endif // WLED_USERMOD_H \ No newline at end of file From 6f5e71164ae2174b47354c489b0ef0dda9fd66bd Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Wed, 25 Mar 2020 05:14:23 -0400 Subject: [PATCH 03/32] Further fixing of includes. --- wled00/wled.h | 2 +- wled00/wled_alexa.cpp | 4 +++- wled00/wled_button.cpp | 6 +++++- wled00/wled_eeprom.cpp | 6 +++--- wled00/wled_hue.cpp | 2 ++ wled00/wled_hue.h | 6 ++++++ wled00/wled_json.cpp | 2 ++ wled00/wled_json.h | 6 ++++++ wled00/wled_led.cpp | 5 +++++ wled00/wled_mqtt.cpp | 2 ++ wled00/wled_notify.cpp | 5 +++-- wled00/wled_notify.h | 2 +- 12 files changed, 39 insertions(+), 9 deletions(-) diff --git a/wled00/wled.h b/wled00/wled.h index 8ef30cbf..c04dfa87 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -514,7 +514,7 @@ public: wledInit(); } -private: +public: // TODO: privacy void wledInit(); void beginStrip(); diff --git a/wled00/wled_alexa.cpp b/wled00/wled_alexa.cpp index ce63a019..1eb33e71 100644 --- a/wled00/wled_alexa.cpp +++ b/wled00/wled_alexa.cpp @@ -1,7 +1,9 @@ #include "wled_alexa.h" #include "wled.h" -#include "src/dependencies/espalexa/EspalexaDevice.h" #include "const.h" +#include "wled_led.h" +#include "wled_eeprom.h" +#include "wled_colors.h" #ifndef WLED_DISABLE_ALEXA void onAlexaChange(EspalexaDevice* dev); diff --git a/wled00/wled_button.cpp b/wled00/wled_button.cpp index 12fe5b49..3825cc84 100644 --- a/wled00/wled_button.cpp +++ b/wled00/wled_button.cpp @@ -1,5 +1,9 @@ #include "wled_button.h" #include "wled.h" +#include "wled_led.h" +#include "wled_eeprom.h" +#include "wled_set.h" + /* * Physical IO */ @@ -46,7 +50,7 @@ void handleButton() if (dur > 6000) //long press { - initAP(true); + WLED::instance().initAP(true); } else if (!buttonLongPressed) { //short press if (macroDoublePress) diff --git a/wled00/wled_eeprom.cpp b/wled00/wled_eeprom.cpp index 1e2b0e62..04b86289 100644 --- a/wled00/wled_eeprom.cpp +++ b/wled00/wled_eeprom.cpp @@ -592,7 +592,7 @@ void savedToPresets() } } -bool applyPreset(byte index, bool loadBri = true) +bool applyPreset(byte index, bool loadBri) { if (index == 255 || index == 0) { @@ -630,7 +630,7 @@ bool applyPreset(byte index, bool loadBri = true) return true; } -void savePreset(byte index, bool persist = true) +void savePreset(byte index, bool persist) { if (index > 16) return; if (index < 1) {saveSettingsToEEPROM();return;} @@ -698,7 +698,7 @@ void applyMacro(byte index) } -void saveMacro(byte index, String mc, bool persist = true) //only commit on single save, not in settings +void saveMacro(byte index, String mc, bool persist) //only commit on single save, not in settings { index-=1; if (index > 15) return; diff --git a/wled00/wled_hue.cpp b/wled00/wled_hue.cpp index 082685d7..abdb4ffa 100644 --- a/wled00/wled_hue.cpp +++ b/wled00/wled_hue.cpp @@ -1,5 +1,7 @@ #include "wled_hue.h" #include "wled.h" +#include "wled_colors.h" +#include "wled_eeprom.h" #ifndef WLED_DISABLE_HUESYNC diff --git a/wled00/wled_hue.h b/wled00/wled_hue.h index dcf39729..e9aa22b2 100644 --- a/wled00/wled_hue.h +++ b/wled00/wled_hue.h @@ -3,8 +3,14 @@ /* * Sync to Philips hue lights */ +#include +#include void handleHue(); void reconnectHue(); +void onHueError(void* arg, AsyncClient* client, int8_t error); +void onHueConnect(void* arg, AsyncClient* client); +void sendHuePoll(); +void onHueData(void* arg, AsyncClient* client, void *data, size_t len); #endif //WLED_HUE_H \ No newline at end of file diff --git a/wled00/wled_json.cpp b/wled00/wled_json.cpp index 43d3136d..17359462 100644 --- a/wled00/wled_json.cpp +++ b/wled00/wled_json.cpp @@ -1,5 +1,7 @@ #include "wled_json.h" #include "wled.h" +#include "wled_eeprom.h" +#include "wled_led.h" void deserializeSegment(JsonObject elem, byte it) { diff --git a/wled00/wled_json.h b/wled00/wled_json.h index 83830faf..a7c2473a 100644 --- a/wled00/wled_json.h +++ b/wled00/wled_json.h @@ -3,6 +3,12 @@ /* * JSON API (De)serialization */ +#include +#include "ESPAsyncWebServer.h" +#include "src/dependencies/json/ArduinoJson-v6.h" +#include "src/dependencies/json/AsyncJson-v6.h" +#include "fx.h" +// TODO: AsynicWebServerRequest conflict? void deserializeSegment(JsonObject elem, byte it); bool deserializeState(JsonObject root); diff --git a/wled00/wled_led.cpp b/wled00/wled_led.cpp index aefb004a..bd657a53 100644 --- a/wled00/wled_led.cpp +++ b/wled00/wled_led.cpp @@ -1,5 +1,10 @@ #include "wled_led.h" #include "wled.h" +#include "wled_notify.h" +#include "wled_blynk.h" +#include "wled_eeprom.h" +#include "wled_mqtt.h" +#include "wled_colors.h" void setValuesFromMainSeg() { diff --git a/wled00/wled_mqtt.cpp b/wled00/wled_mqtt.cpp index d4fc80c0..ce69513b 100644 --- a/wled00/wled_mqtt.cpp +++ b/wled00/wled_mqtt.cpp @@ -1,5 +1,7 @@ #include "wled_mqtt.h" #include "wled.h" +#include "wled_notify.h" +#include "wled_led.h" #ifdef WLED_ENABLE_MQTT #define MQTT_KEEP_ALIVE_TIME 60 // contact the MQTT broker every 60 seconds diff --git a/wled00/wled_notify.cpp b/wled00/wled_notify.cpp index 7827aba9..7913b452 100644 --- a/wled00/wled_notify.cpp +++ b/wled00/wled_notify.cpp @@ -1,12 +1,13 @@ #include "wled_notify.h" #include "wled.h" #include "src/dependencies/e131/ESPAsyncE131.h" +#include "wled_led.h" #define WLEDPACKETSIZE 29 #define UDP_IN_MAXSIZE 1472 -void notify(byte callMode, bool followUp=false) +void notify(byte callMode, bool followUp) { if (!udpConnected) return; switch (callMode) @@ -71,7 +72,7 @@ void notify(byte callMode, bool followUp=false) } -void arlsLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC) +void arlsLock(uint32_t timeoutMs, byte md) { if (!realtimeMode){ for (uint16_t i = 0; i < ledCount; i++) diff --git a/wled00/wled_notify.h b/wled00/wled_notify.h index 63d01142..2a2865b3 100644 --- a/wled00/wled_notify.h +++ b/wled00/wled_notify.h @@ -5,7 +5,7 @@ /* * UDP notifier */ -union e131_packet_t; // Will this compile? +//union e131_packet_t; // Will this compile? class IPAddress; void notify(byte callMode, bool followUp=false); From ccf5e66f316f8d92063cf85a174abfec32226474 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Wed, 25 Mar 2020 05:43:12 -0400 Subject: [PATCH 04/32] Compiles, but does not link. --- wled00/wled_hue.cpp | 2 ++ wled00/wled_hue.h | 2 +- wled00/wled_mqtt.cpp | 3 +++ wled00/wled_notify.h | 1 + wled00/wled_overlay.cpp | 2 ++ wled00/wled_overlay.h | 2 ++ wled00/wled_server.h | 2 ++ wled00/wled_set.cpp | 4 ++-- wled00/wled_xml.cpp | 3 ++- 9 files changed, 17 insertions(+), 4 deletions(-) diff --git a/wled00/wled_hue.cpp b/wled00/wled_hue.cpp index abdb4ffa..61756ec0 100644 --- a/wled00/wled_hue.cpp +++ b/wled00/wled_hue.cpp @@ -2,6 +2,8 @@ #include "wled.h" #include "wled_colors.h" #include "wled_eeprom.h" +#include "wled_notify.h" +#include "wled_led.h" #ifndef WLED_DISABLE_HUESYNC diff --git a/wled00/wled_hue.h b/wled00/wled_hue.h index e9aa22b2..8b26f8b6 100644 --- a/wled00/wled_hue.h +++ b/wled00/wled_hue.h @@ -4,7 +4,7 @@ * Sync to Philips hue lights */ #include -#include +class AsyncClient; void handleHue(); void reconnectHue(); diff --git a/wled00/wled_mqtt.cpp b/wled00/wled_mqtt.cpp index ce69513b..5e96a18f 100644 --- a/wled00/wled_mqtt.cpp +++ b/wled00/wled_mqtt.cpp @@ -2,6 +2,9 @@ #include "wled.h" #include "wled_notify.h" #include "wled_led.h" +#include "wled_colors.h" +#include "wled_xml.h" +#include "wled_set.h" #ifdef WLED_ENABLE_MQTT #define MQTT_KEEP_ALIVE_TIME 60 // contact the MQTT broker every 60 seconds diff --git a/wled00/wled_notify.h b/wled00/wled_notify.h index 2a2865b3..04c65aa4 100644 --- a/wled00/wled_notify.h +++ b/wled00/wled_notify.h @@ -1,6 +1,7 @@ #ifndef WLED_NOTIFY_H #define WLED_NOTIFY_H #include +#include "src/dependencies/e131/ESPAsyncE131.h" #include "const.h" /* * UDP notifier diff --git a/wled00/wled_overlay.cpp b/wled00/wled_overlay.cpp index 93348e79..8cb70786 100644 --- a/wled00/wled_overlay.cpp +++ b/wled00/wled_overlay.cpp @@ -1,5 +1,7 @@ #include "wled_overlay.h" #include "wled.h" +#include "wled_cronixie.h" +#include "wled_ntp.h" void initCronixie() { diff --git a/wled00/wled_overlay.h b/wled00/wled_overlay.h index 47573978..ec18f45b 100644 --- a/wled00/wled_overlay.h +++ b/wled00/wled_overlay.h @@ -8,5 +8,7 @@ void initCronixie(); void handleOverlays(); void handleOverlayDraw(); +void _overlayAnalogCountdown(); +void _overlayAnalogClock(); #endif // WLED_OVERLAY_H \ No newline at end of file diff --git a/wled00/wled_server.h b/wled00/wled_server.h index a03f83e1..46adc962 100644 --- a/wled00/wled_server.h +++ b/wled00/wled_server.h @@ -4,6 +4,8 @@ /* * Server page declarations */ +class AsyncWebServerRequest; + bool isIp(String str); bool captivePortal(AsyncWebServerRequest *request); diff --git a/wled00/wled_set.cpp b/wled00/wled_set.cpp index aff3f0cd..66d9ff1e 100644 --- a/wled00/wled_set.cpp +++ b/wled00/wled_set.cpp @@ -9,7 +9,7 @@ #include "wled_cronixie.h" #include "wled_xml.h" -void _setRandomColor(bool _sec,bool fromButton=false) +void _setRandomColor(bool _sec,bool fromButton) { lastRandomIndex = strip.get_random_wheel_index(lastRandomIndex); if (_sec){ @@ -337,7 +337,7 @@ int getNumVal(const String* req, uint16_t pos) //helper to get int value at a position in string -bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte maxv=255) +bool updateVal(const String* req, const char* key, byte* val, byte minv, byte maxv) { int pos = req->indexOf(key); if (pos < 1) return false; diff --git a/wled00/wled_xml.cpp b/wled00/wled_xml.cpp index 07009cf3..4f2b3f45 100644 --- a/wled00/wled_xml.cpp +++ b/wled00/wled_xml.cpp @@ -1,10 +1,11 @@ #include "wled_xml.h" #include "wled.h" #include "wled_eeprom.h" +#include "wled_ntp.h" //build XML response to HTTP /win API request -char* XML_response(AsyncWebServerRequest *request, char* dest = nullptr) +char* XML_response(AsyncWebServerRequest *request, char* dest) { char sbuf[(dest == nullptr)?1024:1]; //allocate local buffer if none passed obuf = (dest == nullptr)? sbuf:dest; From f2329476ec18578e9acea0f9ebe1f6e332234aaa Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Thu, 26 Mar 2020 04:12:55 -0400 Subject: [PATCH 05/32] Fix linker errors. All global vars declared extern. --- wled00/wled.cpp | 364 +++++++++++++++++++++++++++++++++ wled00/wled.h | 469 +++++++++++++++++++++---------------------- wled00/wled_colors.h | 2 +- wled00/wled_ntp.cpp | 56 ++++++ wled00/wled_ntp.h | 57 ------ 5 files changed, 652 insertions(+), 296 deletions(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 97ed3878..a720cb0b 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -13,6 +13,370 @@ #include "wled_mqtt.h" #include "wled_eeprom.h" #include "wled_server.h" +// Global Variable definitions +char versionString[] = "0.9.1"; + +//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 +#define ABL_MILLIAMPS_DEFAULT 850; //auto lower brightness to stay close to milliampere limit +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 + +#define E131_MAX_UNIVERSE_COUNT 9 +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; +#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 +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; + +//function prototypes +void colorFromUint32(uint32_t, bool = false); +void serveMessage(AsyncWebServerRequest *, uint16_t, String, String, byte); +void handleE131Packet(e131_packet_t *, IPAddress); +void arlsLock(uint32_t, byte); +void handleOverlayDraw(); + +//udp interface objects +WiFiUDP notifierUdp, rgbUdp; +WiFiUDP ntpUdp; +ESPAsyncE131 e131(handleE131Packet); +bool e131NewData = false; + +//led fx library object +WS2812FX strip = WS2812FX(); + +#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) +unsigned long debugTime = 0; +int lastWifiState = 3; +unsigned long wifiStateChangedTime = 0; +int loops = 0; +#else +#define DEBUG_PRINT(x) +#define DEBUG_PRINTLN(x) +#define DEBUG_PRINTF(x) +#endif + + WLED::WLED() { diff --git a/wled00/wled.h b/wled00/wled.h index c04dfa87..04341446 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -123,305 +123,297 @@ extern "C" //version code in format yymmddb (b = daily build) #define VERSION 2003222 -char versionString[] = "0.9.1"; +extern char versionString[]; //AP and OTA default passwords (for maximum change them!) -char apPass[65] = DEFAULT_AP_PASS; -char otaPass[33] = DEFAULT_OTA_PASS; +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! -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 +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) -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 +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 -uint16_t ledCount = 30; //overcurrent prevented by ABL -bool useRGBW = false; //SK6812 strips can contain an extra White channel +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 -bool turnOnAtBoot = true; //turn on LEDs at power-up -byte bootPreset = 0; //save preset to load after power-up +extern bool turnOnAtBoot; //turn on LEDs at power-up +extern byte bootPreset; //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 +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 -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 +extern byte nightlightTargetBri; //brightness after nightlight is over +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 -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) +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 -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 +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 -bool buttonEnabled = true; -byte irEnabled = 0; //Infrared receiver +extern bool buttonEnabled; +extern byte irEnabled; //Infrared receiver -uint16_t udpPort = 21324; //WLED notifier default port -uint16_t udpRgbPort = 19446; //Hyperion port +extern uint16_t udpPort; //WLED notifier default port +extern uint16_t udpRgbPort; //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 +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 -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 +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 -char blynkApiKey[36] = ""; //Auth token for Blynk server. If empty, no connection will be made +extern 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 +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 #define E131_MAX_UNIVERSE_COUNT 9 -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 +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 -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; +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 uint16_t mqttPort; -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; +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 hueApplyOnOff; +extern bool hueApplyBri; +extern bool hueApplyColor; //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 +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 -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 +extern byte overlayDefault; //0: no overlay 1: analog clock 2: single-digit clocl 3: cronixie +extern byte overlayMin; //boundaries of overlay mode +extern byte overlayMax; -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 +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 -char cronixieDisplay[7] = "HHMMSS"; //Cronixie Display mask. See wled13_cronixie.ino -bool cronixieBacklight = true; //Allow digits to be back-illuminated +extern char cronixieDisplay[7]; //Cronixie Display mask. See wled13_cronixie.ino +extern bool cronixieBacklight; //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; +extern bool countdownMode; //Clock will count down towards date +extern byte countdownYear, countdownMonth; //Countdown target date, year is last two digits +extern byte countdownDay, countdownHour; +extern byte countdownMin, countdownSec; -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; +extern byte macroBoot; //macro loaded after startup +extern byte macroNl; //after nightlight delay over +extern byte macroCountdown; +extern byte macroAlexaOn, macroAlexaOff; +extern byte macroButton, macroLongPress, macroDoublePress; //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 +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 -uint16_t userVar0 = 0, userVar1 = 0; +extern uint16_t userVar0, userVar1; #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 +extern byte DMXChannels; // number of channels per fixture +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 #endif //internal global variable declarations //wifi -bool apActive = false; -bool forceReconnect = false; -uint32_t lastReconnectAttempt = 0; -bool interfacesInited = false; -bool wasConnected = false; +extern bool apActive; +extern bool forceReconnect; +extern uint32_t lastReconnectAttempt; +extern bool interfacesInited; +extern bool wasConnected; //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}; +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 colSecT[]; +extern byte colSecOld[]; +extern byte colSecIT[]; -byte lastRandomIndex = 0; //used to save last random color so the new one is not the same +extern byte lastRandomIndex; //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; +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 bool jsonTransitionOnce; //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 +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 -//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 +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 -//button -bool buttonPressedBefore = false; -bool buttonLongPressed = false; -unsigned long buttonPressedTime = 0; -unsigned long buttonWaitTime = 0; +extern bool buttonPressedBefore; +extern bool buttonLongPressed; +extern unsigned long buttonPressedTime; +extern unsigned long buttonWaitTime; -//notifications -bool notifyDirectDefault = notifyDirect; -bool receiveNotifications = true; -unsigned long notificationSentTime = 0; -byte notificationSentCallMode = NOTIFIER_CALL_MODE_INIT; -bool notificationTwoRequired = false; +extern bool notifyDirectDefault; +extern bool receiveNotifications; +extern unsigned long notificationSentTime; +extern byte notificationSentCallMode; +extern bool notificationTwoRequired; -//effects -byte effectCurrent = 0; -byte effectSpeed = 128; -byte effectIntensity = 128; -byte effectPalette = 0; +extern byte effectCurrent; +extern byte effectSpeed; +extern byte effectIntensity; +extern byte effectPalette; -//network -bool udpConnected = false, udpRgbConnected = false; +extern bool udpConnected, udpRgbConnected; -//ui style -bool showWelcomePage = false; +extern bool showWelcomePage; -//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; +extern byte hueError; +//uint16_t hueFailCount; +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; -//overlays -byte overlayCurrent = overlayDefault; -byte overlaySpeed = 200; -unsigned long overlayRefreshMs = 200; -unsigned long overlayRefreshedTime; +extern byte overlayCurrent; +extern byte overlaySpeed; +extern unsigned long overlayRefreshMs; +extern unsigned long overlayRefreshedTime; -//cronixie -byte dP[]{0, 0, 0, 0, 0, 0}; -bool cronixieInit = false; +extern byte dP[]; +extern bool cronixieInit; //countdown -unsigned long countdownTime = 1514764800L; -bool countdownOverTriggered = true; +extern unsigned long countdownTime; +extern bool countdownOverTriggered; //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 +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 -bool blynkEnabled = false; +extern bool blynkEnabled; //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; +extern bool presetCyclingEnabled; +extern byte presetCycleMin, presetCycleMax; +extern uint16_t presetCycleTime; +extern unsigned long presetCycledTime; +extern byte presetCycCurr; +extern bool presetApplyBri; +extern bool saveCurrPresetCycConf; //realtime -byte realtimeMode = REALTIME_MODE_INACTIVE; -IPAddress realtimeIP = (0, 0, 0, 0); -unsigned long realtimeTimeout = 0; +extern byte realtimeMode; +extern IPAddress realtimeIP; +extern unsigned long realtimeTimeout; //mqtt -long lastMqttReconnectAttempt = 0; -long lastInterfaceUpdate = 0; -byte interfaceUpdateCallMode = NOTIFIER_CALL_MODE_INIT; -char mqttStatusTopic[40] = ""; //this must be global because of async handlers +extern long lastMqttReconnectAttempt; +extern long lastInterfaceUpdate; +extern byte interfaceUpdateCallMode; +extern 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; +//auxiliary debug pin +extern byte auxTime; +extern unsigned long auxStartTime; +extern bool auxActive; #endif //alexa udp -String escapedMac; +extern String escapedMac; #ifndef WLED_DISABLE_ALEXA -Espalexa espalexa; -EspalexaDevice *espalexaDevice; +extern Espalexa espalexa; +extern EspalexaDevice *espalexaDevice; #endif //dns server -DNSServer dnsServer; +extern 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; +extern bool ntpConnected; +extern time_t local; +extern unsigned long ntpLastSyncTime; +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 @@ -430,42 +422,43 @@ uint16_t ntpLocalPort = 2390; //string temp buffer (now stored in stack locally) #define OMAX 2048 -char *obuf; -uint16_t olen = 0; +extern char *obuf; +extern uint16_t olen; //presets -uint16_t savedPresets = 0; -int8_t currentPreset = -1; -bool isPreset = false; +extern uint16_t savedPresets; +extern int8_t currentPreset; +extern bool isPreset; -byte errorFlag = 0; +extern byte errorFlag; -String messageHead, messageSub; -byte optionType; +extern String messageHead, messageSub; +extern byte optionType; -bool doReboot = false; //flag to initiate reboot from async handlers -bool doPublishMqtt = false; +extern bool doReboot; //flag to initiate reboot from async handlers +extern bool doPublishMqtt; //server library objects -AsyncWebServer server(80); -AsyncClient *hueClient = NULL; -AsyncMqttClient *mqtt = NULL; +extern AsyncWebServer server; +extern AsyncClient *hueClient; +extern AsyncMqttClient *mqtt; //function prototypes -void colorFromUint32(uint32_t, bool = false); -void serveMessage(AsyncWebServerRequest *, uint16_t, String, String, byte); -void handleE131Packet(e131_packet_t *, IPAddress); -void arlsLock(uint32_t, byte); -void handleOverlayDraw(); +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 -WiFiUDP notifierUdp, rgbUdp; -WiFiUDP ntpUdp; -ESPAsyncE131 e131(handleE131Packet); -bool e131NewData = false; +extern WiFiUDP notifierUdp, rgbUdp; +extern WiFiUDP ntpUdp; +extern ESPAsyncE131 e131; +extern bool e131NewData; //led fx library object -WS2812FX strip = WS2812FX(); +extern WS2812FX strip; + #define WLED_CONNECTED (WiFi.status() == WL_CONNECTED) #define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0) diff --git a/wled00/wled_colors.h b/wled00/wled_colors.h index 2b3ff32c..917311e7 100644 --- a/wled00/wled_colors.h +++ b/wled00/wled_colors.h @@ -5,7 +5,7 @@ * Color conversion methods */ -void colorFromUint32(uint32_t in, bool secondary); +void colorFromUint32(uint32_t in, bool secondary = false); void colorFromUint24(uint32_t in, bool secondary = false); void relativeChangeWhite(int8_t amount, byte lowerBoundary = 0); void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb diff --git a/wled00/wled_ntp.cpp b/wled00/wled_ntp.cpp index 82b99f96..d8d9c38a 100644 --- a/wled00/wled_ntp.cpp +++ b/wled00/wled_ntp.cpp @@ -1,7 +1,63 @@ #include "wled_ntp.h" #include "wled.h" #include "wled_eeprom.h" +TimeChangeRule UTCr = {Last, Sun, Mar, 1, 0}; // UTC +Timezone tzUTC(UTCr, UTCr); +TimeChangeRule BST = {Last, Sun, Mar, 1, 60}; // British Summer Time +TimeChangeRule GMT = {Last, Sun, Oct, 2, 0}; // Standard Time +Timezone tzUK(BST, GMT); + +TimeChangeRule CEST = {Last, Sun, Mar, 2, 120}; //Central European Summer Time +TimeChangeRule CET = {Last, Sun, Oct, 3, 60}; //Central European Standard Time +Timezone tzEUCentral(CEST, CET); + +TimeChangeRule EEST = {Last, Sun, Mar, 3, 180}; //Central European Summer Time +TimeChangeRule EET = {Last, Sun, Oct, 4, 120}; //Central European Standard Time +Timezone tzEUEastern(EEST, EET); + +TimeChangeRule EDT = {Second, Sun, Mar, 2, -240 }; //Daylight time = UTC - 4 hours +TimeChangeRule EST = {First, Sun, Nov, 2, -300 }; //Standard time = UTC - 5 hours +Timezone tzUSEastern(EDT, EST); + +TimeChangeRule CDT = {Second, Sun, Mar, 2, -300 }; //Daylight time = UTC - 5 hours +TimeChangeRule CST = {First, Sun, Nov, 2, -360 }; //Standard time = UTC - 6 hours +Timezone tzUSCentral(CDT, CST); + +Timezone tzCASaskatchewan(CST, CST); //Central without DST + +TimeChangeRule MDT = {Second, Sun, Mar, 2, -360 }; //Daylight time = UTC - 6 hours +TimeChangeRule MST = {First, Sun, Nov, 2, -420 }; //Standard time = UTC - 7 hours +Timezone tzUSMountain(MDT, MST); + +Timezone tzUSArizona(MST, MST); //Mountain without DST + +TimeChangeRule PDT = {Second, Sun, Mar, 2, -420 }; //Daylight time = UTC - 7 hours +TimeChangeRule PST = {First, Sun, Nov, 2, -480 }; //Standard time = UTC - 8 hours +Timezone tzUSPacific(PDT, PST); + +TimeChangeRule ChST = {Last, Sun, Mar, 1, 480}; // China Standard Time = UTC + 8 hours +Timezone tzChina(ChST, ChST); + +TimeChangeRule JST = {Last, Sun, Mar, 1, 540}; // Japan Standard Time = UTC + 9 hours +Timezone tzJapan(JST, JST); + +TimeChangeRule AEDT = {Second, Sun, Oct, 2, 660 }; //Daylight time = UTC + 11 hours +TimeChangeRule AEST = {First, Sun, Apr, 3, 600 }; //Standard time = UTC + 10 hours +Timezone tzAUEastern(AEDT, AEST); + +TimeChangeRule NZDT = {Second, Sun, Sep, 2, 780 }; //Daylight time = UTC + 13 hours +TimeChangeRule NZST = {First, Sun, Apr, 3, 720 }; //Standard time = UTC + 12 hours +Timezone tzNZ(NZDT, NZST); + +TimeChangeRule NKST = {Last, Sun, Mar, 1, 510}; //Pyongyang Time = UTC + 8.5 hours +Timezone tzNK(NKST, NKST); + +TimeChangeRule IST = {Last, Sun, Mar, 1, 330}; // India Standard Time = UTC + 5.5 hours +Timezone tzIndia(IST, IST); + +// Pick your timezone from here. +Timezone* timezones[] = {&tzUTC, &tzUK, &tzEUCentral, &tzEUEastern, &tzUSEastern, &tzUSCentral, &tzUSMountain, &tzUSArizona, &tzUSPacific, &tzChina, &tzJapan, &tzAUEastern, &tzNZ, &tzNK, &tzIndia, &tzCASaskatchewan}; void handleNetworkTime() { diff --git a/wled00/wled_ntp.h b/wled00/wled_ntp.h index 14293342..be683d14 100644 --- a/wled00/wled_ntp.h +++ b/wled00/wled_ntp.h @@ -2,66 +2,9 @@ #define WLED_NTP_H #include #include "timezone/Timezone.h" - /* * Acquires time from NTP server */ -TimeChangeRule UTCr = {Last, Sun, Mar, 1, 0}; // UTC -Timezone tzUTC(UTCr, UTCr); - -TimeChangeRule BST = {Last, Sun, Mar, 1, 60}; // British Summer Time -TimeChangeRule GMT = {Last, Sun, Oct, 2, 0}; // Standard Time -Timezone tzUK(BST, GMT); - -TimeChangeRule CEST = {Last, Sun, Mar, 2, 120}; //Central European Summer Time -TimeChangeRule CET = {Last, Sun, Oct, 3, 60}; //Central European Standard Time -Timezone tzEUCentral(CEST, CET); - -TimeChangeRule EEST = {Last, Sun, Mar, 3, 180}; //Central European Summer Time -TimeChangeRule EET = {Last, Sun, Oct, 4, 120}; //Central European Standard Time -Timezone tzEUEastern(EEST, EET); - -TimeChangeRule EDT = {Second, Sun, Mar, 2, -240 }; //Daylight time = UTC - 4 hours -TimeChangeRule EST = {First, Sun, Nov, 2, -300 }; //Standard time = UTC - 5 hours -Timezone tzUSEastern(EDT, EST); - -TimeChangeRule CDT = {Second, Sun, Mar, 2, -300 }; //Daylight time = UTC - 5 hours -TimeChangeRule CST = {First, Sun, Nov, 2, -360 }; //Standard time = UTC - 6 hours -Timezone tzUSCentral(CDT, CST); - -Timezone tzCASaskatchewan(CST, CST); //Central without DST - -TimeChangeRule MDT = {Second, Sun, Mar, 2, -360 }; //Daylight time = UTC - 6 hours -TimeChangeRule MST = {First, Sun, Nov, 2, -420 }; //Standard time = UTC - 7 hours -Timezone tzUSMountain(MDT, MST); - -Timezone tzUSArizona(MST, MST); //Mountain without DST - -TimeChangeRule PDT = {Second, Sun, Mar, 2, -420 }; //Daylight time = UTC - 7 hours -TimeChangeRule PST = {First, Sun, Nov, 2, -480 }; //Standard time = UTC - 8 hours -Timezone tzUSPacific(PDT, PST); - -TimeChangeRule ChST = {Last, Sun, Mar, 1, 480}; // China Standard Time = UTC + 8 hours -Timezone tzChina(ChST, ChST); - -TimeChangeRule JST = {Last, Sun, Mar, 1, 540}; // Japan Standard Time = UTC + 9 hours -Timezone tzJapan(JST, JST); - -TimeChangeRule AEDT = {Second, Sun, Oct, 2, 660 }; //Daylight time = UTC + 11 hours -TimeChangeRule AEST = {First, Sun, Apr, 3, 600 }; //Standard time = UTC + 10 hours -Timezone tzAUEastern(AEDT, AEST); - -TimeChangeRule NZDT = {Second, Sun, Sep, 2, 780 }; //Daylight time = UTC + 13 hours -TimeChangeRule NZST = {First, Sun, Apr, 3, 720 }; //Standard time = UTC + 12 hours -Timezone tzNZ(NZDT, NZST); - -TimeChangeRule NKST = {Last, Sun, Mar, 1, 510}; //Pyongyang Time = UTC + 8.5 hours -Timezone tzNK(NKST, NKST); - -TimeChangeRule IST = {Last, Sun, Mar, 1, 330}; // India Standard Time = UTC + 5.5 hours -Timezone tzIndia(IST, IST); - -Timezone* timezones[] = {&tzUTC, &tzUK, &tzEUCentral, &tzEUEastern, &tzUSEastern, &tzUSCentral, &tzUSMountain, &tzUSArizona, &tzUSPacific, &tzChina, &tzJapan, &tzAUEastern, &tzNZ, &tzNK, &tzIndia, &tzCASaskatchewan}; void handleNetworkTime(); void sendNTPPacket(); From c6ea2dff8a87dd4f3fedfa754218f23a1bd13016 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Thu, 26 Mar 2020 04:49:35 -0400 Subject: [PATCH 06/32] Add further includes. --- wled00/wled.cpp | 1 + wled00/wled_blynk.cpp | 3 +++ wled00/wled_ir.cpp | 5 ++++- wled00/wled_ir.h | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index a720cb0b..3b3d6936 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -1,4 +1,5 @@ #include "wled.h" +#include #include "wled_led.h" #include "wled_ir.h" #include "wled_notify.h" diff --git a/wled00/wled_blynk.cpp b/wled00/wled_blynk.cpp index c6754a23..2e3d9f7b 100644 --- a/wled00/wled_blynk.cpp +++ b/wled00/wled_blynk.cpp @@ -1,6 +1,9 @@ #include "wled_blynk.h" +#include "const.h" #include "wled.h" #include "src/dependencies/blynk/Blynk/BlynkHandlers.h" +#include "wled_led.h" +#include "wled_colors.h" uint16_t blHue = 0; byte blSat = 255; diff --git a/wled00/wled_ir.cpp b/wled00/wled_ir.cpp index 53f0d23f..f625148e 100644 --- a/wled00/wled_ir.cpp +++ b/wled00/wled_ir.cpp @@ -1,5 +1,8 @@ #include "wled_ir.h" #include "wled.h" +#include "wled_led.h" +#include "wled_colors.h" +#include "wled_eeprom.h" #if defined(WLED_DISABLE_INFRARED) void handleIR(){} @@ -34,7 +37,7 @@ bool decodeIRCustom(uint32_t code) //relatively change brightness, minumum A=5 -void relativeChange(byte* property, int8_t amount, byte lowerBoundary = 0, byte higherBoundary = 0xFF) +void relativeChange(byte* property, int8_t amount, byte lowerBoundary, byte higherBoundary) { int16_t new_val = (int16_t) *property + amount; if (new_val > higherBoundary) new_val = higherBoundary; diff --git a/wled00/wled_ir.h b/wled00/wled_ir.h index 3479f410..3f819da0 100644 --- a/wled00/wled_ir.h +++ b/wled00/wled_ir.h @@ -1,9 +1,24 @@ #ifndef WLED_IR_H #define WLED_IR_H +#include /* * Infrared sensor support for generic 24/40/44 key RGB remotes */ +bool decodeIRCustom(uint32_t code); +void relativeChange(byte* property, int8_t amount, byte lowerBoundary = 0, byte higherBoundary = 0xFF); +void changeEffectSpeed(int8_t amount); +void changeEffectIntensity(int8_t amount); +void decodeIR(uint32_t code); +void decodeIR24(uint32_t code); +void decodeIR24OLD(uint32_t code); +void decodeIR24CT(uint32_t code); +void decodeIR40(uint32_t code); +void decodeIR44(uint32_t code); +void decodeIR21(uint32_t code); +void decodeIR6(uint32_t code); + +void initIR(); void handleIR(); #endif //WLED_IR_H \ No newline at end of file From 7bf1c35dcfac940c9b048c67537a2d7fb5b35f83 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Thu, 26 Mar 2020 04:56:19 -0400 Subject: [PATCH 07/32] Change interface of BlynkSimpleEsp. --- wled00/src/dependencies/blynk/BlynkSimpleEsp.cpp | 5 +++++ wled00/src/dependencies/blynk/BlynkSimpleEsp.h | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 wled00/src/dependencies/blynk/BlynkSimpleEsp.cpp diff --git a/wled00/src/dependencies/blynk/BlynkSimpleEsp.cpp b/wled00/src/dependencies/blynk/BlynkSimpleEsp.cpp new file mode 100644 index 00000000..a15d2c1b --- /dev/null +++ b/wled00/src/dependencies/blynk/BlynkSimpleEsp.cpp @@ -0,0 +1,5 @@ +#include "BlynkSimpleEsp.h" + +WiFiClient _blynkWifiClient; +BlynkArduinoClient _blynkTransport(_blynkWifiClient); +BlynkWifi Blynk(_blynkTransport); \ No newline at end of file diff --git a/wled00/src/dependencies/blynk/BlynkSimpleEsp.h b/wled00/src/dependencies/blynk/BlynkSimpleEsp.h index f6b2a0f1..6697686f 100644 --- a/wled00/src/dependencies/blynk/BlynkSimpleEsp.h +++ b/wled00/src/dependencies/blynk/BlynkSimpleEsp.h @@ -89,8 +89,6 @@ public: }; -static WiFiClient _blynkWifiClient; -static BlynkArduinoClient _blynkTransport(_blynkWifiClient); -BlynkWifi Blynk(_blynkTransport); +extern BlynkWifi Blynk; #endif From 30e3bbd0e8e226bc707c9e0e4b0777dcd87b0727 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Thu, 26 Mar 2020 05:18:19 -0400 Subject: [PATCH 08/32] Renamed min/max macros to fix potential std::min/max conflict (depending on include order). --- wled00/FX.cpp | 66 +++++++++++++++++++++++------------------------ wled00/FX.h | 4 +-- wled00/FX_fcn.cpp | 10 +++---- wled00/wled.h | 8 +++--- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 022b4b23..a57e9dda 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -268,7 +268,7 @@ uint16_t WS2812FX::mode_breath(void) { counter = (counter >> 2) + (counter >> 4); //0-16384 + 0-2048 if (counter < 16384) { if (counter > 8192) counter = 8192 - (counter - 8192); - var = sin16(counter) / 103; //close to parabolic in range 0-8192, max val. 23170 + var = sin16(counter) / 103; //close to parabolic in range 0-8192, MAX val. 23170 } uint8_t lum = 30 + var; @@ -475,8 +475,8 @@ uint16_t WS2812FX::mode_twinkle(void) { uint32_t it = now / cycleTime; if (it != SEGENV.step) { - uint16_t maxOn = map(SEGMENT.intensity, 0, 255, 1, SEGLEN); // make sure at least one LED is on - if (SEGENV.aux0 >= maxOn) + uint16_t MAXOn = map(SEGMENT.intensity, 0, 255, 1, SEGLEN); // make sure at least one LED is on + if (SEGENV.aux0 >= MAXOn) { SEGENV.aux0 = 0; SEGENV.aux1 = random16(); //new seed for our PRNG @@ -601,7 +601,7 @@ uint16_t WS2812FX::mode_hyper_sparkle(void) { } if(random8(5) < 2) { - for(uint16_t i = 0; i < max(1, SEGLEN/3); i++) { + for(uint16_t i = 0; i < MAX(1, SEGLEN/3); i++) { setPixelColor(random16(SEGLEN), SEGCOLOR(1)); } return 20; @@ -1115,7 +1115,7 @@ uint16_t WS2812FX::mode_fireworks() { if (valid1) setPixelColor(SEGENV.aux0 , sv1); if (valid2) setPixelColor(SEGENV.aux1, sv2); - for(uint16_t i=0; i> 1)) == 0) { uint16_t index = random(SEGLEN); setPixelColor(index, color_from_palette(random8(), false, false, 0)); @@ -1162,12 +1162,12 @@ uint16_t WS2812FX::mode_fire_flicker(void) { byte r = (SEGCOLOR(0) >> 16) & 0xFF; byte g = (SEGCOLOR(0) >> 8) & 0xFF; byte b = (SEGCOLOR(0) & 0xFF); - byte lum = (SEGMENT.palette == 0) ? max(w, max(r, max(g, b))) : 255; + byte lum = (SEGMENT.palette == 0) ? MAX(w, MAX(r, MAX(g, b))) : 255; lum /= (((256-SEGMENT.intensity)/16)+1); for(uint16_t i = 0; i < SEGLEN; i++) { byte flicker = random8(lum); if (SEGMENT.palette == 0) { - setPixelColor(i, max(r - flicker, 0), max(g - flicker, 0), max(b - flicker, 0), max(w - flicker, 0)); + setPixelColor(i, MAX(r - flicker, 0), MAX(g - flicker, 0), MAX(b - flicker, 0), MAX(w - flicker, 0)); } else { setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0, 255 - flicker)); } @@ -1197,7 +1197,7 @@ uint16_t WS2812FX::gradient_base(bool loading) { { val = abs(((i>pp) ? p2:pp) -i); } else { - val = min(abs(pp-i),min(abs(p1-i),abs(p2-i))); + val = MIN(abs(pp-i),MIN(abs(p1-i),abs(p2-i))); } val = (brd > val) ? val/brd * 255 : 255; setPixelColor(i, color_blend(SEGCOLOR(0), color_from_palette(i, true, PALETTE_SOLID_WRAP, 1), val)); @@ -1597,8 +1597,8 @@ uint16_t WS2812FX::mode_oscillate(void) uint16_t WS2812FX::mode_lightning(void) { - uint16_t ledstart = random16(SEGLEN); // Determine starting location of flash - uint16_t ledlen = random16(SEGLEN -1 -ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1) + uint16_t ledstart = random16(SEGLEN); // DeterMINe starting location of flash + uint16_t ledlen = random16(SEGLEN -1 -ledstart); // DeterMINe length of flash (not to go beyond NUM_LEDS-1) uint8_t bri = 255/random8(1, 3); if (SEGENV.step == 0) @@ -1778,7 +1778,7 @@ uint16_t WS2812FX::mode_fire_2012() // Step 4. Map from heat cells to LED colors for (uint16_t j = 0; j < SEGLEN; j++) { - CRGB color = ColorFromPalette(currentPalette, min(heat[j],240), 255, LINEARBLEND); + CRGB color = ColorFromPalette(currentPalette, MIN(heat[j],240), 255, LINEARBLEND); setPixelColor(j, color.red, color.green, color.blue); } return FRAMETIME; @@ -2153,9 +2153,9 @@ typedef struct Ripple { uint16_t WS2812FX::ripple_base(bool rainbow) { - uint16_t maxRipples = 1 + (SEGLEN >> 2); - if (maxRipples > 100) maxRipples = 100; - uint16_t dataSize = sizeof(ripple) * maxRipples; + uint16_t MAXRipples = 1 + (SEGLEN >> 2); + if (MAXRipples > 100) MAXRipples = 100; + uint16_t dataSize = sizeof(ripple) * MAXRipples; if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed @@ -2181,7 +2181,7 @@ uint16_t WS2812FX::ripple_base(bool rainbow) } //draw wave - for (uint16_t i = 0; i < maxRipples; i++) + for (uint16_t i = 0; i < MAXRipples; i++) { uint16_t ripplestate = ripples[i].state; if (ripplestate) @@ -2480,8 +2480,8 @@ uint16_t WS2812FX::spots_base(uint16_t threshold) { fill(SEGCOLOR(1)); - uint16_t maxZones = SEGLEN >> 2; - uint16_t zones = 1 + ((SEGMENT.intensity * maxZones) >> 8); + uint16_t MAXZones = SEGLEN >> 2; + uint16_t zones = 1 + ((SEGMENT.intensity * MAXZones) >> 8); uint16_t zoneLen = SEGLEN / zones; uint16_t offset = (SEGLEN - zones * zoneLen) >> 1; @@ -2533,15 +2533,15 @@ typedef struct Ball { */ uint16_t WS2812FX::mode_bouncing_balls(void) { //allocate segment data - uint16_t maxNumBalls = 16; - uint16_t dataSize = sizeof(ball) * maxNumBalls; + uint16_t MAXNumBalls = 16; + uint16_t dataSize = sizeof(ball) * MAXNumBalls; if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed Ball* balls = reinterpret_cast(SEGENV.data); - // number of balls based on intensity setting to max of 7 (cycles colors) + // number of balls based on intensity setting to MAX of 7 (cycles colors) // non-chosen color is a random color - uint8_t numBalls = int(((SEGMENT.intensity * (maxNumBalls - 0.8f)) / 255) + 1); + uint8_t numBalls = int(((SEGMENT.intensity * (MAXNumBalls - 0.8f)) / 255) + 1); float gravity = -9.81; // standard value of gravity float impactVelocityStart = sqrt( -2 * gravity); @@ -2549,7 +2549,7 @@ uint16_t WS2812FX::mode_bouncing_balls(void) { unsigned long time = millis(); if (SEGENV.call == 0) { - for (uint8_t i = 0; i < maxNumBalls; i++) balls[i].lastBounceTime = time; + for (uint8_t i = 0; i < MAXNumBalls; i++) balls[i].lastBounceTime = time; } bool hasCol2 = SEGCOLOR(2); @@ -2573,7 +2573,7 @@ uint16_t WS2812FX::mode_bouncing_balls(void) { uint32_t color = SEGCOLOR(0); if (SEGMENT.palette) { - color = color_wheel(i*(256/max(numBalls, 8))); + color = color_wheel(i*(256/MAX(numBalls, 8))); } else if (hasCol2) { color = SEGCOLOR(i % NUM_COLORS); } @@ -2665,8 +2665,8 @@ typedef struct Spark { */ uint16_t WS2812FX::mode_popcorn(void) { //allocate segment data - uint16_t maxNumPopcorn = 24; - uint16_t dataSize = sizeof(spark) * maxNumPopcorn; + uint16_t MAXNumPopcorn = 24; + uint16_t dataSize = sizeof(spark) * MAXNumPopcorn; if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed Spark* popcorn = reinterpret_cast(SEGENV.data); @@ -2677,7 +2677,7 @@ uint16_t WS2812FX::mode_popcorn(void) { bool hasCol2 = SEGCOLOR(2); fill(hasCol2 ? BLACK : SEGCOLOR(1)); - uint8_t numPopcorn = SEGMENT.intensity*maxNumPopcorn/255; + uint8_t numPopcorn = SEGMENT.intensity*MAXNumPopcorn/255; if (numPopcorn == 0) numPopcorn = 1; for(uint8_t i = 0; i < numPopcorn; i++) { @@ -2792,13 +2792,13 @@ uint16_t WS2812FX::mode_starburst(void) { star* stars = reinterpret_cast(SEGENV.data); - float maxSpeed = 375.0f; // Max velocity + float MAXSpeed = 375.0f; // Max velocity float particleIgnition = 250.0f; // How long to "flash" float particleFadeTime = 1500.0f; // Fade out time for (int j = 0; j < numStars; j++) { - // speed to adjust chance of a burst, max is nearly always. + // speed to adjust chance of a burst, MAX is nearly always. if (random8((144-(SEGMENT.speed >> 1))) == 0 && stars[j].birth == 0) { // Pick a random color and location. @@ -2807,7 +2807,7 @@ uint16_t WS2812FX::mode_starburst(void) { stars[j].color = col_to_crgb(color_wheel(random8())); stars[j].pos = startPos; - stars[j].vel = maxSpeed * (float)(random8())/255.0 * multiplier; + stars[j].vel = MAXSpeed * (float)(random8())/255.0 * multiplier; stars[j].birth = it; stars[j].last = it; // more fragments means larger burst effect @@ -3026,7 +3026,7 @@ uint16_t WS2812FX::mode_drip(void) drops[j].pos = SEGLEN-1; // start at end drops[j].vel = 0; // speed drops[j].col = sourcedrop; // brightness - drops[j].colIndex = 1; // drop state (0 init, 1 forming, 2 falling, 5 bouncing) + drops[j].colIndex = 1; // drop state (0 init, 1 forMINg, 2 falling, 5 bouncing) } setPixelColor(SEGLEN-1,color_blend(BLACK,SEGCOLOR(0), sourcedrop));// water source @@ -3047,7 +3047,7 @@ uint16_t WS2812FX::mode_drip(void) if (drops[j].pos < 0) drops[j].pos = 0; drops[j].vel += gravity; - for (int i=1;i<7-drops[j].colIndex;i++) { // some minor math so we don't expand bouncing droplets + for (int i=1;i<7-drops[j].colIndex;i++) { // some MINor math so we don't expand bouncing droplets setPixelColor(int(drops[j].pos)+i,color_blend(BLACK,SEGCOLOR(0),drops[j].col/i)); //spread pixel with fade while falling } @@ -3055,7 +3055,7 @@ uint16_t WS2812FX::mode_drip(void) setPixelColor(0,color_blend(SEGCOLOR(0),BLACK,drops[j].col)); } } else { // we hit bottom - if (drops[j].colIndex > 2) { // already hit once, so back to forming + if (drops[j].colIndex > 2) { // already hit once, so back to forMINg drops[j].colIndex = 0; drops[j].col = sourcedrop; @@ -3100,7 +3100,7 @@ uint16_t WS2812FX::mode_plasma(void) { */ uint16_t WS2812FX::mode_percent(void) { - uint8_t percent = max(0, min(200, SEGMENT.intensity)); + uint8_t percent = MAX(0, MIN(200, SEGMENT.intensity)); uint16_t active_leds = (percent < 100) ? SEGLEN * percent / 100.0 : SEGLEN * (200 - percent) / 100.0; diff --git a/wled00/FX.h b/wled00/FX.h index d24250f9..210039ef 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -38,8 +38,8 @@ #define DEFAULT_SPEED (uint8_t)128 #define DEFAULT_COLOR (uint32_t)0xFFAA00 -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) +#define MIN(a,b) ((a)<(b)?(a):(b)) +#define MAX(a,b) ((a)>(b)?(a):(b)) /* Not used in all effects yet */ #define WLED_FPS 42 diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 05568623..75ec6510 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -224,7 +224,7 @@ void WS2812FX::show(void) { if(useWackyWS2815PowerModel) { // ignore white component on WS2815 power calculation - powerSum += (max(max(c.R,c.G),c.B)) * 3; + powerSum += (MAX(MAX(c.R,c.G),c.B)) * 3; } else { @@ -638,7 +638,7 @@ uint32_t WS2812FX::color_wheel(uint8_t pos) { } /* - * Returns a new, random wheel index with a minimum distance of 42 from pos. + * Returns a new, random wheel index with a MINimum distance of 42 from pos. */ uint8_t WS2812FX::get_random_wheel_index(uint8_t pos) { uint8_t r = 0, x = 0, y = 0, d = 0; @@ -647,7 +647,7 @@ uint8_t WS2812FX::get_random_wheel_index(uint8_t pos) { r = random8(); x = abs(pos - r); y = 255 - x; - d = min(x, y); + d = MIN(x, y); } return r; } @@ -730,8 +730,8 @@ void WS2812FX::handle_palette(void) CHSV prim_hsv = rgb2hsv_approximate(prim); targetPalette = CRGBPalette16( CHSV(prim_hsv.h, prim_hsv.s, prim_hsv.v), //color itself - CHSV(prim_hsv.h, max(prim_hsv.s - 50,0), prim_hsv.v), //less saturated - CHSV(prim_hsv.h, prim_hsv.s, max(prim_hsv.v - 50,0)), //darker + CHSV(prim_hsv.h, MAX(prim_hsv.s - 50,0), prim_hsv.v), //less saturated + CHSV(prim_hsv.h, prim_hsv.s, MAX(prim_hsv.v - 50,0)), //darker CHSV(prim_hsv.h, prim_hsv.s, prim_hsv.v)); //color itself break;} case 4: {//primary + secondary diff --git a/wled00/wled.h b/wled00/wled.h index 04341446..3b744bcd 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -468,10 +468,10 @@ extern WS2812FX strip; #define DEBUG_PRINT(x) Serial.print(x) #define DEBUG_PRINTLN(x) Serial.println(x) #define DEBUG_PRINTF(x) Serial.printf(x) -unsigned long debugTime = 0; -int lastWifiState = 3; -unsigned long wifiStateChangedTime = 0; -int loops = 0; +extern unsigned long debugTime; +extern int lastWifiState; +extern unsigned long wifiStateChangedTime; +extern int loops; #else #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) From b8342f1c9cde82c15bfed4728130451a5487d6f3 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Sat, 28 Mar 2020 07:32:02 -0400 Subject: [PATCH 09/32] actually call the setup function. --- wled00/wled00.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wled00/wled00.ino b/wled00/wled00.ino index ac993bf6..522447d0 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -3,9 +3,10 @@ */ #include "wled.h" -WLED wled; +WLED& wled; void setup() { - wled.instance(); // Force creation of static instance + wled = WLED::instance(); + wled.setup(); } void loop() { From f35ab125eccb3fca86d27fb4dd7728bb5812e65d Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Sat, 28 Mar 2020 08:30:51 -0400 Subject: [PATCH 10/32] Rename files to remove wled_ --- wled00/{wled_alexa.cpp => alexa.cpp} | 8 +- wled00/{wled_alexa.h => alexa.h} | 32 +- wled00/{wled_blynk.cpp => blynk.cpp} | 6 +- wled00/{wled_blynk.h => blynk.h} | 24 +- wled00/{wled_button.cpp => button.cpp} | 8 +- wled00/{wled_button.h => button.h} | 22 +- wled00/{wled_colors.cpp => colors.cpp} | 2 +- wled00/{wled_colors.h => colors.h} | 38 +- wled00/{wled_cronixie.cpp => cronixie.cpp} | 2 +- wled00/{wled_cronixie.h => cronixie.h} | 24 +- wled00/{wled_dmx.cpp => dmx.cpp} | 2 +- wled00/{wled_dmx.h => dmx.h} | 20 +- wled00/{wled_eeprom.cpp => eeprom.cpp} | 10 +- wled00/{wled_eeprom.h => eeprom.h} | 46 +- wled00/{wled_file.cpp => file.cpp} | 6 +- wled00/{wled_file.h => file.h} | 22 +- wled00/{wled_hue.cpp => hue.cpp} | 10 +- wled00/{wled_hue.h => hue.h} | 30 +- wled00/{wled_ir.cpp => ir.cpp} | 8 +- wled00/{wled_ir.h => ir.h} | 46 +- wled00/{wled_json.cpp => json.cpp} | 6 +- wled00/{wled_json.h => json.h} | 40 +- wled00/{wled_led.cpp => led.cpp} | 12 +- wled00/{wled_led.h => led.h} | 36 +- wled00/{wled_mqtt.cpp => mqtt.cpp} | 12 +- wled00/{wled_mqtt.h => mqtt.h} | 16 +- wled00/{wled_notify.cpp => notify.cpp} | 4 +- wled00/{wled_notify.h => notify.h} | 34 +- wled00/{wled_ntp.cpp => ntp.cpp} | 4 +- wled00/{wled_ntp.h => ntp.h} | 35 +- wled00/{wled_overlay.cpp => overlay.cpp} | 6 +- wled00/{wled_overlay.h => overlay.h} | 26 +- wled00/{wled_server.cpp => server.cpp} | 10 +- wled00/{wled_server.h => server.h} | 40 +- wled00/{wled_set.cpp => set.cpp} | 18 +- wled00/{wled_set.h => set.h} | 30 +- wled00/{wled_usermod.cpp => usermod.cpp} | 0 wled00/{wled_usermod.h => usermod.h} | 14 +- wled00/wled.cpp | 1763 ++++++++++---------- wled00/wled.h | 1038 ++++++------ wled00/{wled_xml.cpp => xml.cpp} | 6 +- wled00/{wled_xml.h => xml.h} | 28 +- 42 files changed, 1772 insertions(+), 1772 deletions(-) rename wled00/{wled_alexa.cpp => alexa.cpp} (95%) rename wled00/{wled_alexa.h => alexa.h} (92%) rename wled00/{wled_blynk.cpp => blynk.cpp} (96%) rename wled00/{wled_blynk.h => blynk.h} (89%) rename wled00/{wled_button.cpp => button.cpp} (96%) rename wled00/{wled_button.h => button.h} (81%) rename wled00/{wled_colors.cpp => colors.cpp} (99%) rename wled00/{wled_colors.h => colors.h} (94%) rename wled00/{wled_cronixie.cpp => cronixie.cpp} (99%) rename wled00/{wled_cronixie.h => cronixie.h} (87%) rename wled00/{wled_dmx.cpp => dmx.cpp} (98%) rename wled00/{wled_dmx.h => dmx.h} (89%) rename wled00/{wled_eeprom.cpp => eeprom.cpp} (99%) rename wled00/{wled_eeprom.h => eeprom.h} (97%) rename wled00/{wled_file.cpp => file.cpp} (98%) rename wled00/{wled_file.h => file.h} (87%) rename wled00/{wled_hue.cpp => hue.cpp} (97%) rename wled00/{wled_hue.h => hue.h} (91%) rename wled00/{wled_ir.cpp => ir.cpp} (99%) rename wled00/{wled_ir.h => ir.h} (94%) rename wled00/{wled_json.cpp => json.cpp} (99%) rename wled00/{wled_json.h => json.h} (94%) rename wled00/{wled_led.cpp => led.cpp} (97%) rename wled00/{wled_led.h => led.h} (93%) rename wled00/{wled_mqtt.cpp => mqtt.cpp} (96%) rename wled00/{wled_mqtt.h => mqtt.h} (82%) rename wled00/{wled_notify.cpp => notify.cpp} (99%) rename wled00/{wled_notify.h => notify.h} (92%) rename wled00/{wled_ntp.cpp => ntp.cpp} (99%) rename wled00/{wled_ntp.h => ntp.h} (82%) rename wled00/{wled_overlay.cpp => overlay.cpp} (98%) rename wled00/{wled_overlay.h => overlay.h} (87%) rename wled00/{wled_server.cpp => server.cpp} (99%) rename wled00/{wled_server.h => server.h} (93%) rename wled00/{wled_set.cpp => set.cpp} (98%) rename wled00/{wled_set.h => set.h} (93%) rename wled00/{wled_usermod.cpp => usermod.cpp} (100%) rename wled00/{wled_usermod.h => usermod.h} (77%) rename wled00/{wled_xml.cpp => xml.cpp} (99%) rename wled00/{wled_xml.h => xml.h} (92%) diff --git a/wled00/wled_alexa.cpp b/wled00/alexa.cpp similarity index 95% rename from wled00/wled_alexa.cpp rename to wled00/alexa.cpp index 1eb33e71..621480d0 100644 --- a/wled00/wled_alexa.cpp +++ b/wled00/alexa.cpp @@ -1,9 +1,9 @@ -#include "wled_alexa.h" +#include "alexa.h" #include "wled.h" #include "const.h" -#include "wled_led.h" -#include "wled_eeprom.h" -#include "wled_colors.h" +#include "led.h" +#include "eeprom.h" +#include "colors.h" #ifndef WLED_DISABLE_ALEXA void onAlexaChange(EspalexaDevice* dev); diff --git a/wled00/wled_alexa.h b/wled00/alexa.h similarity index 92% rename from wled00/wled_alexa.h rename to wled00/alexa.h index 94ad0342..c2adfebe 100644 --- a/wled00/wled_alexa.h +++ b/wled00/alexa.h @@ -1,17 +1,17 @@ -#ifndef WLED_ALEXA_H -#define WLED_ALEXA_H -/* - * Alexa Voice On/Off/Brightness Control. Emulates a Philips Hue bridge to Alexa. - * - * This was put together from these two excellent projects: - * https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch - * https://github.com/probonopd/ESP8266HueEmulator - */ -#include "src/dependencies/espalexa/EspalexaDevice.h" - -void onAlexaChange(EspalexaDevice* dev); -void alexaInit(); -void handleAlexa(); -void onAlexaChange(EspalexaDevice* dev); - +#ifndef WLED_ALEXA_H +#define WLED_ALEXA_H +/* + * Alexa Voice On/Off/Brightness Control. Emulates a Philips Hue bridge to Alexa. + * + * This was put together from these two excellent projects: + * https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch + * https://github.com/probonopd/ESP8266HueEmulator + */ +#include "src/dependencies/espalexa/EspalexaDevice.h" + +void onAlexaChange(EspalexaDevice* dev); +void alexaInit(); +void handleAlexa(); +void onAlexaChange(EspalexaDevice* dev); + #endif // WLED_ALEXA_H \ No newline at end of file diff --git a/wled00/wled_blynk.cpp b/wled00/blynk.cpp similarity index 96% rename from wled00/wled_blynk.cpp rename to wled00/blynk.cpp index 2e3d9f7b..2307a694 100644 --- a/wled00/wled_blynk.cpp +++ b/wled00/blynk.cpp @@ -1,9 +1,9 @@ -#include "wled_blynk.h" +#include "blynk.h" #include "const.h" #include "wled.h" #include "src/dependencies/blynk/Blynk/BlynkHandlers.h" -#include "wled_led.h" -#include "wled_colors.h" +#include "led.h" +#include "colors.h" uint16_t blHue = 0; byte blSat = 255; diff --git a/wled00/wled_blynk.h b/wled00/blynk.h similarity index 89% rename from wled00/wled_blynk.h rename to wled00/blynk.h index e8c8341b..cf3a2e22 100644 --- a/wled00/wled_blynk.h +++ b/wled00/blynk.h @@ -1,13 +1,13 @@ -#ifndef WLED_BLYNK_H -#define WLED_BLYNK_H -#include -/* - * Remote light control with the free Blynk app - */ - -void initBlynk(const char* auth); -void handleBlynk(); -void updateBlynk(); -// Unsure if the macro expansions need to accessed through the declaration... TODO - +#ifndef WLED_BLYNK_H +#define WLED_BLYNK_H +#include +/* + * Remote light control with the free Blynk app + */ + +void initBlynk(const char* auth); +void handleBlynk(); +void updateBlynk(); +// Unsure if the macro expansions need to accessed through the declaration... TODO + #endif //WLED_BLYNK_H \ No newline at end of file diff --git a/wled00/wled_button.cpp b/wled00/button.cpp similarity index 96% rename from wled00/wled_button.cpp rename to wled00/button.cpp index 3825cc84..1afb54d5 100644 --- a/wled00/wled_button.cpp +++ b/wled00/button.cpp @@ -1,8 +1,8 @@ -#include "wled_button.h" +#include "button.h" #include "wled.h" -#include "wled_led.h" -#include "wled_eeprom.h" -#include "wled_set.h" +#include "led.h" +#include "eeprom.h" +#include "set.h" /* * Physical IO diff --git a/wled00/wled_button.h b/wled00/button.h similarity index 81% rename from wled00/wled_button.h rename to wled00/button.h index 5f894477..f974888e 100644 --- a/wled00/wled_button.h +++ b/wled00/button.h @@ -1,12 +1,12 @@ -#ifndef WLED_BUTTON_H -#define WLED_BUTTON_H -#include -/* - * Physical IO - */ - -void shortPressAction(); -void handleButton(); -void handleIO(); - +#ifndef WLED_BUTTON_H +#define WLED_BUTTON_H +#include +/* + * Physical IO + */ + +void shortPressAction(); +void handleButton(); +void handleIO(); + #endif // WLED_BUTTON_H \ No newline at end of file diff --git a/wled00/wled_colors.cpp b/wled00/colors.cpp similarity index 99% rename from wled00/wled_colors.cpp rename to wled00/colors.cpp index dcd32e57..6f247757 100644 --- a/wled00/wled_colors.cpp +++ b/wled00/colors.cpp @@ -1,4 +1,4 @@ -#include "wled_colors.h" +#include "colors.h" #include "wled.h" void colorFromUint32(uint32_t in, bool secondary) diff --git a/wled00/wled_colors.h b/wled00/colors.h similarity index 94% rename from wled00/wled_colors.h rename to wled00/colors.h index 917311e7..85e0adb5 100644 --- a/wled00/wled_colors.h +++ b/wled00/colors.h @@ -1,20 +1,20 @@ -#ifndef WLED_COLORS_H -#define WLED_COLORS_H -#include -/* - * Color conversion methods - */ - -void colorFromUint32(uint32_t in, bool secondary = false); -void colorFromUint24(uint32_t in, bool secondary = false); -void relativeChangeWhite(int8_t amount, byte lowerBoundary = 0); -void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb -void colorCTtoRGB(uint16_t mired, byte* rgb); //white spectrum to rgb - -void colorXYtoRGB(float x, float y, byte* rgb); // only defined if huesync disabled TODO -void colorRGBtoXY(byte* rgb, float* xy); // only defined if huesync disabled TODO - -void colorFromDecOrHexString(byte* rgb, char* in); -void colorRGBtoRGBW(byte* rgb); //rgb to rgbw (http://codewelt.com/rgbw). (RGBW_MODE_LEGACY) - +#ifndef WLED_COLORS_H +#define WLED_COLORS_H +#include +/* + * Color conversion methods + */ + +void colorFromUint32(uint32_t in, bool secondary = false); +void colorFromUint24(uint32_t in, bool secondary = false); +void relativeChangeWhite(int8_t amount, byte lowerBoundary = 0); +void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb +void colorCTtoRGB(uint16_t mired, byte* rgb); //white spectrum to rgb + +void colorXYtoRGB(float x, float y, byte* rgb); // only defined if huesync disabled TODO +void colorRGBtoXY(byte* rgb, float* xy); // only defined if huesync disabled TODO + +void colorFromDecOrHexString(byte* rgb, char* in); +void colorRGBtoRGBW(byte* rgb); //rgb to rgbw (http://codewelt.com/rgbw). (RGBW_MODE_LEGACY) + #endif //WLED_COLORS_H \ No newline at end of file diff --git a/wled00/wled_cronixie.cpp b/wled00/cronixie.cpp similarity index 99% rename from wled00/wled_cronixie.cpp rename to wled00/cronixie.cpp index 107af752..e3b951b8 100644 --- a/wled00/wled_cronixie.cpp +++ b/wled00/cronixie.cpp @@ -1,4 +1,4 @@ -#include "wled_cronixie.h" +#include "cronixie.h" #include "wled.h" #ifndef WLED_DISABLE_CRONIXIE diff --git a/wled00/wled_cronixie.h b/wled00/cronixie.h similarity index 87% rename from wled00/wled_cronixie.h rename to wled00/cronixie.h index 9dea69b3..f6eea6b4 100644 --- a/wled00/wled_cronixie.h +++ b/wled00/cronixie.h @@ -1,13 +1,13 @@ -#ifndef WLED_CRONIXIE_H -#define WLED_CRONIXIE_H -#include -/* - * Support for the Cronixie clock - */ - -byte getSameCodeLength(char code, int index, char const cronixieDisplay[]); -void setCronixie(); -void _overlayCronixie(); -void _drawOverlayCronixie(); - +#ifndef WLED_CRONIXIE_H +#define WLED_CRONIXIE_H +#include +/* + * Support for the Cronixie clock + */ + +byte getSameCodeLength(char code, int index, char const cronixieDisplay[]); +void setCronixie(); +void _overlayCronixie(); +void _drawOverlayCronixie(); + #endif // WLED_CRONIXIE_H \ No newline at end of file diff --git a/wled00/wled_dmx.cpp b/wled00/dmx.cpp similarity index 98% rename from wled00/wled_dmx.cpp rename to wled00/dmx.cpp index f620f777..d024ac71 100644 --- a/wled00/wled_dmx.cpp +++ b/wled00/dmx.cpp @@ -1,4 +1,4 @@ -#include "wled_dmx.h" +#include "dmx.h" #include "wled.h" #ifdef WLED_ENABLE_DMX diff --git a/wled00/wled_dmx.h b/wled00/dmx.h similarity index 89% rename from wled00/wled_dmx.h rename to wled00/dmx.h index 94cbb0d2..707dec91 100644 --- a/wled00/wled_dmx.h +++ b/wled00/dmx.h @@ -1,11 +1,11 @@ -#ifndef WLED_DMX_H -#define WLED_DMX_H -/* - * Support for DMX via MAX485. - * Needs the espdmx library. You might have to change the output pin within the library. Sketchy, i know. - * https://github.com/Rickgg/ESP-Dmx - */ - -void handleDMX(); - +#ifndef WLED_DMX_H +#define WLED_DMX_H +/* + * Support for DMX via MAX485. + * Needs the espdmx library. You might have to change the output pin within the library. Sketchy, i know. + * https://github.com/Rickgg/ESP-Dmx + */ + +void handleDMX(); + #endif //WLED_DMX_H \ No newline at end of file diff --git a/wled00/wled_eeprom.cpp b/wled00/eeprom.cpp similarity index 99% rename from wled00/wled_eeprom.cpp rename to wled00/eeprom.cpp index 04b86289..68b8c35f 100644 --- a/wled00/wled_eeprom.cpp +++ b/wled00/eeprom.cpp @@ -1,9 +1,9 @@ -#include "wled_eeprom.h" +#include "eeprom.h" #include "wled.h" -#include "wled_cronixie.h" -#include "wled_ntp.h" -#include "wled_set.h" -#include "wled_led.h" +#include "cronixie.h" +#include "ntp.h" +#include "set.h" +#include "led.h" //eeprom Version code, enables default settings instead of 0 init on update diff --git a/wled00/wled_eeprom.h b/wled00/eeprom.h similarity index 97% rename from wled00/wled_eeprom.h rename to wled00/eeprom.h index 19f61925..eae52b12 100644 --- a/wled00/wled_eeprom.h +++ b/wled00/eeprom.h @@ -1,23 +1,23 @@ -#ifndef WLED_EPPROM_H -#define WLED_EPPROM_H -#include -/* - * Methods to handle saving and loading to non-volatile memory - * EEPROM Map: https://github.com/Aircoookie/WLED/wiki/EEPROM-Map - */ -#define EEPSIZE 2560 //Maximum is 4096 - -void commit(); -void clearEEPROM(); -void writeStringToEEPROM(uint16_t pos, char* str, uint16_t len); -void readStringFromEEPROM(uint16_t pos, char* str, uint16_t len); -void saveSettingsToEEPROM(); -void loadSettingsFromEEPROM(bool first); -void savedToPresets(); -bool applyPreset(byte index, bool loadBri = true); -void savePreset(byte index, bool persist = true); -void loadMacro(byte index, char* m); -void applyMacro(byte index); -void saveMacro(byte index, String mc, bool persist = true); //only commit on single save, not in settings - -#endif //WLED_EPPROM_H +#ifndef WLED_EPPROM_H +#define WLED_EPPROM_H +#include +/* + * Methods to handle saving and loading to non-volatile memory + * EEPROM Map: https://github.com/Aircoookie/WLED/wiki/EEPROM-Map + */ +#define EEPSIZE 2560 //Maximum is 4096 + +void commit(); +void clearEEPROM(); +void writeStringToEEPROM(uint16_t pos, char* str, uint16_t len); +void readStringFromEEPROM(uint16_t pos, char* str, uint16_t len); +void saveSettingsToEEPROM(); +void loadSettingsFromEEPROM(bool first); +void savedToPresets(); +bool applyPreset(byte index, bool loadBri = true); +void savePreset(byte index, bool persist = true); +void loadMacro(byte index, char* m); +void applyMacro(byte index); +void saveMacro(byte index, String mc, bool persist = true); //only commit on single save, not in settings + +#endif //WLED_EPPROM_H diff --git a/wled00/wled_file.cpp b/wled00/file.cpp similarity index 98% rename from wled00/wled_file.cpp rename to wled00/file.cpp index 81b86d6d..dba27d4f 100644 --- a/wled00/wled_file.cpp +++ b/wled00/file.cpp @@ -1,7 +1,7 @@ -#include "wled_file.h" +#include "file.h" #include "wled.h" -#include "wled_led.h" -#include "wled_notify.h" +#include "led.h" +#include "notify.h" //filesystem #ifndef WLED_DISABLE_FILESYSTEM diff --git a/wled00/wled_file.h b/wled00/file.h similarity index 87% rename from wled00/wled_file.h rename to wled00/file.h index 7457ec4c..90731db6 100644 --- a/wled00/wled_file.h +++ b/wled00/file.h @@ -1,12 +1,12 @@ -#ifndef WLED_FILE_H -#define WLED_FILE_H -#include -#include -/* - * Utility for SPIFFS filesystem & Serial console - */ - -void handleSerial(); -bool handleFileRead(AsyncWebServerRequest*, String path); - +#ifndef WLED_FILE_H +#define WLED_FILE_H +#include +#include +/* + * Utility for SPIFFS filesystem & Serial console + */ + +void handleSerial(); +bool handleFileRead(AsyncWebServerRequest*, String path); + #endif // WLED_FILE_H \ No newline at end of file diff --git a/wled00/wled_hue.cpp b/wled00/hue.cpp similarity index 97% rename from wled00/wled_hue.cpp rename to wled00/hue.cpp index 61756ec0..484f2bd8 100644 --- a/wled00/wled_hue.cpp +++ b/wled00/hue.cpp @@ -1,9 +1,9 @@ -#include "wled_hue.h" +#include "hue.h" #include "wled.h" -#include "wled_colors.h" -#include "wled_eeprom.h" -#include "wled_notify.h" -#include "wled_led.h" +#include "colors.h" +#include "eeprom.h" +#include "notify.h" +#include "led.h" #ifndef WLED_DISABLE_HUESYNC diff --git a/wled00/wled_hue.h b/wled00/hue.h similarity index 91% rename from wled00/wled_hue.h rename to wled00/hue.h index 8b26f8b6..7ce629fb 100644 --- a/wled00/wled_hue.h +++ b/wled00/hue.h @@ -1,16 +1,16 @@ -#ifndef WLED_HUE_H -#define WLED_HUE_H -/* - * Sync to Philips hue lights - */ -#include -class AsyncClient; - -void handleHue(); -void reconnectHue(); -void onHueError(void* arg, AsyncClient* client, int8_t error); -void onHueConnect(void* arg, AsyncClient* client); -void sendHuePoll(); -void onHueData(void* arg, AsyncClient* client, void *data, size_t len); - +#ifndef WLED_HUE_H +#define WLED_HUE_H +/* + * Sync to Philips hue lights + */ +#include +class AsyncClient; + +void handleHue(); +void reconnectHue(); +void onHueError(void* arg, AsyncClient* client, int8_t error); +void onHueConnect(void* arg, AsyncClient* client); +void sendHuePoll(); +void onHueData(void* arg, AsyncClient* client, void *data, size_t len); + #endif //WLED_HUE_H \ No newline at end of file diff --git a/wled00/wled_ir.cpp b/wled00/ir.cpp similarity index 99% rename from wled00/wled_ir.cpp rename to wled00/ir.cpp index f625148e..fcc0f5dd 100644 --- a/wled00/wled_ir.cpp +++ b/wled00/ir.cpp @@ -1,8 +1,8 @@ -#include "wled_ir.h" +#include "ir.h" #include "wled.h" -#include "wled_led.h" -#include "wled_colors.h" -#include "wled_eeprom.h" +#include "led.h" +#include "colors.h" +#include "eeprom.h" #if defined(WLED_DISABLE_INFRARED) void handleIR(){} diff --git a/wled00/wled_ir.h b/wled00/ir.h similarity index 94% rename from wled00/wled_ir.h rename to wled00/ir.h index 3f819da0..e6ecb966 100644 --- a/wled00/wled_ir.h +++ b/wled00/ir.h @@ -1,24 +1,24 @@ -#ifndef WLED_IR_H -#define WLED_IR_H -#include -/* - * Infrared sensor support for generic 24/40/44 key RGB remotes - */ - -bool decodeIRCustom(uint32_t code); -void relativeChange(byte* property, int8_t amount, byte lowerBoundary = 0, byte higherBoundary = 0xFF); -void changeEffectSpeed(int8_t amount); -void changeEffectIntensity(int8_t amount); -void decodeIR(uint32_t code); -void decodeIR24(uint32_t code); -void decodeIR24OLD(uint32_t code); -void decodeIR24CT(uint32_t code); -void decodeIR40(uint32_t code); -void decodeIR44(uint32_t code); -void decodeIR21(uint32_t code); -void decodeIR6(uint32_t code); - -void initIR(); -void handleIR(); - +#ifndef WLED_IR_H +#define WLED_IR_H +#include +/* + * Infrared sensor support for generic 24/40/44 key RGB remotes + */ + +bool decodeIRCustom(uint32_t code); +void relativeChange(byte* property, int8_t amount, byte lowerBoundary = 0, byte higherBoundary = 0xFF); +void changeEffectSpeed(int8_t amount); +void changeEffectIntensity(int8_t amount); +void decodeIR(uint32_t code); +void decodeIR24(uint32_t code); +void decodeIR24OLD(uint32_t code); +void decodeIR24CT(uint32_t code); +void decodeIR40(uint32_t code); +void decodeIR44(uint32_t code); +void decodeIR21(uint32_t code); +void decodeIR6(uint32_t code); + +void initIR(); +void handleIR(); + #endif //WLED_IR_H \ No newline at end of file diff --git a/wled00/wled_json.cpp b/wled00/json.cpp similarity index 99% rename from wled00/wled_json.cpp rename to wled00/json.cpp index 17359462..73659e7e 100644 --- a/wled00/wled_json.cpp +++ b/wled00/json.cpp @@ -1,7 +1,7 @@ -#include "wled_json.h" +#include "json.h" #include "wled.h" -#include "wled_eeprom.h" -#include "wled_led.h" +#include "eeprom.h" +#include "led.h" void deserializeSegment(JsonObject elem, byte it) { diff --git a/wled00/wled_json.h b/wled00/json.h similarity index 94% rename from wled00/wled_json.h rename to wled00/json.h index a7c2473a..77d1b616 100644 --- a/wled00/wled_json.h +++ b/wled00/json.h @@ -1,21 +1,21 @@ -#ifndef WLED_JSON_H -#define WLED_JSON_H -/* - * JSON API (De)serialization - */ -#include -#include "ESPAsyncWebServer.h" -#include "src/dependencies/json/ArduinoJson-v6.h" -#include "src/dependencies/json/AsyncJson-v6.h" -#include "fx.h" -// TODO: AsynicWebServerRequest conflict? - -void deserializeSegment(JsonObject elem, byte it); -bool deserializeState(JsonObject root); -void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id); -void serializeState(JsonObject root); -void serializeInfo(JsonObject root); -void serveJson(AsyncWebServerRequest* request); -void serveLiveLeds(AsyncWebServerRequest* request); - +#ifndef WLED_JSON_H +#define WLED_JSON_H +/* + * JSON API (De)serialization + */ +#include +#include "ESPAsyncWebServer.h" +#include "src/dependencies/json/ArduinoJson-v6.h" +#include "src/dependencies/json/AsyncJson-v6.h" +#include "fx.h" +// TODO: AsynicWebServerRequest conflict? + +void deserializeSegment(JsonObject elem, byte it); +bool deserializeState(JsonObject root); +void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id); +void serializeState(JsonObject root); +void serializeInfo(JsonObject root); +void serveJson(AsyncWebServerRequest* request); +void serveLiveLeds(AsyncWebServerRequest* request); + #endif //WLED_JSON_H \ No newline at end of file diff --git a/wled00/wled_led.cpp b/wled00/led.cpp similarity index 97% rename from wled00/wled_led.cpp rename to wled00/led.cpp index bd657a53..4a16dcff 100644 --- a/wled00/wled_led.cpp +++ b/wled00/led.cpp @@ -1,10 +1,10 @@ -#include "wled_led.h" +#include "led.h" #include "wled.h" -#include "wled_notify.h" -#include "wled_blynk.h" -#include "wled_eeprom.h" -#include "wled_mqtt.h" -#include "wled_colors.h" +#include "notify.h" +#include "blynk.h" +#include "eeprom.h" +#include "mqtt.h" +#include "colors.h" void setValuesFromMainSeg() { diff --git a/wled00/wled_led.h b/wled00/led.h similarity index 93% rename from wled00/wled_led.h rename to wled00/led.h index aebe95e4..d5eb97a8 100644 --- a/wled00/wled_led.h +++ b/wled00/led.h @@ -1,19 +1,19 @@ -#ifndef WLED_LED_H -#define WLED_LED_H -#include -/* - * LED methods - */ - -void setValuesFromMainSeg(); -void resetTimebase(); -void toggleOnOff(); -void setAllLeds(); -void setLedsStandard(bool justColors = false); -bool colorChanged(); -void colorUpdated(int callMode); -void updateInterfaces(uint8_t callMode); -void handleTransitions(); -void handleNightlight(); - +#ifndef WLED_LED_H +#define WLED_LED_H +#include +/* + * LED methods + */ + +void setValuesFromMainSeg(); +void resetTimebase(); +void toggleOnOff(); +void setAllLeds(); +void setLedsStandard(bool justColors = false); +bool colorChanged(); +void colorUpdated(int callMode); +void updateInterfaces(uint8_t callMode); +void handleTransitions(); +void handleNightlight(); + #endif \ No newline at end of file diff --git a/wled00/wled_mqtt.cpp b/wled00/mqtt.cpp similarity index 96% rename from wled00/wled_mqtt.cpp rename to wled00/mqtt.cpp index 5e96a18f..b84184af 100644 --- a/wled00/wled_mqtt.cpp +++ b/wled00/mqtt.cpp @@ -1,10 +1,10 @@ -#include "wled_mqtt.h" +#include "mqtt.h" #include "wled.h" -#include "wled_notify.h" -#include "wled_led.h" -#include "wled_colors.h" -#include "wled_xml.h" -#include "wled_set.h" +#include "notify.h" +#include "led.h" +#include "colors.h" +#include "xml.h" +#include "set.h" #ifdef WLED_ENABLE_MQTT #define MQTT_KEEP_ALIVE_TIME 60 // contact the MQTT broker every 60 seconds diff --git a/wled00/wled_mqtt.h b/wled00/mqtt.h similarity index 82% rename from wled00/wled_mqtt.h rename to wled00/mqtt.h index f1c7160e..de602b98 100644 --- a/wled00/wled_mqtt.h +++ b/wled00/mqtt.h @@ -1,9 +1,9 @@ -#ifndef WLED_MQTT_H -#define WLED_MQTT_H -/* - * MQTT communication protocol for home automation - */ -bool initMqtt(); -void publishMqtt(); - +#ifndef WLED_MQTT_H +#define WLED_MQTT_H +/* + * MQTT communication protocol for home automation + */ +bool initMqtt(); +void publishMqtt(); + #endif //WLED_MQTT_H \ No newline at end of file diff --git a/wled00/wled_notify.cpp b/wled00/notify.cpp similarity index 99% rename from wled00/wled_notify.cpp rename to wled00/notify.cpp index 7913b452..30adfee0 100644 --- a/wled00/wled_notify.cpp +++ b/wled00/notify.cpp @@ -1,7 +1,7 @@ -#include "wled_notify.h" +#include "notify.h" #include "wled.h" #include "src/dependencies/e131/ESPAsyncE131.h" -#include "wled_led.h" +#include "led.h" #define WLEDPACKETSIZE 29 #define UDP_IN_MAXSIZE 1472 diff --git a/wled00/wled_notify.h b/wled00/notify.h similarity index 92% rename from wled00/wled_notify.h rename to wled00/notify.h index 04c65aa4..a0fbfde2 100644 --- a/wled00/wled_notify.h +++ b/wled00/notify.h @@ -1,18 +1,18 @@ -#ifndef WLED_NOTIFY_H -#define WLED_NOTIFY_H -#include -#include "src/dependencies/e131/ESPAsyncE131.h" -#include "const.h" -/* - * UDP notifier - */ -//union e131_packet_t; // Will this compile? -class IPAddress; - -void notify(byte callMode, bool followUp=false); -void arlsLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC); -void handleE131Packet(e131_packet_t* p, IPAddress clientIP); -void handleNotifications(); -void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w); - +#ifndef WLED_NOTIFY_H +#define WLED_NOTIFY_H +#include +#include "src/dependencies/e131/ESPAsyncE131.h" +#include "const.h" +/* + * UDP notifier + */ +//union e131_packet_t; // Will this compile? +class IPAddress; + +void notify(byte callMode, bool followUp=false); +void arlsLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC); +void handleE131Packet(e131_packet_t* p, IPAddress clientIP); +void handleNotifications(); +void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w); + #endif // WLED_NOTIFY_H \ No newline at end of file diff --git a/wled00/wled_ntp.cpp b/wled00/ntp.cpp similarity index 99% rename from wled00/wled_ntp.cpp rename to wled00/ntp.cpp index d8d9c38a..3435760b 100644 --- a/wled00/wled_ntp.cpp +++ b/wled00/ntp.cpp @@ -1,6 +1,6 @@ -#include "wled_ntp.h" +#include "ntp.h" #include "wled.h" -#include "wled_eeprom.h" +#include "eeprom.h" TimeChangeRule UTCr = {Last, Sun, Mar, 1, 0}; // UTC Timezone tzUTC(UTCr, UTCr); diff --git a/wled00/wled_ntp.h b/wled00/ntp.h similarity index 82% rename from wled00/wled_ntp.h rename to wled00/ntp.h index be683d14..9029661d 100644 --- a/wled00/wled_ntp.h +++ b/wled00/ntp.h @@ -1,19 +1,18 @@ -#ifndef WLED_NTP_H -#define WLED_NTP_H -#include -#include "timezone/Timezone.h" -/* - * Acquires time from NTP server - */ - -void handleNetworkTime(); -void sendNTPPacket(); -bool checkNTPResponse(); -void updateLocalTime(); -void getTimeString(char* out); -bool checkCountdown(); -void setCountdown(); -byte weekdayMondayFirst(); -void checkTimers(); - +#ifndef WLED_NTP_H +#define WLED_NTP_H +#include +/* + * Acquires time from NTP server + */ + +void handleNetworkTime(); +void sendNTPPacket(); +bool checkNTPResponse(); +void updateLocalTime(); +void getTimeString(char* out); +bool checkCountdown(); +void setCountdown(); +byte weekdayMondayFirst(); +void checkTimers(); + #endif // WLED_NTP_H \ No newline at end of file diff --git a/wled00/wled_overlay.cpp b/wled00/overlay.cpp similarity index 98% rename from wled00/wled_overlay.cpp rename to wled00/overlay.cpp index 8cb70786..ccdd3d0c 100644 --- a/wled00/wled_overlay.cpp +++ b/wled00/overlay.cpp @@ -1,7 +1,7 @@ -#include "wled_overlay.h" +#include "overlay.h" #include "wled.h" -#include "wled_cronixie.h" -#include "wled_ntp.h" +#include "cronixie.h" +#include "ntp.h" void initCronixie() { diff --git a/wled00/wled_overlay.h b/wled00/overlay.h similarity index 87% rename from wled00/wled_overlay.h rename to wled00/overlay.h index ec18f45b..b403a6e2 100644 --- a/wled00/wled_overlay.h +++ b/wled00/overlay.h @@ -1,14 +1,14 @@ -#ifndef WLED_OVERLAYS_H -#define WLED_OVERLAYS_H -#include -/* - * Used to draw clock overlays over the strip - */ - -void initCronixie(); -void handleOverlays(); -void handleOverlayDraw(); -void _overlayAnalogCountdown(); -void _overlayAnalogClock(); - +#ifndef WLED_OVERLAYS_H +#define WLED_OVERLAYS_H +#include +/* + * Used to draw clock overlays over the strip + */ + +void initCronixie(); +void handleOverlays(); +void handleOverlayDraw(); +void _overlayAnalogCountdown(); +void _overlayAnalogClock(); + #endif // WLED_OVERLAY_H \ No newline at end of file diff --git a/wled00/wled_server.cpp b/wled00/server.cpp similarity index 99% rename from wled00/wled_server.cpp rename to wled00/server.cpp index 542abea4..3249466c 100644 --- a/wled00/wled_server.cpp +++ b/wled00/server.cpp @@ -1,9 +1,9 @@ -#include "wled_server.h" +#include "server.h" #include "wled.h" -#include "wled_file.h" -#include "wled_set.h" -#include "wled_json.h" -#include "wled_xml.h" +#include "file.h" +#include "set.h" +#include "json.h" +#include "xml.h" //Is this an IP? diff --git a/wled00/wled_server.h b/wled00/server.h similarity index 93% rename from wled00/wled_server.h rename to wled00/server.h index 46adc962..ff7133d6 100644 --- a/wled00/wled_server.h +++ b/wled00/server.h @@ -1,21 +1,21 @@ -#ifndef WLED_SERVER_H -#define WLED_SERVER_H -#include -/* - * Server page declarations - */ -class AsyncWebServerRequest; - - -bool isIp(String str); -bool captivePortal(AsyncWebServerRequest *request); -void initServer(); -void serveIndexOrWelcome(AsyncWebServerRequest *request); -void serveIndex(AsyncWebServerRequest* request); -String msgProcessor(const String& var); -void serveMessage(AsyncWebServerRequest* request, uint16_t code, String headl, String subl="", byte optionT=255); -String settingsProcessor(const String& var); -String dmxProcessor(const String& var); -void serveSettings(AsyncWebServerRequest* request); - +#ifndef WLED_SERVER_H +#define WLED_SERVER_H +#include +/* + * Server page declarations + */ +class AsyncWebServerRequest; + + +bool isIp(String str); +bool captivePortal(AsyncWebServerRequest *request); +void initServer(); +void serveIndexOrWelcome(AsyncWebServerRequest *request); +void serveIndex(AsyncWebServerRequest* request); +String msgProcessor(const String& var); +void serveMessage(AsyncWebServerRequest* request, uint16_t code, String headl, String subl="", byte optionT=255); +String settingsProcessor(const String& var); +String dmxProcessor(const String& var); +void serveSettings(AsyncWebServerRequest* request); + #endif //WLED_SERVER_H \ No newline at end of file diff --git a/wled00/wled_set.cpp b/wled00/set.cpp similarity index 98% rename from wled00/wled_set.cpp rename to wled00/set.cpp index 66d9ff1e..1dfeb19d 100644 --- a/wled00/wled_set.cpp +++ b/wled00/set.cpp @@ -1,13 +1,13 @@ -#include "wled_set.h" +#include "set.h" #include "wled.h" -#include "wled_colors.h" -#include "wled_hue.h" -#include "wled_led.h" -#include "wled_blynk.h" -#include "wled_eeprom.h" -#include "wled_alexa.h" -#include "wled_cronixie.h" -#include "wled_xml.h" +#include "colors.h" +#include "hue.h" +#include "led.h" +#include "blynk.h" +#include "eeprom.h" +#include "alexa.h" +#include "cronixie.h" +#include "xml.h" void _setRandomColor(bool _sec,bool fromButton) { diff --git a/wled00/wled_set.h b/wled00/set.h similarity index 93% rename from wled00/wled_set.h rename to wled00/set.h index ebee8c92..6bc7dbd6 100644 --- a/wled00/wled_set.h +++ b/wled00/set.h @@ -1,16 +1,16 @@ -#ifndef WLED_SET_H -#define WLED_SET_H -#include -#include -/* - * Receives client input - */ - -void _setRandomColor(bool _sec,bool fromButton=false); -bool isAsterisksOnly(const char* str, byte maxLen); -void handleSettingsSet(AsyncWebServerRequest *request, byte subPage); -bool handleSet(AsyncWebServerRequest *request, const String& req); -int getNumVal(const String* req, uint16_t pos); -bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte maxv=255); - +#ifndef WLED_SET_H +#define WLED_SET_H +#include +#include +/* + * Receives client input + */ + +void _setRandomColor(bool _sec,bool fromButton=false); +bool isAsterisksOnly(const char* str, byte maxLen); +void handleSettingsSet(AsyncWebServerRequest *request, byte subPage); +bool handleSet(AsyncWebServerRequest *request, const String& req); +int getNumVal(const String* req, uint16_t pos); +bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte maxv=255); + #endif // WLED_SET_H \ No newline at end of file diff --git a/wled00/wled_usermod.cpp b/wled00/usermod.cpp similarity index 100% rename from wled00/wled_usermod.cpp rename to wled00/usermod.cpp diff --git a/wled00/wled_usermod.h b/wled00/usermod.h similarity index 77% rename from wled00/wled_usermod.h rename to wled00/usermod.h index 61ef6b78..8269c6e9 100644 --- a/wled00/wled_usermod.h +++ b/wled00/usermod.h @@ -1,8 +1,8 @@ -#ifndef WLED_USERMOD_H -#define WLED_USERMOD_H - -void userSetup(); -void userConnected(); -void userLoop(); - +#ifndef WLED_USERMOD_H +#define WLED_USERMOD_H + +void userSetup(); +void userConnected(); +void userLoop(); + #endif // WLED_USERMOD_H \ No newline at end of file diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 3b3d6936..106f503b 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -1,882 +1,883 @@ -#include "wled.h" -#include -#include "wled_led.h" -#include "wled_ir.h" -#include "wled_notify.h" -#include "wled_alexa.h" -#include "wled_overlay.h" -#include "wled_file.h" -#include "wled_button.h" -#include "wled_ntp.h" -#include "wled_usermod.h" -#include "wled_blynk.h" -#include "wled_hue.h" -#include "wled_mqtt.h" -#include "wled_eeprom.h" -#include "wled_server.h" -// Global Variable definitions -char versionString[] = "0.9.1"; - -//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 -#define ABL_MILLIAMPS_DEFAULT 850; //auto lower brightness to stay close to milliampere limit -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 - -#define E131_MAX_UNIVERSE_COUNT 9 -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; -#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 -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; - -//function prototypes -void colorFromUint32(uint32_t, bool = false); -void serveMessage(AsyncWebServerRequest *, uint16_t, String, String, byte); -void handleE131Packet(e131_packet_t *, IPAddress); -void arlsLock(uint32_t, byte); -void handleOverlayDraw(); - -//udp interface objects -WiFiUDP notifierUdp, rgbUdp; -WiFiUDP ntpUdp; -ESPAsyncE131 e131(handleE131Packet); -bool e131NewData = false; - -//led fx library object -WS2812FX strip = WS2812FX(); - -#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) -unsigned long debugTime = 0; -int lastWifiState = 3; -unsigned long wifiStateChangedTime = 0; -int loops = 0; -#else -#define DEBUG_PRINT(x) -#define DEBUG_PRINTLN(x) -#define DEBUG_PRINTF(x) -#endif - - - -WLED::WLED() { - -} - -//turns all LEDs off and restarts ESP -void WLED::reset() -{ - briT = 0; - long dly = millis(); - while (millis() - dly < 250) - { - yield(); //enough time to send response to client - } - setAllLeds(); - DEBUG_PRINTLN("MODULE RESET"); - ESP.restart(); -} - -bool oappendi(int i) -{ - char s[11]; - sprintf(s, "%ld", i); - return oappend(s); -} - -bool oappend(const char *txt) -{ - uint16_t len = strlen(txt); - if (olen + len >= OMAX) - return false; //buffer full - strcpy(obuf + olen, txt); - olen += len; - return true; -} - -void WLED::loop() -{ - handleIR(); //2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too - handleConnection(); - handleSerial(); - handleNotifications(); - handleTransitions(); -#ifdef WLED_ENABLE_DMX - handleDMX(); -#endif - userLoop(); - - yield(); - handleIO(); - handleIR(); - handleNetworkTime(); - handleAlexa(); - - handleOverlays(); - yield(); -#ifdef WLED_USE_ANALOG_LEDS - strip.setRgbwPwm(); -#endif - - if (doReboot) - reset(); - - if (!realtimeMode) //block stuff if WARLS/Adalight is enabled - { - if (apActive) - dnsServer.processNextRequest(); -#ifndef WLED_DISABLE_OTA - if (WLED_CONNECTED && aOtaEnabled) - ArduinoOTA.handle(); -#endif - handleNightlight(); - yield(); - - handleHue(); - handleBlynk(); - - yield(); - if (!offMode) - strip.service(); - } - yield(); -#ifdef ESP8266 - MDNS.update(); -#endif - if (millis() - lastMqttReconnectAttempt > 30000) - initMqtt(); - -//DEBUG serial logging -#ifdef WLED_DEBUG - if (millis() - debugTime > 9999) - { - DEBUG_PRINTLN("---DEBUG INFO---"); - DEBUG_PRINT("Runtime: "); - DEBUG_PRINTLN(millis()); - DEBUG_PRINT("Unix time: "); - DEBUG_PRINTLN(now()); - DEBUG_PRINT("Free heap: "); - DEBUG_PRINTLN(ESP.getFreeHeap()); - DEBUG_PRINT("Wifi state: "); - DEBUG_PRINTLN(WiFi.status()); - if (WiFi.status() != lastWifiState) - { - wifiStateChangedTime = millis(); - } - lastWifiState = WiFi.status(); - DEBUG_PRINT("State time: "); - DEBUG_PRINTLN(wifiStateChangedTime); - DEBUG_PRINT("NTP last sync: "); - DEBUG_PRINTLN(ntpLastSyncTime); - DEBUG_PRINT("Client IP: "); - DEBUG_PRINTLN(WiFi.localIP()); - DEBUG_PRINT("Loops/sec: "); - DEBUG_PRINTLN(loops / 10); - loops = 0; - debugTime = millis(); - } - loops++; -#endif // WLED_DEBU -} - -void WLED::wledInit() -{ - EEPROM.begin(EEPSIZE); - ledCount = EEPROM.read(229) + ((EEPROM.read(398) << 8) & 0xFF00); - if (ledCount > MAX_LEDS || ledCount == 0) - ledCount = 30; - -#ifdef ESP8266 -#if LEDPIN == 3 - if (ledCount > MAX_LEDS_DMA) - ledCount = MAX_LEDS_DMA; //DMA method uses too much ram -#endif -#endif - Serial.begin(115200); - Serial.setTimeout(50); - DEBUG_PRINTLN(); - DEBUG_PRINT("---WLED "); - DEBUG_PRINT(versionString); - DEBUG_PRINT(" "); - DEBUG_PRINT(VERSION); - DEBUG_PRINTLN(" INIT---"); -#ifdef ARDUINO_ARCH_ESP32 - DEBUG_PRINT("esp32 "); - DEBUG_PRINTLN(ESP.getSdkVersion()); -#else - DEBUG_PRINT("esp8266 "); - DEBUG_PRINTLN(ESP.getCoreVersion()); -#endif - int heapPreAlloc = ESP.getFreeHeap(); - DEBUG_PRINT("heap "); - DEBUG_PRINTLN(ESP.getFreeHeap()); - - strip.init(EEPROM.read(372), ledCount, EEPROM.read(2204)); //init LEDs quickly - strip.setBrightness(0); - - DEBUG_PRINT("LEDs inited. heap usage ~"); - DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap()); - -#ifndef WLED_DISABLE_FILESYSTEM -#ifdef ARDUINO_ARCH_ESP32 - SPIFFS.begin(true); -#endif - SPIFFS.begin(); -#endif - - DEBUG_PRINTLN("Load EEPROM"); - loadSettingsFromEEPROM(true); - beginStrip(); - userSetup(); - if (strcmp(clientSSID, DEFAULT_CLIENT_SSID) == 0) - showWelcomePage = true; - WiFi.persistent(false); - - if (macroBoot > 0) - applyMacro(macroBoot); - Serial.println("Ada"); - - //generate module IDs - escapedMac = WiFi.macAddress(); - escapedMac.replace(":", ""); - escapedMac.toLowerCase(); - if (strcmp(cmDNS, "x") == 0) //fill in unique mdns default - { - strcpy(cmDNS, "wled-"); - sprintf(cmDNS + 5, "%*s", 6, escapedMac.c_str() + 6); - } - if (mqttDeviceTopic[0] == 0) - { - strcpy(mqttDeviceTopic, "wled/"); - sprintf(mqttDeviceTopic + 5, "%*s", 6, escapedMac.c_str() + 6); - } - if (mqttClientID[0] == 0) - { - strcpy(mqttClientID, "WLED-"); - sprintf(mqttClientID + 5, "%*s", 6, escapedMac.c_str() + 6); - } - - strip.service(); - -#ifndef WLED_DISABLE_OTA - if (aOtaEnabled) - { - ArduinoOTA.onStart([]() { -#ifdef ESP8266 - wifi_set_sleep_type(NONE_SLEEP_T); -#endif - DEBUG_PRINTLN("Start ArduinoOTA"); - }); - if (strlen(cmDNS) > 0) - ArduinoOTA.setHostname(cmDNS); - } -#endif -#ifdef WLED_ENABLE_DMX - dmx.init(512); // initialize with bus length -#endif - //HTTP server page init - initServer(); -} - -void WLED::beginStrip() -{ - // Initialize NeoPixel Strip and button - strip.setShowCallback(handleOverlayDraw); - -#ifdef BTNPIN - pinMode(BTNPIN, INPUT_PULLUP); -#endif - - if (bootPreset > 0) - applyPreset(bootPreset, turnOnAtBoot); - colorUpdated(NOTIFIER_CALL_MODE_INIT); - -//init relay pin -#if RLYPIN >= 0 - pinMode(RLYPIN, OUTPUT); -#if RLYMDE - digitalWrite(RLYPIN, bri); -#else - digitalWrite(RLYPIN, !bri); -#endif -#endif - - //disable button if it is "pressed" unintentionally -#ifdef BTNPIN - if (digitalRead(BTNPIN) == LOW) - buttonEnabled = false; -#else - buttonEnabled = false; -#endif -} - -void WLED::initAP(bool resetAP) -{ - if (apBehavior == AP_BEHAVIOR_BUTTON_ONLY && !resetAP) - return; - - if (!apSSID[0] || resetAP) - strcpy(apSSID, "WLED-AP"); - if (resetAP) - strcpy(apPass, DEFAULT_AP_PASS); - DEBUG_PRINT("Opening access point "); - DEBUG_PRINTLN(apSSID); - WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255, 255, 255, 0)); - WiFi.softAP(apSSID, apPass, apChannel, apHide); - - if (!apActive) //start captive portal if AP active - { - DEBUG_PRINTLN("Init AP interfaces"); - server.begin(); - if (udpPort > 0 && udpPort != ntpLocalPort) - { - udpConnected = notifierUdp.begin(udpPort); - } - if (udpRgbPort > 0 && udpRgbPort != ntpLocalPort && udpRgbPort != udpPort) - { - udpRgbConnected = rgbUdp.begin(udpRgbPort); - } - - dnsServer.setErrorReplyCode(DNSReplyCode::NoError); - dnsServer.start(53, "*", WiFi.softAPIP()); - } - apActive = true; -} - -void WLED::initConnection() -{ - WiFi.disconnect(); //close old connections -#ifdef ESP8266 - WiFi.setPhyMode(WIFI_PHY_MODE_11N); -#endif - - if (staticIP[0] != 0 && staticGateway[0] != 0) - { - WiFi.config(staticIP, staticGateway, staticSubnet, IPAddress(8, 8, 8, 8)); - } - else - { - WiFi.config(0U, 0U, 0U); - } - - lastReconnectAttempt = millis(); - - if (!WLED_WIFI_CONFIGURED) - { - DEBUG_PRINT("No connection configured. "); - if (!apActive) - initAP(); //instantly go to ap mode - return; - } - else if (!apActive) - { - if (apBehavior == AP_BEHAVIOR_ALWAYS) - { - initAP(); - } - else - { - DEBUG_PRINTLN("Access point disabled."); - WiFi.softAPdisconnect(true); - } - } - showWelcomePage = false; - - DEBUG_PRINT("Connecting to "); - DEBUG_PRINT(clientSSID); - DEBUG_PRINTLN("..."); - -#ifdef ESP8266 - WiFi.hostname(serverDescription); -#endif - - WiFi.begin(clientSSID, clientPass); - -#ifdef ARDUINO_ARCH_ESP32 - WiFi.setSleep(!noWifiSleep); - WiFi.setHostname(serverDescription); -#else - wifi_set_sleep_type((noWifiSleep) ? NONE_SLEEP_T : MODEM_SLEEP_T); -#endif -} - -void WLED::initInterfaces() -{ - DEBUG_PRINTLN("Init STA interfaces"); - - if (hueIP[0] == 0) - { - hueIP[0] = WiFi.localIP()[0]; - hueIP[1] = WiFi.localIP()[1]; - hueIP[2] = WiFi.localIP()[2]; - } - - //init Alexa hue emulation - if (alexaEnabled) - alexaInit(); - -#ifndef WLED_DISABLE_OTA - if (aOtaEnabled) - ArduinoOTA.begin(); -#endif - - strip.service(); - // Set up mDNS responder: - if (strlen(cmDNS) > 0) - { - if (!aOtaEnabled) - MDNS.begin(cmDNS); - - DEBUG_PRINTLN("mDNS started"); - MDNS.addService("http", "tcp", 80); - MDNS.addService("wled", "tcp", 80); - MDNS.addServiceTxt("wled", "tcp", "mac", escapedMac.c_str()); - } - server.begin(); - - if (udpPort > 0 && udpPort != ntpLocalPort) - { - udpConnected = notifierUdp.begin(udpPort); - if (udpConnected && udpRgbPort != udpPort) - udpRgbConnected = rgbUdp.begin(udpRgbPort); - } - if (ntpEnabled) - ntpConnected = ntpUdp.begin(ntpLocalPort); - - initBlynk(blynkApiKey); - e131.begin((e131Multicast) ? E131_MULTICAST : E131_UNICAST, e131Universe, E131_MAX_UNIVERSE_COUNT); - reconnectHue(); - initMqtt(); - interfacesInited = true; - wasConnected = true; -} - -byte stacO = 0; -uint32_t lastHeap; -unsigned long heapTime = 0; - -void WLED::handleConnection() -{ - 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 - if (millis() - heapTime > 5000) - { - uint32_t heap = ESP.getFreeHeap(); - if (heap < 9000 && lastHeap < 9000) - { - DEBUG_PRINT("Heap too low! "); - DEBUG_PRINTLN(heap); - forceReconnect = true; - } - lastHeap = heap; - heapTime = millis(); - } - - byte stac = 0; - if (apActive) - { -#ifdef ESP8266 - stac = wifi_softap_get_station_num(); -#else - wifi_sta_list_t stationList; - esp_wifi_ap_get_sta_list(&stationList); - stac = stationList.num; -#endif - if (stac != stacO) - { - stacO = stac; - DEBUG_PRINT("Connected AP clients: "); - DEBUG_PRINTLN(stac); - if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) - { //trying to connect, but not connected - if (stac) - WiFi.disconnect(); //disable search so that AP can work - else - initConnection(); //restart search - } - } - } - if (forceReconnect) - { - DEBUG_PRINTLN("Forcing reconnect."); - initConnection(); - interfacesInited = false; - forceReconnect = false; - wasConnected = false; - return; - } - if (!WLED_CONNECTED) - { - if (interfacesInited) - { - DEBUG_PRINTLN("Disconnected!"); - interfacesInited = false; - initConnection(); - } - if (millis() - lastReconnectAttempt > ((stac) ? 300000 : 20000) && WLED_WIFI_CONFIGURED) - initConnection(); - if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) - initAP(); - } - else if (!interfacesInited) - { //newly connected - DEBUG_PRINTLN(""); - DEBUG_PRINT("Connected! IP address: "); - DEBUG_PRINTLN(WiFi.localIP()); - initInterfaces(); - userConnected(); - - //shut down AP - if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive) - { - dnsServer.stop(); - WiFi.softAPdisconnect(true); - apActive = false; - DEBUG_PRINTLN("Access point disabled."); - } - } -} - -//by https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp -int getSignalQuality(int rssi) -{ - int quality = 0; - - if (rssi <= -100) - { - quality = 0; - } - else if (rssi >= -50) - { - quality = 100; - } - else - { - quality = 2 * (rssi + 100); - } - return quality; +#include "wled.h" +#include +#include "led.h" +#include "ir.h" +#include "notify.h" +#include "alexa.h" +#include "overlay.h" +#include "file.h" +#include "button.h" +#include "ntp.h" +#include "usermod.h" +#include "blynk.h" +#include "hue.h" +#include "mqtt.h" +#include "eeprom.h" +#include "server.h" +// replaced +// Global Variable definitions +char versionString[] = "0.9.1"; + +//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 +#define ABL_MILLIAMPS_DEFAULT 850; //auto lower brightness to stay close to milliampere limit +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 + +#define E131_MAX_UNIVERSE_COUNT 9 +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; +#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 +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; + +//function prototypes +void colorFromUint32(uint32_t, bool = false); +void serveMessage(AsyncWebServerRequest *, uint16_t, String, String, byte); +void handleE131Packet(e131_packet_t *, IPAddress); +void arlsLock(uint32_t, byte); +void handleOverlayDraw(); + +//udp interface objects +WiFiUDP notifierUdp, rgbUdp; +WiFiUDP ntpUdp; +ESPAsyncE131 e131(handleE131Packet); +bool e131NewData = false; + +//led fx library object +WS2812FX strip = WS2812FX(); + +#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) +unsigned long debugTime = 0; +int lastWifiState = 3; +unsigned long wifiStateChangedTime = 0; +int loops = 0; +#else +#define DEBUG_PRINT(x) +#define DEBUG_PRINTLN(x) +#define DEBUG_PRINTF(x) +#endif + + + +WLED::WLED() { + +} + +//turns all LEDs off and restarts ESP +void WLED::reset() +{ + briT = 0; + long dly = millis(); + while (millis() - dly < 250) + { + yield(); //enough time to send response to client + } + setAllLeds(); + DEBUG_PRINTLN("MODULE RESET"); + ESP.restart(); +} + +bool oappendi(int i) +{ + char s[11]; + sprintf(s, "%ld", i); + return oappend(s); +} + +bool oappend(const char *txt) +{ + uint16_t len = strlen(txt); + if (olen + len >= OMAX) + return false; //buffer full + strcpy(obuf + olen, txt); + olen += len; + return true; +} + +void WLED::loop() +{ + handleIR(); //2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too + handleConnection(); + handleSerial(); + handleNotifications(); + handleTransitions(); +#ifdef WLED_ENABLE_DMX + handleDMX(); +#endif + userLoop(); + + yield(); + handleIO(); + handleIR(); + handleNetworkTime(); + handleAlexa(); + + handleOverlays(); + yield(); +#ifdef WLED_USE_ANALOG_LEDS + strip.setRgbwPwm(); +#endif + + if (doReboot) + reset(); + + if (!realtimeMode) //block stuff if WARLS/Adalight is enabled + { + if (apActive) + dnsServer.processNextRequest(); +#ifndef WLED_DISABLE_OTA + if (WLED_CONNECTED && aOtaEnabled) + ArduinoOTA.handle(); +#endif + handleNightlight(); + yield(); + + handleHue(); + handleBlynk(); + + yield(); + if (!offMode) + strip.service(); + } + yield(); +#ifdef ESP8266 + MDNS.update(); +#endif + if (millis() - lastMqttReconnectAttempt > 30000) + initMqtt(); + +//DEBUG serial logging +#ifdef WLED_DEBUG + if (millis() - debugTime > 9999) + { + DEBUG_PRINTLN("---DEBUG INFO---"); + DEBUG_PRINT("Runtime: "); + DEBUG_PRINTLN(millis()); + DEBUG_PRINT("Unix time: "); + DEBUG_PRINTLN(now()); + DEBUG_PRINT("Free heap: "); + DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINT("Wifi state: "); + DEBUG_PRINTLN(WiFi.status()); + if (WiFi.status() != lastWifiState) + { + wifiStateChangedTime = millis(); + } + lastWifiState = WiFi.status(); + DEBUG_PRINT("State time: "); + DEBUG_PRINTLN(wifiStateChangedTime); + DEBUG_PRINT("NTP last sync: "); + DEBUG_PRINTLN(ntpLastSyncTime); + DEBUG_PRINT("Client IP: "); + DEBUG_PRINTLN(WiFi.localIP()); + DEBUG_PRINT("Loops/sec: "); + DEBUG_PRINTLN(loops / 10); + loops = 0; + debugTime = millis(); + } + loops++; +#endif // WLED_DEBU +} + +void WLED::wledInit() +{ + EEPROM.begin(EEPSIZE); + ledCount = EEPROM.read(229) + ((EEPROM.read(398) << 8) & 0xFF00); + if (ledCount > MAX_LEDS || ledCount == 0) + ledCount = 30; + +#ifdef ESP8266 +#if LEDPIN == 3 + if (ledCount > MAX_LEDS_DMA) + ledCount = MAX_LEDS_DMA; //DMA method uses too much ram +#endif +#endif + Serial.begin(115200); + Serial.setTimeout(50); + DEBUG_PRINTLN(); + DEBUG_PRINT("---WLED "); + DEBUG_PRINT(versionString); + DEBUG_PRINT(" "); + DEBUG_PRINT(VERSION); + DEBUG_PRINTLN(" INIT---"); +#ifdef ARDUINO_ARCH_ESP32 + DEBUG_PRINT("esp32 "); + DEBUG_PRINTLN(ESP.getSdkVersion()); +#else + DEBUG_PRINT("esp8266 "); + DEBUG_PRINTLN(ESP.getCoreVersion()); +#endif + int heapPreAlloc = ESP.getFreeHeap(); + DEBUG_PRINT("heap "); + DEBUG_PRINTLN(ESP.getFreeHeap()); + + strip.init(EEPROM.read(372), ledCount, EEPROM.read(2204)); //init LEDs quickly + strip.setBrightness(0); + + DEBUG_PRINT("LEDs inited. heap usage ~"); + DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap()); + +#ifndef WLED_DISABLE_FILESYSTEM +#ifdef ARDUINO_ARCH_ESP32 + SPIFFS.begin(true); +#endif + SPIFFS.begin(); +#endif + + DEBUG_PRINTLN("Load EEPROM"); + loadSettingsFromEEPROM(true); + beginStrip(); + userSetup(); + if (strcmp(clientSSID, DEFAULT_CLIENT_SSID) == 0) + showWelcomePage = true; + WiFi.persistent(false); + + if (macroBoot > 0) + applyMacro(macroBoot); + Serial.println("Ada"); + + //generate module IDs + escapedMac = WiFi.macAddress(); + escapedMac.replace(":", ""); + escapedMac.toLowerCase(); + if (strcmp(cmDNS, "x") == 0) //fill in unique mdns default + { + strcpy(cmDNS, "wled-"); + sprintf(cmDNS + 5, "%*s", 6, escapedMac.c_str() + 6); + } + if (mqttDeviceTopic[0] == 0) + { + strcpy(mqttDeviceTopic, "wled/"); + sprintf(mqttDeviceTopic + 5, "%*s", 6, escapedMac.c_str() + 6); + } + if (mqttClientID[0] == 0) + { + strcpy(mqttClientID, "WLED-"); + sprintf(mqttClientID + 5, "%*s", 6, escapedMac.c_str() + 6); + } + + strip.service(); + +#ifndef WLED_DISABLE_OTA + if (aOtaEnabled) + { + ArduinoOTA.onStart([]() { +#ifdef ESP8266 + wifi_set_sleep_type(NONE_SLEEP_T); +#endif + DEBUG_PRINTLN("Start ArduinoOTA"); + }); + if (strlen(cmDNS) > 0) + ArduinoOTA.setHostname(cmDNS); + } +#endif +#ifdef WLED_ENABLE_DMX + dmx.init(512); // initialize with bus length +#endif + //HTTP server page init + initServer(); +} + +void WLED::beginStrip() +{ + // Initialize NeoPixel Strip and button + strip.setShowCallback(handleOverlayDraw); + +#ifdef BTNPIN + pinMode(BTNPIN, INPUT_PULLUP); +#endif + + if (bootPreset > 0) + applyPreset(bootPreset, turnOnAtBoot); + colorUpdated(NOTIFIER_CALL_MODE_INIT); + +//init relay pin +#if RLYPIN >= 0 + pinMode(RLYPIN, OUTPUT); +#if RLYMDE + digitalWrite(RLYPIN, bri); +#else + digitalWrite(RLYPIN, !bri); +#endif +#endif + + //disable button if it is "pressed" unintentionally +#ifdef BTNPIN + if (digitalRead(BTNPIN) == LOW) + buttonEnabled = false; +#else + buttonEnabled = false; +#endif +} + +void WLED::initAP(bool resetAP) +{ + if (apBehavior == AP_BEHAVIOR_BUTTON_ONLY && !resetAP) + return; + + if (!apSSID[0] || resetAP) + strcpy(apSSID, "WLED-AP"); + if (resetAP) + strcpy(apPass, DEFAULT_AP_PASS); + DEBUG_PRINT("Opening access point "); + DEBUG_PRINTLN(apSSID); + WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255, 255, 255, 0)); + WiFi.softAP(apSSID, apPass, apChannel, apHide); + + if (!apActive) //start captive portal if AP active + { + DEBUG_PRINTLN("Init AP interfaces"); + server.begin(); + if (udpPort > 0 && udpPort != ntpLocalPort) + { + udpConnected = notifierUdp.begin(udpPort); + } + if (udpRgbPort > 0 && udpRgbPort != ntpLocalPort && udpRgbPort != udpPort) + { + udpRgbConnected = rgbUdp.begin(udpRgbPort); + } + + dnsServer.setErrorReplyCode(DNSReplyCode::NoError); + dnsServer.start(53, "*", WiFi.softAPIP()); + } + apActive = true; +} + +void WLED::initConnection() +{ + WiFi.disconnect(); //close old connections +#ifdef ESP8266 + WiFi.setPhyMode(WIFI_PHY_MODE_11N); +#endif + + if (staticIP[0] != 0 && staticGateway[0] != 0) + { + WiFi.config(staticIP, staticGateway, staticSubnet, IPAddress(8, 8, 8, 8)); + } + else + { + WiFi.config(0U, 0U, 0U); + } + + lastReconnectAttempt = millis(); + + if (!WLED_WIFI_CONFIGURED) + { + DEBUG_PRINT("No connection configured. "); + if (!apActive) + initAP(); //instantly go to ap mode + return; + } + else if (!apActive) + { + if (apBehavior == AP_BEHAVIOR_ALWAYS) + { + initAP(); + } + else + { + DEBUG_PRINTLN("Access point disabled."); + WiFi.softAPdisconnect(true); + } + } + showWelcomePage = false; + + DEBUG_PRINT("Connecting to "); + DEBUG_PRINT(clientSSID); + DEBUG_PRINTLN("..."); + +#ifdef ESP8266 + WiFi.hostname(serverDescription); +#endif + + WiFi.begin(clientSSID, clientPass); + +#ifdef ARDUINO_ARCH_ESP32 + WiFi.setSleep(!noWifiSleep); + WiFi.setHostname(serverDescription); +#else + wifi_set_sleep_type((noWifiSleep) ? NONE_SLEEP_T : MODEM_SLEEP_T); +#endif +} + +void WLED::initInterfaces() +{ + DEBUG_PRINTLN("Init STA interfaces"); + + if (hueIP[0] == 0) + { + hueIP[0] = WiFi.localIP()[0]; + hueIP[1] = WiFi.localIP()[1]; + hueIP[2] = WiFi.localIP()[2]; + } + + //init Alexa hue emulation + if (alexaEnabled) + alexaInit(); + +#ifndef WLED_DISABLE_OTA + if (aOtaEnabled) + ArduinoOTA.begin(); +#endif + + strip.service(); + // Set up mDNS responder: + if (strlen(cmDNS) > 0) + { + if (!aOtaEnabled) + MDNS.begin(cmDNS); + + DEBUG_PRINTLN("mDNS started"); + MDNS.addService("http", "tcp", 80); + MDNS.addService("wled", "tcp", 80); + MDNS.addServiceTxt("wled", "tcp", "mac", escapedMac.c_str()); + } + server.begin(); + + if (udpPort > 0 && udpPort != ntpLocalPort) + { + udpConnected = notifierUdp.begin(udpPort); + if (udpConnected && udpRgbPort != udpPort) + udpRgbConnected = rgbUdp.begin(udpRgbPort); + } + if (ntpEnabled) + ntpConnected = ntpUdp.begin(ntpLocalPort); + + initBlynk(blynkApiKey); + e131.begin((e131Multicast) ? E131_MULTICAST : E131_UNICAST, e131Universe, E131_MAX_UNIVERSE_COUNT); + reconnectHue(); + initMqtt(); + interfacesInited = true; + wasConnected = true; +} + +byte stacO = 0; +uint32_t lastHeap; +unsigned long heapTime = 0; + +void WLED::handleConnection() +{ + 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 + if (millis() - heapTime > 5000) + { + uint32_t heap = ESP.getFreeHeap(); + if (heap < 9000 && lastHeap < 9000) + { + DEBUG_PRINT("Heap too low! "); + DEBUG_PRINTLN(heap); + forceReconnect = true; + } + lastHeap = heap; + heapTime = millis(); + } + + byte stac = 0; + if (apActive) + { +#ifdef ESP8266 + stac = wifi_softap_get_station_num(); +#else + wifi_sta_list_t stationList; + esp_wifi_ap_get_sta_list(&stationList); + stac = stationList.num; +#endif + if (stac != stacO) + { + stacO = stac; + DEBUG_PRINT("Connected AP clients: "); + DEBUG_PRINTLN(stac); + if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) + { //trying to connect, but not connected + if (stac) + WiFi.disconnect(); //disable search so that AP can work + else + initConnection(); //restart search + } + } + } + if (forceReconnect) + { + DEBUG_PRINTLN("Forcing reconnect."); + initConnection(); + interfacesInited = false; + forceReconnect = false; + wasConnected = false; + return; + } + if (!WLED_CONNECTED) + { + if (interfacesInited) + { + DEBUG_PRINTLN("Disconnected!"); + interfacesInited = false; + initConnection(); + } + if (millis() - lastReconnectAttempt > ((stac) ? 300000 : 20000) && WLED_WIFI_CONFIGURED) + initConnection(); + if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) + initAP(); + } + else if (!interfacesInited) + { //newly connected + DEBUG_PRINTLN(""); + DEBUG_PRINT("Connected! IP address: "); + DEBUG_PRINTLN(WiFi.localIP()); + initInterfaces(); + userConnected(); + + //shut down AP + if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive) + { + dnsServer.stop(); + WiFi.softAPdisconnect(true); + apActive = false; + DEBUG_PRINTLN("Access point disabled."); + } + } +} + +//by https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp +int getSignalQuality(int rssi) +{ + int quality = 0; + + if (rssi <= -100) + { + quality = 0; + } + else if (rssi >= -50) + { + quality = 100; + } + else + { + quality = 2 * (rssi + 100); + } + return quality; } \ No newline at end of file diff --git a/wled00/wled.h b/wled00/wled.h index 3b744bcd..c6f791cd 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -1,519 +1,519 @@ -#ifndef WLED_H -#define WLED_H - -/* - Main sketch, global variable declarations -*/ -/* - * @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 (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): - -//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: -//#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_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 -//#define WLED_DEBUG - -//library inclusions -#include -#ifdef WLED_ENABLE_DMX -#include -DMXESPSerial dmx; -#endif -#ifdef ESP8266 -#include -#include -#include -extern "C" -{ -#include -} -#else //ESP32 -#include -#include "esp_wifi.h" -#include -#include -#include "SPIFFS.h" -#endif - -#include -#include -#include -#include -#ifndef WLED_DISABLE_OTA -#include -#endif -#include -#include "src/dependencies/time/TimeLib.h" -#include "src/dependencies/timezone/Timezone.h" -#ifndef WLED_DISABLE_ALEXA -#define ESPALEXA_ASYNC -#define ESPALEXA_NO_SUBPAGE -#define ESPALEXA_MAXDEVICES 1 -// #define ESPALEXA_DEBUG -#include "src/dependencies/espalexa/Espalexa.h" -#endif -#ifndef WLED_DISABLE_BLYNK -#include "src/dependencies/blynk/BlynkSimpleEsp.h" -#endif -#include "src/dependencies/e131/ESPAsyncE131.h" -#include "src/dependencies/async-mqtt-client/AsyncMqttClient.h" -#include "src/dependencies/json/AsyncJson-v6.h" -#include "src/dependencies/json/ArduinoJson-v6.h" -#include "html_ui.h" -#include "html_settings.h" -#include "html_other.h" -#include "FX.h" -#include "ir_codes.h" -#include "const.h" - -#ifndef CLIENT_SSID -#define CLIENT_SSID DEFAULT_CLIENT_SSID -#endif - -#ifndef CLIENT_PASS -#define CLIENT_PASS "" -#endif - -#if IR_PIN < 0 -#ifndef WLED_DISABLE_INFRARED -#define WLED_DISABLE_INFRARED -#endif -#endif - -#ifndef WLED_DISABLE_INFRARED -#include -#include -#include -#endif - -// remove flicker because PWM signal of RGB channels can become out of phase -#if defined(WLED_USE_ANALOG_LEDS) && defined(ESP8266) -#include "src/dependencies/arduino/core_esp8266_waveform.h" -#endif - -// enable additional debug output -#ifdef WLED_DEBUG -#ifndef ESP8266 -#include -#endif -#endif - -//version code in format yymmddb (b = daily build) -#define VERSION 2003222 - -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 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 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 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 - -#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 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 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 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 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 countdownDay, countdownHour; -extern byte countdownMin, countdownSec; - -extern byte macroBoot; //macro loaded after startup -extern byte macroNl; //after nightlight delay over -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 uint16_t userVar0, userVar1; - -#ifdef WLED_ENABLE_DMX -//dmx CONFIG -extern byte DMXChannels; // number of channels per fixture -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 -#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 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 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 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 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 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; -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 bool blynkEnabled; - -//preset cycling -extern bool presetCyclingEnabled; -extern byte presetCycleMin, presetCycleMax; -extern uint16_t presetCycleTime; -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 - -#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; -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 doPublishMqtt; - -//server library objects -extern AsyncWebServer server; -extern AsyncClient *hueClient; -extern AsyncMqttClient *mqtt; - -//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) - -//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 - - -// TODO: Inline? -//append new c string to temp buffer efficiently -bool oappend(const char *txt); -//append new number to temp buffer efficiently -bool oappendi(int i); -int getSignalQuality(int rssi); - -class WLED -{ -public: - static WLED &instance() - { - static WLED instance; - return instance; - } - - WLED(); - - void reset(); - void loop(); - - - //boot starts here - void setup() - { - wledInit(); - } - -public: // TODO: privacy - void wledInit(); - void beginStrip(); - - void handleConnection(); - void initAP(bool resetAP = false); - void initConnection(); - void initInterfaces(); -}; -#endif // WLED_H +#ifndef WLED_H +#define WLED_H + +/* + Main sketch, global variable declarations +*/ +/* + * @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 (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): + +//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: +//#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_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 +//#define WLED_DEBUG + +//library inclusions +#include +#ifdef WLED_ENABLE_DMX +#include +DMXESPSerial dmx; +#endif +#ifdef ESP8266 +#include +#include +#include +extern "C" +{ +#include +} +#else //ESP32 +#include +#include "esp_wifi.h" +#include +#include +#include "SPIFFS.h" +#endif + +#include +#include +#include +#include +#ifndef WLED_DISABLE_OTA +#include +#endif +#include +#include "src/dependencies/time/TimeLib.h" +#include "src/dependencies/timezone/Timezone.h" +#ifndef WLED_DISABLE_ALEXA +#define ESPALEXA_ASYNC +#define ESPALEXA_NO_SUBPAGE +#define ESPALEXA_MAXDEVICES 1 +// #define ESPALEXA_DEBUG +#include "src/dependencies/espalexa/Espalexa.h" +#endif +#ifndef WLED_DISABLE_BLYNK +#include "src/dependencies/blynk/BlynkSimpleEsp.h" +#endif +#include "src/dependencies/e131/ESPAsyncE131.h" +#include "src/dependencies/async-mqtt-client/AsyncMqttClient.h" +#include "src/dependencies/json/AsyncJson-v6.h" +#include "src/dependencies/json/ArduinoJson-v6.h" +#include "html_ui.h" +#include "html_settings.h" +#include "html_other.h" +#include "FX.h" +#include "ir_codes.h" +#include "const.h" + +#ifndef CLIENT_SSID +#define CLIENT_SSID DEFAULT_CLIENT_SSID +#endif + +#ifndef CLIENT_PASS +#define CLIENT_PASS "" +#endif + +#if IR_PIN < 0 +#ifndef WLED_DISABLE_INFRARED +#define WLED_DISABLE_INFRARED +#endif +#endif + +#ifndef WLED_DISABLE_INFRARED +#include +#include +#include +#endif + +// remove flicker because PWM signal of RGB channels can become out of phase +#if defined(WLED_USE_ANALOG_LEDS) && defined(ESP8266) +#include "src/dependencies/arduino/core_esp8266_waveform.h" +#endif + +// enable additional debug output +#ifdef WLED_DEBUG +#ifndef ESP8266 +#include +#endif +#endif + +//version code in format yymmddb (b = daily build) +#define VERSION 2003222 + +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 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 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 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 + +#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 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 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 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 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 countdownDay, countdownHour; +extern byte countdownMin, countdownSec; + +extern byte macroBoot; //macro loaded after startup +extern byte macroNl; //after nightlight delay over +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 uint16_t userVar0, userVar1; + +#ifdef WLED_ENABLE_DMX +//dmx CONFIG +extern byte DMXChannels; // number of channels per fixture +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 +#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 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 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 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 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 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; +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 bool blynkEnabled; + +//preset cycling +extern bool presetCyclingEnabled; +extern byte presetCycleMin, presetCycleMax; +extern uint16_t presetCycleTime; +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 + +#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; +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 doPublishMqtt; + +//server library objects +extern AsyncWebServer server; +extern AsyncClient *hueClient; +extern AsyncMqttClient *mqtt; + +//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) + +//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 + + +// TODO: Inline? +//append new c string to temp buffer efficiently +bool oappend(const char *txt); +//append new number to temp buffer efficiently +bool oappendi(int i); +int getSignalQuality(int rssi); + +class WLED +{ +public: + static WLED &instance() + { + static WLED instance; + return instance; + } + + WLED(); + + void reset(); + void loop(); + + + //boot starts here + void setup() + { + wledInit(); + } + +public: // TODO: privacy + void wledInit(); + void beginStrip(); + + void handleConnection(); + void initAP(bool resetAP = false); + void initConnection(); + void initInterfaces(); +}; +#endif // WLED_H diff --git a/wled00/wled_xml.cpp b/wled00/xml.cpp similarity index 99% rename from wled00/wled_xml.cpp rename to wled00/xml.cpp index 4f2b3f45..930ab4b0 100644 --- a/wled00/wled_xml.cpp +++ b/wled00/xml.cpp @@ -1,7 +1,7 @@ -#include "wled_xml.h" +#include "xml.h" #include "wled.h" -#include "wled_eeprom.h" -#include "wled_ntp.h" +#include "eeprom.h" +#include "ntp.h" //build XML response to HTTP /win API request diff --git a/wled00/wled_xml.h b/wled00/xml.h similarity index 92% rename from wled00/wled_xml.h rename to wled00/xml.h index 5cfb1dbb..02298295 100644 --- a/wled00/wled_xml.h +++ b/wled00/xml.h @@ -1,15 +1,15 @@ -#ifndef WLED_XML_H -#define WLED_XML_H -#include -#include - -/* - * Sending XML status files to client - */ -char* XML_response(AsyncWebServerRequest *request, char* dest = nullptr); -char* URL_response(AsyncWebServerRequest *request); -void sappend(char stype, const char* key, int val); -void sappends(char stype, const char* key, char* val); -void getSettingsJS(byte subPage, char* dest); - +#ifndef WLED_XML_H +#define WLED_XML_H +#include +#include + +/* + * Sending XML status files to client + */ +char* XML_response(AsyncWebServerRequest *request, char* dest = nullptr); +char* URL_response(AsyncWebServerRequest *request); +void sappend(char stype, const char* key, int val); +void sappends(char stype, const char* key, char* val); +void getSettingsJS(byte subPage, char* dest); + #endif // WLED_XML_H \ No newline at end of file From f99f13a090581ea037850b167edbe15d3d0daf98 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Sat, 28 Mar 2020 08:45:20 -0400 Subject: [PATCH 11/32] Avoid name collision. Fix wled instance access in ino. --- usermods/blynk_relay_control/wled06_usermod.ino | 2 +- usermods/stairway_wipe_basic/wled06_usermod.ino | 2 +- wled00/alexa.cpp | 2 +- wled00/button.cpp | 2 +- wled00/hue.cpp | 2 +- wled00/ir.cpp | 2 +- wled00/json.cpp | 2 +- wled00/led.cpp | 2 +- wled00/ntp.cpp | 4 +++- wled00/set.cpp | 2 +- wled00/usermod.cpp | 2 +- wled00/wled.cpp | 3 +-- wled00/wled00.ino | 6 ++---- wled00/{eeprom.cpp => wled_eeprom.cpp} | 3 ++- wled00/{eeprom.h => wled_eeprom.h} | 0 wled00/xml.cpp | 2 +- 16 files changed, 19 insertions(+), 19 deletions(-) rename wled00/{eeprom.cpp => wled_eeprom.cpp} (99%) rename wled00/{eeprom.h => wled_eeprom.h} (100%) diff --git a/usermods/blynk_relay_control/wled06_usermod.ino b/usermods/blynk_relay_control/wled06_usermod.ino index 1004b1ed..d4028ea5 100644 --- a/usermods/blynk_relay_control/wled06_usermod.ino +++ b/usermods/blynk_relay_control/wled06_usermod.ino @@ -1,7 +1,7 @@ /* * This file allows you to add own functionality to WLED more easily * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality - * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in wled01_eeprom.h) + * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in wled_eeprom.h) * bytes 2400+ are currently ununsed, but might be used for future wled features */ diff --git a/usermods/stairway_wipe_basic/wled06_usermod.ino b/usermods/stairway_wipe_basic/wled06_usermod.ino index 3d493cc1..0cc85df7 100644 --- a/usermods/stairway_wipe_basic/wled06_usermod.ino +++ b/usermods/stairway_wipe_basic/wled06_usermod.ino @@ -1,7 +1,7 @@ /* * This file allows you to add own functionality to WLED more easily * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality - * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in wled01_eeprom.h) + * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in wled_eeprom.h) * bytes 2400+ are currently ununsed, but might be used for future wled features */ diff --git a/wled00/alexa.cpp b/wled00/alexa.cpp index 621480d0..e35f5b35 100644 --- a/wled00/alexa.cpp +++ b/wled00/alexa.cpp @@ -2,7 +2,7 @@ #include "wled.h" #include "const.h" #include "led.h" -#include "eeprom.h" +#include "wled_eeprom.h" #include "colors.h" #ifndef WLED_DISABLE_ALEXA diff --git a/wled00/button.cpp b/wled00/button.cpp index 1afb54d5..a80061ee 100644 --- a/wled00/button.cpp +++ b/wled00/button.cpp @@ -1,7 +1,7 @@ #include "button.h" #include "wled.h" #include "led.h" -#include "eeprom.h" +#include "wled_eeprom.h" #include "set.h" /* diff --git a/wled00/hue.cpp b/wled00/hue.cpp index 484f2bd8..a186a314 100644 --- a/wled00/hue.cpp +++ b/wled00/hue.cpp @@ -1,7 +1,7 @@ #include "hue.h" #include "wled.h" #include "colors.h" -#include "eeprom.h" +#include "wled_eeprom.h" #include "notify.h" #include "led.h" diff --git a/wled00/ir.cpp b/wled00/ir.cpp index fcc0f5dd..32b0ee93 100644 --- a/wled00/ir.cpp +++ b/wled00/ir.cpp @@ -2,7 +2,7 @@ #include "wled.h" #include "led.h" #include "colors.h" -#include "eeprom.h" +#include "wled_eeprom.h" #if defined(WLED_DISABLE_INFRARED) void handleIR(){} diff --git a/wled00/json.cpp b/wled00/json.cpp index 73659e7e..6d71e414 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -1,6 +1,6 @@ #include "json.h" #include "wled.h" -#include "eeprom.h" +#include "wled_eeprom.h" #include "led.h" void deserializeSegment(JsonObject elem, byte it) diff --git a/wled00/led.cpp b/wled00/led.cpp index 4a16dcff..7f4d6309 100644 --- a/wled00/led.cpp +++ b/wled00/led.cpp @@ -2,7 +2,7 @@ #include "wled.h" #include "notify.h" #include "blynk.h" -#include "eeprom.h" +#include "wled_eeprom.h" #include "mqtt.h" #include "colors.h" diff --git a/wled00/ntp.cpp b/wled00/ntp.cpp index 3435760b..20663109 100644 --- a/wled00/ntp.cpp +++ b/wled00/ntp.cpp @@ -1,6 +1,8 @@ #include "ntp.h" +#include "src/dependencies/timezone/Timezone.h" #include "wled.h" -#include "eeprom.h" +#include "wled_eeprom.h" + TimeChangeRule UTCr = {Last, Sun, Mar, 1, 0}; // UTC Timezone tzUTC(UTCr, UTCr); diff --git a/wled00/set.cpp b/wled00/set.cpp index 1dfeb19d..0a7a4ff4 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -4,7 +4,7 @@ #include "hue.h" #include "led.h" #include "blynk.h" -#include "eeprom.h" +#include "wled_eeprom.h" #include "alexa.h" #include "cronixie.h" #include "xml.h" diff --git a/wled00/usermod.cpp b/wled00/usermod.cpp index c780ffee..6589c07c 100644 --- a/wled00/usermod.cpp +++ b/wled00/usermod.cpp @@ -2,7 +2,7 @@ /* * This file allows you to add own functionality to WLED more easily * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality - * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in wled01_eeprom.h) + * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in wled01_wled_eeprom.h) * bytes 2400+ are currently ununsed, but might be used for future wled features */ diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 106f503b..2d474eb3 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -12,9 +12,8 @@ #include "blynk.h" #include "hue.h" #include "mqtt.h" -#include "eeprom.h" +#include "wled_eeprom.h" #include "server.h" -// replaced // Global Variable definitions char versionString[] = "0.9.1"; diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 522447d0..e3334837 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -3,12 +3,10 @@ */ #include "wled.h" -WLED& wled; void setup() { - wled = WLED::instance(); - wled.setup(); + WLED::instance().setup(); } void loop() { - wled.loop(); + WLED::instance().loop(); } \ No newline at end of file diff --git a/wled00/eeprom.cpp b/wled00/wled_eeprom.cpp similarity index 99% rename from wled00/eeprom.cpp rename to wled00/wled_eeprom.cpp index 68b8c35f..0087641a 100644 --- a/wled00/eeprom.cpp +++ b/wled00/wled_eeprom.cpp @@ -1,4 +1,5 @@ -#include "eeprom.h" +#include "wled_eeprom.h" +#include #include "wled.h" #include "cronixie.h" #include "ntp.h" diff --git a/wled00/eeprom.h b/wled00/wled_eeprom.h similarity index 100% rename from wled00/eeprom.h rename to wled00/wled_eeprom.h diff --git a/wled00/xml.cpp b/wled00/xml.cpp index 930ab4b0..09e42011 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -1,6 +1,6 @@ #include "xml.h" #include "wled.h" -#include "eeprom.h" +#include "wled_eeprom.h" #include "ntp.h" From cc2de04f6b3c912291bbf57d15a06f40ccf99620 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Sat, 28 Mar 2020 09:24:07 -0400 Subject: [PATCH 12/32] Avoid name collision. --- wled00/wled.cpp | 2 +- wled00/{server.cpp => wled_server.cpp} | 2 +- wled00/{server.h => wled_server.h} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename wled00/{server.cpp => wled_server.cpp} (99%) rename wled00/{server.h => wled_server.h} (100%) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 2d474eb3..4945ffb7 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -13,7 +13,7 @@ #include "hue.h" #include "mqtt.h" #include "wled_eeprom.h" -#include "server.h" +#include "wled_server.h" // Global Variable definitions char versionString[] = "0.9.1"; diff --git a/wled00/server.cpp b/wled00/wled_server.cpp similarity index 99% rename from wled00/server.cpp rename to wled00/wled_server.cpp index 3249466c..d5b4eebc 100644 --- a/wled00/server.cpp +++ b/wled00/wled_server.cpp @@ -1,4 +1,4 @@ -#include "server.h" +#include "wled_server.h" #include "wled.h" #include "file.h" #include "set.h" diff --git a/wled00/server.h b/wled00/wled_server.h similarity index 100% rename from wled00/server.h rename to wled00/wled_server.h From d2f55e1064a1188f0b831979c4e9ddde96c29a53 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 03:55:44 -0400 Subject: [PATCH 13/32] Make dmx.h header only. --- wled00/dmx.cpp | 52 ----------------------------------------------- wled00/dmx.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- wled00/wled.h | 4 ---- 3 files changed, 54 insertions(+), 57 deletions(-) delete mode 100644 wled00/dmx.cpp diff --git a/wled00/dmx.cpp b/wled00/dmx.cpp deleted file mode 100644 index d024ac71..00000000 --- a/wled00/dmx.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "dmx.h" -#include "wled.h" - -#ifdef WLED_ENABLE_DMX -void handleDMX() { - // TODO: calculate brightness manually if no shutter channel is set - - uint8_t brightness = strip.getBrightness(); - - 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 - byte w = in >> 24 & 0xFF; - byte r = in >> 16 & 0xFF; - byte g = in >> 8 & 0xFF; - byte b = in & 0xFF; - - int DMXFixtureStart = DMXStart + (DMXGap * i); - for (int j = 0; j < DMXChannels; j++) { - int DMXAddr = DMXFixtureStart + j; - switch (DMXFixtureMap[j]) { - case 0: // Set this channel to 0. Good way to tell strobe- and fade-functions to fuck right off. - dmx.write(DMXAddr, 0); - break; - case 1: // Red - dmx.write(DMXAddr, r); - break; - case 2: // Green - dmx.write(DMXAddr, g); - break; - case 3: // Blue - dmx.write(DMXAddr, b); - break; - case 4: // White - dmx.write(DMXAddr, w); - break; - case 5: // Shutter channel. Controls the brightness. - dmx.write(DMXAddr, brightness); - break; - case 6:// Sets this channel to 255. Like 0, but more wholesome. - dmx.write(DMXAddr, 255); - break; - } - } - } - - dmx.update(); // update the DMX bus -} - -#else -void handleDMX() {} -#endif diff --git a/wled00/dmx.h b/wled00/dmx.h index 707dec91..76aab484 100644 --- a/wled00/dmx.h +++ b/wled00/dmx.h @@ -1,11 +1,64 @@ #ifndef WLED_DMX_H #define WLED_DMX_H +#include "wled.h" /* * Support for DMX via MAX485. * Needs the espdmx library. You might have to change the output pin within the library. Sketchy, i know. * https://github.com/Rickgg/ESP-Dmx */ -void handleDMX(); +#ifdef WLED_ENABLE_DMX +#include +DMXESPSerial dmx; + +#ifdef WLED_ENABLE_DMX +void handleDMX() { + // TODO: calculate brightness manually if no shutter channel is set + + uint8_t brightness = strip.getBrightness(); + + 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 + byte w = in >> 24 & 0xFF; + byte r = in >> 16 & 0xFF; + byte g = in >> 8 & 0xFF; + byte b = in & 0xFF; + + int DMXFixtureStart = DMXStart + (DMXGap * i); + for (int j = 0; j < DMXChannels; j++) { + int DMXAddr = DMXFixtureStart + j; + switch (DMXFixtureMap[j]) { + case 0: // Set this channel to 0. Good way to tell strobe- and fade-functions to fuck right off. + dmx.write(DMXAddr, 0); + break; + case 1: // Red + dmx.write(DMXAddr, r); + break; + case 2: // Green + dmx.write(DMXAddr, g); + break; + case 3: // Blue + dmx.write(DMXAddr, b); + break; + case 4: // White + dmx.write(DMXAddr, w); + break; + case 5: // Shutter channel. Controls the brightness. + dmx.write(DMXAddr, brightness); + break; + case 6:// Sets this channel to 255. Like 0, but more wholesome. + dmx.write(DMXAddr, 255); + break; + } + } + } + + dmx.update(); // update the DMX bus +} + +#else +void handleDMX() {} +#endif #endif //WLED_DMX_H \ No newline at end of file diff --git a/wled00/wled.h b/wled00/wled.h index c6f791cd..e5c4f493 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -37,10 +37,6 @@ //library inclusions #include -#ifdef WLED_ENABLE_DMX -#include -DMXESPSerial dmx; -#endif #ifdef ESP8266 #include #include From 3e1eb02f54b674cbe74064f81b4eca987394e97f Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 04:21:47 -0400 Subject: [PATCH 14/32] Comment cleanup and line reduction. --- wled00/wled.h | 345 ++++++++++++++++++-------------------------------- 1 file changed, 124 insertions(+), 221 deletions(-) diff --git a/wled00/wled.h b/wled00/wled.h index e5c4f493..9e373216 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); From 408d63825a5176f370fd04b6ea4662c6a3d27286 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 04:26:41 -0400 Subject: [PATCH 15/32] Function prototype cleanup. --- wled00/set.cpp | 1 + wled00/wled.cpp | 8 +------- wled00/wled.h | 7 ------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/wled00/set.cpp b/wled00/set.cpp index 0a7a4ff4..f26795c8 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -8,6 +8,7 @@ #include "alexa.h" #include "cronixie.h" #include "xml.h" +#include "wled_server.h" void _setRandomColor(bool _sec,bool fromButton) { diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 4945ffb7..c6dac0d2 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -14,6 +14,7 @@ #include "mqtt.h" #include "wled_eeprom.h" #include "wled_server.h" + // Global Variable definitions char versionString[] = "0.9.1"; @@ -343,13 +344,6 @@ AsyncWebServer server(80); AsyncClient *hueClient = NULL; AsyncMqttClient *mqtt = NULL; -//function prototypes -void colorFromUint32(uint32_t, bool = false); -void serveMessage(AsyncWebServerRequest *, uint16_t, String, String, byte); -void handleE131Packet(e131_packet_t *, IPAddress); -void arlsLock(uint32_t, byte); -void handleOverlayDraw(); - //udp interface objects WiFiUDP notifierUdp, rgbUdp; WiFiUDP ntpUdp; diff --git a/wled00/wled.h b/wled00/wled.h index 9e373216..e825668e 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -354,13 +354,6 @@ extern ESPAsyncE131 e131; extern bool e131NewData; extern WS2812FX strip; -// 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(); - #define WLED_CONNECTED (WiFi.status() == WL_CONNECTED) #define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0) From de63bdac3951707f781691afd788d8e8a4319bc3 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 04:35:52 -0400 Subject: [PATCH 16/32] Code reorg. --- wled00/wled.cpp | 11 +---------- wled00/wled.h | 11 +++-------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index c6dac0d2..6edd58e2 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -356,23 +356,14 @@ WS2812FX strip = WS2812FX(); #define WLED_CONNECTED (WiFi.status() == WL_CONNECTED) #define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0) -//debug macros +//debug macro variable definitions #ifdef WLED_DEBUG -#define DEBUG_PRINT(x) Serial.print(x) -#define DEBUG_PRINTLN(x) Serial.println(x) -#define DEBUG_PRINTF(x) Serial.printf(x) unsigned long debugTime = 0; int lastWifiState = 3; unsigned long wifiStateChangedTime = 0; int loops = 0; -#else -#define DEBUG_PRINT(x) -#define DEBUG_PRINTLN(x) -#define DEBUG_PRINTF(x) #endif - - WLED::WLED() { } diff --git a/wled00/wled.h b/wled00/wled.h index e825668e..abcffac1 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -381,28 +381,23 @@ int getSignalQuality(int rssi); class WLED { public: + WLED(); static WLED &instance() { static WLED instance; return instance; } - WLED(); - - void reset(); - void loop(); - - //boot starts here void setup() { wledInit(); } + void loop(); + void reset(); -public: // TODO: privacy void wledInit(); void beginStrip(); - void handleConnection(); void initAP(bool resetAP = false); void initConnection(); From 40ac760285425a6c1d7f6c2b8c9d0bee49f7e342 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 04:41:42 -0400 Subject: [PATCH 17/32] Move getSignalQuality to json.cpp --- wled00/json.cpp | 20 ++++++++++++++++++++ wled00/wled.cpp | 20 -------------------- wled00/wled.h | 1 - 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/wled00/json.cpp b/wled00/json.cpp index 6d71e414..782dc8f6 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -249,6 +249,26 @@ void serializeState(JsonObject root) } } +//by https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp +int getSignalQuality(int rssi) +{ + int quality = 0; + + if (rssi <= -100) + { + quality = 0; + } + else if (rssi >= -50) + { + quality = 100; + } + else + { + quality = 2 * (rssi + 100); + } + return quality; +} + void serializeInfo(JsonObject root) { root["ver"] = versionString; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 6edd58e2..18bc4fca 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -845,23 +845,3 @@ void WLED::handleConnection() } } } - -//by https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp -int getSignalQuality(int rssi) -{ - int quality = 0; - - if (rssi <= -100) - { - quality = 0; - } - else if (rssi >= -50) - { - quality = 100; - } - else - { - quality = 2 * (rssi + 100); - } - return quality; -} \ No newline at end of file diff --git a/wled00/wled.h b/wled00/wled.h index abcffac1..07606676 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -376,7 +376,6 @@ extern int loops; bool oappend(const char *txt); // append new number to temp buffer efficiently bool oappendi(int i); -int getSignalQuality(int rssi); class WLED { From 7e21955211282daa581ee912da9d426c7f46aba8 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 04:43:37 -0400 Subject: [PATCH 18/32] wledInit -> setup --- wled00/wled.cpp | 2 +- wled00/wled.h | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 18bc4fca..fe3d7bd9 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -484,7 +484,7 @@ void WLED::loop() #endif // WLED_DEBU } -void WLED::wledInit() +void WLED::setup() { EEPROM.begin(EEPSIZE); ledCount = EEPROM.read(229) + ((EEPROM.read(398) << 8) & 0xFF00); diff --git a/wled00/wled.h b/wled00/wled.h index 07606676..9262c6f1 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -388,14 +388,11 @@ public: } //boot starts here - void setup() - { - wledInit(); - } + void setup(); + void loop(); void reset(); - void wledInit(); void beginStrip(); void handleConnection(); void initAP(bool resetAP = false); From c54092c932ee84ca3a385f38ceb28bbc40b83967 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 05:04:20 -0400 Subject: [PATCH 19/32] Remove redundant defines. --- wled00/wled.cpp | 13 +------------ wled00/wled.h | 7 ++++++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index fe3d7bd9..670868e6 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -45,7 +45,6 @@ bool noWifiSleep = false; //disabling modem sleep modes will i //LED CONFIG uint16_t ledCount = 30; //overcurrent prevented by ABL bool useRGBW = false; //SK6812 strips can contain an extra White channel -#define ABL_MILLIAMPS_DEFAULT 850; //auto lower brightness to stay close to milliampere limit bool turnOnAtBoot = true; //turn on LEDs at power-up byte bootPreset = 0; //save preset to load after power-up @@ -95,7 +94,6 @@ 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 -#define E131_MAX_UNIVERSE_COUNT 9 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] @@ -315,14 +313,8 @@ unsigned long ntpLastSyncTime = 999000000L; unsigned long ntpPacketSentTime = 999000000L; IPAddress ntpServerIP; uint16_t ntpLocalPort = 2390; -#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 +// Temp buffer char *obuf; uint16_t olen = 0; @@ -353,9 +345,6 @@ bool e131NewData = false; //led fx library object WS2812FX strip = WS2812FX(); -#define WLED_CONNECTED (WiFi.status() == WL_CONNECTED) -#define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0) - //debug macro variable definitions #ifdef WLED_DEBUG unsigned long debugTime = 0; diff --git a/wled00/wled.h b/wled00/wled.h index 4eebead2..3e6c11be 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -137,7 +137,7 @@ extern IPAddress staticSubnet; extern bool noWifiSleep; extern uint16_t ledCount; extern bool useRGBW; -#define ABL_MILLIAMPS_DEFAULT 850; +#define ABL_MILLIAMPS_DEFAULT 850; //auto lower brightness to stay close to milliampere limit extern bool turnOnAtBoot; extern byte bootPreset; extern byte col[]; @@ -332,11 +332,16 @@ 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; + extern uint16_t savedPresets; extern int8_t currentPreset; extern bool isPreset; From a47d48c9735eaef7bd96d84a15c83cafc2c1e5bc Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 05:19:09 -0400 Subject: [PATCH 20/32] Add clang format. --- .clang-format | 4 + wled00/wled.cpp | 829 +++++++++++++++++++++++------------------------- 2 files changed, 403 insertions(+), 430 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..56df2b76 --- /dev/null +++ b/.clang-format @@ -0,0 +1,4 @@ +--- + BasedOnStyle: Webkit + IndentWidth: 2 + \ No newline at end of file diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 670868e6..fd47592f 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -1,19 +1,19 @@ #include "wled.h" -#include -#include "led.h" -#include "ir.h" -#include "notify.h" #include "alexa.h" -#include "overlay.h" -#include "file.h" -#include "button.h" -#include "ntp.h" -#include "usermod.h" #include "blynk.h" +#include "button.h" +#include "file.h" #include "hue.h" +#include "ir.h" +#include "led.h" #include "mqtt.h" +#include "notify.h" +#include "ntp.h" +#include "overlay.h" +#include "usermod.h" #include "wled_eeprom.h" #include "wled_server.h" +#include // Global Variable definitions char versionString[] = "0.9.1"; @@ -25,131 +25,131 @@ 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 +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 +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 +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 +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 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 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 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) +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 +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 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 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 +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 +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 +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 +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 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 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 +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 +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 +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 +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 +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 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 +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 cronixieBacklight = true; //Allow digits to be back-illuminated -bool countdownMode = false; //Clock will count down towards date +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 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 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; @@ -157,9 +157,9 @@ 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}; +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 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 @@ -172,12 +172,12 @@ 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 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 @@ -195,8 +195,8 @@ 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 +byte briNlT = 0; //current nightlight brightness +byte colNlT[] { 0, 0, 0, 0 }; //current nightlight color //brightness unsigned long lastOnTime = 0; @@ -205,7 +205,7 @@ byte bri = briS; byte briOld = 0; byte briT = 0; byte briIT = 0; -byte briLast = 128; //brightness before turned off. Used for toggle function +byte briLast = 128; //brightness before turned off. Used for toggle function byte whiteLast = 128; //white channel before turned off. Used for toggle function //button @@ -251,7 +251,7 @@ unsigned long overlayRefreshMs = 200; unsigned long overlayRefreshedTime; //cronixie -byte dP[]{0, 0, 0, 0, 0, 0}; +byte dP[] { 0, 0, 0, 0, 0, 0 }; bool cronixieInit = false; //countdown @@ -260,10 +260,10 @@ 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 +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 @@ -300,7 +300,7 @@ bool auxActive = false, auxActiveBefore = false; String escapedMac; #ifndef WLED_DISABLE_ALEXA Espalexa espalexa; -EspalexaDevice *espalexaDevice; +EspalexaDevice* espalexaDevice; #endif //dns server @@ -315,7 +315,7 @@ IPAddress ntpServerIP; uint16_t ntpLocalPort = 2390; // Temp buffer -char *obuf; +char* obuf; uint16_t olen = 0; //presets @@ -333,8 +333,8 @@ bool doPublishMqtt = false; //server library objects AsyncWebServer server(80); -AsyncClient *hueClient = NULL; -AsyncMqttClient *mqtt = NULL; +AsyncClient* hueClient = NULL; +AsyncMqttClient* mqtt = NULL; //udp interface objects WiFiUDP notifierUdp, rgbUdp; @@ -353,396 +353,376 @@ unsigned long wifiStateChangedTime = 0; int loops = 0; #endif -WLED::WLED() { - +WLED::WLED() +{ } //turns all LEDs off and restarts ESP void WLED::reset() { - briT = 0; - long dly = millis(); - while (millis() - dly < 250) - { - yield(); //enough time to send response to client - } - setAllLeds(); - DEBUG_PRINTLN("MODULE RESET"); - ESP.restart(); + briT = 0; + long dly = millis(); + while (millis() - dly < 250) { + yield(); //enough time to send response to client + } + setAllLeds(); + DEBUG_PRINTLN("MODULE RESET"); + ESP.restart(); } bool oappendi(int i) { - char s[11]; - sprintf(s, "%ld", i); - return oappend(s); + char s[11]; + sprintf(s, "%ld", i); + return oappend(s); } -bool oappend(const char *txt) +bool oappend(const char* txt) { - uint16_t len = strlen(txt); - if (olen + len >= OMAX) - return false; //buffer full - strcpy(obuf + olen, txt); - olen += len; - return true; + uint16_t len = strlen(txt); + if (olen + len >= OMAX) + return false; //buffer full + strcpy(obuf + olen, txt); + olen += len; + return true; } void WLED::loop() { - handleIR(); //2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too - handleConnection(); - handleSerial(); - handleNotifications(); - handleTransitions(); + handleIR(); //2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too + handleConnection(); + handleSerial(); + handleNotifications(); + handleTransitions(); #ifdef WLED_ENABLE_DMX - handleDMX(); + handleDMX(); #endif - userLoop(); + userLoop(); - yield(); - handleIO(); - handleIR(); - handleNetworkTime(); - handleAlexa(); + yield(); + handleIO(); + handleIR(); + handleNetworkTime(); + handleAlexa(); - handleOverlays(); - yield(); + handleOverlays(); + yield(); #ifdef WLED_USE_ANALOG_LEDS - strip.setRgbwPwm(); + strip.setRgbwPwm(); #endif - if (doReboot) - reset(); + if (doReboot) + reset(); - if (!realtimeMode) //block stuff if WARLS/Adalight is enabled - { - if (apActive) - dnsServer.processNextRequest(); + if (!realtimeMode) //block stuff if WARLS/Adalight is enabled + { + if (apActive) + dnsServer.processNextRequest(); #ifndef WLED_DISABLE_OTA - if (WLED_CONNECTED && aOtaEnabled) - ArduinoOTA.handle(); + if (WLED_CONNECTED && aOtaEnabled) + ArduinoOTA.handle(); #endif - handleNightlight(); - yield(); - - handleHue(); - handleBlynk(); - - yield(); - if (!offMode) - strip.service(); - } + handleNightlight(); yield(); + + handleHue(); + handleBlynk(); + + yield(); + if (!offMode) + strip.service(); + } + yield(); #ifdef ESP8266 - MDNS.update(); + MDNS.update(); #endif - if (millis() - lastMqttReconnectAttempt > 30000) - initMqtt(); + if (millis() - lastMqttReconnectAttempt > 30000) + initMqtt(); //DEBUG serial logging #ifdef WLED_DEBUG - if (millis() - debugTime > 9999) - { - DEBUG_PRINTLN("---DEBUG INFO---"); - DEBUG_PRINT("Runtime: "); - DEBUG_PRINTLN(millis()); - DEBUG_PRINT("Unix time: "); - DEBUG_PRINTLN(now()); - DEBUG_PRINT("Free heap: "); - DEBUG_PRINTLN(ESP.getFreeHeap()); - DEBUG_PRINT("Wifi state: "); - DEBUG_PRINTLN(WiFi.status()); - if (WiFi.status() != lastWifiState) - { - wifiStateChangedTime = millis(); - } - lastWifiState = WiFi.status(); - DEBUG_PRINT("State time: "); - DEBUG_PRINTLN(wifiStateChangedTime); - DEBUG_PRINT("NTP last sync: "); - DEBUG_PRINTLN(ntpLastSyncTime); - DEBUG_PRINT("Client IP: "); - DEBUG_PRINTLN(WiFi.localIP()); - DEBUG_PRINT("Loops/sec: "); - DEBUG_PRINTLN(loops / 10); - loops = 0; - debugTime = millis(); + if (millis() - debugTime > 9999) { + DEBUG_PRINTLN("---DEBUG INFO---"); + DEBUG_PRINT("Runtime: "); + DEBUG_PRINTLN(millis()); + DEBUG_PRINT("Unix time: "); + DEBUG_PRINTLN(now()); + DEBUG_PRINT("Free heap: "); + DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINT("Wifi state: "); + DEBUG_PRINTLN(WiFi.status()); + if (WiFi.status() != lastWifiState) { + wifiStateChangedTime = millis(); } - loops++; + lastWifiState = WiFi.status(); + DEBUG_PRINT("State time: "); + DEBUG_PRINTLN(wifiStateChangedTime); + DEBUG_PRINT("NTP last sync: "); + DEBUG_PRINTLN(ntpLastSyncTime); + DEBUG_PRINT("Client IP: "); + DEBUG_PRINTLN(WiFi.localIP()); + DEBUG_PRINT("Loops/sec: "); + DEBUG_PRINTLN(loops / 10); + loops = 0; + debugTime = millis(); + } + loops++; #endif // WLED_DEBU } void WLED::setup() { - EEPROM.begin(EEPSIZE); - ledCount = EEPROM.read(229) + ((EEPROM.read(398) << 8) & 0xFF00); - if (ledCount > MAX_LEDS || ledCount == 0) - ledCount = 30; + EEPROM.begin(EEPSIZE); + ledCount = EEPROM.read(229) + ((EEPROM.read(398) << 8) & 0xFF00); + if (ledCount > MAX_LEDS || ledCount == 0) + ledCount = 30; #ifdef ESP8266 #if LEDPIN == 3 - if (ledCount > MAX_LEDS_DMA) - ledCount = MAX_LEDS_DMA; //DMA method uses too much ram + if (ledCount > MAX_LEDS_DMA) + ledCount = MAX_LEDS_DMA; //DMA method uses too much ram #endif #endif - Serial.begin(115200); - Serial.setTimeout(50); - DEBUG_PRINTLN(); - DEBUG_PRINT("---WLED "); - DEBUG_PRINT(versionString); - DEBUG_PRINT(" "); - DEBUG_PRINT(VERSION); - DEBUG_PRINTLN(" INIT---"); + Serial.begin(115200); + Serial.setTimeout(50); + DEBUG_PRINTLN(); + DEBUG_PRINT("---WLED "); + DEBUG_PRINT(versionString); + DEBUG_PRINT(" "); + DEBUG_PRINT(VERSION); + DEBUG_PRINTLN(" INIT---"); #ifdef ARDUINO_ARCH_ESP32 - DEBUG_PRINT("esp32 "); - DEBUG_PRINTLN(ESP.getSdkVersion()); + DEBUG_PRINT("esp32 "); + DEBUG_PRINTLN(ESP.getSdkVersion()); #else - DEBUG_PRINT("esp8266 "); - DEBUG_PRINTLN(ESP.getCoreVersion()); + DEBUG_PRINT("esp8266 "); + DEBUG_PRINTLN(ESP.getCoreVersion()); #endif - int heapPreAlloc = ESP.getFreeHeap(); - DEBUG_PRINT("heap "); - DEBUG_PRINTLN(ESP.getFreeHeap()); + int heapPreAlloc = ESP.getFreeHeap(); + DEBUG_PRINT("heap "); + DEBUG_PRINTLN(ESP.getFreeHeap()); - strip.init(EEPROM.read(372), ledCount, EEPROM.read(2204)); //init LEDs quickly - strip.setBrightness(0); + strip.init(EEPROM.read(372), ledCount, EEPROM.read(2204)); //init LEDs quickly + strip.setBrightness(0); - DEBUG_PRINT("LEDs inited. heap usage ~"); - DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap()); + DEBUG_PRINT("LEDs inited. heap usage ~"); + DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap()); #ifndef WLED_DISABLE_FILESYSTEM #ifdef ARDUINO_ARCH_ESP32 - SPIFFS.begin(true); + SPIFFS.begin(true); #endif - SPIFFS.begin(); + SPIFFS.begin(); #endif - DEBUG_PRINTLN("Load EEPROM"); - loadSettingsFromEEPROM(true); - beginStrip(); - userSetup(); - if (strcmp(clientSSID, DEFAULT_CLIENT_SSID) == 0) - showWelcomePage = true; - WiFi.persistent(false); + DEBUG_PRINTLN("Load EEPROM"); + loadSettingsFromEEPROM(true); + beginStrip(); + userSetup(); + if (strcmp(clientSSID, DEFAULT_CLIENT_SSID) == 0) + showWelcomePage = true; + WiFi.persistent(false); - if (macroBoot > 0) - applyMacro(macroBoot); - Serial.println("Ada"); + if (macroBoot > 0) + applyMacro(macroBoot); + Serial.println("Ada"); - //generate module IDs - escapedMac = WiFi.macAddress(); - escapedMac.replace(":", ""); - escapedMac.toLowerCase(); - if (strcmp(cmDNS, "x") == 0) //fill in unique mdns default - { - strcpy(cmDNS, "wled-"); - sprintf(cmDNS + 5, "%*s", 6, escapedMac.c_str() + 6); - } - if (mqttDeviceTopic[0] == 0) - { - strcpy(mqttDeviceTopic, "wled/"); - sprintf(mqttDeviceTopic + 5, "%*s", 6, escapedMac.c_str() + 6); - } - if (mqttClientID[0] == 0) - { - strcpy(mqttClientID, "WLED-"); - sprintf(mqttClientID + 5, "%*s", 6, escapedMac.c_str() + 6); - } + //generate module IDs + escapedMac = WiFi.macAddress(); + escapedMac.replace(":", ""); + escapedMac.toLowerCase(); + if (strcmp(cmDNS, "x") == 0) //fill in unique mdns default + { + strcpy(cmDNS, "wled-"); + sprintf(cmDNS + 5, "%*s", 6, escapedMac.c_str() + 6); + } + if (mqttDeviceTopic[0] == 0) { + strcpy(mqttDeviceTopic, "wled/"); + sprintf(mqttDeviceTopic + 5, "%*s", 6, escapedMac.c_str() + 6); + } + if (mqttClientID[0] == 0) { + strcpy(mqttClientID, "WLED-"); + sprintf(mqttClientID + 5, "%*s", 6, escapedMac.c_str() + 6); + } - strip.service(); + strip.service(); #ifndef WLED_DISABLE_OTA - if (aOtaEnabled) - { - ArduinoOTA.onStart([]() { + if (aOtaEnabled) { + ArduinoOTA.onStart([]() { #ifdef ESP8266 - wifi_set_sleep_type(NONE_SLEEP_T); + wifi_set_sleep_type(NONE_SLEEP_T); #endif - DEBUG_PRINTLN("Start ArduinoOTA"); - }); - if (strlen(cmDNS) > 0) - ArduinoOTA.setHostname(cmDNS); - } + DEBUG_PRINTLN("Start ArduinoOTA"); + }); + if (strlen(cmDNS) > 0) + ArduinoOTA.setHostname(cmDNS); + } #endif #ifdef WLED_ENABLE_DMX - dmx.init(512); // initialize with bus length + dmx.init(512); // initialize with bus length #endif - //HTTP server page init - initServer(); + //HTTP server page init + initServer(); } void WLED::beginStrip() { - // Initialize NeoPixel Strip and button - strip.setShowCallback(handleOverlayDraw); + // Initialize NeoPixel Strip and button + strip.setShowCallback(handleOverlayDraw); #ifdef BTNPIN - pinMode(BTNPIN, INPUT_PULLUP); + pinMode(BTNPIN, INPUT_PULLUP); #endif - if (bootPreset > 0) - applyPreset(bootPreset, turnOnAtBoot); - colorUpdated(NOTIFIER_CALL_MODE_INIT); + if (bootPreset > 0) + applyPreset(bootPreset, turnOnAtBoot); + colorUpdated(NOTIFIER_CALL_MODE_INIT); //init relay pin #if RLYPIN >= 0 - pinMode(RLYPIN, OUTPUT); + pinMode(RLYPIN, OUTPUT); #if RLYMDE - digitalWrite(RLYPIN, bri); + digitalWrite(RLYPIN, bri); #else - digitalWrite(RLYPIN, !bri); + digitalWrite(RLYPIN, !bri); #endif #endif - //disable button if it is "pressed" unintentionally + //disable button if it is "pressed" unintentionally #ifdef BTNPIN - if (digitalRead(BTNPIN) == LOW) - buttonEnabled = false; -#else + if (digitalRead(BTNPIN) == LOW) buttonEnabled = false; +#else + buttonEnabled = false; #endif } void WLED::initAP(bool resetAP) { - if (apBehavior == AP_BEHAVIOR_BUTTON_ONLY && !resetAP) - return; + if (apBehavior == AP_BEHAVIOR_BUTTON_ONLY && !resetAP) + return; - if (!apSSID[0] || resetAP) - strcpy(apSSID, "WLED-AP"); - if (resetAP) - strcpy(apPass, DEFAULT_AP_PASS); - DEBUG_PRINT("Opening access point "); - DEBUG_PRINTLN(apSSID); - WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255, 255, 255, 0)); - WiFi.softAP(apSSID, apPass, apChannel, apHide); + if (!apSSID[0] || resetAP) + strcpy(apSSID, "WLED-AP"); + if (resetAP) + strcpy(apPass, DEFAULT_AP_PASS); + DEBUG_PRINT("Opening access point "); + DEBUG_PRINTLN(apSSID); + WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255, 255, 255, 0)); + WiFi.softAP(apSSID, apPass, apChannel, apHide); - if (!apActive) //start captive portal if AP active - { - DEBUG_PRINTLN("Init AP interfaces"); - server.begin(); - if (udpPort > 0 && udpPort != ntpLocalPort) - { - udpConnected = notifierUdp.begin(udpPort); - } - if (udpRgbPort > 0 && udpRgbPort != ntpLocalPort && udpRgbPort != udpPort) - { - udpRgbConnected = rgbUdp.begin(udpRgbPort); - } - - dnsServer.setErrorReplyCode(DNSReplyCode::NoError); - dnsServer.start(53, "*", WiFi.softAPIP()); + if (!apActive) //start captive portal if AP active + { + DEBUG_PRINTLN("Init AP interfaces"); + server.begin(); + if (udpPort > 0 && udpPort != ntpLocalPort) { + udpConnected = notifierUdp.begin(udpPort); } - apActive = true; + if (udpRgbPort > 0 && udpRgbPort != ntpLocalPort && udpRgbPort != udpPort) { + udpRgbConnected = rgbUdp.begin(udpRgbPort); + } + + dnsServer.setErrorReplyCode(DNSReplyCode::NoError); + dnsServer.start(53, "*", WiFi.softAPIP()); + } + apActive = true; } void WLED::initConnection() { - WiFi.disconnect(); //close old connections + WiFi.disconnect(); //close old connections #ifdef ESP8266 - WiFi.setPhyMode(WIFI_PHY_MODE_11N); + WiFi.setPhyMode(WIFI_PHY_MODE_11N); #endif - if (staticIP[0] != 0 && staticGateway[0] != 0) - { - WiFi.config(staticIP, staticGateway, staticSubnet, IPAddress(8, 8, 8, 8)); - } - else - { - WiFi.config(0U, 0U, 0U); - } + if (staticIP[0] != 0 && staticGateway[0] != 0) { + WiFi.config(staticIP, staticGateway, staticSubnet, IPAddress(8, 8, 8, 8)); + } else { + WiFi.config(0U, 0U, 0U); + } - lastReconnectAttempt = millis(); + lastReconnectAttempt = millis(); - if (!WLED_WIFI_CONFIGURED) - { - DEBUG_PRINT("No connection configured. "); - if (!apActive) - initAP(); //instantly go to ap mode - return; + if (!WLED_WIFI_CONFIGURED) { + DEBUG_PRINT("No connection configured. "); + if (!apActive) + initAP(); //instantly go to ap mode + return; + } else if (!apActive) { + if (apBehavior == AP_BEHAVIOR_ALWAYS) { + initAP(); + } else { + DEBUG_PRINTLN("Access point disabled."); + WiFi.softAPdisconnect(true); } - else if (!apActive) - { - if (apBehavior == AP_BEHAVIOR_ALWAYS) - { - initAP(); - } - else - { - DEBUG_PRINTLN("Access point disabled."); - WiFi.softAPdisconnect(true); - } - } - showWelcomePage = false; + } + showWelcomePage = false; - DEBUG_PRINT("Connecting to "); - DEBUG_PRINT(clientSSID); - DEBUG_PRINTLN("..."); + DEBUG_PRINT("Connecting to "); + DEBUG_PRINT(clientSSID); + DEBUG_PRINTLN("..."); #ifdef ESP8266 - WiFi.hostname(serverDescription); + WiFi.hostname(serverDescription); #endif - WiFi.begin(clientSSID, clientPass); + WiFi.begin(clientSSID, clientPass); #ifdef ARDUINO_ARCH_ESP32 - WiFi.setSleep(!noWifiSleep); - WiFi.setHostname(serverDescription); + WiFi.setSleep(!noWifiSleep); + WiFi.setHostname(serverDescription); #else - wifi_set_sleep_type((noWifiSleep) ? NONE_SLEEP_T : MODEM_SLEEP_T); + wifi_set_sleep_type((noWifiSleep) ? NONE_SLEEP_T : MODEM_SLEEP_T); #endif } void WLED::initInterfaces() { - DEBUG_PRINTLN("Init STA interfaces"); + DEBUG_PRINTLN("Init STA interfaces"); - if (hueIP[0] == 0) - { - hueIP[0] = WiFi.localIP()[0]; - hueIP[1] = WiFi.localIP()[1]; - hueIP[2] = WiFi.localIP()[2]; - } + if (hueIP[0] == 0) { + hueIP[0] = WiFi.localIP()[0]; + hueIP[1] = WiFi.localIP()[1]; + hueIP[2] = WiFi.localIP()[2]; + } - //init Alexa hue emulation - if (alexaEnabled) - alexaInit(); + //init Alexa hue emulation + if (alexaEnabled) + alexaInit(); #ifndef WLED_DISABLE_OTA - if (aOtaEnabled) - ArduinoOTA.begin(); + if (aOtaEnabled) + ArduinoOTA.begin(); #endif - strip.service(); - // Set up mDNS responder: - if (strlen(cmDNS) > 0) - { - if (!aOtaEnabled) - MDNS.begin(cmDNS); + strip.service(); + // Set up mDNS responder: + if (strlen(cmDNS) > 0) { + if (!aOtaEnabled) + MDNS.begin(cmDNS); - DEBUG_PRINTLN("mDNS started"); - MDNS.addService("http", "tcp", 80); - MDNS.addService("wled", "tcp", 80); - MDNS.addServiceTxt("wled", "tcp", "mac", escapedMac.c_str()); - } - server.begin(); + DEBUG_PRINTLN("mDNS started"); + MDNS.addService("http", "tcp", 80); + MDNS.addService("wled", "tcp", 80); + MDNS.addServiceTxt("wled", "tcp", "mac", escapedMac.c_str()); + } + server.begin(); - if (udpPort > 0 && udpPort != ntpLocalPort) - { - udpConnected = notifierUdp.begin(udpPort); - if (udpConnected && udpRgbPort != udpPort) - udpRgbConnected = rgbUdp.begin(udpRgbPort); - } - if (ntpEnabled) - ntpConnected = ntpUdp.begin(ntpLocalPort); + if (udpPort > 0 && udpPort != ntpLocalPort) { + udpConnected = notifierUdp.begin(udpPort); + if (udpConnected && udpRgbPort != udpPort) + udpRgbConnected = rgbUdp.begin(udpRgbPort); + } + if (ntpEnabled) + ntpConnected = ntpUdp.begin(ntpLocalPort); - initBlynk(blynkApiKey); - e131.begin((e131Multicast) ? E131_MULTICAST : E131_UNICAST, e131Universe, E131_MAX_UNIVERSE_COUNT); - reconnectHue(); - initMqtt(); - interfacesInited = true; - wasConnected = true; + initBlynk(blynkApiKey); + e131.begin((e131Multicast) ? E131_MULTICAST : E131_UNICAST, e131Universe, E131_MAX_UNIVERSE_COUNT); + reconnectHue(); + initMqtt(); + interfacesInited = true; + wasConnected = true; } byte stacO = 0; @@ -751,86 +731,75 @@ unsigned long heapTime = 0; void WLED::handleConnection() { - if (millis() < 2000 && (!WLED_WIFI_CONFIGURED || apBehavior == AP_BEHAVIOR_ALWAYS)) - return; - if (lastReconnectAttempt == 0) - initConnection(); + 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 - if (millis() - heapTime > 5000) - { - uint32_t heap = ESP.getFreeHeap(); - if (heap < 9000 && lastHeap < 9000) - { - DEBUG_PRINT("Heap too low! "); - DEBUG_PRINTLN(heap); - forceReconnect = true; - } - lastHeap = heap; - heapTime = millis(); + //reconnect WiFi to clear stale allocations if heap gets too low + if (millis() - heapTime > 5000) { + uint32_t heap = ESP.getFreeHeap(); + if (heap < 9000 && lastHeap < 9000) { + DEBUG_PRINT("Heap too low! "); + DEBUG_PRINTLN(heap); + forceReconnect = true; } + lastHeap = heap; + heapTime = millis(); + } - byte stac = 0; - if (apActive) - { + byte stac = 0; + if (apActive) { #ifdef ESP8266 - stac = wifi_softap_get_station_num(); + stac = wifi_softap_get_station_num(); #else - wifi_sta_list_t stationList; - esp_wifi_ap_get_sta_list(&stationList); - stac = stationList.num; + wifi_sta_list_t stationList; + esp_wifi_ap_get_sta_list(&stationList); + stac = stationList.num; #endif - if (stac != stacO) - { - stacO = stac; - DEBUG_PRINT("Connected AP clients: "); - DEBUG_PRINTLN(stac); - if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) - { //trying to connect, but not connected - if (stac) - WiFi.disconnect(); //disable search so that AP can work - else - initConnection(); //restart search - } - } + if (stac != stacO) { + stacO = stac; + DEBUG_PRINT("Connected AP clients: "); + DEBUG_PRINTLN(stac); + if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) { //trying to connect, but not connected + if (stac) + WiFi.disconnect(); //disable search so that AP can work + else + initConnection(); //restart search + } } - if (forceReconnect) - { - DEBUG_PRINTLN("Forcing reconnect."); - initConnection(); - interfacesInited = false; - forceReconnect = false; - wasConnected = false; - return; + } + if (forceReconnect) { + DEBUG_PRINTLN("Forcing reconnect."); + initConnection(); + interfacesInited = false; + forceReconnect = false; + wasConnected = false; + return; + } + if (!WLED_CONNECTED) { + if (interfacesInited) { + DEBUG_PRINTLN("Disconnected!"); + interfacesInited = false; + initConnection(); } - if (!WLED_CONNECTED) - { - if (interfacesInited) - { - DEBUG_PRINTLN("Disconnected!"); - interfacesInited = false; - initConnection(); - } - if (millis() - lastReconnectAttempt > ((stac) ? 300000 : 20000) && WLED_WIFI_CONFIGURED) - initConnection(); - if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) - initAP(); - } - else if (!interfacesInited) - { //newly connected - DEBUG_PRINTLN(""); - DEBUG_PRINT("Connected! IP address: "); - DEBUG_PRINTLN(WiFi.localIP()); - initInterfaces(); - userConnected(); + if (millis() - lastReconnectAttempt > ((stac) ? 300000 : 20000) && WLED_WIFI_CONFIGURED) + initConnection(); + if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) + initAP(); + } else if (!interfacesInited) { //newly connected + DEBUG_PRINTLN(""); + DEBUG_PRINT("Connected! IP address: "); + DEBUG_PRINTLN(WiFi.localIP()); + initInterfaces(); + userConnected(); - //shut down AP - if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive) - { - dnsServer.stop(); - WiFi.softAPdisconnect(true); - apActive = false; - DEBUG_PRINTLN("Access point disabled."); - } + //shut down AP + if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive) { + dnsServer.stop(); + WiFi.softAPdisconnect(true); + apActive = false; + DEBUG_PRINTLN("Access point disabled."); } + } } From ffbedbc1e62dd25c4a4e798182a831666fe3e3d2 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 06:27:36 -0400 Subject: [PATCH 21/32] Add clang format to git ignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ea49cb51..5e61e156 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /wled00/Release /wled00/extLibs /platformio_override.ini +.clang-format From 8d75c06852e44e3b87b3b2002a40cee4796af7d0 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 06:42:21 -0400 Subject: [PATCH 22/32] Format changes. --- .clang-format | 10 +- wled00/wled.cpp | 366 ++++++++++++++++++++++++------------------------ wled00/wled.h | 188 +++++++++++++------------ 3 files changed, 287 insertions(+), 277 deletions(-) diff --git a/.clang-format b/.clang-format index 56df2b76..aedd2246 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,12 @@ --- BasedOnStyle: Webkit IndentWidth: 2 - \ No newline at end of file + AlignTrailingComments: true + SpacesBeforeTrailingComments: 8 + AllowShortIfStatementsOnASingleLine: Always + AllowShortLoopsOnASingleLine: true + AllowShortLambdasOnASingleLine: true + AllowShortCaseLabelsOnASingleLine: true + AllowShortFunctionsOnASingleLine: All + AllowShortBlocksOnASingleLine: true + IndentCaseLabels: true \ No newline at end of file diff --git a/wled00/wled.cpp b/wled00/wled.cpp index fd47592f..48231599 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -18,224 +18,224 @@ // Global Variable definitions char versionString[] = "0.9.1"; -//AP and OTA default passwords (for maximum change them!) +// 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! +// 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 +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) +// 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 +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 +// 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 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 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 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) +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 +// 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 +// Sync CONFIG bool buttonEnabled = true; -byte irEnabled = 0; //Infrared receiver +byte irEnabled = 0; // Infrared receiver -uint16_t udpPort = 21324; //WLED notifier default port -uint16_t udpRgbPort = 19446; //Hyperion port +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 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 +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 +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 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 +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 +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 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 +// 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 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 +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 +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 +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 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 +// 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 + // 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 +// 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 +// 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 +byte lastRandomIndex = 0; // used to save last random color so the new one is not the same -//transitions +// 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 +float tperLast = 0; // crossfade transition progress, 0.0f - 1.0f bool jsonTransitionOnce = false; -//nightlight +// 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 +byte briNlT = 0; // current nightlight brightness +byte colNlT[] { 0, 0, 0, 0 }; // current nightlight color -//brightness +// 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 +byte briLast = 128; // brightness before turned off. Used for toggle function +byte whiteLast = 128; // white channel before turned off. Used for toggle function -//button +// button bool buttonPressedBefore = false; bool buttonLongPressed = false; unsigned long buttonPressedTime = 0; unsigned long buttonWaitTime = 0; -//notifications +// notifications bool notifyDirectDefault = notifyDirect; bool receiveNotifications = true; unsigned long notificationSentTime = 0; byte notificationSentCallMode = NOTIFIER_CALL_MODE_INIT; bool notificationTwoRequired = false; -//effects +// effects byte effectCurrent = 0; byte effectSpeed = 128; byte effectIntensity = 128; byte effectPalette = 0; -//network +// network bool udpConnected = false, udpRgbConnected = false; -//ui style +// ui style bool showWelcomePage = false; -//hue +// hue byte hueError = HUE_ERROR_INACTIVE; -//uint16_t hueFailCount = 0; +// uint16_t hueFailCount = 0; float hueXLast = 0, hueYLast = 0; uint16_t hueHueLast = 0, hueCtLast = 0; byte hueSatLast = 0, hueBriLast = 0; @@ -244,32 +244,32 @@ bool hueAuthRequired = false; bool hueReceived = false; bool hueStoreAllowed = false, hueNewKey = false; -//overlays +// overlays byte overlayCurrent = overlayDefault; byte overlaySpeed = 200; unsigned long overlayRefreshMs = 200; unsigned long overlayRefreshedTime; -//cronixie +// cronixie byte dP[] { 0, 0, 0, 0, 0, 0 }; bool cronixieInit = false; -//countdown +// countdown unsigned long countdownTime = 1514764800L; bool countdownOverTriggered = true; -//timer +// 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 +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 +// blynk bool blynkEnabled = false; -//preset cycling +// preset cycling bool presetCyclingEnabled = false; byte presetCycleMin = 1, presetCycleMax = 5; uint16_t presetCycleTime = 1250; @@ -278,35 +278,35 @@ byte presetCycCurr = presetCycleMin; bool presetApplyBri = true; bool saveCurrPresetCycConf = false; -//realtime +// realtime byte realtimeMode = REALTIME_MODE_INACTIVE; IPAddress realtimeIP = (0, 0, 0, 0); unsigned long realtimeTimeout = 0; -//mqtt +// mqtt long lastMqttReconnectAttempt = 0; long lastInterfaceUpdate = 0; byte interfaceUpdateCallMode = NOTIFIER_CALL_MODE_INIT; -char mqttStatusTopic[40] = ""; //this must be global because of async handlers +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; + // auxiliary debug pin + byte auxTime = 0; + unsigned long auxStartTime = 0; + bool auxActive = false, auxActiveBefore = false; #endif -//alexa udp +// alexa udp String escapedMac; #ifndef WLED_DISABLE_ALEXA -Espalexa espalexa; -EspalexaDevice* espalexaDevice; + Espalexa espalexa; + EspalexaDevice* espalexaDevice; #endif -//dns server +// dns server DNSServer dnsServer; -//network time +// network time bool ntpConnected = false; time_t local = 0; unsigned long ntpLastSyncTime = 999000000L; @@ -318,7 +318,7 @@ uint16_t ntpLocalPort = 2390; char* obuf; uint16_t olen = 0; -//presets +// presets uint16_t savedPresets = 0; int8_t currentPreset = -1; bool isPreset = false; @@ -328,42 +328,42 @@ byte errorFlag = 0; String messageHead, messageSub; byte optionType; -bool doReboot = false; //flag to initiate reboot from async handlers +bool doReboot = false; // flag to initiate reboot from async handlers bool doPublishMqtt = false; -//server library objects +// server library objects AsyncWebServer server(80); AsyncClient* hueClient = NULL; AsyncMqttClient* mqtt = NULL; -//udp interface objects +// udp interface objects WiFiUDP notifierUdp, rgbUdp; WiFiUDP ntpUdp; ESPAsyncE131 e131(handleE131Packet); bool e131NewData = false; -//led fx library object +// led fx library object WS2812FX strip = WS2812FX(); -//debug macro variable definitions +// debug macro variable definitions #ifdef WLED_DEBUG -unsigned long debugTime = 0; -int lastWifiState = 3; -unsigned long wifiStateChangedTime = 0; -int loops = 0; + unsigned long debugTime = 0; + int lastWifiState = 3; + unsigned long wifiStateChangedTime = 0; + int loops = 0; #endif WLED::WLED() { } -//turns all LEDs off and restarts ESP +// turns all LEDs off and restarts ESP void WLED::reset() { briT = 0; long dly = millis(); while (millis() - dly < 250) { - yield(); //enough time to send response to client + yield(); // enough time to send response to client } setAllLeds(); DEBUG_PRINTLN("MODULE RESET"); @@ -381,7 +381,7 @@ bool oappend(const char* txt) { uint16_t len = strlen(txt); if (olen + len >= OMAX) - return false; //buffer full + return false; // buffer full strcpy(obuf + olen, txt); olen += len; return true; @@ -389,7 +389,7 @@ bool oappend(const char* txt) void WLED::loop() { - handleIR(); //2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too + handleIR(); // 2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too handleConnection(); handleSerial(); handleNotifications(); @@ -414,7 +414,7 @@ void WLED::loop() if (doReboot) reset(); - if (!realtimeMode) //block stuff if WARLS/Adalight is enabled + if (!realtimeMode) // block stuff if WARLS/Adalight is enabled { if (apActive) dnsServer.processNextRequest(); @@ -439,7 +439,7 @@ void WLED::loop() if (millis() - lastMqttReconnectAttempt > 30000) initMqtt(); -//DEBUG serial logging +// DEBUG serial logging #ifdef WLED_DEBUG if (millis() - debugTime > 9999) { DEBUG_PRINTLN("---DEBUG INFO---"); @@ -467,7 +467,7 @@ void WLED::loop() debugTime = millis(); } loops++; -#endif // WLED_DEBU +#endif // WLED_DEBU } void WLED::setup() @@ -478,10 +478,10 @@ void WLED::setup() ledCount = 30; #ifdef ESP8266 -#if LEDPIN == 3 - if (ledCount > MAX_LEDS_DMA) - ledCount = MAX_LEDS_DMA; //DMA method uses too much ram -#endif + #if LEDPIN == 3 + if (ledCount > MAX_LEDS_DMA) + ledCount = MAX_LEDS_DMA; // DMA method uses too much ram + #endif #endif Serial.begin(115200); Serial.setTimeout(50); @@ -502,17 +502,17 @@ void WLED::setup() DEBUG_PRINT("heap "); DEBUG_PRINTLN(ESP.getFreeHeap()); - strip.init(EEPROM.read(372), ledCount, EEPROM.read(2204)); //init LEDs quickly + strip.init(EEPROM.read(372), ledCount, EEPROM.read(2204)); // init LEDs quickly strip.setBrightness(0); DEBUG_PRINT("LEDs inited. heap usage ~"); DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap()); #ifndef WLED_DISABLE_FILESYSTEM -#ifdef ARDUINO_ARCH_ESP32 - SPIFFS.begin(true); -#endif - SPIFFS.begin(); + #ifdef ARDUINO_ARCH_ESP32 + SPIFFS.begin(true); + #endif + SPIFFS.begin(); #endif DEBUG_PRINTLN("Load EEPROM"); @@ -527,11 +527,11 @@ void WLED::setup() applyMacro(macroBoot); Serial.println("Ada"); - //generate module IDs + // generate module IDs escapedMac = WiFi.macAddress(); escapedMac.replace(":", ""); escapedMac.toLowerCase(); - if (strcmp(cmDNS, "x") == 0) //fill in unique mdns default + if (strcmp(cmDNS, "x") == 0) // fill in unique mdns default { strcpy(cmDNS, "wled-"); sprintf(cmDNS + 5, "%*s", 6, escapedMac.c_str() + 6); @@ -560,9 +560,9 @@ void WLED::setup() } #endif #ifdef WLED_ENABLE_DMX - dmx.init(512); // initialize with bus length + dmx.init(512); // initialize with bus length #endif - //HTTP server page init + // HTTP server page init initServer(); } @@ -579,7 +579,7 @@ void WLED::beginStrip() applyPreset(bootPreset, turnOnAtBoot); colorUpdated(NOTIFIER_CALL_MODE_INIT); -//init relay pin +// init relay pin #if RLYPIN >= 0 pinMode(RLYPIN, OUTPUT); #if RLYMDE @@ -589,7 +589,7 @@ void WLED::beginStrip() #endif #endif - //disable button if it is "pressed" unintentionally + // disable button if it is "pressed" unintentionally #ifdef BTNPIN if (digitalRead(BTNPIN) == LOW) buttonEnabled = false; @@ -612,7 +612,7 @@ void WLED::initAP(bool resetAP) WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255, 255, 255, 0)); WiFi.softAP(apSSID, apPass, apChannel, apHide); - if (!apActive) //start captive portal if AP active + if (!apActive) // start captive portal if AP active { DEBUG_PRINTLN("Init AP interfaces"); server.begin(); @@ -631,7 +631,7 @@ void WLED::initAP(bool resetAP) void WLED::initConnection() { - WiFi.disconnect(); //close old connections + WiFi.disconnect(); // close old connections #ifdef ESP8266 WiFi.setPhyMode(WIFI_PHY_MODE_11N); #endif @@ -647,7 +647,7 @@ void WLED::initConnection() if (!WLED_WIFI_CONFIGURED) { DEBUG_PRINT("No connection configured. "); if (!apActive) - initAP(); //instantly go to ap mode + initAP(); // instantly go to ap mode return; } else if (!apActive) { if (apBehavior == AP_BEHAVIOR_ALWAYS) { @@ -687,7 +687,7 @@ void WLED::initInterfaces() hueIP[2] = WiFi.localIP()[2]; } - //init Alexa hue emulation + // init Alexa hue emulation if (alexaEnabled) alexaInit(); @@ -736,7 +736,7 @@ void WLED::handleConnection() if (lastReconnectAttempt == 0) initConnection(); - //reconnect WiFi to clear stale allocations if heap gets too low + // reconnect WiFi to clear stale allocations if heap gets too low if (millis() - heapTime > 5000) { uint32_t heap = ESP.getFreeHeap(); if (heap < 9000 && lastHeap < 9000) { @@ -761,11 +761,11 @@ void WLED::handleConnection() stacO = stac; DEBUG_PRINT("Connected AP clients: "); DEBUG_PRINTLN(stac); - if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) { //trying to connect, but not connected + if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) { // trying to connect, but not connected if (stac) - WiFi.disconnect(); //disable search so that AP can work + WiFi.disconnect(); // disable search so that AP can work else - initConnection(); //restart search + initConnection(); // restart search } } } @@ -787,14 +787,14 @@ void WLED::handleConnection() initConnection(); if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) initAP(); - } else if (!interfacesInited) { //newly connected + } else if (!interfacesInited) { // newly connected DEBUG_PRINTLN(""); DEBUG_PRINT("Connected! IP address: "); DEBUG_PRINTLN(WiFi.localIP()); initInterfaces(); userConnected(); - //shut down AP + // shut down AP if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive) { dnsServer.stop(); WiFi.softAPdisconnect(true); diff --git a/wled00/wled.h b/wled00/wled.h index 3e6c11be..72686a00 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -14,41 +14,41 @@ // 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: -//#define WLED_DISABLE_OTA //saves 14kb +//#define WLED_DISABLE_OTA // saves 14kb // 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_DMX //uses 3.5kb +//#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_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 +#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 //#define WLED_DEBUG // Library inclusions. #include -#ifdef ESP8266 -#include -#include -#include -extern "C" -{ -#include -} -#else //ESP32 -#include -#include "esp_wifi.h" -#include -#include -#include "SPIFFS.h" + #ifdef ESP8266 + #include + #include + #include + extern "C" + { + #include + } +#else // ESP32 + #include + #include "esp_wifi.h" + #include + #include + #include "SPIFFS.h" #endif #include @@ -56,25 +56,28 @@ extern "C" #include #include #ifndef WLED_DISABLE_OTA -#include + #include #endif #include #include "src/dependencies/time/TimeLib.h" #include "src/dependencies/timezone/Timezone.h" + #ifndef WLED_DISABLE_ALEXA -#define ESPALEXA_ASYNC -#define ESPALEXA_NO_SUBPAGE -#define ESPALEXA_MAXDEVICES 1 -// #define ESPALEXA_DEBUG -#include "src/dependencies/espalexa/Espalexa.h" + #define ESPALEXA_ASYNC + #define ESPALEXA_NO_SUBPAGE + #define ESPALEXA_MAXDEVICES 1 + // #define ESPALEXA_DEBUG + #include "src/dependencies/espalexa/Espalexa.h" #endif #ifndef WLED_DISABLE_BLYNK -#include "src/dependencies/blynk/BlynkSimpleEsp.h" + #include "src/dependencies/blynk/BlynkSimpleEsp.h" #endif + #include "src/dependencies/e131/ESPAsyncE131.h" #include "src/dependencies/async-mqtt-client/AsyncMqttClient.h" #include "src/dependencies/json/AsyncJson-v6.h" #include "src/dependencies/json/ArduinoJson-v6.h" + #include "html_ui.h" #include "html_settings.h" #include "html_other.h" @@ -83,35 +86,35 @@ extern "C" #include "const.h" #ifndef CLIENT_SSID -#define CLIENT_SSID DEFAULT_CLIENT_SSID + #define CLIENT_SSID DEFAULT_CLIENT_SSID #endif #ifndef CLIENT_PASS -#define CLIENT_PASS "" + #define CLIENT_PASS "" #endif #if IR_PIN < 0 -#ifndef WLED_DISABLE_INFRARED -#define WLED_DISABLE_INFRARED -#endif + #ifndef WLED_DISABLE_INFRARED + #define WLED_DISABLE_INFRARED + #endif #endif #ifndef WLED_DISABLE_INFRARED -#include -#include -#include + #include + #include + #include #endif // remove flicker because PWM signal of RGB channels can become out of phase #if defined(WLED_USE_ANALOG_LEDS) && defined(ESP8266) -#include "src/dependencies/arduino/core_esp8266_waveform.h" + #include "src/dependencies/arduino/core_esp8266_waveform.h" #endif // enable additional debug output #ifdef WLED_DEBUG -#ifndef ESP8266 -#include -#endif + #ifndef ESP8266 + #include + #endif #endif // version code in format yymmddb (b = daily build) @@ -137,7 +140,7 @@ 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 +#define ABL_MILLIAMPS_DEFAULT 850; // auto lower brightness to stay close to milliampere limit extern bool turnOnAtBoot; extern byte bootPreset; extern byte col[]; @@ -224,11 +227,10 @@ extern bool wifiLock; extern bool aOtaEnabled; extern uint16_t userVar0, userVar1; #ifdef WLED_ENABLE_DMX -extern byte DMXChannels; -extern byte DMXFixtureMap[15]; -extern -extern uint16_t DMXGap; -extern uint16_t DMXStart; + extern byte DMXChannels; + extern byte DMXFixtureMap[15]; + extern uint16_t DMXGap; + extern uint16_t DMXStart; #endif extern bool apActive; extern bool forceReconnect; @@ -315,15 +317,17 @@ extern long lastInterfaceUpdate; extern byte interfaceUpdateCallMode; extern char mqttStatusTopic[40]; #if AUXPIN >= 0 -extern byte auxTime; -extern unsigned long auxStartTime; -extern bool auxActive; + extern byte auxTime; + extern unsigned long auxStartTime; + extern bool auxActive; #endif extern String escapedMac; #ifndef WLED_DISABLE_ALEXA -extern Espalexa espalexa; -extern EspalexaDevice *espalexaDevice; + extern Espalexa espalexa; + extern EspalexaDevice *espalexaDevice; #endif + +#define NTP_PACKET_SIZE 48 extern DNSServer dnsServer; extern bool ntpConnected; extern time_t local; @@ -331,15 +335,14 @@ extern unsigned long ntpLastSyncTime; 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 +// 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) +// string temp buffer (now stored in stack locally) #define OMAX 2048 -extern char *obuf; +extern char* obuf; extern uint16_t olen; extern uint16_t savedPresets; @@ -348,11 +351,11 @@ extern bool isPreset; extern byte errorFlag; extern String messageHead, messageSub; extern byte optionType; -extern bool doReboot; +extern bool doReboot; extern bool doPublishMqtt; extern AsyncWebServer server; -extern AsyncClient *hueClient; -extern AsyncMqttClient *mqtt; +extern AsyncClient* hueClient; +extern AsyncMqttClient* mqtt; extern WiFiUDP notifierUdp, rgbUdp; extern WiFiUDP ntpUdp; extern ESPAsyncE131 e131; @@ -362,46 +365,45 @@ 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 +// 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; + #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) + #define DEBUG_PRINT(x) + #define DEBUG_PRINTLN(x) + #define DEBUG_PRINTF(x) #endif // append new c string to temp buffer efficiently -bool oappend(const char *txt); +bool oappend(const char* txt); // append new number to temp buffer efficiently bool oappendi(int i); -class WLED -{ +class WLED { public: - WLED(); - static WLED &instance() - { - static WLED instance; - return instance; - } + WLED(); + static WLED& instance() + { + static WLED instance; + return instance; + } - //boot starts here - void setup(); + // boot starts here + void setup(); - void loop(); - void reset(); + void loop(); + void reset(); - void beginStrip(); - void handleConnection(); - void initAP(bool resetAP = false); - void initConnection(); - void initInterfaces(); + void beginStrip(); + void handleConnection(); + void initAP(bool resetAP = false); + void initConnection(); + void initInterfaces(); }; -#endif // WLED_H +#endif // WLED_H From aea07f42d1a55155d79269ec775959a41c8e38fd Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 06:56:51 -0400 Subject: [PATCH 23/32] Fix mistaken substitute. --- wled00/FX.cpp | 50 +++++++++++++++++++++++------------------------ wled00/FX_fcn.cpp | 2 +- wled00/blynk.h | 2 +- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index e5408a42..7230a9b3 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -268,7 +268,7 @@ uint16_t WS2812FX::mode_breath(void) { counter = (counter >> 2) + (counter >> 4); //0-16384 + 0-2048 if (counter < 16384) { if (counter > 8192) counter = 8192 - (counter - 8192); - var = sin16(counter) / 103; //close to parabolic in range 0-8192, MAX val. 23170 + var = sin16(counter) / 103; //close to parabolic in range 0-8192, max val. 23170 } uint8_t lum = 30 + var; @@ -475,8 +475,8 @@ uint16_t WS2812FX::mode_twinkle(void) { uint32_t it = now / cycleTime; if (it != SEGENV.step) { - uint16_t MAXOn = map(SEGMENT.intensity, 0, 255, 1, SEGLEN); // make sure at least one LED is on - if (SEGENV.aux0 >= MAXOn) + uint16_t maxOn = map(SEGMENT.intensity, 0, 255, 1, SEGLEN); // make sure at least one LED is on + if (SEGENV.aux0 >= maxOn) { SEGENV.aux0 = 0; SEGENV.aux1 = random16(); //new seed for our PRNG @@ -1597,8 +1597,8 @@ uint16_t WS2812FX::mode_oscillate(void) uint16_t WS2812FX::mode_lightning(void) { - uint16_t ledstart = random16(SEGLEN); // DeterMINe starting location of flash - uint16_t ledlen = random16(SEGLEN -1 -ledstart); // DeterMINe length of flash (not to go beyond NUM_LEDS-1) + uint16_t ledstart = random16(SEGLEN); // Determine starting location of flash + uint16_t ledlen = random16(SEGLEN -1 -ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1) uint8_t bri = 255/random8(1, 3); if (SEGENV.step == 0) @@ -2153,9 +2153,9 @@ typedef struct Ripple { uint16_t WS2812FX::ripple_base(bool rainbow) { - uint16_t MAXRipples = 1 + (SEGLEN >> 2); - if (MAXRipples > 100) MAXRipples = 100; - uint16_t dataSize = sizeof(ripple) * MAXRipples; + uint16_t maxRipples = 1 + (SEGLEN >> 2); + if (maxRipples > 100) maxRipples = 100; + uint16_t dataSize = sizeof(ripple) * maxRipples; if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed @@ -2181,7 +2181,7 @@ uint16_t WS2812FX::ripple_base(bool rainbow) } //draw wave - for (uint16_t i = 0; i < MAXRipples; i++) + for (uint16_t i = 0; i < maxRipples; i++) { uint16_t ripplestate = ripples[i].state; if (ripplestate) @@ -2480,8 +2480,8 @@ uint16_t WS2812FX::spots_base(uint16_t threshold) { fill(SEGCOLOR(1)); - uint16_t MAXZones = SEGLEN >> 2; - uint16_t zones = 1 + ((SEGMENT.intensity * MAXZones) >> 8); + uint16_t maxZones = SEGLEN >> 2; + uint16_t zones = 1 + ((SEGMENT.intensity * maxZones) >> 8); uint16_t zoneLen = SEGLEN / zones; uint16_t offset = (SEGLEN - zones * zoneLen) >> 1; @@ -2533,15 +2533,15 @@ typedef struct Ball { */ uint16_t WS2812FX::mode_bouncing_balls(void) { //allocate segment data - uint16_t MAXNumBalls = 16; - uint16_t dataSize = sizeof(ball) * MAXNumBalls; + uint16_t maxNumBalls = 16; + uint16_t dataSize = sizeof(ball) * maxNumBalls; if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed Ball* balls = reinterpret_cast(SEGENV.data); - // number of balls based on intensity setting to MAX of 7 (cycles colors) + // number of balls based on intensity setting to max of 7 (cycles colors) // non-chosen color is a random color - uint8_t numBalls = int(((SEGMENT.intensity * (MAXNumBalls - 0.8f)) / 255) + 1); + uint8_t numBalls = int(((SEGMENT.intensity * (maxNumBalls - 0.8f)) / 255) + 1); float gravity = -9.81; // standard value of gravity float impactVelocityStart = sqrt( -2 * gravity); @@ -2549,7 +2549,7 @@ uint16_t WS2812FX::mode_bouncing_balls(void) { unsigned long time = millis(); if (SEGENV.call == 0) { - for (uint8_t i = 0; i < MAXNumBalls; i++) balls[i].lastBounceTime = time; + for (uint8_t i = 0; i < maxNumBalls; i++) balls[i].lastBounceTime = time; } bool hasCol2 = SEGCOLOR(2); @@ -2665,8 +2665,8 @@ typedef struct Spark { */ uint16_t WS2812FX::mode_popcorn(void) { //allocate segment data - uint16_t MAXNumPopcorn = 24; - uint16_t dataSize = sizeof(spark) * MAXNumPopcorn; + uint16_t maxNumPopcorn = 24; + uint16_t dataSize = sizeof(spark) * maxNumPopcorn; if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed Spark* popcorn = reinterpret_cast(SEGENV.data); @@ -2677,7 +2677,7 @@ uint16_t WS2812FX::mode_popcorn(void) { bool hasCol2 = SEGCOLOR(2); fill(hasCol2 ? BLACK : SEGCOLOR(1)); - uint8_t numPopcorn = SEGMENT.intensity*MAXNumPopcorn/255; + uint8_t numPopcorn = SEGMENT.intensity*maxNumPopcorn/255; if (numPopcorn == 0) numPopcorn = 1; for(uint8_t i = 0; i < numPopcorn; i++) { @@ -2792,13 +2792,13 @@ uint16_t WS2812FX::mode_starburst(void) { star* stars = reinterpret_cast(SEGENV.data); - float MAXSpeed = 375.0f; // Max velocity + float maxSpeed = 375.0f; // Max velocity float particleIgnition = 250.0f; // How long to "flash" float particleFadeTime = 1500.0f; // Fade out time for (int j = 0; j < numStars; j++) { - // speed to adjust chance of a burst, MAX is nearly always. + // speed to adjust chance of a burst, max is nearly always. if (random8((144-(SEGMENT.speed >> 1))) == 0 && stars[j].birth == 0) { // Pick a random color and location. @@ -2807,7 +2807,7 @@ uint16_t WS2812FX::mode_starburst(void) { stars[j].color = col_to_crgb(color_wheel(random8())); stars[j].pos = startPos; - stars[j].vel = MAXSpeed * (float)(random8())/255.0 * multiplier; + stars[j].vel = maxSpeed * (float)(random8())/255.0 * multiplier; stars[j].birth = it; stars[j].last = it; // more fragments means larger burst effect @@ -3026,7 +3026,7 @@ uint16_t WS2812FX::mode_drip(void) drops[j].pos = SEGLEN-1; // start at end drops[j].vel = 0; // speed drops[j].col = sourcedrop; // brightness - drops[j].colIndex = 1; // drop state (0 init, 1 forMINg, 2 falling, 5 bouncing) + drops[j].colIndex = 1; // drop state (0 init, 1 forming, 2 falling, 5 bouncing) } setPixelColor(SEGLEN-1,color_blend(BLACK,SEGCOLOR(0), sourcedrop));// water source @@ -3047,7 +3047,7 @@ uint16_t WS2812FX::mode_drip(void) if (drops[j].pos < 0) drops[j].pos = 0; drops[j].vel += gravity; - for (int i=1;i<7-drops[j].colIndex;i++) { // some MINor math so we don't expand bouncing droplets + for (int i=1;i<7-drops[j].colIndex;i++) { // some minor math so we don't expand bouncing droplets setPixelColor(int(drops[j].pos)+i,color_blend(BLACK,SEGCOLOR(0),drops[j].col/i)); //spread pixel with fade while falling } @@ -3055,7 +3055,7 @@ uint16_t WS2812FX::mode_drip(void) setPixelColor(0,color_blend(SEGCOLOR(0),BLACK,drops[j].col)); } } else { // we hit bottom - if (drops[j].colIndex > 2) { // already hit once, so back to forMINg + if (drops[j].colIndex > 2) { // already hit once, so back to forming drops[j].colIndex = 0; drops[j].col = sourcedrop; diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 75ec6510..de89a430 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -638,7 +638,7 @@ uint32_t WS2812FX::color_wheel(uint8_t pos) { } /* - * Returns a new, random wheel index with a MINimum distance of 42 from pos. + * Returns a new, random wheel index with a minimum distance of 42 from pos. */ uint8_t WS2812FX::get_random_wheel_index(uint8_t pos) { uint8_t r = 0, x = 0, y = 0, d = 0; diff --git a/wled00/blynk.h b/wled00/blynk.h index cf3a2e22..f17f774a 100644 --- a/wled00/blynk.h +++ b/wled00/blynk.h @@ -8,6 +8,6 @@ void initBlynk(const char* auth); void handleBlynk(); void updateBlynk(); -// Unsure if the macro expansions need to accessed through the declaration... TODO +// TODO: Make sure that the macro expansions are handled correctly. #endif //WLED_BLYNK_H \ No newline at end of file From 8ff4f50f79aa0f663f25408c621d235225734272 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 07:24:45 -0400 Subject: [PATCH 24/32] Fix visual studio project files and organize. --- wled00/wled00.vcxproj | 317 +++++----------- wled00/wled00.vcxproj.filters | 657 ++++++++++++++++++++-------------- 2 files changed, 483 insertions(+), 491 deletions(-) diff --git a/wled00/wled00.vcxproj b/wled00/wled00.vcxproj index 2183ad26..e095b8f7 100644 --- a/wled00/wled00.vcxproj +++ b/wled00/wled00.vcxproj @@ -104,231 +104,103 @@ CppCode - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - - - CppCode - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -350,6 +222,11 @@ + + + + + VisualMicroDebugger @@ -362,4 +239,4 @@ - \ No newline at end of file + diff --git a/wled00/wled00.vcxproj.filters b/wled00/wled00.vcxproj.filters index e2c2b219..ef1f47bd 100644 --- a/wled00/wled00.vcxproj.filters +++ b/wled00/wled00.vcxproj.filters @@ -1,272 +1,387 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - - - - - - - - - - - - - - - - - - - - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {72fe60da-ba26-45b4-82c1-bdff809975da} + + + {8880888d-efea-4189-a25a-834b7b3bb756} + + + + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files\Dependencies + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files\Dependencies + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + \ No newline at end of file From a9a7720a1158dc5b7a2c95c430bcebbc14c4ae3f Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 07:45:33 -0400 Subject: [PATCH 25/32] Import dmx output library into project. --- wled00/dmx.h | 39 ++++----- wled00/src/dependencies/dmx/ESPDMX.cpp | 106 +++++++++++++++++++++++++ wled00/src/dependencies/dmx/ESPDMX.h | 31 ++++++++ wled00/wled.cpp | 1 + 4 files changed, 158 insertions(+), 19 deletions(-) create mode 100644 wled00/src/dependencies/dmx/ESPDMX.cpp create mode 100644 wled00/src/dependencies/dmx/ESPDMX.h diff --git a/wled00/dmx.h b/wled00/dmx.h index 76aab484..0ab2a4a2 100644 --- a/wled00/dmx.h +++ b/wled00/dmx.h @@ -1,64 +1,65 @@ #ifndef WLED_DMX_H #define WLED_DMX_H -#include "wled.h" +#include "wled.h" /* * Support for DMX via MAX485. - * Needs the espdmx library. You might have to change the output pin within the library. Sketchy, i know. + * Change the output pin in src/dependencies/ESPDMX.cpp if needed. + * Library from: * https://github.com/Rickgg/ESP-Dmx */ #ifdef WLED_ENABLE_DMX -#include +#include "src/dependencies/dmx/ESPDMX.h" DMXESPSerial dmx; -#ifdef WLED_ENABLE_DMX -void handleDMX() { +void handleDMX() +{ // TODO: calculate brightness manually if no shutter channel is set - + uint8_t brightness = strip.getBrightness(); - for (int i = 0; i < ledCount; i++) { // uses the amount of LEDs as fixture count + 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); // time to get the colors for the individual fixtures as suggested by AirCookie at issue #462 byte w = in >> 24 & 0xFF; byte r = in >> 16 & 0xFF; - byte g = in >> 8 & 0xFF; - byte b = in & 0xFF; + byte g = in >> 8 & 0xFF; + byte b = in & 0xFF; int DMXFixtureStart = DMXStart + (DMXGap * i); for (int j = 0; j < DMXChannels; j++) { int DMXAddr = DMXFixtureStart + j; switch (DMXFixtureMap[j]) { - case 0: // Set this channel to 0. Good way to tell strobe- and fade-functions to fuck right off. + case 0: // Set this channel to 0. Good way to tell strobe- and fade-functions to fuck right off. dmx.write(DMXAddr, 0); break; - case 1: // Red + case 1: // Red dmx.write(DMXAddr, r); break; - case 2: // Green + case 2: // Green dmx.write(DMXAddr, g); break; - case 3: // Blue + case 3: // Blue dmx.write(DMXAddr, b); break; - case 4: // White + case 4: // White dmx.write(DMXAddr, w); break; - case 5: // Shutter channel. Controls the brightness. + case 5: // Shutter channel. Controls the brightness. dmx.write(DMXAddr, brightness); break; - case 6:// Sets this channel to 255. Like 0, but more wholesome. + case 6: // Sets this channel to 255. Like 0, but more wholesome. dmx.write(DMXAddr, 255); break; } } } - dmx.update(); // update the DMX bus + dmx.update(); // update the DMX bus } #else void handleDMX() {} #endif -#endif //WLED_DMX_H \ No newline at end of file +#endif //WLED_DMX_H \ No newline at end of file diff --git a/wled00/src/dependencies/dmx/ESPDMX.cpp b/wled00/src/dependencies/dmx/ESPDMX.cpp new file mode 100644 index 00000000..f3ece1c8 --- /dev/null +++ b/wled00/src/dependencies/dmx/ESPDMX.cpp @@ -0,0 +1,106 @@ +// - - - - - +// ESPDMX - A Arduino library for sending and receiving DMX using the builtin serial hardware port. +// ESPDMX.cpp: Library implementation file +// +// Copyright (C) 2015 Rick +// This work is licensed under a GNU style license. +// +// Last change: Marcel Seerig +// +// Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx +// - - - - - + +/* ----- LIBRARIES ----- */ +#include + +#include "ESPDMX.h" + + + +#define dmxMaxChannel 512 +#define defaultMax 32 + +#define DMXSPEED 250000 +#define DMXFORMAT SERIAL_8N2 +#define BREAKSPEED 83333 +#define BREAKFORMAT SERIAL_8N1 + +bool dmxStarted = false; +int sendPin = 2; //dafault on ESP8266 + +//DMX value array and size. Entry 0 will hold startbyte +uint8_t dmxData[dmxMaxChannel] = {}; +int chanSize; + + +void DMXESPSerial::init() { + chanSize = defaultMax; + + Serial1.begin(DMXSPEED); + pinMode(sendPin, OUTPUT); + dmxStarted = true; +} + +// Set up the DMX-Protocol +void DMXESPSerial::init(int chanQuant) { + + if (chanQuant > dmxMaxChannel || chanQuant <= 0) { + chanQuant = defaultMax; + } + + chanSize = chanQuant; + + Serial1.begin(DMXSPEED); + pinMode(sendPin, OUTPUT); + dmxStarted = true; +} + +// Function to read DMX data +uint8_t DMXESPSerial::read(int Channel) { + if (dmxStarted == false) init(); + + if (Channel < 1) Channel = 1; + if (Channel > dmxMaxChannel) Channel = dmxMaxChannel; + return(dmxData[Channel]); +} + +// Function to send DMX data +void DMXESPSerial::write(int Channel, uint8_t value) { + if (dmxStarted == false) init(); + + if (Channel < 1) Channel = 1; + if (Channel > chanSize) Channel = chanSize; + if (value < 0) value = 0; + if (value > 255) value = 255; + + dmxData[Channel] = value; +} + +void DMXESPSerial::end() { + delete dmxData; + chanSize = 0; + Serial1.end(); + dmxStarted == false; +} + +void DMXESPSerial::update() { + if (dmxStarted == false) init(); + + //Send break + digitalWrite(sendPin, HIGH); + Serial1.begin(BREAKSPEED, BREAKFORMAT); + Serial1.write(0); + Serial1.flush(); + delay(1); + Serial1.end(); + + //send data + Serial1.begin(DMXSPEED, DMXFORMAT); + digitalWrite(sendPin, LOW); + Serial1.write(dmxData, chanSize); + Serial1.flush(); + delay(1); + Serial1.end(); +} + +// Function to update the DMX bus diff --git a/wled00/src/dependencies/dmx/ESPDMX.h b/wled00/src/dependencies/dmx/ESPDMX.h new file mode 100644 index 00000000..4585bdd2 --- /dev/null +++ b/wled00/src/dependencies/dmx/ESPDMX.h @@ -0,0 +1,31 @@ +// - - - - - +// ESPDMX - A Arduino library for sending and receiving DMX using the builtin serial hardware port. +// ESPDMX.cpp: Library implementation file +// +// Copyright (C) 2015 Rick +// This work is licensed under a GNU style license. +// +// Last change: Marcel Seerig +// +// Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx +// - - - - - + +#include + + +#ifndef ESPDMX_h +#define ESPDMX_h + +// ---- Methods ---- + +class DMXESPSerial { +public: + void init(); + void init(int MaxChan); + uint8_t read(int Channel); + void write(int channel, uint8_t value); + void update(); + void end(); +}; + +#endif diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 48231599..fdb60776 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -2,6 +2,7 @@ #include "alexa.h" #include "blynk.h" #include "button.h" +#include "dmx.h" #include "file.h" #include "hue.h" #include "ir.h" From ad70fcba7fc2dbda16ec78b27a1ad443378a5ef4 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 08:00:58 -0400 Subject: [PATCH 26/32] Typo fix. --- wled00/overlay.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wled00/overlay.h b/wled00/overlay.h index b403a6e2..f7b54d5d 100644 --- a/wled00/overlay.h +++ b/wled00/overlay.h @@ -1,5 +1,5 @@ -#ifndef WLED_OVERLAYS_H -#define WLED_OVERLAYS_H +#ifndef WLED_OVERLAY_H +#define WLED_OVERLAY_H #include /* * Used to draw clock overlays over the strip From cf29ddc8d0d25a240648f044d798eb4ebd59f710 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 08:03:55 -0400 Subject: [PATCH 27/32] Typo fix. --- wled00/usermod.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/usermod.cpp b/wled00/usermod.cpp index 6589c07c..96c1f8a6 100644 --- a/wled00/usermod.cpp +++ b/wled00/usermod.cpp @@ -2,7 +2,7 @@ /* * This file allows you to add own functionality to WLED more easily * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality - * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in wled01_wled_eeprom.h) + * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in wled_eeprom.h) * bytes 2400+ are currently ununsed, but might be used for future wled features */ From 9875fbef0aa2c159eec8496dfd77fda80e8cd930 Mon Sep 17 00:00:00 2001 From: Travis J Dean Date: Mon, 30 Mar 2020 08:34:20 -0400 Subject: [PATCH 28/32] Layout changes. --- wled00/wled.h | 2 +- wled00/wled00.vcxproj.filters | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wled00/wled.h b/wled00/wled.h index 72686a00..70b197c8 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -35,7 +35,7 @@ // Library inclusions. #include - #ifdef ESP8266 +#ifdef ESP8266 #include #include #include diff --git a/wled00/wled00.vcxproj.filters b/wled00/wled00.vcxproj.filters index ef1f47bd..39fe509e 100644 --- a/wled00/wled00.vcxproj.filters +++ b/wled00/wled00.vcxproj.filters @@ -135,9 +135,6 @@ Header Files\Dependencies - - Header Files\Dependencies - Header Files\Dependencies @@ -147,9 +144,6 @@ Header Files\Dependencies - - Header Files\Dependencies - Header Files\Dependencies @@ -258,6 +252,12 @@ Header Files + + Header Files + + + Header Files + From a88ae2ca56a277d070906832a534960f1eecc26c Mon Sep 17 00:00:00 2001 From: Travis Dean Date: Mon, 30 Mar 2020 08:48:01 -0400 Subject: [PATCH 29/32] Delete .clang-format --- .clang-format | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .clang-format diff --git a/.clang-format b/.clang-format deleted file mode 100644 index aedd2246..00000000 --- a/.clang-format +++ /dev/null @@ -1,12 +0,0 @@ ---- - BasedOnStyle: Webkit - IndentWidth: 2 - AlignTrailingComments: true - SpacesBeforeTrailingComments: 8 - AllowShortIfStatementsOnASingleLine: Always - AllowShortLoopsOnASingleLine: true - AllowShortLambdasOnASingleLine: true - AllowShortCaseLabelsOnASingleLine: true - AllowShortFunctionsOnASingleLine: All - AllowShortBlocksOnASingleLine: true - IndentCaseLabels: true \ No newline at end of file From 6268cadc950db2e58d1837361ebe2e64db9f27f5 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Tue, 31 Mar 2020 02:38:08 +0200 Subject: [PATCH 30/32] Function definitions in func_declare.h Significantly reducing number of header files --- CHANGELOG.md | 36 ++--- wled00/alexa.cpp | 14 +- wled00/alexa.h | 17 --- wled00/blynk.cpp | 8 +- wled00/blynk.h | 13 -- wled00/button.cpp | 4 - wled00/button.h | 12 -- wled00/colors.cpp | 5 +- wled00/colors.h | 20 --- wled00/const.h | 7 +- wled00/cronixie.cpp | 243 ------------------------------- wled00/cronixie.h | 13 -- wled00/{dmx.h => dmx.cpp} | 5 +- wled00/e131.cpp | 144 +++++++++++++++++++ wled00/file.cpp | 86 +---------- wled00/file.h | 12 -- wled00/func_declare.h | 183 ++++++++++++++++++++++++ wled00/hue.cpp | 9 +- wled00/hue.h | 16 --- wled00/ir.cpp | 8 +- wled00/ir.h | 24 ---- wled00/json.cpp | 7 +- wled00/json.h | 21 --- wled00/led.cpp | 10 +- wled00/led.h | 19 --- wled00/mqtt.cpp | 10 +- wled00/mqtt.h | 9 -- wled00/notify.h | 18 --- wled00/ntp.cpp | 6 +- wled00/ntp.h | 18 --- wled00/overlay.cpp | 253 ++++++++++++++++++++++++++++++++- wled00/overlay.h | 14 -- wled00/set.cpp | 14 +- wled00/set.h | 16 --- wled00/{notify.cpp => udp.cpp} | 148 +------------------ wled00/usermod.cpp | 2 +- wled00/usermod.h | 8 -- wled00/wled.cpp | 17 +-- wled00/wled.h | 9 +- wled00/wled00.ino | 6 +- wled00/wled_eeprom.cpp | 9 +- wled00/wled_eeprom.h | 23 --- wled00/wled_serial.cpp | 83 +++++++++++ wled00/wled_server.cpp | 8 +- wled00/wled_server.h | 21 --- wled00/xml.cpp | 6 +- wled00/xml.h | 15 -- 47 files changed, 759 insertions(+), 890 deletions(-) delete mode 100644 wled00/alexa.h delete mode 100644 wled00/blynk.h delete mode 100644 wled00/button.h delete mode 100644 wled00/colors.h delete mode 100644 wled00/cronixie.cpp delete mode 100644 wled00/cronixie.h rename wled00/{dmx.h => dmx.cpp} (96%) create mode 100644 wled00/e131.cpp delete mode 100644 wled00/file.h create mode 100644 wled00/func_declare.h delete mode 100644 wled00/hue.h delete mode 100644 wled00/ir.h delete mode 100644 wled00/json.h delete mode 100644 wled00/led.h delete mode 100644 wled00/mqtt.h delete mode 100644 wled00/notify.h delete mode 100644 wled00/ntp.h delete mode 100644 wled00/overlay.h delete mode 100644 wled00/set.h rename wled00/{notify.cpp => udp.cpp} (55%) delete mode 100644 wled00/usermod.h delete mode 100644 wled00/wled_eeprom.h create mode 100644 wled00/wled_serial.cpp delete mode 100644 wled00/wled_server.h delete mode 100644 wled00/xml.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d3a466c..a9804b1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,43 +2,47 @@ ### Development versions after 0.9.1 release +#### Build 2003300 + +- Major change of project structure from .ino to .cpp and func_declare.h + #### Build 2003262 - - Fixed compilation for Analog LEDs - - Fixed sync settings network port fields too small +- Fixed compilation for Analog LEDs +- Fixed sync settings network port fields too small #### Build 2003261 - - Fixed live preview not displaying whole light if over 255 LEDs +- Fixed live preview not displaying whole light if over 255 LEDs #### Build 2003251 - - Added Pacifica effect (tentative, doesn't yet support other colors) - - Added Atlantica palette - - Fixed ESP32 build of Espalexa +- Added Pacifica effect (tentative, doesn't yet support other colors) +- Added Atlantica palette +- Fixed ESP32 build of Espalexa #### Build 2003222 - - Fixed Alexa Whites on non-RGBW lights (bump Espalexa to 2.4.5) +- Fixed Alexa Whites on non-RGBW lights (bump Espalexa to 2.4.5) #### Build 2003221 - - Moved Cronixie driver from FX library to drawOverlay handler +- Moved Cronixie driver from FX library to drawOverlay handler #### Build 2003211 - - Added custom mapping compile define to FX_fcn.h - - Merged pull request #784 by @TravisDean: Fixed initialization bug when toggling skip first - - Added link to youtube videos by Room31 to readme +- Added custom mapping compile define to FX_fcn.h +- Merged pull request #784 by @TravisDean: Fixed initialization bug when toggling skip first +- Added link to youtube videos by Room31 to readme #### Build 2003141 - - Fixed color of main segment returned in JSON API during transition not being target color (closes #765) - - Fixed arlsLock() being called after pixels set in E1.31 (closes #772) - - Fixed HTTP API calls not having an effect if no segment selected (now applies to main segment) +- Fixed color of main segment returned in JSON API during transition not being target color (closes #765) +- Fixed arlsLock() being called after pixels set in E1.31 (closes #772) +- Fixed HTTP API calls not having an effect if no segment selected (now applies to main segment) #### Build 2003121 - - Created changelog.md - make tracking changes to code easier - - Merged pull request #766 by @pille: Fix E1.31 out-of sequence detection +- Created changelog.md - make tracking changes to code easier +- Merged pull request #766 by @pille: Fix E1.31 out-of sequence detection diff --git a/wled00/alexa.cpp b/wled00/alexa.cpp index e35f5b35..c9f61ff2 100644 --- a/wled00/alexa.cpp +++ b/wled00/alexa.cpp @@ -1,9 +1,13 @@ -#include "alexa.h" #include "wled.h" -#include "const.h" -#include "led.h" -#include "wled_eeprom.h" -#include "colors.h" + +/* + * Alexa Voice On/Off/Brightness/Color Control. Emulates a Philips Hue bridge to Alexa. + * + * This was put together from these two excellent projects: + * https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch + * https://github.com/probonopd/ESP8266HueEmulator + */ +#include "src/dependencies/espalexa/EspalexaDevice.h" #ifndef WLED_DISABLE_ALEXA void onAlexaChange(EspalexaDevice* dev); diff --git a/wled00/alexa.h b/wled00/alexa.h deleted file mode 100644 index c2adfebe..00000000 --- a/wled00/alexa.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef WLED_ALEXA_H -#define WLED_ALEXA_H -/* - * Alexa Voice On/Off/Brightness Control. Emulates a Philips Hue bridge to Alexa. - * - * This was put together from these two excellent projects: - * https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch - * https://github.com/probonopd/ESP8266HueEmulator - */ -#include "src/dependencies/espalexa/EspalexaDevice.h" - -void onAlexaChange(EspalexaDevice* dev); -void alexaInit(); -void handleAlexa(); -void onAlexaChange(EspalexaDevice* dev); - -#endif // WLED_ALEXA_H \ No newline at end of file diff --git a/wled00/blynk.cpp b/wled00/blynk.cpp index 2307a694..39b43ba8 100644 --- a/wled00/blynk.cpp +++ b/wled00/blynk.cpp @@ -1,9 +1,9 @@ -#include "blynk.h" -#include "const.h" #include "wled.h" #include "src/dependencies/blynk/Blynk/BlynkHandlers.h" -#include "led.h" -#include "colors.h" + +/* + * Remote light control with the free Blynk app + */ uint16_t blHue = 0; byte blSat = 255; diff --git a/wled00/blynk.h b/wled00/blynk.h deleted file mode 100644 index f17f774a..00000000 --- a/wled00/blynk.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef WLED_BLYNK_H -#define WLED_BLYNK_H -#include -/* - * Remote light control with the free Blynk app - */ - -void initBlynk(const char* auth); -void handleBlynk(); -void updateBlynk(); -// TODO: Make sure that the macro expansions are handled correctly. - -#endif //WLED_BLYNK_H \ No newline at end of file diff --git a/wled00/button.cpp b/wled00/button.cpp index a80061ee..e71cce96 100644 --- a/wled00/button.cpp +++ b/wled00/button.cpp @@ -1,8 +1,4 @@ -#include "button.h" #include "wled.h" -#include "led.h" -#include "wled_eeprom.h" -#include "set.h" /* * Physical IO diff --git a/wled00/button.h b/wled00/button.h deleted file mode 100644 index f974888e..00000000 --- a/wled00/button.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef WLED_BUTTON_H -#define WLED_BUTTON_H -#include -/* - * Physical IO - */ - -void shortPressAction(); -void handleButton(); -void handleIO(); - -#endif // WLED_BUTTON_H \ No newline at end of file diff --git a/wled00/colors.cpp b/wled00/colors.cpp index 6f247757..f76499a0 100644 --- a/wled00/colors.cpp +++ b/wled00/colors.cpp @@ -1,6 +1,9 @@ -#include "colors.h" #include "wled.h" +/* + * Color conversion methods + */ + void colorFromUint32(uint32_t in, bool secondary) { if (secondary) { diff --git a/wled00/colors.h b/wled00/colors.h deleted file mode 100644 index 85e0adb5..00000000 --- a/wled00/colors.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef WLED_COLORS_H -#define WLED_COLORS_H -#include -/* - * Color conversion methods - */ - -void colorFromUint32(uint32_t in, bool secondary = false); -void colorFromUint24(uint32_t in, bool secondary = false); -void relativeChangeWhite(int8_t amount, byte lowerBoundary = 0); -void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb -void colorCTtoRGB(uint16_t mired, byte* rgb); //white spectrum to rgb - -void colorXYtoRGB(float x, float y, byte* rgb); // only defined if huesync disabled TODO -void colorRGBtoXY(byte* rgb, float* xy); // only defined if huesync disabled TODO - -void colorFromDecOrHexString(byte* rgb, char* in); -void colorRGBtoRGBW(byte* rgb); //rgb to rgbw (http://codewelt.com/rgbw). (RGBW_MODE_LEGACY) - -#endif //WLED_COLORS_H \ No newline at end of file diff --git a/wled00/const.h b/wled00/const.h index 21be1953..535a5987 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -1,5 +1,5 @@ -#ifndef wled_const_h -#define wled_const_h +#ifndef WLED_CONST_H +#define WLED_CONST_H //Defaults #define DEFAULT_CLIENT_SSID "Your_Network" @@ -72,4 +72,7 @@ #define HUE_ERROR_TIMEOUT 251 #define HUE_ERROR_ACTIVE 255 +//EEPROM size +#define EEPSIZE 2560 //Maximum is 4096 + #endif diff --git a/wled00/cronixie.cpp b/wled00/cronixie.cpp deleted file mode 100644 index e3b951b8..00000000 --- a/wled00/cronixie.cpp +++ /dev/null @@ -1,243 +0,0 @@ -#include "cronixie.h" -#include "wled.h" - -#ifndef WLED_DISABLE_CRONIXIE -byte _digitOut[6] = {10,10,10,10,10,10}; - -byte getSameCodeLength(char code, int index, char const cronixieDisplay[]) -{ - byte counter = 0; - - for (int i = index+1; i < 6; i++) - { - if (cronixieDisplay[i] == code) - { - counter++; - } else { - return counter; - } - } - return counter; -} - -void setCronixie() -{ - /* - * digit purpose index - * 0-9 | 0-9 (incl. random) - * 10 | blank - * 11 | blank, bg off - * 12 | test upw. - * 13 | test dnw. - * 14 | binary AM/PM - * 15 | BB upper +50 for no trailing 0 - * 16 | BBB - * 17 | BBBB - * 18 | BBBBB - * 19 | BBBBBB - * 20 | H - * 21 | HH - * 22 | HHH - * 23 | HHHH - * 24 | M - * 25 | MM - * 26 | MMM - * 27 | MMMM - * 28 | MMMMM - * 29 | MMMMMM - * 30 | S - * 31 | SS - * 32 | SSS - * 33 | SSSS - * 34 | SSSSS - * 35 | SSSSSS - * 36 | Y - * 37 | YY - * 38 | YYYY - * 39 | I - * 40 | II - * 41 | W - * 42 | WW - * 43 | D - * 44 | DD - * 45 | DDD - * 46 | V - * 47 | VV - * 48 | VVV - * 49 | VVVV - * 50 | VVVVV - * 51 | VVVVVV - * 52 | v - * 53 | vv - * 54 | vvv - * 55 | vvvv - * 56 | vvvvv - * 57 | vvvvvv - */ - - //H HourLower | HH - Hour 24. | AH - Hour 12. | HHH Hour of Month | HHHH Hour of Year - //M MinuteUpper | MM Minute of Hour | MMM Minute of 12h | MMMM Minute of Day | MMMMM Minute of Month | MMMMMM Minute of Year - //S SecondUpper | SS Second of Minute | SSS Second of 10 Minute | SSSS Second of Hour | SSSSS Second of Day | SSSSSS Second of Week - //B AM/PM | BB 0-6/6-12/12-18/18-24 | BBB 0-3... | BBBB 0-1.5... | BBBBB 0-1 | BBBBBB 0-0.5 - - //Y YearLower | YY - Year LU | YYYY - Std. - //I MonthLower | II - Month of Year - //W Week of Month | WW Week of Year - //D Day of Week | DD Day Of Month | DDD Day Of Year - - DEBUG_PRINT("cset "); - DEBUG_PRINTLN(cronixieDisplay); - - overlayRefreshMs = 1997; //Only refresh every 2secs if no seconds are displayed - - for (int i = 0; i < 6; i++) - { - dP[i] = 10; - switch (cronixieDisplay[i]) - { - case '_': dP[i] = 10; break; - case '-': dP[i] = 11; break; - case 'r': dP[i] = random(1,7); break; //random btw. 1-6 - case 'R': dP[i] = random(0,10); break; //random btw. 0-9 - //case 't': break; //Test upw. - //case 'T': break; //Test dnw. - case 'b': dP[i] = 14 + getSameCodeLength('b',i,cronixieDisplay); i = i+dP[i]-14; break; - case 'B': dP[i] = 14 + getSameCodeLength('B',i,cronixieDisplay); i = i+dP[i]-14; break; - case 'h': dP[i] = 70 + getSameCodeLength('h',i,cronixieDisplay); i = i+dP[i]-70; break; - case 'H': dP[i] = 20 + getSameCodeLength('H',i,cronixieDisplay); i = i+dP[i]-20; break; - case 'A': dP[i] = 108; i++; break; - case 'a': dP[i] = 58; i++; break; - case 'm': dP[i] = 74 + getSameCodeLength('m',i,cronixieDisplay); i = i+dP[i]-74; break; - case 'M': dP[i] = 24 + getSameCodeLength('M',i,cronixieDisplay); i = i+dP[i]-24; break; - case 's': dP[i] = 80 + getSameCodeLength('s',i,cronixieDisplay); i = i+dP[i]-80; overlayRefreshMs = 497; break; //refresh more often bc. of secs - case 'S': dP[i] = 30 + getSameCodeLength('S',i,cronixieDisplay); i = i+dP[i]-30; overlayRefreshMs = 497; break; - case 'Y': dP[i] = 36 + getSameCodeLength('Y',i,cronixieDisplay); i = i+dP[i]-36; break; - case 'y': dP[i] = 86 + getSameCodeLength('y',i,cronixieDisplay); i = i+dP[i]-86; break; - case 'I': dP[i] = 39 + getSameCodeLength('I',i,cronixieDisplay); i = i+dP[i]-39; break; //Month. Don't ask me why month and minute both start with M. - case 'i': dP[i] = 89 + getSameCodeLength('i',i,cronixieDisplay); i = i+dP[i]-89; break; - //case 'W': break; - //case 'w': break; - case 'D': dP[i] = 43 + getSameCodeLength('D',i,cronixieDisplay); i = i+dP[i]-43; break; - case 'd': dP[i] = 93 + getSameCodeLength('d',i,cronixieDisplay); i = i+dP[i]-93; break; - case '0': dP[i] = 0; break; - case '1': dP[i] = 1; break; - case '2': dP[i] = 2; break; - case '3': dP[i] = 3; break; - case '4': dP[i] = 4; break; - case '5': dP[i] = 5; break; - case '6': dP[i] = 6; break; - case '7': dP[i] = 7; break; - case '8': dP[i] = 8; break; - case '9': dP[i] = 9; break; - //case 'V': break; //user var0 - //case 'v': break; //user var1 - } - } - DEBUG_PRINT("result "); - for (int i = 0; i < 5; i++) - { - DEBUG_PRINT((int)dP[i]); - DEBUG_PRINT(" "); - } - DEBUG_PRINTLN((int)dP[5]); - - _overlayCronixie(); //refresh -} - -void _overlayCronixie() -{ - byte h = hour(local); - byte h0 = h; - byte m = minute(local); - byte s = second(local); - byte d = day(local); - byte mi = month(local); - int y = year(local); - //this has to be changed in time for 22nd century - y -= 2000; if (y<0) y += 30; //makes countdown work - - if (useAMPM && !countdownMode) - { - if (h>12) h-=12; - else if (h==0) h+=12; - } - for (int i = 0; i < 6; i++) - { - if (dP[i] < 12) _digitOut[i] = dP[i]; - else { - if (dP[i] < 65) - { - switch(dP[i]) - { - case 21: _digitOut[i] = h/10; _digitOut[i+1] = h- _digitOut[i]*10; i++; break; //HH - case 25: _digitOut[i] = m/10; _digitOut[i+1] = m- _digitOut[i]*10; i++; break; //MM - case 31: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; i++; break; //SS - - case 20: _digitOut[i] = h- (h/10)*10; break; //H - case 24: _digitOut[i] = m/10; break; //M - case 30: _digitOut[i] = s/10; break; //S - - case 43: _digitOut[i] = weekday(local); _digitOut[i]--; if (_digitOut[i]<1) _digitOut[i]= 7; break; //D - case 44: _digitOut[i] = d/10; _digitOut[i+1] = d- _digitOut[i]*10; i++; break; //DD - case 40: _digitOut[i] = mi/10; _digitOut[i+1] = mi- _digitOut[i]*10; i++; break; //II - case 37: _digitOut[i] = y/10; _digitOut[i+1] = y- _digitOut[i]*10; i++; break; //YY - case 39: _digitOut[i] = 2; _digitOut[i+1] = 0; _digitOut[i+2] = y/10; _digitOut[i+3] = y- _digitOut[i+2]*10; i+=3; break; //YYYY - - //case 16: _digitOut[i+2] = ((h0/3)&1)?1:0; i++; //BBB (BBBB NI) - //case 15: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:0; i++; //BB - case 14: _digitOut[i] = (h0>11)?1:0; break; //B - } - } else - { - switch(dP[i]) - { - case 71: _digitOut[i] = h/10; _digitOut[i+1] = h- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //hh - case 75: _digitOut[i] = m/10; _digitOut[i+1] = m- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //mm - case 81: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //ss - //case 66: _digitOut[i+2] = ((h0/3)&1)?1:10; i++; //bbb (bbbb NI) - //case 65: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:10; i++; //bb - case 64: _digitOut[i] = (h0>11)?1:10; break; //b - - case 93: _digitOut[i] = weekday(local); _digitOut[i]--; if (_digitOut[i]<1) _digitOut[i]= 7; break; //d - case 94: _digitOut[i] = d/10; _digitOut[i+1] = d- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //dd - case 90: _digitOut[i] = mi/10; _digitOut[i+1] = mi- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //ii - case 87: _digitOut[i] = y/10; _digitOut[i+1] = y- _digitOut[i]*10; i++; break; //yy - case 89: _digitOut[i] = 2; _digitOut[i+1] = 0; _digitOut[i+2] = y/10; _digitOut[i+3] = y- _digitOut[i+2]*10; i+=3; break; //yyyy - } - } - } - } -} - -void _drawOverlayCronixie() -{ - byte offsets[] = {5, 0, 6, 1, 7, 2, 8, 3, 9, 4}; - - for (uint16_t i = 0; i < 6; i++) - { - byte o = 10*i; - byte excl = 10; - if(_digitOut[i] < 10) excl = offsets[_digitOut[i]]; - excl += o; - - if (cronixieBacklight && _digitOut[i] <11) - { - uint32_t col = strip.gamma32(strip.getSegment(0).colors[1]); - for (uint16_t j=o; j< o+10; j++) { - if (j != excl) strip.setPixelColor(j, col); - } - } else - { - for (uint16_t j=o; j< o+10; j++) { - if (j != excl) strip.setPixelColor(j, 0); - } - } - } -} - -#else // WLED_DISABLE_CRONIXIE -byte getSameCodeLength(char code, int index, char const cronixieDisplay[]) {} -void setCronixie() {} -void _overlayCronixie() {} -void _drawOverlayCronixie() {} -#endif diff --git a/wled00/cronixie.h b/wled00/cronixie.h deleted file mode 100644 index f6eea6b4..00000000 --- a/wled00/cronixie.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef WLED_CRONIXIE_H -#define WLED_CRONIXIE_H -#include -/* - * Support for the Cronixie clock - */ - -byte getSameCodeLength(char code, int index, char const cronixieDisplay[]); -void setCronixie(); -void _overlayCronixie(); -void _drawOverlayCronixie(); - -#endif // WLED_CRONIXIE_H \ No newline at end of file diff --git a/wled00/dmx.h b/wled00/dmx.cpp similarity index 96% rename from wled00/dmx.h rename to wled00/dmx.cpp index 0ab2a4a2..596624a6 100644 --- a/wled00/dmx.h +++ b/wled00/dmx.cpp @@ -1,6 +1,5 @@ -#ifndef WLED_DMX_H -#define WLED_DMX_H #include "wled.h" + /* * Support for DMX via MAX485. * Change the output pin in src/dependencies/ESPDMX.cpp if needed. @@ -61,5 +60,3 @@ void handleDMX() #else void handleDMX() {} #endif - -#endif //WLED_DMX_H \ No newline at end of file diff --git a/wled00/e131.cpp b/wled00/e131.cpp new file mode 100644 index 00000000..2034f84d --- /dev/null +++ b/wled00/e131.cpp @@ -0,0 +1,144 @@ +#include "wled.h" + +/* + * E1.31 handler + */ + +void handleE131Packet(e131_packet_t* p, IPAddress clientIP){ + //E1.31 protocol support + + uint16_t uni = htons(p->universe); + uint8_t previousUniverses = uni - e131Universe; + uint16_t possibleLEDsInCurrentUniverse; + uint16_t dmxChannels = htons(p->property_value_count) -1; + + // only listen for universes we're handling & allocated memory + if (uni >= (e131Universe + E131_MAX_UNIVERSE_COUNT)) return; + + if (e131SkipOutOfSequence) + if (p->sequence_number < e131LastSequenceNumber[uni-e131Universe] && p->sequence_number > 20 && e131LastSequenceNumber[uni-e131Universe] < 250){ + DEBUG_PRINT("skipping E1.31 frame (last seq="); + DEBUG_PRINT(e131LastSequenceNumber[uni-e131Universe]); + DEBUG_PRINT(", current seq="); + DEBUG_PRINT(p->sequence_number); + DEBUG_PRINT(", universe="); + DEBUG_PRINT(uni); + DEBUG_PRINTLN(")"); + return; + } + e131LastSequenceNumber[uni-e131Universe] = p->sequence_number; + + // update status info + realtimeIP = clientIP; + + switch (DMXMode) { + case DMX_MODE_DISABLED: + return; // nothing to do + break; + + case DMX_MODE_SINGLE_RGB: + if (uni != e131Universe) return; + if (dmxChannels-DMXAddress+1 < 3) return; + arlsLock(realtimeTimeoutMs, REALTIME_MODE_E131); + for (uint16_t i = 0; i < ledCount; i++) + setRealtimePixel(i, p->property_values[DMXAddress+0], p->property_values[DMXAddress+1], p->property_values[DMXAddress+2], 0); + break; + + case DMX_MODE_SINGLE_DRGB: + if (uni != e131Universe) return; + if (dmxChannels-DMXAddress+1 < 4) return; + arlsLock(realtimeTimeoutMs, REALTIME_MODE_E131); + if (DMXOldDimmer != p->property_values[DMXAddress+0]) { + DMXOldDimmer = p->property_values[DMXAddress+0]; + bri = p->property_values[DMXAddress+0]; + strip.setBrightness(bri); + } + for (uint16_t i = 0; i < ledCount; i++) + setRealtimePixel(i, p->property_values[DMXAddress+1], p->property_values[DMXAddress+2], p->property_values[DMXAddress+3], 0); + break; + + case DMX_MODE_EFFECT: + if (uni != e131Universe) return; + if (dmxChannels-DMXAddress+1 < 11) return; + if (DMXOldDimmer != p->property_values[DMXAddress+0]) { + DMXOldDimmer = p->property_values[DMXAddress+0]; + bri = p->property_values[DMXAddress+0]; + } + if (p->property_values[DMXAddress+1] < MODE_COUNT) + effectCurrent = p->property_values[DMXAddress+ 1]; + effectSpeed = p->property_values[DMXAddress+ 2]; // flickers + effectIntensity = p->property_values[DMXAddress+ 3]; + effectPalette = p->property_values[DMXAddress+ 4]; + col[0] = p->property_values[DMXAddress+ 5]; + col[1] = p->property_values[DMXAddress+ 6]; + col[2] = p->property_values[DMXAddress+ 7]; + colSec[0] = p->property_values[DMXAddress+ 8]; + colSec[1] = p->property_values[DMXAddress+ 9]; + colSec[2] = p->property_values[DMXAddress+10]; + if (dmxChannels-DMXAddress+1 > 11) + { + col[3] = p->property_values[DMXAddress+11]; //white + colSec[3] = p->property_values[DMXAddress+12]; + } + transitionDelayTemp = 0; // act fast + colorUpdated(NOTIFIER_CALL_MODE_NOTIFICATION); // don't send UDP + return; // don't activate realtime live mode + break; + + case DMX_MODE_MULTIPLE_RGB: + arlsLock(realtimeTimeoutMs, REALTIME_MODE_E131); + if (previousUniverses == 0) { + // first universe of this fixture + possibleLEDsInCurrentUniverse = (dmxChannels - DMXAddress + 1) / 3; + for (uint16_t i = 0; i < ledCount; i++) { + if (i >= possibleLEDsInCurrentUniverse) break; // more LEDs will follow in next universe(s) + setRealtimePixel(i, p->property_values[DMXAddress+i*3+0], p->property_values[DMXAddress+i*3+1], p->property_values[DMXAddress+i*3+2], 0); + } + } else if (previousUniverses > 0 && uni < (e131Universe + E131_MAX_UNIVERSE_COUNT)) { + // additional universe(s) of this fixture + uint16_t numberOfLEDsInPreviousUniverses = ((512 - DMXAddress + 1) / 3); // first universe + if (previousUniverses > 1) numberOfLEDsInPreviousUniverses += (512 / 3) * (previousUniverses - 1); // extended universe(s) before current + possibleLEDsInCurrentUniverse = dmxChannels / 3; + for (uint16_t i = numberOfLEDsInPreviousUniverses; i < ledCount; i++) { + uint8_t j = i - numberOfLEDsInPreviousUniverses; + if (j >= possibleLEDsInCurrentUniverse) break; // more LEDs will follow in next universe(s) + setRealtimePixel(i, p->property_values[j*3+1], p->property_values[j*3+2], p->property_values[j*3+3], 0); + } + } + break; + + case DMX_MODE_MULTIPLE_DRGB: + arlsLock(realtimeTimeoutMs, REALTIME_MODE_E131); + if (previousUniverses == 0) { + // first universe of this fixture + if (DMXOldDimmer != p->property_values[DMXAddress+0]) { + DMXOldDimmer = p->property_values[DMXAddress+0]; + bri = p->property_values[DMXAddress+0]; + strip.setBrightness(bri); + } + possibleLEDsInCurrentUniverse = (dmxChannels - DMXAddress) / 3; + for (uint16_t i = 0; i < ledCount; i++) { + if (i >= possibleLEDsInCurrentUniverse) break; // more LEDs will follow in next universe(s) + setRealtimePixel(i, p->property_values[DMXAddress+i*3+1], p->property_values[DMXAddress+i*3+2], p->property_values[DMXAddress+i*3+3], 0); + } + } else if (previousUniverses > 0 && uni < (e131Universe + E131_MAX_UNIVERSE_COUNT)) { + // additional universe(s) of this fixture + uint16_t numberOfLEDsInPreviousUniverses = ((512 - DMXAddress + 1) / 3); // first universe + if (previousUniverses > 1) numberOfLEDsInPreviousUniverses += (512 / 3) * (previousUniverses - 1); // extended universe(s) before current + possibleLEDsInCurrentUniverse = dmxChannels / 3; + for (uint16_t i = numberOfLEDsInPreviousUniverses; i < ledCount; i++) { + uint8_t j = i - numberOfLEDsInPreviousUniverses; + if (j >= possibleLEDsInCurrentUniverse) break; // more LEDs will follow in next universe(s) + setRealtimePixel(i, p->property_values[j*3+1], p->property_values[j*3+2], p->property_values[j*3+3], 0); + } + } + break; + + default: + DEBUG_PRINTLN("unknown E1.31 DMX mode"); + return; // nothing to do + break; + } + + e131NewData = true; +} diff --git a/wled00/file.cpp b/wled00/file.cpp index dba27d4f..eb0dcb93 100644 --- a/wled00/file.cpp +++ b/wled00/file.cpp @@ -1,7 +1,8 @@ -#include "file.h" #include "wled.h" -#include "led.h" -#include "notify.h" + +/* + * Utility for SPIFFS filesystem + */ //filesystem #ifndef WLED_DISABLE_FILESYSTEM @@ -12,85 +13,6 @@ #include "SPIFFSEditor.h" #endif -enum class AdaState { - Header_A, - Header_d, - Header_a, - Header_CountHi, - Header_CountLo, - Header_CountCheck, - Data_Red, - Data_Green, - Data_Blue -}; - -// Maybe Adalight should not be in filehandling? TODO -void handleSerial() -{ - #ifdef WLED_ENABLE_ADALIGHT - static auto state = AdaState::Header_A; - static uint16_t count = 0; - static uint16_t pixel = 0; - static byte check = 0x00; - static byte red = 0x00; - static byte green = 0x00; - - while (Serial.available() > 0) - { - yield(); - byte next = Serial.read(); - switch (state) { - case AdaState::Header_A: - if (next == 'A') state = AdaState::Header_d; - break; - case AdaState::Header_d: - if (next == 'd') state = AdaState::Header_a; - else state = AdaState::Header_A; - break; - case AdaState::Header_a: - if (next == 'a') state = AdaState::Header_CountHi; - else state = AdaState::Header_A; - break; - case AdaState::Header_CountHi: - pixel = 0; - count = next * 0x100; - check = next; - state = AdaState::Header_CountLo; - break; - case AdaState::Header_CountLo: - count += next + 1; - check = check ^ next ^ 0x55; - state = AdaState::Header_CountCheck; - break; - case AdaState::Header_CountCheck: - if (check == next) state = AdaState::Data_Red; - else state = AdaState::Header_A; - break; - case AdaState::Data_Red: - red = next; - state = AdaState::Data_Green; - break; - case AdaState::Data_Green: - green = next; - state = AdaState::Data_Blue; - break; - case AdaState::Data_Blue: - byte blue = next; - setRealtimePixel(pixel++, red, green, blue, 0); - if (--count > 0) state = AdaState::Data_Red; - else { - if (!realtimeMode && bri == 0) strip.setBrightness(briLast); - arlsLock(realtimeTimeoutMs, REALTIME_MODE_ADALIGHT); - - strip.show(); - state = AdaState::Header_A; - } - break; - } - } - #endif -} - #if !defined WLED_DISABLE_FILESYSTEM && defined WLED_ENABLE_FS_SERVING //Un-comment any file types you need diff --git a/wled00/file.h b/wled00/file.h deleted file mode 100644 index 90731db6..00000000 --- a/wled00/file.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef WLED_FILE_H -#define WLED_FILE_H -#include -#include -/* - * Utility for SPIFFS filesystem & Serial console - */ - -void handleSerial(); -bool handleFileRead(AsyncWebServerRequest*, String path); - -#endif // WLED_FILE_H \ No newline at end of file diff --git a/wled00/func_declare.h b/wled00/func_declare.h new file mode 100644 index 00000000..db3cb4bc --- /dev/null +++ b/wled00/func_declare.h @@ -0,0 +1,183 @@ +#ifndef WLED_FUNC_DECLARE_H +#define WLED_FUNC_DECLARE_H +#include +#include "src/dependencies/espalexa/EspalexaDevice.h" +#include "src/dependencies/e131/ESPAsyncE131.h" + +/* + * All globally accessible functions are declared here + */ + +//alexa.cpp +void onAlexaChange(EspalexaDevice* dev); +void alexaInit(); +void handleAlexa(); +void onAlexaChange(EspalexaDevice* dev); + +//blynk.cpp +void initBlynk(const char* auth); +void handleBlynk(); +void updateBlynk(); + +//button.cpp +void shortPressAction(); +void handleButton(); +void handleIO(); + +//colors.cpp +void colorFromUint32(uint32_t in, bool secondary = false); +void colorFromUint24(uint32_t in, bool secondary = false); +void relativeChangeWhite(int8_t amount, byte lowerBoundary = 0); +void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb +void colorCTtoRGB(uint16_t mired, byte* rgb); //white spectrum to rgb + +void colorXYtoRGB(float x, float y, byte* rgb); // only defined if huesync disabled TODO +void colorRGBtoXY(byte* rgb, float* xy); // only defined if huesync disabled TODO + +void colorFromDecOrHexString(byte* rgb, char* in); +void colorRGBtoRGBW(byte* rgb); //rgb to rgbw (http://codewelt.com/rgbw). (RGBW_MODE_LEGACY) + +//e131.cpp +void handleE131Packet(e131_packet_t* p, IPAddress clientIP); + +//file.cpp +bool handleFileRead(AsyncWebServerRequest*, String path); + +//dmx.cpp +void handleDMX(); + +//hue.cpp +void handleHue(); +void reconnectHue(); +void onHueError(void* arg, AsyncClient* client, int8_t error); +void onHueConnect(void* arg, AsyncClient* client); +void sendHuePoll(); +void onHueData(void* arg, AsyncClient* client, void *data, size_t len); + +//ir.cpp +bool decodeIRCustom(uint32_t code); +void relativeChange(byte* property, int8_t amount, byte lowerBoundary = 0, byte higherBoundary = 0xFF); +void changeEffectSpeed(int8_t amount); +void changeEffectIntensity(int8_t amount); +void decodeIR(uint32_t code); +void decodeIR24(uint32_t code); +void decodeIR24OLD(uint32_t code); +void decodeIR24CT(uint32_t code); +void decodeIR40(uint32_t code); +void decodeIR44(uint32_t code); +void decodeIR21(uint32_t code); +void decodeIR6(uint32_t code); + +void initIR(); +void handleIR(); + +//json.cpp +#include "ESPAsyncWebServer.h" +#include "src/dependencies/json/ArduinoJson-v6.h" +#include "src/dependencies/json/AsyncJson-v6.h" +#include "FX.h" +// TODO: AsynicWebServerRequest conflict? + +void deserializeSegment(JsonObject elem, byte it); +bool deserializeState(JsonObject root); +void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id); +void serializeState(JsonObject root); +void serializeInfo(JsonObject root); +void serveJson(AsyncWebServerRequest* request); +void serveLiveLeds(AsyncWebServerRequest* request); + +//led.cpp +void setValuesFromMainSeg(); +void resetTimebase(); +void toggleOnOff(); +void setAllLeds(); +void setLedsStandard(bool justColors = false); +bool colorChanged(); +void colorUpdated(int callMode); +void updateInterfaces(uint8_t callMode); +void handleTransitions(); +void handleNightlight(); + +//mqtt.cpp +bool initMqtt(); +void publishMqtt(); + +//notify.cpp +void notify(byte callMode, bool followUp=false); +void arlsLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC); +void handleNotifications(); +void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w); + +//ntp.cpp +void handleNetworkTime(); +void sendNTPPacket(); +bool checkNTPResponse(); +void updateLocalTime(); +void getTimeString(char* out); +bool checkCountdown(); +void setCountdown(); +byte weekdayMondayFirst(); +void checkTimers(); + +//overlay.cpp +void initCronixie(); +void handleOverlays(); +void handleOverlayDraw(); +void _overlayAnalogCountdown(); +void _overlayAnalogClock(); + +byte getSameCodeLength(char code, int index, char const cronixieDisplay[]); +void setCronixie(); +void _overlayCronixie(); +void _drawOverlayCronixie(); + +//set.cpp +void _setRandomColor(bool _sec,bool fromButton=false); +bool isAsterisksOnly(const char* str, byte maxLen); +void handleSettingsSet(AsyncWebServerRequest *request, byte subPage); +bool handleSet(AsyncWebServerRequest *request, const String& req); +int getNumVal(const String* req, uint16_t pos); +bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte maxv=255); + +//usermod.cpp +void userSetup(); +void userConnected(); +void userLoop(); + +//wled_eeprom.cpp +void commit(); +void clearEEPROM(); +void writeStringToEEPROM(uint16_t pos, char* str, uint16_t len); +void readStringFromEEPROM(uint16_t pos, char* str, uint16_t len); +void saveSettingsToEEPROM(); +void loadSettingsFromEEPROM(bool first); +void savedToPresets(); +bool applyPreset(byte index, bool loadBri = true); +void savePreset(byte index, bool persist = true); +void loadMacro(byte index, char* m); +void applyMacro(byte index); +void saveMacro(byte index, String mc, bool persist = true); //only commit on single save, not in settings + +//wled_serial.cpp +void handleSerial(); + +//wled_server.cpp +bool isIp(String str); +bool captivePortal(AsyncWebServerRequest *request); +void initServer(); +void serveIndexOrWelcome(AsyncWebServerRequest *request); +void serveIndex(AsyncWebServerRequest* request); +String msgProcessor(const String& var); +void serveMessage(AsyncWebServerRequest* request, uint16_t code, String headl, String subl="", byte optionT=255); +String settingsProcessor(const String& var); +String dmxProcessor(const String& var); +void serveSettings(AsyncWebServerRequest* request); + +//xml.cpp +char* XML_response(AsyncWebServerRequest *request, char* dest = nullptr); +char* URL_response(AsyncWebServerRequest *request); +void sappend(char stype, const char* key, int val); +void sappends(char stype, const char* key, char* val); +void getSettingsJS(byte subPage, char* dest); + +#endif diff --git a/wled00/hue.cpp b/wled00/hue.cpp index a186a314..77091f63 100644 --- a/wled00/hue.cpp +++ b/wled00/hue.cpp @@ -1,9 +1,8 @@ -#include "hue.h" #include "wled.h" -#include "colors.h" -#include "wled_eeprom.h" -#include "notify.h" -#include "led.h" + +/* + * Sync to Philips hue lights + */ #ifndef WLED_DISABLE_HUESYNC diff --git a/wled00/hue.h b/wled00/hue.h deleted file mode 100644 index 7ce629fb..00000000 --- a/wled00/hue.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef WLED_HUE_H -#define WLED_HUE_H -/* - * Sync to Philips hue lights - */ -#include -class AsyncClient; - -void handleHue(); -void reconnectHue(); -void onHueError(void* arg, AsyncClient* client, int8_t error); -void onHueConnect(void* arg, AsyncClient* client); -void sendHuePoll(); -void onHueData(void* arg, AsyncClient* client, void *data, size_t len); - -#endif //WLED_HUE_H \ No newline at end of file diff --git a/wled00/ir.cpp b/wled00/ir.cpp index 32b0ee93..046991db 100644 --- a/wled00/ir.cpp +++ b/wled00/ir.cpp @@ -1,8 +1,8 @@ -#include "ir.h" #include "wled.h" -#include "led.h" -#include "colors.h" -#include "wled_eeprom.h" + +/* + * Infrared sensor support for generic 24/40/44 key RGB remotes + */ #if defined(WLED_DISABLE_INFRARED) void handleIR(){} diff --git a/wled00/ir.h b/wled00/ir.h deleted file mode 100644 index e6ecb966..00000000 --- a/wled00/ir.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef WLED_IR_H -#define WLED_IR_H -#include -/* - * Infrared sensor support for generic 24/40/44 key RGB remotes - */ - -bool decodeIRCustom(uint32_t code); -void relativeChange(byte* property, int8_t amount, byte lowerBoundary = 0, byte higherBoundary = 0xFF); -void changeEffectSpeed(int8_t amount); -void changeEffectIntensity(int8_t amount); -void decodeIR(uint32_t code); -void decodeIR24(uint32_t code); -void decodeIR24OLD(uint32_t code); -void decodeIR24CT(uint32_t code); -void decodeIR40(uint32_t code); -void decodeIR44(uint32_t code); -void decodeIR21(uint32_t code); -void decodeIR6(uint32_t code); - -void initIR(); -void handleIR(); - -#endif //WLED_IR_H \ No newline at end of file diff --git a/wled00/json.cpp b/wled00/json.cpp index e79737c4..31208bf5 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -1,7 +1,8 @@ -#include "json.h" #include "wled.h" -#include "wled_eeprom.h" -#include "led.h" + +/* + * JSON API (De)serialization + */ void deserializeSegment(JsonObject elem, byte it) { diff --git a/wled00/json.h b/wled00/json.h deleted file mode 100644 index 77d1b616..00000000 --- a/wled00/json.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef WLED_JSON_H -#define WLED_JSON_H -/* - * JSON API (De)serialization - */ -#include -#include "ESPAsyncWebServer.h" -#include "src/dependencies/json/ArduinoJson-v6.h" -#include "src/dependencies/json/AsyncJson-v6.h" -#include "fx.h" -// TODO: AsynicWebServerRequest conflict? - -void deserializeSegment(JsonObject elem, byte it); -bool deserializeState(JsonObject root); -void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id); -void serializeState(JsonObject root); -void serializeInfo(JsonObject root); -void serveJson(AsyncWebServerRequest* request); -void serveLiveLeds(AsyncWebServerRequest* request); - -#endif //WLED_JSON_H \ No newline at end of file diff --git a/wled00/led.cpp b/wled00/led.cpp index 7f4d6309..c3f50cc2 100644 --- a/wled00/led.cpp +++ b/wled00/led.cpp @@ -1,10 +1,8 @@ -#include "led.h" #include "wled.h" -#include "notify.h" -#include "blynk.h" -#include "wled_eeprom.h" -#include "mqtt.h" -#include "colors.h" + +/* + * LED methods + */ void setValuesFromMainSeg() { diff --git a/wled00/led.h b/wled00/led.h deleted file mode 100644 index d5eb97a8..00000000 --- a/wled00/led.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef WLED_LED_H -#define WLED_LED_H -#include -/* - * LED methods - */ - -void setValuesFromMainSeg(); -void resetTimebase(); -void toggleOnOff(); -void setAllLeds(); -void setLedsStandard(bool justColors = false); -bool colorChanged(); -void colorUpdated(int callMode); -void updateInterfaces(uint8_t callMode); -void handleTransitions(); -void handleNightlight(); - -#endif \ No newline at end of file diff --git a/wled00/mqtt.cpp b/wled00/mqtt.cpp index b84184af..9c15f5bb 100644 --- a/wled00/mqtt.cpp +++ b/wled00/mqtt.cpp @@ -1,10 +1,8 @@ -#include "mqtt.h" #include "wled.h" -#include "notify.h" -#include "led.h" -#include "colors.h" -#include "xml.h" -#include "set.h" + +/* + * MQTT communication protocol for home automation + */ #ifdef WLED_ENABLE_MQTT #define MQTT_KEEP_ALIVE_TIME 60 // contact the MQTT broker every 60 seconds diff --git a/wled00/mqtt.h b/wled00/mqtt.h deleted file mode 100644 index de602b98..00000000 --- a/wled00/mqtt.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef WLED_MQTT_H -#define WLED_MQTT_H -/* - * MQTT communication protocol for home automation - */ -bool initMqtt(); -void publishMqtt(); - -#endif //WLED_MQTT_H \ No newline at end of file diff --git a/wled00/notify.h b/wled00/notify.h deleted file mode 100644 index a0fbfde2..00000000 --- a/wled00/notify.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef WLED_NOTIFY_H -#define WLED_NOTIFY_H -#include -#include "src/dependencies/e131/ESPAsyncE131.h" -#include "const.h" -/* - * UDP notifier - */ -//union e131_packet_t; // Will this compile? -class IPAddress; - -void notify(byte callMode, bool followUp=false); -void arlsLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC); -void handleE131Packet(e131_packet_t* p, IPAddress clientIP); -void handleNotifications(); -void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w); - -#endif // WLED_NOTIFY_H \ No newline at end of file diff --git a/wled00/ntp.cpp b/wled00/ntp.cpp index 20663109..d6332fd2 100644 --- a/wled00/ntp.cpp +++ b/wled00/ntp.cpp @@ -1,7 +1,9 @@ -#include "ntp.h" #include "src/dependencies/timezone/Timezone.h" #include "wled.h" -#include "wled_eeprom.h" + +/* + * Acquires time from NTP server + */ TimeChangeRule UTCr = {Last, Sun, Mar, 1, 0}; // UTC Timezone tzUTC(UTCr, UTCr); diff --git a/wled00/ntp.h b/wled00/ntp.h deleted file mode 100644 index 9029661d..00000000 --- a/wled00/ntp.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef WLED_NTP_H -#define WLED_NTP_H -#include -/* - * Acquires time from NTP server - */ - -void handleNetworkTime(); -void sendNTPPacket(); -bool checkNTPResponse(); -void updateLocalTime(); -void getTimeString(char* out); -bool checkCountdown(); -void setCountdown(); -byte weekdayMondayFirst(); -void checkTimers(); - -#endif // WLED_NTP_H \ No newline at end of file diff --git a/wled00/overlay.cpp b/wled00/overlay.cpp index ccdd3d0c..ceb6fc20 100644 --- a/wled00/overlay.cpp +++ b/wled00/overlay.cpp @@ -1,7 +1,8 @@ -#include "overlay.h" #include "wled.h" -#include "cronixie.h" -#include "ntp.h" + +/* + * Used to draw clock overlays over the strip + */ void initCronixie() { @@ -127,3 +128,249 @@ void handleOverlayDraw() { case 3: _drawOverlayCronixie(); break; } } + + +/* + * Support for the Cronixie clock + */ + +#ifndef WLED_DISABLE_CRONIXIE +byte _digitOut[6] = {10,10,10,10,10,10}; + +byte getSameCodeLength(char code, int index, char const cronixieDisplay[]) +{ + byte counter = 0; + + for (int i = index+1; i < 6; i++) + { + if (cronixieDisplay[i] == code) + { + counter++; + } else { + return counter; + } + } + return counter; +} + +void setCronixie() +{ + /* + * digit purpose index + * 0-9 | 0-9 (incl. random) + * 10 | blank + * 11 | blank, bg off + * 12 | test upw. + * 13 | test dnw. + * 14 | binary AM/PM + * 15 | BB upper +50 for no trailing 0 + * 16 | BBB + * 17 | BBBB + * 18 | BBBBB + * 19 | BBBBBB + * 20 | H + * 21 | HH + * 22 | HHH + * 23 | HHHH + * 24 | M + * 25 | MM + * 26 | MMM + * 27 | MMMM + * 28 | MMMMM + * 29 | MMMMMM + * 30 | S + * 31 | SS + * 32 | SSS + * 33 | SSSS + * 34 | SSSSS + * 35 | SSSSSS + * 36 | Y + * 37 | YY + * 38 | YYYY + * 39 | I + * 40 | II + * 41 | W + * 42 | WW + * 43 | D + * 44 | DD + * 45 | DDD + * 46 | V + * 47 | VV + * 48 | VVV + * 49 | VVVV + * 50 | VVVVV + * 51 | VVVVVV + * 52 | v + * 53 | vv + * 54 | vvv + * 55 | vvvv + * 56 | vvvvv + * 57 | vvvvvv + */ + + //H HourLower | HH - Hour 24. | AH - Hour 12. | HHH Hour of Month | HHHH Hour of Year + //M MinuteUpper | MM Minute of Hour | MMM Minute of 12h | MMMM Minute of Day | MMMMM Minute of Month | MMMMMM Minute of Year + //S SecondUpper | SS Second of Minute | SSS Second of 10 Minute | SSSS Second of Hour | SSSSS Second of Day | SSSSSS Second of Week + //B AM/PM | BB 0-6/6-12/12-18/18-24 | BBB 0-3... | BBBB 0-1.5... | BBBBB 0-1 | BBBBBB 0-0.5 + + //Y YearLower | YY - Year LU | YYYY - Std. + //I MonthLower | II - Month of Year + //W Week of Month | WW Week of Year + //D Day of Week | DD Day Of Month | DDD Day Of Year + + DEBUG_PRINT("cset "); + DEBUG_PRINTLN(cronixieDisplay); + + overlayRefreshMs = 1997; //Only refresh every 2secs if no seconds are displayed + + for (int i = 0; i < 6; i++) + { + dP[i] = 10; + switch (cronixieDisplay[i]) + { + case '_': dP[i] = 10; break; + case '-': dP[i] = 11; break; + case 'r': dP[i] = random(1,7); break; //random btw. 1-6 + case 'R': dP[i] = random(0,10); break; //random btw. 0-9 + //case 't': break; //Test upw. + //case 'T': break; //Test dnw. + case 'b': dP[i] = 14 + getSameCodeLength('b',i,cronixieDisplay); i = i+dP[i]-14; break; + case 'B': dP[i] = 14 + getSameCodeLength('B',i,cronixieDisplay); i = i+dP[i]-14; break; + case 'h': dP[i] = 70 + getSameCodeLength('h',i,cronixieDisplay); i = i+dP[i]-70; break; + case 'H': dP[i] = 20 + getSameCodeLength('H',i,cronixieDisplay); i = i+dP[i]-20; break; + case 'A': dP[i] = 108; i++; break; + case 'a': dP[i] = 58; i++; break; + case 'm': dP[i] = 74 + getSameCodeLength('m',i,cronixieDisplay); i = i+dP[i]-74; break; + case 'M': dP[i] = 24 + getSameCodeLength('M',i,cronixieDisplay); i = i+dP[i]-24; break; + case 's': dP[i] = 80 + getSameCodeLength('s',i,cronixieDisplay); i = i+dP[i]-80; overlayRefreshMs = 497; break; //refresh more often bc. of secs + case 'S': dP[i] = 30 + getSameCodeLength('S',i,cronixieDisplay); i = i+dP[i]-30; overlayRefreshMs = 497; break; + case 'Y': dP[i] = 36 + getSameCodeLength('Y',i,cronixieDisplay); i = i+dP[i]-36; break; + case 'y': dP[i] = 86 + getSameCodeLength('y',i,cronixieDisplay); i = i+dP[i]-86; break; + case 'I': dP[i] = 39 + getSameCodeLength('I',i,cronixieDisplay); i = i+dP[i]-39; break; //Month. Don't ask me why month and minute both start with M. + case 'i': dP[i] = 89 + getSameCodeLength('i',i,cronixieDisplay); i = i+dP[i]-89; break; + //case 'W': break; + //case 'w': break; + case 'D': dP[i] = 43 + getSameCodeLength('D',i,cronixieDisplay); i = i+dP[i]-43; break; + case 'd': dP[i] = 93 + getSameCodeLength('d',i,cronixieDisplay); i = i+dP[i]-93; break; + case '0': dP[i] = 0; break; + case '1': dP[i] = 1; break; + case '2': dP[i] = 2; break; + case '3': dP[i] = 3; break; + case '4': dP[i] = 4; break; + case '5': dP[i] = 5; break; + case '6': dP[i] = 6; break; + case '7': dP[i] = 7; break; + case '8': dP[i] = 8; break; + case '9': dP[i] = 9; break; + //case 'V': break; //user var0 + //case 'v': break; //user var1 + } + } + DEBUG_PRINT("result "); + for (int i = 0; i < 5; i++) + { + DEBUG_PRINT((int)dP[i]); + DEBUG_PRINT(" "); + } + DEBUG_PRINTLN((int)dP[5]); + + _overlayCronixie(); //refresh +} + +void _overlayCronixie() +{ + byte h = hour(local); + byte h0 = h; + byte m = minute(local); + byte s = second(local); + byte d = day(local); + byte mi = month(local); + int y = year(local); + //this has to be changed in time for 22nd century + y -= 2000; if (y<0) y += 30; //makes countdown work + + if (useAMPM && !countdownMode) + { + if (h>12) h-=12; + else if (h==0) h+=12; + } + for (int i = 0; i < 6; i++) + { + if (dP[i] < 12) _digitOut[i] = dP[i]; + else { + if (dP[i] < 65) + { + switch(dP[i]) + { + case 21: _digitOut[i] = h/10; _digitOut[i+1] = h- _digitOut[i]*10; i++; break; //HH + case 25: _digitOut[i] = m/10; _digitOut[i+1] = m- _digitOut[i]*10; i++; break; //MM + case 31: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; i++; break; //SS + + case 20: _digitOut[i] = h- (h/10)*10; break; //H + case 24: _digitOut[i] = m/10; break; //M + case 30: _digitOut[i] = s/10; break; //S + + case 43: _digitOut[i] = weekday(local); _digitOut[i]--; if (_digitOut[i]<1) _digitOut[i]= 7; break; //D + case 44: _digitOut[i] = d/10; _digitOut[i+1] = d- _digitOut[i]*10; i++; break; //DD + case 40: _digitOut[i] = mi/10; _digitOut[i+1] = mi- _digitOut[i]*10; i++; break; //II + case 37: _digitOut[i] = y/10; _digitOut[i+1] = y- _digitOut[i]*10; i++; break; //YY + case 39: _digitOut[i] = 2; _digitOut[i+1] = 0; _digitOut[i+2] = y/10; _digitOut[i+3] = y- _digitOut[i+2]*10; i+=3; break; //YYYY + + //case 16: _digitOut[i+2] = ((h0/3)&1)?1:0; i++; //BBB (BBBB NI) + //case 15: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:0; i++; //BB + case 14: _digitOut[i] = (h0>11)?1:0; break; //B + } + } else + { + switch(dP[i]) + { + case 71: _digitOut[i] = h/10; _digitOut[i+1] = h- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //hh + case 75: _digitOut[i] = m/10; _digitOut[i+1] = m- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //mm + case 81: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //ss + //case 66: _digitOut[i+2] = ((h0/3)&1)?1:10; i++; //bbb (bbbb NI) + //case 65: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:10; i++; //bb + case 64: _digitOut[i] = (h0>11)?1:10; break; //b + + case 93: _digitOut[i] = weekday(local); _digitOut[i]--; if (_digitOut[i]<1) _digitOut[i]= 7; break; //d + case 94: _digitOut[i] = d/10; _digitOut[i+1] = d- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //dd + case 90: _digitOut[i] = mi/10; _digitOut[i+1] = mi- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //ii + case 87: _digitOut[i] = y/10; _digitOut[i+1] = y- _digitOut[i]*10; i++; break; //yy + case 89: _digitOut[i] = 2; _digitOut[i+1] = 0; _digitOut[i+2] = y/10; _digitOut[i+3] = y- _digitOut[i+2]*10; i+=3; break; //yyyy + } + } + } + } +} + +void _drawOverlayCronixie() +{ + byte offsets[] = {5, 0, 6, 1, 7, 2, 8, 3, 9, 4}; + + for (uint16_t i = 0; i < 6; i++) + { + byte o = 10*i; + byte excl = 10; + if(_digitOut[i] < 10) excl = offsets[_digitOut[i]]; + excl += o; + + if (cronixieBacklight && _digitOut[i] <11) + { + uint32_t col = strip.gamma32(strip.getSegment(0).colors[1]); + for (uint16_t j=o; j< o+10; j++) { + if (j != excl) strip.setPixelColor(j, col); + } + } else + { + for (uint16_t j=o; j< o+10; j++) { + if (j != excl) strip.setPixelColor(j, 0); + } + } + } +} + +#else // WLED_DISABLE_CRONIXIE +byte getSameCodeLength(char code, int index, char const cronixieDisplay[]) {} +void setCronixie() {} +void _overlayCronixie() {} +void _drawOverlayCronixie() {} +#endif diff --git a/wled00/overlay.h b/wled00/overlay.h deleted file mode 100644 index f7b54d5d..00000000 --- a/wled00/overlay.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef WLED_OVERLAY_H -#define WLED_OVERLAY_H -#include -/* - * Used to draw clock overlays over the strip - */ - -void initCronixie(); -void handleOverlays(); -void handleOverlayDraw(); -void _overlayAnalogCountdown(); -void _overlayAnalogClock(); - -#endif // WLED_OVERLAY_H \ No newline at end of file diff --git a/wled00/set.cpp b/wled00/set.cpp index f26795c8..7fa2a327 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -1,14 +1,8 @@ -#include "set.h" #include "wled.h" -#include "colors.h" -#include "hue.h" -#include "led.h" -#include "blynk.h" -#include "wled_eeprom.h" -#include "alexa.h" -#include "cronixie.h" -#include "xml.h" -#include "wled_server.h" + +/* + * Receives client input + */ void _setRandomColor(bool _sec,bool fromButton) { diff --git a/wled00/set.h b/wled00/set.h deleted file mode 100644 index 6bc7dbd6..00000000 --- a/wled00/set.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef WLED_SET_H -#define WLED_SET_H -#include -#include -/* - * Receives client input - */ - -void _setRandomColor(bool _sec,bool fromButton=false); -bool isAsterisksOnly(const char* str, byte maxLen); -void handleSettingsSet(AsyncWebServerRequest *request, byte subPage); -bool handleSet(AsyncWebServerRequest *request, const String& req); -int getNumVal(const String* req, uint16_t pos); -bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte maxv=255); - -#endif // WLED_SET_H \ No newline at end of file diff --git a/wled00/notify.cpp b/wled00/udp.cpp similarity index 55% rename from wled00/notify.cpp rename to wled00/udp.cpp index 30adfee0..52879803 100644 --- a/wled00/notify.cpp +++ b/wled00/udp.cpp @@ -1,12 +1,12 @@ -#include "notify.h" #include "wled.h" -#include "src/dependencies/e131/ESPAsyncE131.h" -#include "led.h" + +/* + * UDP sync notifier + */ #define WLEDPACKETSIZE 29 #define UDP_IN_MAXSIZE 1472 - void notify(byte callMode, bool followUp) { if (!udpConnected) return; @@ -87,146 +87,6 @@ void arlsLock(uint32_t timeoutMs, byte md) } -void handleE131Packet(e131_packet_t* p, IPAddress clientIP){ - //E1.31 protocol support - - uint16_t uni = htons(p->universe); - uint8_t previousUniverses = uni - e131Universe; - uint16_t possibleLEDsInCurrentUniverse; - uint16_t dmxChannels = htons(p->property_value_count) -1; - - // only listen for universes we're handling & allocated memory - if (uni >= (e131Universe + E131_MAX_UNIVERSE_COUNT)) return; - - if (e131SkipOutOfSequence) - if (p->sequence_number < e131LastSequenceNumber[uni-e131Universe] && p->sequence_number > 20 && e131LastSequenceNumber[uni-e131Universe] < 250){ - DEBUG_PRINT("skipping E1.31 frame (last seq="); - DEBUG_PRINT(e131LastSequenceNumber[uni-e131Universe]); - DEBUG_PRINT(", current seq="); - DEBUG_PRINT(p->sequence_number); - DEBUG_PRINT(", universe="); - DEBUG_PRINT(uni); - DEBUG_PRINTLN(")"); - return; - } - e131LastSequenceNumber[uni-e131Universe] = p->sequence_number; - - // update status info - realtimeIP = clientIP; - - switch (DMXMode) { - case DMX_MODE_DISABLED: - return; // nothing to do - break; - - case DMX_MODE_SINGLE_RGB: - if (uni != e131Universe) return; - if (dmxChannels-DMXAddress+1 < 3) return; - arlsLock(realtimeTimeoutMs, REALTIME_MODE_E131); - for (uint16_t i = 0; i < ledCount; i++) - setRealtimePixel(i, p->property_values[DMXAddress+0], p->property_values[DMXAddress+1], p->property_values[DMXAddress+2], 0); - break; - - case DMX_MODE_SINGLE_DRGB: - if (uni != e131Universe) return; - if (dmxChannels-DMXAddress+1 < 4) return; - arlsLock(realtimeTimeoutMs, REALTIME_MODE_E131); - if (DMXOldDimmer != p->property_values[DMXAddress+0]) { - DMXOldDimmer = p->property_values[DMXAddress+0]; - bri = p->property_values[DMXAddress+0]; - strip.setBrightness(bri); - } - for (uint16_t i = 0; i < ledCount; i++) - setRealtimePixel(i, p->property_values[DMXAddress+1], p->property_values[DMXAddress+2], p->property_values[DMXAddress+3], 0); - break; - - case DMX_MODE_EFFECT: - if (uni != e131Universe) return; - if (dmxChannels-DMXAddress+1 < 11) return; - if (DMXOldDimmer != p->property_values[DMXAddress+0]) { - DMXOldDimmer = p->property_values[DMXAddress+0]; - bri = p->property_values[DMXAddress+0]; - } - if (p->property_values[DMXAddress+1] < MODE_COUNT) - effectCurrent = p->property_values[DMXAddress+ 1]; - effectSpeed = p->property_values[DMXAddress+ 2]; // flickers - effectIntensity = p->property_values[DMXAddress+ 3]; - effectPalette = p->property_values[DMXAddress+ 4]; - col[0] = p->property_values[DMXAddress+ 5]; - col[1] = p->property_values[DMXAddress+ 6]; - col[2] = p->property_values[DMXAddress+ 7]; - colSec[0] = p->property_values[DMXAddress+ 8]; - colSec[1] = p->property_values[DMXAddress+ 9]; - colSec[2] = p->property_values[DMXAddress+10]; - if (dmxChannels-DMXAddress+1 > 11) - { - col[3] = p->property_values[DMXAddress+11]; //white - colSec[3] = p->property_values[DMXAddress+12]; - } - transitionDelayTemp = 0; // act fast - colorUpdated(NOTIFIER_CALL_MODE_NOTIFICATION); // don't send UDP - return; // don't activate realtime live mode - break; - - case DMX_MODE_MULTIPLE_RGB: - arlsLock(realtimeTimeoutMs, REALTIME_MODE_E131); - if (previousUniverses == 0) { - // first universe of this fixture - possibleLEDsInCurrentUniverse = (dmxChannels - DMXAddress + 1) / 3; - for (uint16_t i = 0; i < ledCount; i++) { - if (i >= possibleLEDsInCurrentUniverse) break; // more LEDs will follow in next universe(s) - setRealtimePixel(i, p->property_values[DMXAddress+i*3+0], p->property_values[DMXAddress+i*3+1], p->property_values[DMXAddress+i*3+2], 0); - } - } else if (previousUniverses > 0 && uni < (e131Universe + E131_MAX_UNIVERSE_COUNT)) { - // additional universe(s) of this fixture - uint16_t numberOfLEDsInPreviousUniverses = ((512 - DMXAddress + 1) / 3); // first universe - if (previousUniverses > 1) numberOfLEDsInPreviousUniverses += (512 / 3) * (previousUniverses - 1); // extended universe(s) before current - possibleLEDsInCurrentUniverse = dmxChannels / 3; - for (uint16_t i = numberOfLEDsInPreviousUniverses; i < ledCount; i++) { - uint8_t j = i - numberOfLEDsInPreviousUniverses; - if (j >= possibleLEDsInCurrentUniverse) break; // more LEDs will follow in next universe(s) - setRealtimePixel(i, p->property_values[j*3+1], p->property_values[j*3+2], p->property_values[j*3+3], 0); - } - } - break; - - case DMX_MODE_MULTIPLE_DRGB: - arlsLock(realtimeTimeoutMs, REALTIME_MODE_E131); - if (previousUniverses == 0) { - // first universe of this fixture - if (DMXOldDimmer != p->property_values[DMXAddress+0]) { - DMXOldDimmer = p->property_values[DMXAddress+0]; - bri = p->property_values[DMXAddress+0]; - strip.setBrightness(bri); - } - possibleLEDsInCurrentUniverse = (dmxChannels - DMXAddress) / 3; - for (uint16_t i = 0; i < ledCount; i++) { - if (i >= possibleLEDsInCurrentUniverse) break; // more LEDs will follow in next universe(s) - setRealtimePixel(i, p->property_values[DMXAddress+i*3+1], p->property_values[DMXAddress+i*3+2], p->property_values[DMXAddress+i*3+3], 0); - } - } else if (previousUniverses > 0 && uni < (e131Universe + E131_MAX_UNIVERSE_COUNT)) { - // additional universe(s) of this fixture - uint16_t numberOfLEDsInPreviousUniverses = ((512 - DMXAddress + 1) / 3); // first universe - if (previousUniverses > 1) numberOfLEDsInPreviousUniverses += (512 / 3) * (previousUniverses - 1); // extended universe(s) before current - possibleLEDsInCurrentUniverse = dmxChannels / 3; - for (uint16_t i = numberOfLEDsInPreviousUniverses; i < ledCount; i++) { - uint8_t j = i - numberOfLEDsInPreviousUniverses; - if (j >= possibleLEDsInCurrentUniverse) break; // more LEDs will follow in next universe(s) - setRealtimePixel(i, p->property_values[j*3+1], p->property_values[j*3+2], p->property_values[j*3+3], 0); - } - } - break; - - default: - DEBUG_PRINTLN("unknown E1.31 DMX mode"); - return; // nothing to do - break; - } - - e131NewData = true; -} - - void handleNotifications() { //send second notification if enabled diff --git a/wled00/usermod.cpp b/wled00/usermod.cpp index 96c1f8a6..2c7c881f 100644 --- a/wled00/usermod.cpp +++ b/wled00/usermod.cpp @@ -2,7 +2,7 @@ /* * This file allows you to add own functionality to WLED more easily * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality - * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in wled_eeprom.h) + * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in const.h) * bytes 2400+ are currently ununsed, but might be used for future wled features */ diff --git a/wled00/usermod.h b/wled00/usermod.h deleted file mode 100644 index 8269c6e9..00000000 --- a/wled00/usermod.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WLED_USERMOD_H -#define WLED_USERMOD_H - -void userSetup(); -void userConnected(); -void userLoop(); - -#endif // WLED_USERMOD_H \ No newline at end of file diff --git a/wled00/wled.cpp b/wled00/wled.cpp index fdb60776..7579a9c5 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -1,23 +1,8 @@ #include "wled.h" -#include "alexa.h" -#include "blynk.h" -#include "button.h" -#include "dmx.h" -#include "file.h" -#include "hue.h" -#include "ir.h" -#include "led.h" -#include "mqtt.h" -#include "notify.h" -#include "ntp.h" -#include "overlay.h" -#include "usermod.h" -#include "wled_eeprom.h" -#include "wled_server.h" #include // Global Variable definitions -char versionString[] = "0.9.1"; +char versionString[] = "0.9.1n"; // AP and OTA default passwords (for maximum change them!) char apPass[65] = DEFAULT_AP_PASS; diff --git a/wled00/wled.h b/wled00/wled.h index 70b197c8..926fa0c8 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -3,10 +3,13 @@ /* Main sketch, global variable declarations @title WLED project sketch - @version 0.9.1 + @version 0.9.1n @author Christian Schwinne */ +// version code in format yymmddb (b = daily build) +#define VERSION 2003300 + // 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). @@ -78,6 +81,7 @@ #include "src/dependencies/json/AsyncJson-v6.h" #include "src/dependencies/json/ArduinoJson-v6.h" +#include "func_declare.h" #include "html_ui.h" #include "html_settings.h" #include "html_other.h" @@ -117,9 +121,6 @@ #endif #endif -// version code in format yymmddb (b = daily build) -#define VERSION 2003301 - // Global external variable declaration. See wled.cpp for definitions and comments. extern char versionString[]; extern char apPass[65]; diff --git a/wled00/wled00.ino b/wled00/wled00.ino index e3334837..f806e5b3 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -1,6 +1,6 @@ /* - Arduino Studio support file. -*/ + * Arduino IDE compatibility file. + */ #include "wled.h" void setup() { @@ -9,4 +9,4 @@ void setup() { void loop() { WLED::instance().loop(); -} \ No newline at end of file +} diff --git a/wled00/wled_eeprom.cpp b/wled00/wled_eeprom.cpp index 0087641a..ccb16ff5 100644 --- a/wled00/wled_eeprom.cpp +++ b/wled00/wled_eeprom.cpp @@ -1,11 +1,10 @@ -#include "wled_eeprom.h" #include #include "wled.h" -#include "cronixie.h" -#include "ntp.h" -#include "set.h" -#include "led.h" +/* + * Methods to handle saving and loading to non-volatile memory + * EEPROM Map: https://github.com/Aircoookie/WLED/wiki/EEPROM-Map + */ //eeprom Version code, enables default settings instead of 0 init on update #define EEPVER 18 diff --git a/wled00/wled_eeprom.h b/wled00/wled_eeprom.h deleted file mode 100644 index eae52b12..00000000 --- a/wled00/wled_eeprom.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef WLED_EPPROM_H -#define WLED_EPPROM_H -#include -/* - * Methods to handle saving and loading to non-volatile memory - * EEPROM Map: https://github.com/Aircoookie/WLED/wiki/EEPROM-Map - */ -#define EEPSIZE 2560 //Maximum is 4096 - -void commit(); -void clearEEPROM(); -void writeStringToEEPROM(uint16_t pos, char* str, uint16_t len); -void readStringFromEEPROM(uint16_t pos, char* str, uint16_t len); -void saveSettingsToEEPROM(); -void loadSettingsFromEEPROM(bool first); -void savedToPresets(); -bool applyPreset(byte index, bool loadBri = true); -void savePreset(byte index, bool persist = true); -void loadMacro(byte index, char* m); -void applyMacro(byte index); -void saveMacro(byte index, String mc, bool persist = true); //only commit on single save, not in settings - -#endif //WLED_EPPROM_H diff --git a/wled00/wled_serial.cpp b/wled00/wled_serial.cpp new file mode 100644 index 00000000..a472729d --- /dev/null +++ b/wled00/wled_serial.cpp @@ -0,0 +1,83 @@ +#include "wled.h" + +/* + * Adalight handler + */ + +enum class AdaState { + Header_A, + Header_d, + Header_a, + Header_CountHi, + Header_CountLo, + Header_CountCheck, + Data_Red, + Data_Green, + Data_Blue +}; + +void handleSerial() +{ + #ifdef WLED_ENABLE_ADALIGHT + static auto state = AdaState::Header_A; + static uint16_t count = 0; + static uint16_t pixel = 0; + static byte check = 0x00; + static byte red = 0x00; + static byte green = 0x00; + + while (Serial.available() > 0) + { + yield(); + byte next = Serial.read(); + switch (state) { + case AdaState::Header_A: + if (next == 'A') state = AdaState::Header_d; + break; + case AdaState::Header_d: + if (next == 'd') state = AdaState::Header_a; + else state = AdaState::Header_A; + break; + case AdaState::Header_a: + if (next == 'a') state = AdaState::Header_CountHi; + else state = AdaState::Header_A; + break; + case AdaState::Header_CountHi: + pixel = 0; + count = next * 0x100; + check = next; + state = AdaState::Header_CountLo; + break; + case AdaState::Header_CountLo: + count += next + 1; + check = check ^ next ^ 0x55; + state = AdaState::Header_CountCheck; + break; + case AdaState::Header_CountCheck: + if (check == next) state = AdaState::Data_Red; + else state = AdaState::Header_A; + break; + case AdaState::Data_Red: + red = next; + state = AdaState::Data_Green; + break; + case AdaState::Data_Green: + green = next; + state = AdaState::Data_Blue; + break; + case AdaState::Data_Blue: + byte blue = next; + setRealtimePixel(pixel++, red, green, blue, 0); + if (--count > 0) state = AdaState::Data_Red; + else { + if (!realtimeMode && bri == 0) strip.setBrightness(briLast); + arlsLock(realtimeTimeoutMs, REALTIME_MODE_ADALIGHT); + + strip.show(); + state = AdaState::Header_A; + } + break; + } + } + #endif +} diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index d5b4eebc..cd623bc4 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -1,10 +1,8 @@ -#include "wled_server.h" #include "wled.h" -#include "file.h" -#include "set.h" -#include "json.h" -#include "xml.h" +/* + * Integrated HTTP web server page declarations + */ //Is this an IP? bool isIp(String str) { diff --git a/wled00/wled_server.h b/wled00/wled_server.h deleted file mode 100644 index ff7133d6..00000000 --- a/wled00/wled_server.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef WLED_SERVER_H -#define WLED_SERVER_H -#include -/* - * Server page declarations - */ -class AsyncWebServerRequest; - - -bool isIp(String str); -bool captivePortal(AsyncWebServerRequest *request); -void initServer(); -void serveIndexOrWelcome(AsyncWebServerRequest *request); -void serveIndex(AsyncWebServerRequest* request); -String msgProcessor(const String& var); -void serveMessage(AsyncWebServerRequest* request, uint16_t code, String headl, String subl="", byte optionT=255); -String settingsProcessor(const String& var); -String dmxProcessor(const String& var); -void serveSettings(AsyncWebServerRequest* request); - -#endif //WLED_SERVER_H \ No newline at end of file diff --git a/wled00/xml.cpp b/wled00/xml.cpp index 09e42011..3af1e54c 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -1,8 +1,8 @@ -#include "xml.h" #include "wled.h" -#include "wled_eeprom.h" -#include "ntp.h" +/* + * Sending XML status files to client + */ //build XML response to HTTP /win API request char* XML_response(AsyncWebServerRequest *request, char* dest) diff --git a/wled00/xml.h b/wled00/xml.h deleted file mode 100644 index 02298295..00000000 --- a/wled00/xml.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef WLED_XML_H -#define WLED_XML_H -#include -#include - -/* - * Sending XML status files to client - */ -char* XML_response(AsyncWebServerRequest *request, char* dest = nullptr); -char* URL_response(AsyncWebServerRequest *request); -void sappend(char stype, const char* key, int val); -void sappends(char stype, const char* key, char* val); -void getSettingsJS(byte subPage, char* dest); - -#endif // WLED_XML_H \ No newline at end of file From 5cb2a39746e922fecc996a80617c79bf16bb766d Mon Sep 17 00:00:00 2001 From: cschwinne Date: Mon, 6 Apr 2020 02:25:17 +0200 Subject: [PATCH 31/32] Consolidated global variables in wled.h --- CHANGELOG.md | 4 + wled00/const.h | 13 ++ wled00/dmx.cpp | 2 +- wled00/wled.cpp | 339 +-------------------------- wled00/wled.h | 610 ++++++++++++++++++++++++++++-------------------- 5 files changed, 375 insertions(+), 593 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9804b1f..8df63ff8 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 535a5987..ef19e51b 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 596624a6..ea087124 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 7579a9c5..701b98e3 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 926fa0c8..0c6d3114 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 From 8da985b6d03a7a77b2bc6932dbe95fcb9fb36bd2 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Tue, 7 Apr 2020 00:04:09 +0200 Subject: [PATCH 32/32] Fixed RBG and BGR getPixelColor (#825) Improved formatting --- CHANGELOG.md | 5 + wled00/FX_fcn.cpp | 4 +- wled00/const.h | 4 + wled00/{func_declare.h => fcn_declare.h} | 4 +- wled00/html_other.h | 2 +- wled00/html_settings.h | 4 +- wled00/wled.cpp | 4 + wled00/wled.h | 114 ++++++++++++----------- wled00/wled00.ino | 11 ++- 9 files changed, 90 insertions(+), 62 deletions(-) rename wled00/{func_declare.h => fcn_declare.h} (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8df63ff8..d92a1966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ### Development versions after 0.9.1 release +#### Build 2004061 + +- Fixed RBG and BGR getPixelColor (#825) +- Improved formatting + #### Build 2004060 - Consolidated global variables in wled.h diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index de89a430..69b8c88a 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -412,8 +412,8 @@ uint32_t WS2812FX::getPixelColor(uint16_t i) case 0: return ((col.W << 24) | (col.G << 8) | (col.R << 16) | (col.B)); //0 = GRB, default case 1: return ((col.W << 24) | (col.R << 8) | (col.G << 16) | (col.B)); //1 = RGB, common for WS2811 case 2: return ((col.W << 24) | (col.B << 8) | (col.R << 16) | (col.G)); //2 = BRG - case 3: return ((col.W << 24) | (col.R << 8) | (col.B << 16) | (col.G)); //3 = RBG - case 4: return ((col.W << 24) | (col.B << 8) | (col.G << 16) | (col.R)); //4 = BGR + case 3: return ((col.W << 24) | (col.B << 8) | (col.G << 16) | (col.R)); //3 = RBG + case 4: return ((col.W << 24) | (col.R << 8) | (col.B << 16) | (col.G)); //4 = BGR case 5: return ((col.W << 24) | (col.G << 8) | (col.B << 16) | (col.R)); //5 = GBR } return 0; diff --git a/wled00/const.h b/wled00/const.h index ef19e51b..173d7e7d 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -1,6 +1,10 @@ #ifndef WLED_CONST_H #define WLED_CONST_H +/* + * Readability defines and their associated numerical values + compile-time constants + */ + //Defaults #define DEFAULT_CLIENT_SSID "Your_Network" #define DEFAULT_AP_PASS "wled1234" diff --git a/wled00/func_declare.h b/wled00/fcn_declare.h similarity index 99% rename from wled00/func_declare.h rename to wled00/fcn_declare.h index db3cb4bc..c0826d6a 100644 --- a/wled00/func_declare.h +++ b/wled00/fcn_declare.h @@ -1,5 +1,5 @@ -#ifndef WLED_FUNC_DECLARE_H -#define WLED_FUNC_DECLARE_H +#ifndef WLED_FCN_DECLARE_H +#define WLED_FCN_DECLARE_H #include #include "src/dependencies/espalexa/EspalexaDevice.h" #include "src/dependencies/e131/ESPAsyncE131.h" diff --git a/wled00/html_other.h b/wled00/html_other.h index e27c64dd..ce36cff4 100644 --- a/wled00/html_other.h +++ b/wled00/html_other.h @@ -1,5 +1,5 @@ /* - * Various pages + * Various web pages */ //USER HTML HERE (/u subpage) diff --git a/wled00/html_settings.h b/wled00/html_settings.h index 284d9b30..e2d94f97 100644 --- a/wled00/html_settings.h +++ b/wled00/html_settings.h @@ -1,6 +1,6 @@ /* - Settings html -*/ + * Settings html + */ //common CSS of settings pages const char PAGE_settingsCss[] PROGMEM = R"=====()====="; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 701b98e3..b68723bb 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -2,6 +2,10 @@ #include "wled.h" #include +/* + * Main WLED class implementation. Mostly initialization and connection logic + */ + WLED::WLED() { } diff --git a/wled00/wled.h b/wled00/wled.h index 0c6d3114..6f4b2cb0 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2004060 +#define VERSION 2004061 // 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). @@ -81,7 +81,7 @@ #include "src/dependencies/json/AsyncJson-v6.h" #include "src/dependencies/json/ArduinoJson-v6.h" -#include "func_declare.h" +#include "fcn_declare.h" #include "html_ui.h" #include "html_settings.h" #include "html_other.h" @@ -128,6 +128,12 @@ #define DEBUG_PRINTF(x) #endif +// GLOBAL VARIABLES +// both declared and defined in header (solution from http://www.keil.com/support/docs/1868.htm) +// +//e.g. byte test = 2 becomes WLED_GLOBAL byte test _INIT(2); +// int arr[]{0,1,2} becomes WLED_GLOBAL int arr[] _INIT_N(({0,1,2})); + #ifndef WLED_DEFINE_GLOBAL_VARS # define WLED_GLOBAL extern # define _INIT(x) @@ -170,13 +176,13 @@ WLED_GLOBAL bool noWifiSleep _INIT(false); // disabling // 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 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 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 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); @@ -189,52 +195,52 @@ WLED_GLOBAL bool skipFirstLed _INIT(false); // ignore first LED in strip 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 +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 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 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 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 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 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 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 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 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 @@ -255,30 +261,30 @@ WLED_GLOBAL int utcOffsetSecs _INIT(0); // Seconds to offset from UTC 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 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 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 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 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); +WLED_GLOBAL uint16_t userVar0 _INIT(0), userVar1 _INIT(0); //available for use in usermod #ifdef WLED_ENABLE_DMX // dmx CONFIG diff --git a/wled00/wled00.ino b/wled00/wled00.ino index f806e5b3..866543ab 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -1,5 +1,14 @@ /* - * Arduino IDE compatibility file. + * WLED Arduino IDE compatibility file. + * + * Where has everything gone? + * + * In April 2020, the project's structure underwent a major change. + * Global variables are now found in file "wled.h" + * Global function declarations are found in "fcn_declare.h" + * + * Usermod compatibility: Existing wled06_usermod.ino mods should continue to work. Delete usermod.cpp. + * New usermods should use usermod.cpp instead. */ #include "wled.h"