idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
idfxx::button Class Reference

GPIO push-button with debounce, click, long press, and autorepeat support. More...

Classes

struct  config
 Button configuration. More...
 

Public Types

enum class  mode : int {
  poll = 0 ,
  interrupt = 1
}
 Button detection mode. More...
 
enum class  event_type : int {
  pressed = 0 ,
  released = 1 ,
  clicked = 2 ,
  long_press = 3
}
 Button event type. More...
 

Public Member Functions

 button (config cfg)
 Creates a button and begins monitoring.
 
 ~button ()
 Destroys the button.
 
 button (const button &)=delete
 
buttonoperator= (const button &)=delete
 
 button (button &&other) noexcept
 
buttonoperator= (button &&other) noexcept
 

Static Public Member Functions

static result< buttonmake (config cfg)
 Creates a button and begins monitoring.
 

Detailed Description

GPIO push-button with debounce, click, long press, and autorepeat support.

Handles push-button input events including press, release, click, long press, and autorepeat. Delivers events via a callback configured at construction time.

This type is non-copyable and move-only.

Definition at line 38 of file button.hpp.

Member Enumeration Documentation

◆ event_type

Button event type.

When autorepeat is disabled, the event sequence for a short press is: pressed -> released -> clicked and for a long press: pressed -> long_press -> released

When autorepeat is enabled, long press detection is disabled. Instead, holding the button generates repeated clicked events: pressed -> clicked -> clicked -> ... -> released

Enumerator
pressed 

Button pressed.

released 

Button released.

clicked 

Short press completed (pressed then released)

long_press 

Button held beyond long-press threshold.

Definition at line 62 of file button.hpp.

◆ mode

Button detection mode.

Enumerator
poll 

Periodic timer polling (default)

interrupt 

GPIO interrupt with debounce timer.

Definition at line 44 of file button.hpp.

Constructor & Destructor Documentation

◆ button() [1/3]

idfxx::button::button ( config  cfg)
explicit

Creates a button and begins monitoring.

Parameters
cfgButton configuration. pin and callback must be set.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled.
Exceptions
std::system_erroron failure.
std::system_errorwith errc::invalid_arg if pin is not connected, or callback is not set.

◆ ~button()

idfxx::button::~button ( )

Destroys the button.

Stops monitoring and releases resources.

◆ button() [2/3]

idfxx::button::button ( const button )
delete

◆ button() [3/3]

idfxx::button::button ( button &&  other)
noexcept

Member Function Documentation

◆ make()

static result< button > idfxx::button::make ( config  cfg)
static

Creates a button and begins monitoring.

Parameters
cfgButton configuration. pin and callback must be set.
Returns
The new button, or an error.
Return values
invalid_argpin is not connected, or callback is not set.

◆ operator=() [1/2]

button & idfxx::button::operator= ( button &&  other)
noexcept

◆ operator=() [2/2]

button & idfxx::button::operator= ( const button )
delete

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