Can a usermod make use of WLED buttons?

For a usermod I worked on today, I created input routines based on code from button.cpp (just enough to handle debounce, short press and long press).

I saw how handleButton() can be used in the usermod to just return true and disable (I assume) the WLED button handling.

Can it go the other way? Is there a way for a usermod to get the benefits of seeing if Button 1 was double pressed, or Button 2 was released? It looks like there might be some way to hook in to that, but my web/forum/discord/REDDIT searching skills didn’t lead me to an answer.

The idea would be to avoid replicating so much code since buttons.cpp already does everything I needed, plus much more.


What do you want to achieve?

I want to have a Preset that uses an effect (like “blink” or whatever) on Segment 0, and have it play only to that segement, but also want to have Segment 1 and 2 (for example) playing a Preset that makes them solid.

I think I need to dive in to the checkboxes and enable/disable stuff in the UI. (Or learn the json so I can edit them there.)

Using JSON API is the way to go.

Can I call that from a usermod? This is for a standalone box that reads inputs, and kicks off patterns based on inputs. But it’s not a simple “if button X, run preset Y”. It has behaviors and modes and such.

The initial idea was to let the UI be used to build presets, then the usermod invokes them. Preset effects can be changed by folks who don’t know how to code.

If you are writing a usermod forego JSON and manipulate WLED state directly.

Actually it is. You just need to wrap your head around it.

Ideally, the presets would be configured through the web UI, so they can be changed without recompiling code.

Is there a C/C++ (?) function call API list that would show me how to launch an effect on a segment? Being able to say “do blinking, this speed, this color, this brightness, on LEDS 0-128” would be a good start for me.

If you are content with up to 14 buttons, you do not need to write usermod. Use existing stuff built into WLED.
You will need to compile yourself, though.

I am compiling out of git currently. The need for usermod is the complex sates that know what pattern to launch. It’s not just light switch type modes – certain combinations of buttons go in to a config mode, versus normal run mode, etc.