Skip to main content

ButtHead

Struct ButtHead 

Source
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>

Source

pub fn new(config: &'static Config<I::Duration>) -> Self

Creates a new ButtHead instance with the given configuration.

Source

pub fn is_pressed(&self) -> bool

Returns true if the button is currently physically pressed.

Source

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.

Source

pub fn update(&mut self, is_pressed: bool, now: I) -> UpdateResult<I::Duration>

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.

Auto Trait Implementations§

§

impl<I> Freeze for ButtHead<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for ButtHead<I>

§

impl<I> Send for ButtHead<I>
where I: Send, <I as TimeInstant>::Duration: Sync,

§

impl<I> Sync for ButtHead<I>
where I: Sync, <I as TimeInstant>::Duration: Sync,

§

impl<I> Unpin for ButtHead<I>
where I: Unpin,

§

impl<I> UnsafeUnpin for ButtHead<I>
where I: UnsafeUnpin,

§

impl<I> UnwindSafe for ButtHead<I>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.