Expand description
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.