#no-std #embedded-toolkit

no-std embtk-rotary-encoder

Embedded Toolkit helpers for handling rotary encoder input

1 unstable release

0.1.0 Feb 3, 2019

#683 in #embedded

MIT/Apache

13KB
241 lines

Embedded Toolkit / rotary-encoder

docs crates.io ci

Documentation

On docs.rs

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

A helper for handling rotary encoder input, mainly for use on embedded platforms.

use embtk_rotary_encoder::RotaryEncoder;

// The `u16` type will be accepted as a raw position output from your QEI peripheral
let mut enc: RotaryEncoder<u16, _, _> =
// `4i8` below is the number of raw divisions per full physical division.
// `10u32` is the timeout in any kind of ticks you like.
// You'll supply a timestamp every time you receive an even from a peripheral.
RotaryEncoder::new(4i8, 10u32);

assert_eq!(enc.get_delta(65534u16, 1), 0); // we haven't moved full 4 divisions yet
assert_eq!(enc.get_delta(65532u16, 2), -1); // full 4 divisions down => 1 logical division down

assert_eq!(enc.get_delta(65530u16, 3), 0);
assert_eq!(enc.get_delta(65528u16, 20), 0); // too late, read about timeouts below

A note about timeout:

Sometimes you may lose an event from a peripheral or even a peripheral might be buggy. In this case you'll end up slightly off grid, i.e. you'll see the transition to a next division not when you feel the tactile feedback from an encoder but somewhere between the positions.

To remedy that, there's a timeout which, on expiry, makes a current position of an encoder a reference for subsequent moves.

Dependencies

~150KB