Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
Public Member Functions | List of all members
sbl::components::control::Button Class Reference

Debounced button with edge detection and held-duration tracking. More...

#include <button.hpp>

Collaboration diagram for sbl::components::control::Button:

Public Member Functions

 Button (const ButtonConfig &config={})
 
void update (bool logical_state)
 Feed a new logical GPIO reading.
 
bool pressed () const
 Current debounced state (true = pressed)
 
bool raw () const
 Last raw (unfiltered) reading.
 
bool just_pressed ()
 True if button was just pressed (rising edge)
 
bool just_released ()
 True if button was just released (falling edge)
 
uint32_t held_count () const
 Ticks the button has been held down.
 
void reset ()
 Reset all state.
 

Detailed Description

Debounced button with edge detection and held-duration tracking.

Note
All public methods are ISR-safe — pure state machine with no hardware I/O.

Definition at line 35 of file button.hpp.

Constructor & Destructor Documentation

◆ Button()

sbl::components::control::Button::Button ( const ButtonConfig config = {})
inlineexplicit

Definition at line 37 of file button.hpp.

Member Function Documentation

◆ held_count()

uint32_t sbl::components::control::Button::held_count ( ) const
inline

Ticks the button has been held down.

Returns raw tick count (caller knows update rate). Resets to 0 on press, continues counting while held.

Definition at line 115 of file button.hpp.

◆ just_pressed()

bool sbl::components::control::Button::just_pressed ( )
inline

True if button was just pressed (rising edge)

Resets on read — call once per update cycle.

Definition at line 92 of file button.hpp.

◆ just_released()

bool sbl::components::control::Button::just_released ( )
inline

True if button was just released (falling edge)

Resets on read — call once per update cycle.

Definition at line 103 of file button.hpp.

◆ pressed()

bool sbl::components::control::Button::pressed ( ) const
inline

Current debounced state (true = pressed)

Definition at line 82 of file button.hpp.

◆ raw()

bool sbl::components::control::Button::raw ( ) const
inline

Last raw (unfiltered) reading.

Definition at line 85 of file button.hpp.

◆ reset()

void sbl::components::control::Button::reset ( )
inline

Reset all state.

Definition at line 118 of file button.hpp.

◆ update()

void sbl::components::control::Button::update ( bool  logical_state)
inline

Feed a new logical GPIO reading.

Call once per update cycle. Debounce: the stable state only changes when debounce_count consecutive identical readings are seen.

Parameters
logical_statetrue = pressed (Gpio::read already handles active_low)

Definition at line 51 of file button.hpp.

Referenced by sbl::button::read().

Here is the caller graph for this function:

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