Struct rotary_encoder_embedded::RotaryEncoder

source ·
pub struct RotaryEncoder<MODE, DT, CLK> { /* private fields */ }
Expand description

Rotary Encoder

Implementations§

source§

impl<DT, CLK> RotaryEncoder<AngularVelocityMode, DT, CLK>
where DT: InputPin, CLK: InputPin,

source

pub fn set_velocity_inc_factor(&mut self, inc_factor: f32)

Set the velocity_inc_factor. How quickly the velocity increases to 1.0.

source

pub fn set_velocity_dec_factor(&mut self, dec_factor: f32)

Set the velocity_dec_factor. How quickly the velocity decreases or cools-down

source

pub fn set_velocity_action_ms(&mut self, action_ms: u64)

Set the velocity_action_ms. The window of duration (milliseconds) that the velocity will increase

source

pub fn decay_velocity(&mut self)

This function should be called periodically, either via a timer or the main loop. This function will reduce the angular velocity over time, the amount is configurable via the constructor

source

pub fn update(&mut self, current_time_millis: u64) -> Direction

Update the state machine of the RotaryEncoder. This should be called ideally from an interrupt vector when either the DT or CLK pins state changes. This function will update the RotaryEncoder’s Direction and current Angular Velocity.

  • current_time - Current timestamp in ms (strictly monotonously increasing)
source

pub fn velocity(&self) -> Velocity

Returns the current angular velocity of the RotaryEncoder The Angular Velocity is a value between 0.0 and 1.0 This is useful for incrementing/decrementing a value in an exponential fashion

source§

impl<DT, CLK, MODE> RotaryEncoder<MODE, DT, CLK>
where DT: InputPin, CLK: InputPin,

source

pub fn into_angular_velocity_mode( self ) -> RotaryEncoder<AngularVelocityMode, DT, CLK>

Configure RotaryEncoder to use the AngularVelocityMode API

source§

impl<DT, CLK> RotaryEncoder<StandardMode, DT, CLK>
where DT: InputPin, CLK: InputPin,

source

pub fn update(&mut self) -> Direction

Updates the RotaryEncoder, updating the direction property

source§

impl<LOGIC, DT, CLK> RotaryEncoder<LOGIC, DT, CLK>
where DT: InputPin, CLK: InputPin,

source

pub fn into_standard_mode(self) -> RotaryEncoder<StandardMode, DT, CLK>

Configure RotaryEncoder to use the standard API

source§

impl<MODE, DT, CLK> RotaryEncoder<MODE, DT, CLK>
where DT: InputPin, CLK: InputPin,

Common

source

pub fn pins_mut(&mut self) -> (&mut DT, &mut CLK)

Borrow a mutable reference to the underlying InputPins. This is useful for clearing hardware interrupts.

source

pub fn release(self) -> (DT, CLK)

Release the underying resources such as the InputPins back to the initiator

source

pub fn mode(&mut self) -> &mut MODE

Borrow the underlying mode

source§

impl<DT, CLK> RotaryEncoder<InitalizeMode, DT, CLK>
where DT: InputPin, CLK: InputPin,

source

pub fn new(pin_dt: DT, pin_clk: CLK) -> Self

Initiates a new RotaryEncoder in InitalizeMode, taking two InputPins InputPin.

Auto Trait Implementations§

§

impl<MODE, DT, CLK> Freeze for RotaryEncoder<MODE, DT, CLK>
where MODE: Freeze, DT: Freeze, CLK: Freeze,

§

impl<MODE, DT, CLK> RefUnwindSafe for RotaryEncoder<MODE, DT, CLK>
where MODE: RefUnwindSafe, DT: RefUnwindSafe, CLK: RefUnwindSafe,

§

impl<MODE, DT, CLK> Send for RotaryEncoder<MODE, DT, CLK>
where MODE: Send, DT: Send, CLK: Send,

§

impl<MODE, DT, CLK> Sync for RotaryEncoder<MODE, DT, CLK>
where MODE: Sync, DT: Sync, CLK: Sync,

§

impl<MODE, DT, CLK> Unpin for RotaryEncoder<MODE, DT, CLK>
where MODE: Unpin, DT: Unpin, CLK: Unpin,

§

impl<MODE, DT, CLK> UnwindSafe for RotaryEncoder<MODE, DT, CLK>
where MODE: UnwindSafe, DT: UnwindSafe, CLK: 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.