Fixed button-caused asyncserver unresponsiveness

Fixed RGBW power calculation
pull/133/head
cschwinne 2019-02-20 15:10:23 +01:00
rodzic ba19e20833
commit b422a80249
4 zmienionych plików z 47 dodań i 33 usunięć

Wyświetl plik

@ -8,8 +8,8 @@
//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 BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended)
#define IR_PIN 4 //infrared pin.
#define AUXPIN 15 //unused auxiliary output pin
#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

Wyświetl plik

@ -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
{
powerSum *= 3;
powerSum >> 2; //same as /= 4
powerSum = powerSum >> 2; //same as /= 4
}
uint32_t powerSum0 = powerSum;

Wyświetl plik

@ -27,28 +27,17 @@
//to toggle usb serial debug (un)comment following line(s)
//#define WLED_DEBUG
//library inclusions
#include <Arduino.h>
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#include <ESPmDNS.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
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ESP8266HTTPClient.h>
#ifndef WLED_DISABLE_INFRARED
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
#endif
#endif
#include <ESPAsyncWebServer.h>
@ -78,9 +67,27 @@
#include "WS2812FX.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)
#define VERSION 1902191
#define VERSION 1902201
char versionString[] = "0.8.4-dev";
@ -281,6 +288,7 @@ byte briLast = 127; //brightness before turned off. Us
//button
bool buttonPressedBefore = false;
unsigned long buttonPressedTime = 0;
unsigned long buttonReleasedTime = 0;
//notifications
bool notifyDirectDefault = notifyDirect;

Wyświetl plik

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