diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index 2cd5e28393..7bbcbf3f87 100644 --- a/wled00/data/settings_leds.htm +++ b/wled00/data/settings_leds.htm @@ -85,7 +85,22 @@ //check for pin conflicts if (LC.value!="" && LC.value!="-1") { let p = d.rsvd.concat(d.um_p); // used pin array - d.Sf.querySelectorAll("select.pin").forEach((e)=>{if(e.value>-1)p.push(parseInt(e.value));}) // buttons, IR & relay + d.Sf.querySelectorAll("select.pin").forEach((e)=>{ + if(e.value>-1) { + // Check if this is a button pin (name starts with "BT") + if (e.name.startsWith("BT")) { + // Get button type field (BEx where BTx is the pin field) + let btnTypeField = d.Sf["BE" + e.name.substring(2)]; + // Only add to used pins if button is not disabled (type != 0) + if (btnTypeField && btnTypeField.value != "0") { + p.push(parseInt(e.value)); + } + } else { + // For IR and Relay pins, add normally + p.push(parseInt(e.value)); + } + } + }) // buttons, IR & relay if (p.some((e)=>e==parseInt(LC.value))) { alert(`Sorry, pins ${JSON.stringify(p)} can't be used.`); LC.value=""; @@ -387,7 +402,22 @@ if (nm.search(/^L[0-4]/) == 0) // pin fields if (LC.value!="" && LC.value!="-1") { let p = d.rsvd.concat(d.um_p); // used pin array - d.Sf.querySelectorAll("select.pin").forEach((e)=>{if(e.value>-1)p.push(parseInt(e.value));}) // buttons, IR & relay + d.Sf.querySelectorAll("select.pin").forEach((e)=>{ + if(e.value>-1) { + // Check if this is a button pin (name starts with "BT") + if (e.name.startsWith("BT")) { + // Get button type field (BEx where BTx is the pin field) + let btnTypeField = d.Sf["BE" + e.name.substring(2)]; + // Only add to used pins if button is not disabled (type != 0) + if (btnTypeField && btnTypeField.value != "0") { + p.push(parseInt(e.value)); + } + } else { + // For IR and Relay pins, add normally + p.push(parseInt(e.value)); + } + } + }) // buttons, IR & relay for (j=0; j10) char be[4] = "BE"; be[2] = offset+i; be[3] = 0; // button type (use A,B,C,... if WLED_MAX_BUTTONS>10) - int hw_btn_pin = request->arg(bt).toInt(); + int hw_btn_pin = request->hasArg(bt) ? request->arg(bt).toInt() : -1; if (i >= buttons.size()) buttons.emplace_back(hw_btn_pin, request->arg(be).toInt()); // add button to vector else { buttons[i].pin = hw_btn_pin; @@ -327,7 +327,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) } } // we should remove all unused buttons from the vector - for (int i = buttons.size()-1; i > 0; i--) { + for (int i = buttons.size()-1; i >= 0; i--) { if (buttons[i].pin < 0 && buttons[i].type == BTN_TYPE_NONE) { buttons.erase(buttons.begin() + i); // remove button from vector }