Skyward boardcore
|
Utility to detects if buttons are pressed, long pressed or long-long pressed and calls a callback in each case. More...
#include <ButtonHandler.h>
Public Types | |
using | ButtonCallback = std::function<void(ButtonEvent)> |
Public Member Functions | |
bool | registerButtonCallback (miosix::GpioPin pin, ButtonCallback callback) |
Registers a callback on the specified pin. | |
bool | unregisterButtonCallback (miosix::GpioPin pin) |
Unregisters the callback associated with the specified pin, if any. | |
bool | start () |
Starts the ButtonHandler's task scheduler. | |
void | stop () |
Stops the ButtonHandler's task scheduler. | |
![]() | |
Singleton (const Singleton &)=delete | |
Singleton & | operator= (const Singleton &)=delete |
Additional Inherited Members | |
![]() | |
static ButtonHandler & | getInstance () |
![]() | |
Singleton () | |
Utility to detects if buttons are pressed, long pressed or long-long pressed and calls a callback in each case.
Note: The ButtonHandler assumes the all the buttons to be pulldown meaning that when the button is pressed, the pin is assumed low.
TODO: Allow to set pullup or pulldown configuration for each registered pin.
Definition at line 51 of file ButtonHandler.h.
using Boardcore::ButtonHandler::ButtonCallback = std::function<void(ButtonEvent)> |
Definition at line 60 of file ButtonHandler.h.
bool Boardcore::ButtonHandler::registerButtonCallback | ( | miosix::GpioPin | pin, |
ButtonCallback | callback ) |
Registers a callback on the specified pin.
pin | Pin to listen to. |
callback | Function to call on button events. |
Definition at line 30 of file ButtonHandler.cpp.
bool Boardcore::ButtonHandler::start | ( | ) |
Starts the ButtonHandler's task scheduler.
Note that the scheduler is started as soon as the ButtonHandler is first used.
Definition at line 52 of file ButtonHandler.cpp.
void Boardcore::ButtonHandler::stop | ( | ) |
Stops the ButtonHandler's task scheduler.
Definition at line 54 of file ButtonHandler.cpp.
bool Boardcore::ButtonHandler::unregisterButtonCallback | ( | miosix::GpioPin | pin | ) |
Unregisters the callback associated with the specified pin, if any.
pin | Pin whose callback function is to be removed. |
Definition at line 47 of file ButtonHandler.cpp.