Allow disable internal pull-up resistors.

Fixes #2896 and #2899
This commit is contained in:
Blaz Kristan 2022-11-26 23:56:55 +01:00
parent 1db25d4b20
commit f7004e7a7c
6 changed files with 495 additions and 477 deletions

View File

@ -192,6 +192,9 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
// read multiple button configuration // read multiple button configuration
JsonObject btn_obj = hw["btn"]; 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")]; JsonArray hw_btn_ins = btn_obj[F("ins")];
if (!hw_btn_ins.isNull()) { if (!hw_btn_ins.isNull()) {
uint8_t s = 0; uint8_t s = 0;
@ -200,11 +203,15 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
int8_t pin = btn["pin"][0] | -1; int8_t pin = btn["pin"][0] | -1;
if (pin > -1 && pinManager.allocatePin(pin, false, PinOwner::Button)) { if (pin > -1 && pinManager.allocatePin(pin, false, PinOwner::Button)) {
btnPin[s] = pin; btnPin[s] = pin;
#ifdef ESP32 if (disablePullUp) {
pinMode(btnPin[s], buttonType[s]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP); pinMode(btnPin[s], INPUT);
#else } else {
pinMode(btnPin[s], INPUT_PULLUP); #ifdef ESP32
#endif pinMode(btnPin[s], buttonType[s]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP);
#else
pinMode(btnPin[s], INPUT_PULLUP);
#endif
}
} else { } else {
btnPin[s] = -1; btnPin[s] = -1;
} }
@ -735,6 +742,7 @@ void serializeConfig() {
// button(s) // button(s)
JsonObject hw_btn = hw.createNestedObject("btn"); JsonObject hw_btn = hw.createNestedObject("btn");
hw_btn["max"] = WLED_MAX_BUTTONS; // just information about max number of buttons (not actually used) 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"); JsonArray hw_btn_ins = hw_btn.createNestedArray("ins");
// configuration for all buttons // configuration for all buttons

View File

@ -617,6 +617,7 @@ Length: <input type="number" name="XC${i}" id="xc${i}" class="l" min="1" max="65
</div> </div>
<hr class="sml"> <hr class="sml">
<div id="btns"></div> <div id="btns"></div>
Disable internal pull-up/down: <input type="checkbox" name="IP"><br>
Touch threshold: <input type="number" class="s" min="0" max="100" name="TT" required><br> Touch threshold: <input type="number" class="s" min="0" max="100" name="TT" required><br>
IR GPIO: <input type="number" min="-1" max="48" name="IR" onchange="UI()" class="xs"><select name="IT" onchange="UI()"> IR GPIO: <input type="number" min="-1" max="48" name="IR" onchange="UI()" class="xs"><select name="IT" onchange="UI()">
<option value=0>Remote disabled</option> <option value=0>Remote disabled</option>

File diff suppressed because it is too large Load Diff

View File

@ -161,6 +161,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
} }
rlyMde = (bool)request->hasArg(F("RM")); rlyMde = (bool)request->hasArg(F("RM"));
disablePullUp = (bool)request->hasArg(F("IP"));
for (uint8_t i=0; i<WLED_MAX_BUTTONS; i++) { for (uint8_t i=0; i<WLED_MAX_BUTTONS; i++) {
char bt[4] = "BT"; bt[2] = (i<10?48:55)+i; bt[3] = 0; // button pin (use A,B,C,... if WLED_MAX_BUTTONS>10) char bt[4] = "BT"; bt[2] = (i<10?48:55)+i; bt[3] = 0; // button pin (use A,B,C,... if WLED_MAX_BUTTONS>10)
char be[4] = "BE"; be[2] = (i<10?48:55)+i; be[3] = 0; // button type (use A,B,C,... if WLED_MAX_BUTTONS>10) char be[4] = "BE"; be[2] = (i<10?48:55)+i; be[3] = 0; // button type (use A,B,C,... if WLED_MAX_BUTTONS>10)
@ -168,11 +169,15 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
if (pinManager.allocatePin(hw_btn_pin,false,PinOwner::Button)) { if (pinManager.allocatePin(hw_btn_pin,false,PinOwner::Button)) {
btnPin[i] = hw_btn_pin; btnPin[i] = hw_btn_pin;
buttonType[i] = request->arg(be).toInt(); buttonType[i] = request->arg(be).toInt();
#ifdef ESP32 if (disablePullUp) {
pinMode(btnPin[i], buttonType[i]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP); pinMode(btnPin[i], INPUT);
#else } else {
pinMode(btnPin[i], INPUT_PULLUP); #ifdef ESP32
#endif pinMode(btnPin[i], buttonType[i]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP);
#else
pinMode(btnPin[i], INPUT_PULLUP);
#endif
}
} else { } else {
btnPin[i] = -1; btnPin[i] = -1;
buttonType[i] = BTN_TYPE_NONE; buttonType[i] = BTN_TYPE_NONE;

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2211260 #define VERSION 2211261
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG
@ -516,6 +516,7 @@ WLED_GLOBAL bool buttonPressedBefore[WLED_MAX_BUTTONS] _INIT({false});
WLED_GLOBAL bool buttonLongPressed[WLED_MAX_BUTTONS] _INIT({false}); WLED_GLOBAL bool buttonLongPressed[WLED_MAX_BUTTONS] _INIT({false});
WLED_GLOBAL unsigned long buttonPressedTime[WLED_MAX_BUTTONS] _INIT({0}); WLED_GLOBAL unsigned long buttonPressedTime[WLED_MAX_BUTTONS] _INIT({0});
WLED_GLOBAL unsigned long buttonWaitTime[WLED_MAX_BUTTONS] _INIT({0}); WLED_GLOBAL unsigned long buttonWaitTime[WLED_MAX_BUTTONS] _INIT({0});
WLED_GLOBAL bool disablePullUp _INIT(false);
WLED_GLOBAL byte touchThreshold _INIT(TOUCH_THRESHOLD); WLED_GLOBAL byte touchThreshold _INIT(TOUCH_THRESHOLD);
// notifications // notifications

View File

@ -458,6 +458,7 @@ void getSettingsJS(byte subPage, char* dest)
oappend(itoa(buttonType[i],nS,10)); oappend(itoa(buttonType[i],nS,10));
oappend(SET_F(");")); oappend(SET_F(");"));
} }
sappend('c',SET_F("IP"),disablePullUp);
sappend('v',SET_F("TT"),touchThreshold); sappend('v',SET_F("TT"),touchThreshold);
sappend('v',SET_F("IR"),irPin); sappend('v',SET_F("IR"),irPin);
sappend('v',SET_F("IT"),irEnabled); sappend('v',SET_F("IT"),irEnabled);