Class daisy::ButtonMonitor¶
template <typename BackendType, uint32_t numButtons>
ClassList > daisy > ButtonMonitor
A button monitor that generates events in a UiEventQueue .More...
#include <ButtonMonitor.h>
Public Functions¶
Type | Name |
---|---|
ButtonMonitor () |
|
BackendType & | GetBackend () |
uint16_t | GetNumButtonsMonitored () const |
void | Init (UiEventQueue & queueToAddEventsTo, BackendType & backend, uint16_t debounceTimeoutMs=50, uint32_t doubleClickTimeoutMs=500, uint32_t retriggerTimeoutMs=2000, uint32_t retriggerPeriodMs=50) |
bool | IsButtonPressed (uint16_t buttonId) const |
void | Process () |
Detailed Description¶
Author:
jelliesen
This class monitors a number of buttons and detects changes in their state. When a change is detected, an event is added to a UiEventQueue. If required, software debouncing can be applied.
This class can monitor an arbitrary number of buttons or switches, as configured by its template argument numButtons
. Each of the buttons is identified by an ID number from 0 .. numButtons - 1
. This number will also be used when events are posted to the UiEventQueue. It's suggested to define an enum in your project like this: In different projects, diffent ways of reading the button states will be used. That's why this class uses a generic backend that you'll have to write. The BackendType class will provide the source data for each button or switch. An instance of this backend must be supplied via the constructor. It must implement the following public function via which the ButtonMonitor will request the current state of the button:
Template parameters:
BackendType
The class type of the backend that will supply button states.numButtons
The number of buttons to monitor.
Public Functions Documentation¶
function ButtonMonitor [½]¶
function GetBackend¶
Returns the BackendType that is used by the monitor.
function GetNumButtonsMonitored¶
Returns the number of buttons that are monitored by this class.
function Init¶
inline void daisy::ButtonMonitor::Init (
UiEventQueue & queueToAddEventsTo,
BackendType & backend,
uint16_t debounceTimeoutMs=50,
uint32_t doubleClickTimeoutMs=500,
uint32_t retriggerTimeoutMs=2000,
uint32_t retriggerPeriodMs=50
)
Initialises the ButtonMonitor.
Parameters:
queueToAddEventsTo
The UiEventQueue to which events should be posted.backend
The backend that supplies the current state of each button.debounceTimeoutMs
A event is posted to the queue if the button state doesn't change fordebounceTimeoutMs
. Can be 0 to disable debouncing.doubleClickTimeoutMs
The timeout for detecting double clicks.retriggerTimeoutMs
The timeout after which a button will be retriggered when held down. 0 to disable retriggering.retriggerPeriodMs
The speed with which a button will be retriggered when held down.
function IsButtonPressed¶
Returns true, if the given button is currently pressed.
Parameters:
buttonId
The unique ID of the button (< numButtons)
function Process¶
Checks the value of each button and generates messages for the UIEventQueue. Call this at regular intervals, ideally from your main() idle loop.
The documentation for this class was generated from the following file external-docs/libDaisy/src/ui/ButtonMonitor.h