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>
impl<Mode, Clk, Dt, Steps, T, PM> IncrementalEncoder<Mode, Clk, Dt, Steps, T, PM>
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,
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,
Sourcepub fn reversed(self) -> Self
pub fn reversed(self) -> Self
Sets the encoder’s reversed mode, making it report flipped movements and positions.
Sourcepub fn is_reversed(&self) -> bool
pub fn is_reversed(&self) -> bool
Returns true
if the encoder is reversed, otherwise false
.
Sourcepub fn pins_mut(&mut self) -> (&mut Clk, &mut Dt)
pub fn pins_mut(&mut self) -> (&mut Clk, &mut Dt)
Returns mutable borrows for the signal channel pins.
Sourcepub fn position(&self) -> T
pub fn position(&self) -> T
Returns the encoder’s position counter relative to its initial position in number of cycles.
Sourcepub fn set_position(&mut self, position: T)
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>,
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>,
Sourcepub fn poll(&mut self) -> Result<Option<Mode::Movement>, Error>
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.
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.
Sourcepub fn into_async(self) -> IncrementalEncoder<Mode, Clk, Dt, Steps, T, Async>where
IncrementalDecoder<Steps, T>: Default,
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>,
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>,
Sourcepub async fn poll(&mut self) -> Result<Option<Mode::Movement>, Error>
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.
Sourcepub fn into_blocking(
self,
) -> IncrementalEncoder<Mode, Clk, Dt, Steps, T, Blocking>where
IncrementalDecoder<Steps, T>: Default,
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