From a0fd02e0c0b7ccf35b77b9b11a3fc6c8dcfed347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Kristan?= Date: Thu, 20 May 2021 06:45:02 +0200 Subject: [PATCH] Inverted button support. Config save/load fix. --- wled00/button.cpp | 25 ++++++++++++++++++++----- wled00/cfg.cpp | 22 ++++++++++++++++------ wled00/data/settings_leds.htm | 2 ++ wled00/data/settings_time.htm | 4 ++-- wled00/html_settings.h | 12 ++++++------ wled00/set.cpp | 23 +++++++++++------------ wled00/wled.h | 2 +- 7 files changed, 58 insertions(+), 32 deletions(-) diff --git a/wled00/button.cpp b/wled00/button.cpp index 1b949feb4..26218c154 100644 --- a/wled00/button.cpp +++ b/wled00/button.cpp @@ -20,11 +20,26 @@ void shortPressAction(uint8_t b) bool isButtonPressed(uint8_t i) { if (btnPin[i]<0) return false; - //TODO: this may need switch statement (for inverted buttons) - #ifdef ARDUINO_ARCH_ESP32 - if (buttonType[i]==BTN_TYPE_TOUCH && touchRead(btnPin[i]) <= touchThreshold) return true; else - #endif - if (digitalRead(btnPin[i]) == LOW) return true; + switch (buttonType[i]) { + case BTN_TYPE_NONE: + case BTN_TYPE_RESERVED: + break; + case BTN_TYPE_PUSH: + case BTN_TYPE_SWITCH: + if (digitalRead(btnPin[i]) == LOW) return true; + break; + case BTN_TYPE_PUSH_ACT_HIGH: + case BTN_TYPE_SWITCH_ACT_HIGH: + if (digitalRead(btnPin[i]) == HIGH) return true; + break; + case BTN_TYPE_TOUCH: + #ifdef ARDUINO_ARCH_ESP32 + if (touchRead(btnPin[i]) <= touchThreshold) return true; + DEBUG_PRINT(F("Touch value: ")); + DEBUG_PRINTLN(touchRead(btnPin[i])); + #endif + break; + } return false; } diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 437918ff4..5db704904 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -161,9 +161,18 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { macroDoublePress[s] = 0; } } else { - //TODO: fix JSON API call (and new install) + // new install/missing configuration (button 0 has defaults) + if (fromFS) + for (uint8_t s=1; s c += ``; c += ` ×
`; diff --git a/wled00/data/settings_time.htm b/wled00/data/settings_time.htm index a2426c99b..0515de1f3 100644 --- a/wled00/data/settings_time.htm +++ b/wled00/data/settings_time.htm @@ -172,10 +172,10 @@ - + - + diff --git a/wled00/html_settings.h b/wled00/html_settings.h index b07d34d4b..ce8f05acd 100644 --- a/wled00/html_settings.h +++ b/wled00/html_settings.h @@ -74,7 +74,7 @@ Do not enable if WiFi is working correctly, increases power consumption.
LED Settings
push
switch
short
on->off
long
off->on
doubledouble
N/A