embedded-hal
embedded-hal copied to clipboard
`Qei` API
- What is missing in this API?
- Can this API be implemented for different devices?
Update: this trait is available in release v0.1.0 behind the "unproven" Cargo feature.
I wrote a library for a simple rotary encoder library, and after posting about it in the rust-embedded/awesome-rust thread, someone directed me to this trait, that I had no idea existed.
I'm having trouble for seeing how to map to the methods provided in the trait. Particularly the direction method.
Direction in embedded-hal has 2 variants, and the direction() function returns Direction. However, in my case, it's possible there is no change in direction, and the Count type itself has no inherent direction. The only thing I can think of is returning Updirection if the count is above zero and Down in the other case, but that doesn't really provide anything useful for a rotary encoder
It's very possible I'm just not understanding something, but I can't see how it fits together at all.
In my case, something like this would make a lot more sense:
pub trait Qei {
type Count;
fn count(&self) -> Self::Count;
fn direction(&self) -> Option<Direction>;
}
or even,
fn direction(&mut self) -> Option<Direction>
In this case, I can put the code that does the transformation of state -> Direction (and updates the internal count) in the direction() function