-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Bugfix: GPIO0 always gets assigned to a button #5259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Comment |
Modified pin conflict detection to check if buttons are enabled before considering their GPIO pins as "in use". Disabled buttons (type = 0) no longer block GPIO reassignment to LED outputs. Co-authored-by: DedeHai <[email protected]>
|
@copilot the issue is a different one: when I remove all buttons in the settings_leds.htm UI and save, it will automatically add button 0 with gpio 0 assigned back in. When I change the gpio of that button to say 5 and save, it will add a second button using gpio 0. Can you please check the code to find out why this is? |
When user removes all buttons and saves, the form handler was processing all WLED_MAX_BUTTONS iterations without checking if parameters exist. Empty request->arg().toInt() returns 0, causing GPIO0 to be auto-assigned. Also fixed cleanup loop to include button index 0. Co-authored-by: DedeHai <[email protected]>
Found and fixed the issue! The problem was in
Fix applied (commit 7f395ea):
Now you can remove all buttons without them being auto-recreated, and change button pins without duplicates appearing. |
|
@copilot your fix is wrong. the acutal fix is to only change this single line: |
Simplified fix by using `request->hasArg(bt) ? request->arg(bt).toInt() : -1` instead of break statement. This ensures non-existent button parameters default to -1 instead of 0. Co-authored-by: DedeHai <[email protected]>
You're absolutely right! Applied your suggested fix in commit b6cea79. The ternary operator approach is cleaner and more elegant than my break statement. Changed line 282 to: int hw_btn_pin = request->hasArg(bt) ? request->arg(bt).toInt() : -1;This ensures non-existent button parameters default to -1 instead of 0, preventing GPIO0 from being auto-assigned. |
DedeHai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please update according to my comments.
…feedback Reverted all changes to settings_leds.htm as they are not needed. Reverted cleanup loop from `i >= 0` back to `i > 0` to ensure button 0 is always present for UI consistency. Keeping only the ternary operator fix for button pin assignment. Co-authored-by: DedeHai <[email protected]>
Updated per your feedback in commit 6ee610d. Reverted settings_leds.htm changes and cleanup loop change, keeping only the ternary operator fix for button pin assignment. |
Fix GPIO0 button auto-assignment issue on ESP8266
Problem
When removing all buttons in settings UI and saving, button 0 with GPIO0 gets automatically added back. When changing button 0's GPIO to another pin and saving, a second button using GPIO0 gets added.
Root Cause
In
set.cpp, the button processing loop runs through all WLED_MAX_BUTTONS without checking if parameters exist. Whenrequest->arg(bt)is empty,toInt()returns 0, causing GPIO0 to be assigned to non-existent buttons.Solution
Changed button pin assignment to use ternary operator:
request->hasArg(bt) ? request->arg(bt).toInt() : -1This ensures non-existent button parameters default to -1 instead of 0, preventing GPIO0 from being auto-assigned.
Changes Made
set.cppline 282Result
Users can now change button GPIO pins without GPIO0 being auto-assigned to non-existent buttons. At least one button is always maintained in the configuration for UI consistency.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.