From 4104dec87fa3efc47876aaac4b1da125e0e82e36 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Wed, 19 May 2021 20:23:35 +0200 Subject: [PATCH] Addet touch button and touch threshold. Fixed some errors. --- wled00/button.cpp | 8 +++++--- wled00/cfg.cpp | 3 +++ wled00/const.h | 1 + wled00/data/settings_leds.htm | 10 ++++++---- wled00/html_settings.h | 5 +++-- wled00/set.cpp | 1 + wled00/wled.h | 1 + wled00/xml.cpp | 1 + 8 files changed, 21 insertions(+), 9 deletions(-) diff --git a/wled00/button.cpp b/wled00/button.cpp index ce8421bc..1b949feb 100644 --- a/wled00/button.cpp +++ b/wled00/button.cpp @@ -19,10 +19,12 @@ void shortPressAction(uint8_t b) bool isButtonPressed(uint8_t i) { - if (btnPin[i]>=0 && digitalRead(btnPin[i]) == LOW) return true; - #ifdef TOUCHPIN - if (touchRead(TOUCHPIN) <= TOUCH_THRESHOLD) return true; + 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; return false; } diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 976f9241..7121964c 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -163,6 +163,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { } else { //TODO: fix JSON API call (and new install) } + CJSON(touchThreshold,hw[F("btn")][F("touch-thershold")]); + /* JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0]; CJSON(buttonType, hw_btn_ins_0["type"]); @@ -568,6 +570,7 @@ void serializeConfig() { hw_btn_ins_0_macros.add(macroLongPress[i]); hw_btn_ins_0_macros.add(macroDoublePress[i]); } + hw_btn[F("touch-threshold")] = touchThreshold; JsonObject hw_ir = hw.createNestedObject("ir"); hw_ir["pin"] = irPin; diff --git a/wled00/const.h b/wled00/const.h index 4012a758..6dfda5ff 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -159,6 +159,7 @@ #define BTN_TYPE_PUSH_ACT_HIGH 3 //not implemented #define BTN_TYPE_SWITCH 4 #define BTN_TYPE_SWITCH_ACT_HIGH 5 //not implemented +#define BTN_TYPE_TOUCH 6 //Ethernet board types #define WLED_NUM_ETH_TYPES 5 diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index 9d7b1798..81e3727c 100644 --- a/wled00/data/settings_leds.htm +++ b/wled00/data/settings_leds.htm @@ -288,10 +288,11 @@ Reverse (rotated 180°): var bt = "BT" + i; var be = "BE" + i; c += `Button ${i} pin: `; - c += `` + c += ``; + c += ``; + c += ``; + c += ``; c += ``; c += ` ×
`; gId("btns").innerHTML = c; @@ -353,6 +354,7 @@ Reverse (rotated 180°): Use less than 800 LEDs per pin for the best experience!

+ Touch threshold:
IR pin: