CrossGuard
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
PushButton Class Reference

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
 
PushButtonoperator= (const PushButton &)=delete
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PushButton()

PushButton::PushButton ( int pin)

Constructor that initializes a PushButton with a specific GPIO pin.

Constructs a PushButton instance associated with a specific GPIO pin.

Parameters
pinThe GPIO pin number associated with the button.
pinGPIO pin number to be used for the push button.

◆ ~PushButton()

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.

Member Function Documentation

◆ initialize()

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.

◆ registerButtonPressCallback()

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.

Parameters
callbackThe function to call when the button is pressed.
callbackThe callback function to execute on a button press.

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