From 1caaf04dfa1411cf43a2110aa130a38135e7fbf1 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 20 Feb 2019 23:44:34 +0100 Subject: [PATCH] Various performance and reliability improvements --- wled00/NpbWrapper.h | 26 ++------------------------ wled00/WS2812FX_fcn.cpp | 2 +- wled00/wled00.ino | 9 +++++---- wled00/wled03_set.ino | 7 ++++--- wled00/wled05_init.ino | 7 ++++--- wled00/wled15_hue.ino | 6 ------ wled00/wled18_server.ino | 29 +++++++++++++++++------------ 7 files changed, 33 insertions(+), 53 deletions(-) diff --git a/wled00/NpbWrapper.h b/wled00/NpbWrapper.h index 1d82c29d..9bded7f5 100644 --- a/wled00/NpbWrapper.h +++ b/wled00/NpbWrapper.h @@ -2,24 +2,15 @@ #ifndef NpbWrapper_h #define NpbWrapper_h -//#define WORKAROUND_ESP32_BITBANG -//see https://github.com/Aircoookie/WLED/issues/2 for flicker free ESP32 support - //PIN CONFIGURATION -#define LEDPIN 2 //strip pin. Any for ESP32, gpio2 or 3 is recommended for ESP8266 (gpio2/3 are labeled D4/RX on NodeMCU and Wemos) +#define LEDPIN 3 //strip pin. Any for ESP32, gpio2 or 3 is recommended for ESP8266 (gpio2/3 are labeled D4/RX on NodeMCU and Wemos) #define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended) #define IR_PIN 4 //infrared pin (-1 to disable) #define AUXPIN -1 //unused auxiliary output pin (-1 to disable) - //automatically uses the right driver method for each platform #ifdef ARDUINO_ARCH_ESP32 - #ifdef WORKAROUND_ESP32_BITBANG - #define PIXELMETHOD NeoEsp32BitBangWs2813Method - #pragma message "Software BitBang is used because of your NeoPixelBus version. Look in NpbWrapper.h for instructions on how to mitigate flickering." - #else - #define PIXELMETHOD NeoWs2813Method - #endif + #define PIXELMETHOD NeoWs2813Method #else //esp8266 //autoselect the right method depending on strip pin #if LEDPIN == 2 @@ -86,24 +77,11 @@ public: void Show() { - #ifdef ARDUINO_ARCH_ESP32 - #ifdef WORKAROUND_ESP32_BITBANG - delay(1); - portDISABLE_INTERRUPTS(); //this is a workaround to prevent flickering (see https://github.com/adafruit/Adafruit_NeoPixel/issues/139) - #endif - #endif - switch (_type) { case NeoPixelType_Grb: _pGrb->Show(); break; case NeoPixelType_Grbw: _pGrbw->Show(); break; } - - #ifdef ARDUINO_ARCH_ESP32 - #ifdef WORKAROUND_ESP32_BITBANG - portENABLE_INTERRUPTS(); - #endif - #endif } bool CanShow() const diff --git a/wled00/WS2812FX_fcn.cpp b/wled00/WS2812FX_fcn.cpp index 90c5711e..e013933e 100644 --- a/wled00/WS2812FX_fcn.cpp +++ b/wled00/WS2812FX_fcn.cpp @@ -27,7 +27,7 @@ #include "WS2812FX.h" #include "palettes.h" -#define LED_SKIP_AMOUNT 1 +#define LED_SKIP_AMOUNT 24 void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst) { diff --git a/wled00/wled00.ino b/wled00/wled00.ino index e7d5dd9f..9ff67552 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -87,7 +87,7 @@ //version code in format yymmddb (b = daily build) -#define VERSION 1902201 +#define VERSION 1902202 char versionString[] = "0.8.4-dev"; @@ -399,12 +399,12 @@ unsigned int ntpLocalPort = 2390; #define NTP_PACKET_SIZE 48 //string temp buffer -#define OMAX 2000 +#define OMAX 2048 char obuf[OMAX]; uint16_t olen = 0; String messageHead, messageSub; -uint32_t optionType; +byte optionType; bool doReboot = false; //flag to initiate reboot from async handlers @@ -463,7 +463,7 @@ const byte gamma8[] = { String txd = "Please disable OTA Lock in security settings!"; //function prototypes -void serveMessage(AsyncWebServerRequest*,uint16_t,String,String,uint32_t); +void serveMessage(AsyncWebServerRequest*,uint16_t,String,String,byte); //turns all LEDs off and restarts ESP @@ -532,6 +532,7 @@ void loop() { handleHue(); handleBlynk(); } + yield(); if (briT) lastOnTime = millis(); if (millis() - lastOnTime < 600) strip.service(); } diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index 33e12ab7..f7a0390a 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -55,9 +55,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) { int t = request->arg("LC").toInt(); if (t > 0 && t <= 1200) ledCount = t; - //RMT eats up too much RAM - #ifdef ARDUINO_ARCH_ESP32 - if (ledCount > 600) ledCount = 600; + #ifndef ARDUINO_ARCH_ESP32 + #if LEDPIN == 3 + if (ledCount > 300) ledCount = 300; //DMA method uses too much ram + #endif #endif strip.ablMilliampsMax = request->arg("MA").toInt(); useRGBW = request->hasArg("EW"); diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index d8fe3559..8ab5b82f 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -7,9 +7,10 @@ void wledInit() EEPROM.begin(EEPSIZE); ledCount = EEPROM.read(229) + ((EEPROM.read(398) << 8) & 0xFF00); if (ledCount > 1200 || ledCount == 0) ledCount = 30; - //RMT eats up too much RAM - #ifdef ARDUINO_ARCH_ESP32 - if (ledCount > 600) ledCount = 600; + #ifndef ARDUINO_ARCH_ESP32 + #if LEDPIN == 3 + if (ledCount > 300) ledCount = 300; //DMA method uses too much ram + #endif #endif Serial.begin(115200); Serial.setTimeout(50); diff --git a/wled00/wled15_hue.ino b/wled00/wled15_hue.ino index 6efd6611..c042b5df 100644 --- a/wled00/wled15_hue.ino +++ b/wled00/wled15_hue.ino @@ -38,12 +38,6 @@ void reconnectHue() hueClient->onError(&onHueError, hueClient); hueAuthRequired = (strlen(hueApiKey)<20); } - if (hueClient->connecting()) return; //don't start multiple connections before timeout - if (hueClient->connected()) - { - if (hueClient->getRemoteAddress() == uint32_t(hueIP) && huePollingEnabled) {sendHuePoll(); return;} //already connected - hueClient->close(); return; - } hueClient->connect(hueIP, 80); } diff --git a/wled00/wled18_server.ino b/wled00/wled18_server.ino index f6418adb..82119391 100644 --- a/wled00/wled18_server.ino +++ b/wled00/wled18_server.ino @@ -28,7 +28,7 @@ void initServer() }); server.on("/reset", HTTP_GET, [](AsyncWebServerRequest *request){ - serveMessage(request, 200,"Rebooting now...","Please wait ~15 seconds...",132); + serveMessage(request, 200,"Rebooting now...","Please wait ~10 seconds...",129); doReboot = true; }); @@ -60,7 +60,7 @@ void initServer() server.on("/settings/sec", HTTP_POST, [](AsyncWebServerRequest *request){ handleSettingsSet(request, 6); - serveMessage(request, 200,"Security settings saved.","Rebooting now, please wait ~15 seconds...",132); + serveMessage(request, 200,"Security settings saved.","Rebooting now, please wait ~10 seconds...",129); doReboot = true; }); @@ -72,6 +72,10 @@ void initServer() request->send_P(200, "application/json", JSON_palette_names); }); + server.on("/json/info", HTTP_ANY, [](AsyncWebServerRequest *request){ + request->send(500, "application/json", "{\"error\":\"Not implemented\"}"); + }); + server.on("/json", HTTP_ANY, [](AsyncWebServerRequest *request){ request->send(500, "application/json", "{\"error\":\"Not implemented\"}"); }); @@ -139,7 +143,7 @@ void initServer() { serveMessage(request, 500, "Failed updating firmware!", "Please check your file and retry!", 254); return; } - serveMessage(request, 200, "Successfully updated firmware!", "Please wait while the module reboots...", 132); + serveMessage(request, 200, "Successfully updated firmware!", "Please wait while the module reboots...", 131); doReboot = true; },[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){ if(!index){ @@ -256,20 +260,21 @@ String msgProcessor(const String& var) messageBody += messageHead; messageBody += ""; messageBody += messageSub; + uint32_t optt = optionType; - if (optionType < 60) //redirect to settings after optionType seconds + if (optt < 60) //redirect to settings after optionType seconds { - messageBody += ""; - } else if (optionType < 120) //redirect back after optionType-60 seconds, unused + messageBody += ""; + } else if (optt < 120) //redirect back after optionType-60 seconds, unused { - //messageBody += ""; - } else if (optionType < 180) //reload parent after optionType-120 seconds + //messageBody += ""; + } else if (optt < 180) //reload parent after optionType-120 seconds { - messageBody += ""; - } else if (optionType == 253) + messageBody += ""; + } else if (optt == 253) { messageBody += "

"; //button to settings - } else if (optionType == 254) + } else if (optt == 254) { messageBody += "

"; } @@ -279,7 +284,7 @@ String msgProcessor(const String& var) } -void serveMessage(AsyncWebServerRequest* request, uint16_t code, String headl, String subl="", uint32_t optionT=255) +void serveMessage(AsyncWebServerRequest* request, uint16_t code, String headl, String subl="", byte optionT=255) { olen = 0; getCSSColors();