Skip to content

WLED 0.15+ always resets GPIO 0 to become a button pin (two new bugs) #4629

Open
@Arcitec

Description

@Arcitec

What happened?

The ability to have more than 2 buttons has introduced a bug in WLED's pin handling.

  • The WLED_MAX_BUTTONS default array length is dynamic and is 2 for ESP8266 and 4 for ESP32. It can also be edited by the compiler flag to become even larger if wanted.
  • WLED only gives 2 default values for BTNPIN and BTNTYPE. Which means there's some unspecified values in the array on ESP32:
#define BTNPIN 0,-1
#define BTNTYPE BTN_TYPE_PUSH,BTN_TYPE_NONE
  • C++ arrays default all unspecified values to 0. So btnPin[4] = {2,3} becomes {2,3,0,0} automatically. So for example, WLED's default values for an ESP32 binary will look like this:
int8_t btnPin[4] = {0, -1, 0, 0};
byte buttonType[4] = {2, 0, 0, 0};
  • Bug 1: The WLED code that is supposed to fix this at the first launch in cfg.cpp: if (fromFS) { never executes. That code is supposed to set GPIO = -1 and Type = NONE for every button pin whose pre-defined firmware setting for the GPIO was either -1 or the type was NONE. Basically a "reset all unused pins". But that code never executes!
  • This means that all of the unused/unspecified button pins all stay defined as "GPIO 0 type NONE (0)".
  • Bug 2: There's a second bug in the button initialization code: It activates and takes over ownership of ALL "defined" (>= 0) button GPIO pins even if their type is set to NONE (Disabled). So it steals/allocates all "disabled" button pins too. If a button setting is "disabled", it should not steal ownership of them!
  • And because the button initialization code runs after the LED initialization, it means that GPIO 0 is always overwritten to become a button pin instead of an LED pin on all ESP32 devices.
  • The most important bug is that the settings cleanup code never executes. But the "pins are taken over by the button handler even if their type is set to NONE (Disabled)" is a nasty bug too.

There is a temporary workaround via compiler flags: By manually specifying every array index on ESP32 builds:

-D WLED_MAX_BUTTONS=4
-D BTNPIN=0,-1,-1,-1
-D BTNTYPE=2,0,0,0

To Reproduce Bug

x

Expected Behavior

x

Install Method

Binary from WLED.me

What version of WLED?

0.15 and newer

Which microcontroller/board are you seeing the problem on?

ESP32

Relevant log/trace output

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions