Skip to content
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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mathieucarbou
Copy link
Contributor

@mathieucarbou mathieucarbou commented Nov 30, 2023

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 mathieucarbou changed the title Allow button to be reconfigured at runtime (close #18) Allow button to be reconfigured at runtime (close #18 and fix #24) Nov 30, 2023
@rwmingis
Copy link
Owner

rwmingis commented Dec 4, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

High Heap memory consumption ? Is it normal ? v2.0.1 does not compile
2 participants