InterruptButton icon indicating copy to clipboard operation
InterruptButton copied to clipboard

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

Open mathieucarbou opened this issue 2 years ago • 3 comments

  • Close #18
  • Fix #24

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:

  • setPin
  • setPressedState
  • setPinMode
  • setLongKeyPressMS
  • setAutoRepeatMS
  • setDoubleClickMS
  • setDebounceUS
  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.

mathieucarbou avatar Nov 30 '23 11:11 mathieucarbou

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 avatar Dec 04 '23 08:12 rwmingis

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.

rwmingis avatar Jul 02 '24 12:07 rwmingis

hi there, it looks like this PR has not been pushed to the main, right?

homonto avatar Jan 11 '25 10:01 homonto