Fixed button-caused asyncserver unresponsiveness

Fixed RGBW power calculation
This commit is contained in:
cschwinne 2019-02-20 15:10:23 +01:00
parent ba19e20833
commit b422a80249
4 changed files with 47 additions and 33 deletions

View File

@ -8,8 +8,8 @@
//PIN CONFIGURATION //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 2 //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 BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended)
#define IR_PIN 4 //infrared pin. #define IR_PIN 4 //infrared pin (-1 to disable)
#define AUXPIN 15 //unused auxiliary output pin #define AUXPIN -1 //unused auxiliary output pin (-1 to disable)
//automatically uses the right driver method for each platform //automatically uses the right driver method for each platform

View File

@ -217,7 +217,7 @@ void WS2812FX::show(void) {
if (_rgbwMode) //RGBW led total output with white LEDs enabled is still 50mA, so each channel uses less if (_rgbwMode) //RGBW led total output with white LEDs enabled is still 50mA, so each channel uses less
{ {
powerSum *= 3; powerSum *= 3;
powerSum >> 2; //same as /= 4 powerSum = powerSum >> 2; //same as /= 4
} }
uint32_t powerSum0 = powerSum; uint32_t powerSum0 = powerSum;

View File

@ -27,28 +27,17 @@
//to toggle usb serial debug (un)comment following line(s) //to toggle usb serial debug (un)comment following line(s)
//#define WLED_DEBUG //#define WLED_DEBUG
//library inclusions //library inclusions
#include <Arduino.h> #include <Arduino.h>
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h> #include <WiFi.h>
#include <ESPmDNS.h> #include <ESPmDNS.h>
#include <AsyncTCP.h> #include <AsyncTCP.h>
#include <HTTPClient.h>
/*#ifndef WLED_DISABLE_INFRARED
#include <IRremote.h>
#endif*/ //there are issues with ESP32 infrared, so it is disabled for now
#else #else
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266mDNS.h> #include <ESP8266mDNS.h>
#include <ESPAsyncTCP.h> #include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h> #include <ESPAsyncWebServer.h>
#include <ESP8266HTTPClient.h>
#ifndef WLED_DISABLE_INFRARED
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
#endif
#endif #endif
#include <ESPAsyncWebServer.h> #include <ESPAsyncWebServer.h>
@ -78,9 +67,27 @@
#include "WS2812FX.h" #include "WS2812FX.h"
#include "ir_codes.h" #include "ir_codes.h"
#if IR_PIN < 0
#ifndef WLED_DISABLE_INFRARED
#define WLED_DISABLE_INFRARED
#endif
#endif
#ifdef ARDUINO_ARCH_ESP32
/*#ifndef WLED_DISABLE_INFRARED
#include <IRremote.h>
#endif*/ //there are issues with ESP32 infrared, so it is disabled for now
#else
#ifndef WLED_DISABLE_INFRARED
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
#endif
#endif
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 1902191 #define VERSION 1902201
char versionString[] = "0.8.4-dev"; char versionString[] = "0.8.4-dev";
@ -281,6 +288,7 @@ byte briLast = 127; //brightness before turned off. Us
//button //button
bool buttonPressedBefore = false; bool buttonPressedBefore = false;
unsigned long buttonPressedTime = 0; unsigned long buttonPressedTime = 0;
unsigned long buttonReleasedTime = 0;
//notifications //notifications
bool notifyDirectDefault = notifyDirect; bool notifyDirectDefault = notifyDirect;

View File

@ -4,38 +4,43 @@
void handleButton() void handleButton()
{ {
if (buttonEnabled) if (buttonEnabled && millis() - buttonReleasedTime > 20) //debounce
{ {
if (digitalRead(BTNPIN) == LOW && !buttonPressedBefore) if (digitalRead(BTNPIN) == LOW && !buttonPressedBefore) //pressed
{ {
buttonPressedTime = millis(); buttonPressedTime = millis();
buttonPressedBefore = true; buttonPressedBefore = true;
} }
else if (digitalRead(BTNPIN) == HIGH && buttonPressedBefore) else if (digitalRead(BTNPIN) == HIGH && buttonPressedBefore) //released
{ {
delay(15); //debounce if (buttonReleasedTime == 0) {
if (digitalRead(BTNPIN) == HIGH) buttonReleasedTime = millis();
{ } else {
if (millis() - buttonPressedTime > 7000) {initAP();} if (digitalRead(BTNPIN) == HIGH)
else if (millis() - buttonPressedTime > 700)
{ {
if (macroLongPress != 0) {applyMacro(macroLongPress);} if (buttonReleasedTime - buttonPressedTime > 7000) {initAP();}
else _setRandomColor(false,true); else if (buttonReleasedTime - buttonPressedTime > 700)
}
else {
if (macroButton == 0)
{ {
toggleOnOff(); if (macroLongPress != 0) {applyMacro(macroLongPress);}
colorUpdated(2); else _setRandomColor(false,true);
} else {
applyMacro(macroButton);
} }
else {
if (macroButton == 0)
{
toggleOnOff();
colorUpdated(2);
} else {
applyMacro(macroButton);
}
}
buttonPressedBefore = false;
} }
buttonPressedBefore = false; buttonReleasedTime = 0;
} }
} }
} }
#if AUXPIN >= 0
//output //output
if (auxActive || auxActiveBefore) if (auxActive || auxActiveBefore)
{ {
@ -62,4 +67,5 @@ void handleButton()
} }
} }
} }
#endif
} }