Various performance and reliability improvements

This commit is contained in:
cschwinne 2019-02-20 23:44:34 +01:00
parent b422a80249
commit 1caaf04dfa
7 changed files with 33 additions and 53 deletions

View File

@ -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
#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

View File

@ -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)
{

View File

@ -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();
}

View File

@ -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");

View File

@ -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);

View File

@ -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);
}

View File

@ -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 += "</h2>";
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 += "<script>setTimeout(RS," + String(optionType*1000) + ")</script>";
} else if (optionType < 120) //redirect back after optionType-60 seconds, unused
messageBody += "<script>setTimeout(RS," + String(optt*1000) + ")</script>";
} else if (optt < 120) //redirect back after optionType-60 seconds, unused
{
//messageBody += "<script>setTimeout(B," + String((optionType-60)*1000) + ")</script>";
} else if (optionType < 180) //reload parent after optionType-120 seconds
//messageBody += "<script>setTimeout(B," + String((optt-60)*1000) + ")</script>";
} else if (optt < 180) //reload parent after optionType-120 seconds
{
messageBody += "<script>setTimeout(RP," + String((optionType-120)*1000) + ")</script>";
} else if (optionType == 253)
messageBody += "<script>setTimeout(RP," + String((optt-120)*1000) + ")</script>";
} else if (optt == 253)
{
messageBody += "<br><br><form action=/settings><button class=\"bt\" type=submit>Back</button></form>"; //button to settings
} else if (optionType == 254)
} else if (optt == 254)
{
messageBody += "<br><br><button type=\"button\" class=\"bt\" onclick=\"B()\">Back</button>";
}
@ -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();