From f7004e7a7cfe74945e8a70256f07bab91fd04ceb Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Sat, 26 Nov 2022 23:56:55 +0100 Subject: [PATCH] Allow disable internal pull-up resistors. Fixes #2896 and #2899 --- wled00/cfg.cpp | 18 +- wled00/data/settings_leds.htm | 1 + wled00/html_settings.h | 934 +++++++++++++++++----------------- wled00/set.cpp | 15 +- wled00/wled.h | 3 +- wled00/xml.cpp | 1 + 6 files changed, 495 insertions(+), 477 deletions(-) diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 6849e273..32c2a0d5 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -192,6 +192,9 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { // read multiple button configuration JsonObject btn_obj = hw["btn"]; + int pull = -1; // trick for inverted setting + CJSON(pull, btn_obj[F("pull")]); + if (pull>=0) disablePullUp = pull; JsonArray hw_btn_ins = btn_obj[F("ins")]; if (!hw_btn_ins.isNull()) { uint8_t s = 0; @@ -200,11 +203,15 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { int8_t pin = btn["pin"][0] | -1; if (pin > -1 && pinManager.allocatePin(pin, false, PinOwner::Button)) { btnPin[s] = pin; - #ifdef ESP32 - pinMode(btnPin[s], buttonType[s]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP); - #else - pinMode(btnPin[s], INPUT_PULLUP); - #endif + if (disablePullUp) { + pinMode(btnPin[s], INPUT); + } else { + #ifdef ESP32 + pinMode(btnPin[s], buttonType[s]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP); + #else + pinMode(btnPin[s], INPUT_PULLUP); + #endif + } } else { btnPin[s] = -1; } @@ -735,6 +742,7 @@ void serializeConfig() { // button(s) JsonObject hw_btn = hw.createNestedObject("btn"); hw_btn["max"] = WLED_MAX_BUTTONS; // just information about max number of buttons (not actually used) + hw_btn[F("pull")] = !disablePullUp; JsonArray hw_btn_ins = hw_btn.createNestedArray("ins"); // configuration for all buttons diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index 6f1dc59b..befcc9a6 100644 --- a/wled00/data/settings_leds.htm +++ b/wled00/data/settings_leds.htm @@ -617,6 +617,7 @@ Length:
+ Disable internal pull-up/down:
Touch threshold:
IR GPIO: