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 clock = SysClock::new();
let mut encoder = MyEncoder::new(
    pin_a.into_active_low_switch(),
    pin_b.into_active_low_switch(),
);

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

Implementations

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

Consumses self and release (SwitchA, SwitchB).

Trait Implementations

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Consumes the IoPin returning a Switch of the appropriate ActiveLevel. Read more
Consumes the IoPin returning a Switch<IoPin, ActiveLow>. Read more
Consumes the IoPin returning a Switch<IoPin, ActiveHigh>. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.