1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::receiver::DecodingError;
use crate::Protocol;
pub trait DecoderStateMachine: Protocol {
type State: DecoderState;
type RangeData;
type InternalStatus: Into<Status>;
fn state() -> Self::State;
fn ranges(resolution: usize) -> Self::RangeData;
fn event_full(
res: &mut Self::State,
rd: &Self::RangeData,
edge: bool,
delta_t: usize,
) -> Self::InternalStatus;
fn command(state: &Self::State) -> Option<Self::Cmd>;
}
pub trait ConstDecodeStateMachine<const R: usize>: DecoderStateMachine {
const RANGES: Self::RangeData;
fn event(res: &mut Self::State, delta_samples: usize, edge: bool) -> Self::InternalStatus {
Self::event_full(res, &Self::RANGES, edge, delta_samples)
}
}
pub trait DecoderState {
fn reset(&mut self);
}
#[derive(PartialEq, Eq, Copy, Clone)]
pub enum Status {
Idle,
Receiving,
Done,
Error(DecodingError),
}