Debounces a switch sampled at any rate and classifies the press.
More...
#include <isf15acp4_button.hpp>
|
| constexpr | ButtonDebouncer (const ButtonConfig &config={}) noexcept |
| | A debouncer with the given configuration, switch open.
|
| |
| constexpr void | Configure (const ButtonConfig &config) noexcept |
| | Take a new configuration and forget the state (the next sample is adopted again).
|
| |
| constexpr const ButtonConfig & | GetConfig () const noexcept |
| |
|
constexpr void | Reset () noexcept |
| | Forget the state: the next Update() adopts its level without an event.
|
| |
| constexpr ButtonUpdate | Update (bool down, uint32_t now_ms) noexcept |
| | Feed one sample.
|
| |
| constexpr bool | IsDown () const noexcept |
| |
| constexpr uint32_t | PressCount () const noexcept |
| |
Debounces a switch sampled at any rate and classifies the press.
A level change is accepted once the new level has been seen continuously for debounce_ms (a sample of the old level in between starts the wait again). Pressed and Released carry the time of the first sample of the new level, so the debounce delay is not in the timestamp. Poll at least twice per debounce time: a press shorter than the poll period is not seen. One event is returned per Update(); a second condition that is due stays due and is returned by the next call.
◆ ButtonDebouncer()
| constexpr isf15acp4::ButtonDebouncer::ButtonDebouncer |
( |
const ButtonConfig & |
config = {} | ) |
|
|
inlineexplicitconstexprnoexcept |
A debouncer with the given configuration, switch open.
- Parameters
-
| config | The configuration; the caller has checked it with Validate(). |
◆ Configure()
| constexpr void isf15acp4::ButtonDebouncer::Configure |
( |
const ButtonConfig & |
config | ) |
|
|
inlineconstexprnoexcept |
Take a new configuration and forget the state (the next sample is adopted again).
- Parameters
-
| config | The configuration; the caller has checked it with Validate(). |
◆ GetConfig()
| constexpr const ButtonConfig & isf15acp4::ButtonDebouncer::GetConfig |
( |
| ) |
const |
|
inlineconstexprnoexcept |
- Returns
- The configuration in use. No state change.
◆ IsDown()
| constexpr bool isf15acp4::ButtonDebouncer::IsDown |
( |
| ) |
const |
|
inlineconstexprnoexcept |
- Returns
- The debounced level: true while the switch is down.
◆ PressCount()
| constexpr uint32_t isf15acp4::ButtonDebouncer::PressCount |
( |
| ) |
const |
|
inlineconstexprnoexcept |
- Returns
- Presses counted since construction (wraps at 2^32).
◆ Update()
| constexpr ButtonUpdate isf15acp4::ButtonDebouncer::Update |
( |
bool |
down, |
|
|
uint32_t |
now_ms |
|
) |
| |
|
inlineconstexprnoexcept |
Feed one sample.
- Parameters
-
| down | true when the switch is closed (the caller applied the polarity). |
| now_ms | A millisecond counter; may wrap. |
- Returns
- The event of this sample. The first sample after construction or
Reset() sets the level and returns None, also when the switch is already down.
The documentation for this class was generated from the following file: