CrossGuard
|
Manages the interaction with a physical push button connected to a GPIO pin. More...
#include <PushButton.h>
Public Types | |
using | ButtonCallback = std::function<void()> |
Callback type for button press events. | |
Public Member Functions | |
PushButton (int pin) | |
Constructor that initializes a PushButton with a specific GPIO pin. | |
~PushButton () | |
Destructor that cleans up ISR handling if necessary. | |
void | initialize () |
Initializes the button's GPIO pin and sets up the interrupt service routine. | |
void | registerButtonPressCallback (ButtonCallback callback) |
Registers a callback function to be called when the button is pressed. | |
PushButton (const PushButton &)=delete | |
PushButton & | operator= (const PushButton &)=delete |
Manages the interaction with a physical push button connected to a GPIO pin.
This class encapsulates the setup and usage of a GPIO pin as a push button input on a Raspberry Pi, including debouncing and handling button press events via callbacks. The class is designed to be used on systems where the PiGPIO library is available but also includes a stub for non-Raspberry Pi systems.
PushButton::PushButton | ( | int | pin | ) |
Constructor that initializes a PushButton with a specific GPIO pin.
Constructs a PushButton instance associated with a specific GPIO pin.
pin | The GPIO pin number associated with the button. |
pin | GPIO pin number to be used for the push button. |
PushButton::~PushButton | ( | ) |
Destructor that cleans up ISR handling if necessary.
Destructs the PushButton instance.
This destructor ensures that the interrupt service routine is detached, preventing any callbacks from being called after the object is destroyed.
void PushButton::initialize | ( | ) |
Initializes the button's GPIO pin and sets up the interrupt service routine.
Initializes the PushButton hardware interface.
This method sets the GPIO pin as an input and attaches an interrupt handler that is triggered on the falling edge (button press).
This method sets up the GPIO pin as an input with an internal pull-up resistor and registers the interrupt service routine to handle button presses.
void PushButton::registerButtonPressCallback | ( | ButtonCallback | callback | ) |
Registers a callback function to be called when the button is pressed.
Registers a callback to be invoked when the button is pressed.
callback | The function to call when the button is pressed. |
callback | The callback function to execute on a button press. |