Struct IncrementalEncoder

Source
pub struct IncrementalEncoder<Mode, Clk, Dt, Steps = FullStep, T = i32, PM = Blocking> { /* private fields */ }
Expand description

A robust incremental encoder with support for multiple step-modes.

Implementations§

Source§

impl<Mode, Clk, Dt, Steps, T, PM> IncrementalEncoder<Mode, Clk, Dt, Steps, T, PM>
where Mode: OperationMode, Clk: InputPin, Dt: InputPin, Steps: StepMode, T: Zero, PM: PollMode,

Source

pub fn new(pin_clk: Clk, pin_dt: Dt) -> Self
where IncrementalDecoder<Steps, T>: Default, Clk: InputPin, Dt: InputPin,

Creates an incremental encoder driver for the given pins.

Source§

impl<Mode, Clk, Dt, Steps, T, PM> IncrementalEncoder<Mode, Clk, Dt, Steps, T, PM>
where Mode: OperationMode, Clk: InputPin, Dt: InputPin, Steps: StepMode, T: Copy + Zero + One + SaturatingAdd + WrappingNeg + From<i8>, PM: PollMode,

Source

pub fn reversed(self) -> Self

Sets the encoder’s reversed mode, making it report flipped movements and positions.

Source

pub fn is_reversed(&self) -> bool

Returns true if the encoder is reversed, otherwise false.

Source

pub fn pins_mut(&mut self) -> (&mut Clk, &mut Dt)

Returns mutable borrows for the signal channel pins.

Source

pub fn release(self) -> (Clk, Dt)

Consumes self, returning the signal channel pins.

Source

pub fn reset(&mut self)

Resets the encoder to its initial state.

Source

pub fn position(&self) -> T

Returns the encoder’s position counter relative to its initial position in number of cycles.

Source

pub fn set_position(&mut self, position: T)

Sets the encoder’s position.

Source§

impl<Mode, Clk, Dt, Steps, T> IncrementalEncoder<Mode, Clk, Dt, Steps, T, Blocking>
where Mode: OperationMode, Clk: InputPin, Dt: InputPin, Steps: StepMode, T: Copy + Zero + One + SaturatingAdd + WrappingNeg + From<i8>,

Source

pub fn poll(&mut self) -> Result<Option<Mode::Movement>, Error>

Updates the encoder’s state based on the given clock and data pins, returning the direction if a movement was detected, None if no movement was detected, or Err(_) if an invalid input (i.e. a positional “jump”) was detected.

Depending on whether it matters why the encoder did not detect a movement (e.g. due to actual lack of movement or an erroneous read) you would either call encoder.poll() directly, or via encoder.poll().unwrap_or_default() to fall back to None in case of Err(_).

Source§

impl<Mode, Clk, Dt, Steps, T> IncrementalEncoder<Mode, Clk, Dt, Steps, T, Blocking>
where Mode: OperationMode, Clk: InputPin + Wait, Dt: InputPin + Wait, Steps: StepMode, T: Copy + Zero + One + SaturatingAdd + WrappingNeg + From<i8>,

If async is enabled, and the pins provided satisfy the AsyncInputPin trait, the into_async() method is exposed.

Source

pub fn into_async(self) -> IncrementalEncoder<Mode, Clk, Dt, Steps, T, Async>
where IncrementalDecoder<Steps, T>: Default,

Reconfigure the driver so that poll() is an async fn

Source§

impl<Mode, Clk, Dt, Steps, T> IncrementalEncoder<Mode, Clk, Dt, Steps, T, Async>
where Mode: OperationMode, Clk: InputPin + Wait, Dt: InputPin + Wait, Steps: StepMode, T: Copy + Zero + One + SaturatingAdd + WrappingNeg + From<i8>,

Source

pub async fn poll(&mut self) -> Result<Option<Mode::Movement>, Error>

Updates the encoder’s state based on the given clock and data pins, returning the direction if a movement was detected, None if no movement was detected, or Err(_) if an invalid input (i.e. a positional “jump”) was detected.

Depending on whether it matters why the encoder did not detect a movement (e.g. due to actual lack of movement or an erroneous read) you would either call encoder.poll() directly, or via encoder.poll().unwrap_or_default() to fall back to None in case of Err(_).

Waits asynchronously for any of the pins to change state, before returning.

Source

pub fn into_blocking( self, ) -> IncrementalEncoder<Mode, Clk, Dt, Steps, T, Blocking>
where IncrementalDecoder<Steps, T>: Default,

Reconfigure the driver so that poll() is a blocking function

Trait Implementations§

Source§

impl<Mode: Debug, Clk: Debug, Dt: Debug, Steps: Debug, T: Debug, PM: Debug> Debug for IncrementalEncoder<Mode, Clk, Dt, Steps, T, PM>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Mode, Clk, Dt, Steps, T, PM> Freeze for IncrementalEncoder<Mode, Clk, Dt, Steps, T, PM>
where Clk: Freeze, Dt: Freeze, T: Freeze,

§

impl<Mode, Clk, Dt, Steps, T, PM> RefUnwindSafe for IncrementalEncoder<Mode, Clk, Dt, Steps, T, PM>

§

impl<Mode, Clk, Dt, Steps, T, PM> Send for IncrementalEncoder<Mode, Clk, Dt, Steps, T, PM>
where Clk: Send, Dt: Send, T: Send, Mode: Send, PM: Send, Steps: Send,

§

impl<Mode, Clk, Dt, Steps, T, PM> Sync for IncrementalEncoder<Mode, Clk, Dt, Steps, T, PM>
where Clk: Sync, Dt: Sync, T: Sync, Mode: Sync, PM: Sync, Steps: Sync,

§

impl<Mode, Clk, Dt, Steps, T, PM> Unpin for IncrementalEncoder<Mode, Clk, Dt, Steps, T, PM>
where Clk: Unpin, Dt: Unpin, T: Unpin, Mode: Unpin, PM: Unpin, Steps: Unpin,

§

impl<Mode, Clk, Dt, Steps, T, PM> UnwindSafe for IncrementalEncoder<Mode, Clk, Dt, Steps, T, PM>
where Clk: UnwindSafe, Dt: UnwindSafe, T: UnwindSafe, Mode: UnwindSafe, PM: UnwindSafe, Steps: 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, M> ForwardCompat<T, M> for T

Source§

fn forward(self) -> Forward<T, M>

Create an e-h-c forward compatibility wrapper around and e-h object Available methods depend on the wrapped type
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> ReverseCompat<T> for T

Source§

fn reverse(self) -> Reverse<T>

Create an e-h-c wrapper around and e-h object Available methods depend on the wrapped type

Source§

fn reverse_cell(self) -> Reverse<RefCell<T>>

Create an e-h-c reverse compatibility wrapper using a ref-cell for interior mutability (required for InputPin types)

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.