quadrature_encoder/mode/
linear.rs1use quadrature_decoder::Change;
4
5use crate::mode::OperationMode;
6
7use super::Movement;
8
9#[repr(i8)]
11#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
12pub enum LinearMovement {
13 Forward = 1,
15 Backward = -1,
17}
18
19impl LinearMovement {
20 pub fn flipped(self) -> Self {
22 match self {
23 Self::Forward => Self::Backward,
24 Self::Backward => Self::Forward,
25 }
26 }
27}
28
29impl From<Change> for LinearMovement {
30 fn from(change: Change) -> Self {
35 match change {
36 Change::Positive => Self::Forward,
37 Change::Negative => Self::Backward,
38 }
39 }
40}
41
42impl Movement for LinearMovement {
43 fn flipped(self) -> Self {
44 match self {
45 Self::Forward => Self::Backward,
46 Self::Backward => Self::Forward,
47 }
48 }
49}
50
51pub struct Linear;
53
54impl OperationMode for Linear {
55 type Movement = LinearMovement;
56}