pub struct Debouncer {
stable: bool,
candidate: bool,
count: u8,
}Expand description
Software debouncer state.
Holds the last stable level and a running counter that increments while
the raw input matches the candidate new level and resets when it does
not. Once the counter reaches DEBOUNCE_STABLE_SAMPLES the candidate
becomes the new stable level.
Fields§
§stable: boolCurrently-accepted stable level.
candidate: boolCandidate level being observed.
count: u8Consecutive samples matching candidate.
Implementations§
Source§impl Debouncer
impl Debouncer
Sourcepub const fn new(initial: bool) -> Self
pub const fn new(initial: bool) -> Self
Build a fresh debouncer assuming the initial level is initial.
Sourcepub fn sample(&mut self, level: bool) -> Option<bool>
pub fn sample(&mut self, level: bool) -> Option<bool>
Feed one new sample.
Returns Some(level) when the stable level just changed as a
result of this sample, None otherwise. The caller can use this
as a trigger to issue a press/release event.
Sourcepub const fn stable(&self) -> bool
pub const fn stable(&self) -> bool
Current stable level (without consuming a sample).
Useful for diagnostics: a task can query the current stable state
without committing to a sampling cycle. The touch_task logs
this at startup so the developer can confirm the resting state of
the button line via defmt RTT or USB CDC trace.