Struct Encoder

Source
pub struct Encoder<SwitchA: InputSwitch, SwitchB: InputSwitch, Config: EncoderConfig> { /* private fields */ }
Expand description

Concrete implementation of encoder.

§Type Params

SwitchA - InputSwitch that provides input A channel.

SwitchB - InputSwitch that provides input B channel.

Config - EncoderConfig that provides configs for encoder.

§Example

encoder_config!(
    SomeEncoderConfig,
    debounce_timer: MyElapsedTimer = MyElapsedTimer::new(2.millis()),
    counts_div: i8 = 4
);

type MyEncoder<SwitchA, SwitchB> = Encoder<SwitchA, SwitchB, SomeEncoderConfig>;

let mut encoder = MyEncoder::new(
    pin_a.into_active_low_switch(),
    pin_b.into_active_low_switch(),
);

loop {
    match encoder.update().unwrap() {
        EncoderEvent::NoTurn => do_something_when_no_turn(),
        EncoderEvent::ClockwiseTurn => do_something_upon_clockwise_turn(),
        EncoderEvent::CounterClockwiseTurn => do_something_upon_counter_clockwise_turn(),
    }
}

Implementations§

Source§

impl<SwitchA: InputSwitch, SwitchB: InputSwitch, Config: EncoderConfig> Encoder<SwitchA, SwitchB, Config>

Source

pub fn new(input_switch_a: SwitchA, input_switch_b: SwitchB) -> Self

Creates a new Encoder<SwitchA, SwitchB, Config> from concretes SwitchA, SwitchB.

Source

pub fn release_input_switches(self) -> (SwitchA, SwitchB)

Consumses self and release (SwitchA, SwitchB).

Trait Implementations§

Source§

impl<SwitchA: InputSwitch, SwitchB: InputSwitch, Config: EncoderConfig> Control for Encoder<SwitchA, SwitchB, Config>
where <DebouncedInput<SwitchA, Config> as Control>::Error: From<<DebouncedInput<SwitchB, Config> as Control>::Error>,

Source§

type Event = EncoderEvent

Source§

type Error = <DebouncedInput<SwitchA, Config> as Control>::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<SwitchA, SwitchB, Config> Freeze for Encoder<SwitchA, SwitchB, Config>
where <Config as EncoderConfig>::Counts: Freeze, SwitchA: Freeze, SwitchB: Freeze, <<Config as DebouncedInputConfig>::Timer as ElapsedTimer>::Timestamp: Freeze,

§

impl<SwitchA, SwitchB, Config> RefUnwindSafe for Encoder<SwitchA, SwitchB, Config>

§

impl<SwitchA, SwitchB, Config> Send for Encoder<SwitchA, SwitchB, Config>
where <Config as EncoderConfig>::Counts: Send, SwitchA: Send, SwitchB: Send, <<Config as DebouncedInputConfig>::Timer as ElapsedTimer>::Timestamp: Send, Config: Send,

§

impl<SwitchA, SwitchB, Config> Sync for Encoder<SwitchA, SwitchB, Config>
where <Config as EncoderConfig>::Counts: Sync, SwitchA: Sync, SwitchB: Sync, <<Config as DebouncedInputConfig>::Timer as ElapsedTimer>::Timestamp: Sync, Config: Sync,

§

impl<SwitchA, SwitchB, Config> Unpin for Encoder<SwitchA, SwitchB, Config>
where <Config as EncoderConfig>::Counts: Unpin, SwitchA: Unpin, SwitchB: Unpin, <<Config as DebouncedInputConfig>::Timer as ElapsedTimer>::Timestamp: Unpin, Config: Unpin,

§

impl<SwitchA, SwitchB, Config> UnwindSafe for Encoder<SwitchA, SwitchB, Config>
where <Config as EncoderConfig>::Counts: UnwindSafe, SwitchA: UnwindSafe, SwitchB: 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.