M5Utility 0.3.1 git rev:a8c5625
Loading...
Searching...
No Matches
m5::utility::button::Status Class Reference

Button status management. More...

#include <button_status.hpp>

Public Types

enum class  button_state_t : uint8_t { state_nochange , state_clicked , state_hold , state_decide_click_count }
 Button status.
 

Public Member Functions

 Status (const uint16_t hold_ms=500, const uint16_t debounce_ms=10, const uint16_t double_click_ms=0)
 Constructor.
 
Settings
void setDebounceThreshold (const uint32_t msec)
 Set debounce time(ms)
 
void setHoldThreshold (const uint32_t msec)
 Set time to be considered hold(ms)
 
void setDoubleClickThreshold (const uint32_t msec)
 Set the time within which a second click still counts as a multiple click(ms)
 
uint32_t getDebounceThreshold (void) const
 Gets the debounce time(ms)
 
uint32_t getHoldThreshold (void) const
 Gets the time to be considered hold(ms)
 
uint32_t getDoubleClickThreshold (void) const
 Gets the time within which a second click still counts as a multiple click(ms)
 
Button status
bool isPressed (void) const
 Is pressed?
 
bool isReleased (void) const
 Is released?
 
bool isHolding (void) const
 Returns true if the button is currently held pressed.
 
bool wasPressed (void) const
 Returns true if button was pressed.
 
bool wasReleased (void) const
 Returns true if button was released.
 
bool wasClicked (void) const
 Returns true when the button is pressed briefly and released.
 
bool wasHold (void) const
 Returns true when the button has been held pressed for a while.
 
bool wasSingleClicked (void) const
 Returns true when some time has passed since the button was single clicked.
 
bool wasDoubleClicked (void) const
 Returns true when some time has passed since the button was double clicked.
 
bool wasDecideClickCount (void) const
 Returns true when some time has passed since the button was multiple clicked.
 
uint8_t getClickCount (void) const
 Gets the number of consecutive button clicks.
 
bool wasChangePressed (void) const
 Has the button press state changed?
 
bool wasReleasedAfterHold (void) const
 Pressed and released a button for more than the set hold time?
 
bool wasReleaseFor (const uint32_t ms) const
 Was it pressed for more than the specified time?
 
bool pressedFor (const uint32_t ms) const
 Is pressed for more than the specified time?
 
bool releasedFor (const uint32_t ms) const
 Is released for more than the specified time?
 
Status
void setRawState (const uint32_t msec, const bool press)
 
void setState (const uint32_t msec, const button_state_t state)
 
button_state_t getState (void) const
 
uint32_t lastChange (void) const
 
uint32_t getUpdateMsec (void) const
 

Detailed Description

Button status management.

Note
Class compatible with Button_Class in M5Unified

Constructor & Destructor Documentation

◆ Status()

m5::utility::button::Status::Status ( const uint16_t hold_ms = 500,
const uint16_t debounce_ms = 10,
const uint16_t double_click_ms = 0 )
inlineexplicit

Constructor.

Parameters
hold_msTime to be considered hold(ms)
debounce_msDebounce time(ms)
double_click_msTime within which a second click still counts as a multiple click(ms). 0 follows hold_ms

Member Function Documentation

◆ getDoubleClickThreshold()

uint32_t m5::utility::button::Status::getDoubleClickThreshold ( void ) const
inline

Gets the time within which a second click still counts as a multiple click(ms)

Returns
The configured time, or the hold threshold while it is left at 0

◆ setDoubleClickThreshold()

void m5::utility::button::Status::setDoubleClickThreshold ( const uint32_t msec)
inline

Set the time within which a second click still counts as a multiple click(ms)

Parameters
msecTime(ms). 0 follows the hold threshold
Note
The click count is decided once this time has passed since the last release, so it is also how long wasSingleClicked() and friends are delayed by