Struct DebouncedInput

Source
pub struct DebouncedInput<Switch: InputSwitch, Config: DebouncedInputConfig> { /* private fields */ }
Expand description

Concrete implementation of debounced input.

§Type Params

Switch - InputSwitch that provides input for debouncing.

Config - DebouncedInputConfig that provides configs for debouncing.

§Example

debounced_input_config!(
    SomeDebouncedInputConfig,
    debounce_timer: MyElapsedTimer = MyElapsedTimer::new(20.millis())
);

type MyDebouncedInput<Switch> = DebouncedInput<Switch, SomeDebouncedInputConfig>;

let mut debounced_input = MyDebouncedInput::new(pin.into_active_low_switch());

loop {
    match debounced_input.update().unwrap() {
        DebouncedInputEvent::Low => do_something_when_low(),
        DebouncedInputEvent::High => do_something_when_high(),
        DebouncedInputEvent::Rise => do_something_upon_rise(),
        DebouncedInputEvent::Fall => do_something_upon_fall(),
    }
}

Implementations§

Source§

impl<Switch: InputSwitch, Config: DebouncedInputConfig> DebouncedInput<Switch, Config>

Source

pub fn new(input_switch: Switch) -> Self

Creates a new DebouncedInput<Switch, Config> from a concrete Switch.

input_switch - an concrete instance of Switch.

Source

pub fn is_high(&self) -> bool

Returns the is stable high state.

Source

pub fn is_low(&self) -> bool

Returns the is stable low state.

Source

pub fn borrow_input_switch(&self) -> &Switch

Borrow Switch.

Source

pub fn release_input_switch(self) -> Switch

Consumes self and release Switch.

Trait Implementations§

Source§

impl<Switch: InputSwitch, Config: DebouncedInputConfig> Control for DebouncedInput<Switch, Config>

Source§

type Event = DebouncedInputEvent

Source§

type Error = Error<<<<Config as DebouncedInputConfig>::Timer as ElapsedTimer>::Timestamp as Timestamp>::Error, <Switch as InputSwitch>::Error>

Source§

fn update(&mut self) -> Result<Self::Event, Self::Error>

Update a control and return an current event or error after update.

Auto Trait Implementations§

§

impl<Switch, Config> Freeze for DebouncedInput<Switch, Config>
where Switch: Freeze, <<Config as DebouncedInputConfig>::Timer as ElapsedTimer>::Timestamp: Freeze,

§

impl<Switch, Config> RefUnwindSafe for DebouncedInput<Switch, Config>

§

impl<Switch, Config> Send for DebouncedInput<Switch, Config>
where Switch: Send, <<Config as DebouncedInputConfig>::Timer as ElapsedTimer>::Timestamp: Send, Config: Send,

§

impl<Switch, Config> Sync for DebouncedInput<Switch, Config>
where Switch: Sync, <<Config as DebouncedInputConfig>::Timer as ElapsedTimer>::Timestamp: Sync, Config: Sync,

§

impl<Switch, Config> Unpin for DebouncedInput<Switch, Config>
where Switch: Unpin, <<Config as DebouncedInputConfig>::Timer as ElapsedTimer>::Timestamp: Unpin, Config: Unpin,

§

impl<Switch, Config> UnwindSafe for DebouncedInput<Switch, Config>
where Switch: UnwindSafe, <<Config as DebouncedInputConfig>::Timer as ElapsedTimer>::Timestamp: UnwindSafe, Config: UnwindSafe,

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> IntoSwitch for T

Source§

fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>

Consumes the IoPin returning a Switch of the appropriate ActiveLevel. Read more
Source§

fn into_active_low_switch(self) -> Switch<Self, ActiveLow>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveLow>. Read more
Source§

fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveHigh>. Read more
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.