Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::ButtonHandler Class Reference

Utility to detects if buttons are pressed, long pressed or long-long pressed and calls a callback in each case. More...

#include <ButtonHandler.h>

Inheritance diagram for Boardcore::ButtonHandler:
Collaboration diagram for Boardcore::ButtonHandler:

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.
 
- Public Member Functions inherited from Boardcore::Singleton< ButtonHandler >
 Singleton (const Singleton &)=delete
 
Singletonoperator= (const Singleton &)=delete
 

Additional Inherited Members

- Static Public Member Functions inherited from Boardcore::Singleton< ButtonHandler >
static ButtonHandlergetInstance ()
 
- Protected Member Functions inherited from Boardcore::Singleton< ButtonHandler >
 Singleton ()
 

Detailed Description

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.

Member Typedef Documentation

◆ ButtonCallback

Definition at line 60 of file ButtonHandler.h.

Member Function Documentation

◆ registerButtonCallback()

bool Boardcore::ButtonHandler::registerButtonCallback ( miosix::GpioPin pin,
ButtonCallback callback )

Registers a callback on the specified pin.

Parameters
pinPin to listen to.
callbackFunction to call on button events.
Returns
False if another callback was already registered for the pin.

Definition at line 30 of file ButtonHandler.cpp.

◆ start()

bool Boardcore::ButtonHandler::start ( )

Starts the ButtonHandler's task scheduler.

Note that the scheduler is started as soon as the ButtonHandler is first used.

Returns
Whether the task scheduler was started or not.

Definition at line 52 of file ButtonHandler.cpp.

◆ stop()

void Boardcore::ButtonHandler::stop ( )

Stops the ButtonHandler's task scheduler.

Definition at line 54 of file ButtonHandler.cpp.

◆ unregisterButtonCallback()

bool Boardcore::ButtonHandler::unregisterButtonCallback ( miosix::GpioPin pin)

Unregisters the callback associated with the specified pin, if any.

Parameters
pinPin whose callback function is to be removed.
Returns
True if a callback was present and removed for the given pin.

Definition at line 47 of file ButtonHandler.cpp.


The documentation for this class was generated from the following files: