Generic Class for handling momentary/latching switches
Inspired/influenced by Mutable Instruments (pichenettes) Switch classes
#include <switch.h>
Public Types | |
| enum | Type { TYPE_TOGGLE , TYPE_MOMENTARY } |
| enum | Polarity { POLARITY_NORMAL , POLARITY_INVERTED } |
Public Member Functions | |
| Switch () | |
| ~Switch () | |
| void | Init (Pin pin, float update_rate, Type t, Polarity pol, GPIO::Pull pu=GPIO::Pull::PULLUP) |
| void | Init (Pin pin, float update_rate=0.f) |
| void | Debounce () |
| bool | RisingEdge () const |
| bool | FallingEdge () const |
| bool | Pressed () const |
| bool | RawState () |
| float | TimeHeldMs () const |
| void | SetUpdateRate (float update_rate) |
| enum daisy::Switch::Type |
|
inline |
|
inline |
| void daisy::Switch::Debounce | ( | ) |
Called at update_rate to debounce and handle timing for the switch. In order for events not to be missed, its important that the Edge/Pressed checks be made at the same rate as the debounce function is being called.
|
inline |
| void daisy::Switch::Init | ( | Pin | pin, |
| float | update_rate, | ||
| Type | t, | ||
| Polarity | pol, | ||
| GPIO::Pull | pu = GPIO::Pull::PULLUP ) |
Initializes the switch object with a given port/pin combo.
| pin | port/pin object to tell the switch which hardware pin to use. |
| update_rate | Does nothing. Backwards compatibility until next breaking update. |
| t | switch type – Default: TYPE_MOMENTARY |
| pol | switch polarity – Default: POLARITY_INVERTED |
| pu | switch pull up/down – Default: PULL_UP |
| void daisy::Switch::Init | ( | Pin | pin, |
| float | update_rate = 0.f ) |
Simplified Init.
| pin | port/pin object to tell the switch which hardware pin to use. |
| update_rate | Left for backwards compatibility until next breaking change. |
|
inline |
|
inline |
|
inline |
|
inline |
Left for backwards compatability until next breaking change
| update_rate | Doesn't do anything |
|
inline |