pub struct ButtHead<I: TimeInstant> { /* private fields */ }Expand description
Button input processor.
Expects clean, debounced input. If your button is subject to mechanical
bounce, debounce the signal before passing it to update().
Implementations§
Source§impl<I: TimeInstant> ButtHead<I>
impl<I: TimeInstant> ButtHead<I>
Sourcepub fn new(config: &'static Config<I::Duration>) -> Self
pub fn new(config: &'static Config<I::Duration>) -> Self
Creates a new ButtHead instance with the given configuration.
Sourcepub fn is_pressed(&self) -> bool
pub fn is_pressed(&self) -> bool
Returns true if the button is currently physically pressed.
Sourcepub fn press_instant(&self) -> Option<I>
pub fn press_instant(&self) -> Option<I>
Returns the instant at which the button was last pressed, or None if
the button is not currently pressed.
Sourcepub fn pressed_duration(&self, now: I) -> Option<I::Duration>
pub fn pressed_duration(&self, now: I) -> Option<I::Duration>
Returns how long the button has been continuously held, or None if it
is not currently pressed.
Sourcepub fn cancel_pending_click(&mut self) -> bool
pub fn cancel_pending_click(&mut self) -> bool
Cancels the pending Click event when the state machine is in
WaitForMultiClick. Returns true if cancelled, false if the state
machine was not waiting for a click (nothing to cancel).
Call this from an Event::Release { click_follows: true, .. } handler
to suppress the upcoming Click (e.g. when the release was part of a
multi-button combo gesture). The state machine returns to Idle and no
Click event will fire.
Sourcepub fn update(
&mut self,
is_pressed: bool,
now: I,
) -> UpdateResult<I::Duration, I>
pub fn update( &mut self, is_pressed: bool, now: I, ) -> UpdateResult<I::Duration, I>
Advances the state machine.
is_pressed is the raw pin state (before active-low inversion).
now is the current timestamp. Returns the resulting event and the
recommended time for the next call.