rwmingis / InterruptButton

This is an interrupt based button event library for the ESP32. It enables binding user defined actions to button events including 'Key Down', Key Up' , 'Key Press', 'Long Key Press' 'AutoRepeat Press' and 'Double-Click'. The actions associated it these events may be executed Asynchronously, Synchronously, or a Hybrid between the two.
MIT License
30 stars 8 forks source link

Allow button to be reconfigured at runtime (close #18 and fix #24) #26

Open mathieucarbou opened 10 months ago

mathieucarbou commented 10 months ago

Usage:

declare the button in your class:

  private:
    InterruptButton _button;
  };

In the begin method, initialise the button as usual. But note the use of setPin. Other getters are available:

  InterruptButton::setMode(Mode_Synchronous);

  _button.setPin(pin);
  _button.setLongPressInterval(8000);
  _button.bind(events::Event_KeyPress, [this]()
               { _callback(ButtonConfig.getPressAction()); });
  _button.bind(events::Event_LongKeyPress, [this]()
               { _callback(ButtonConfig.getLongPressAction()); });

if you want to "release" the button:

  _button.unbind(events::Event_KeyPress);
  _button.unbind(events::Event_LongKeyPress);
  _button.setPin(GPIO_NUM_NC);

if you want to just change the pin, the code will automatically deregister the existing interrupt handler and create a new one:

  _button.setPin(a_new_number);

The previous behaviour is kept, which is to initialise things within the first bind() call.

All that has been tested - I am using that in my project currently.

rwmingis commented 10 months ago

Hi Mathieu, got all your notes. Am travelling for work atm, but will sit down in the next week or so and go through them.

rwmingis commented 3 months ago

Hi Mathieu, just an update, I am working on this suggested feature inclusion of yours, but I am encompassing it into a bigger update. Have modified the main constructor so that all arguments are optional, that way you can initialise as your have done with default settings and then change only the ones you want at runtime. You can also change the pin as requested.

Also adding a bit that lets you change the menu count at run time which requires tracking of all instances so taking a little time to implement that as well. Tracking will help in a few areas actually

Cheers.