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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
pub mod decoder;
pub mod encoder;
mod apple;
mod nec16;
mod raw;
mod samsung;
mod standard;
#[cfg(test)]
mod tests;
use core::marker::PhantomData;
pub use apple::AppleNecCommand;
pub use nec16::Nec16Command;
pub use raw::NecDebugCmd;
pub use samsung::SamsungNecCommand;
pub use standard::NecCommand;
use crate::protocol::Protocol;
pub struct Nec<C: NecCommandVariant = NecCommand> {
pub(crate) cmd: PhantomData<C>,
}
impl<C: NecCommandVariant> Protocol for Nec<C> {
type Cmd = C;
}
pub type SamsungNec = Nec<SamsungNecCommand>;
pub type Nec16 = Nec<Nec16Command>;
pub type AppleNec = Nec<AppleNecCommand>;
pub type NecDebug = Nec<NecDebugCmd>;
pub trait NecCommandVariant: Sized {
const PULSE_DISTANCE: &'static NecPulseLen;
fn validate(bits: u32) -> bool;
fn unpack(bits: u32, repeat: bool) -> Option<Self>;
fn pack(&self) -> u32;
}
const NEC_STANDARD_TIMING: &NecPulseLen = &NecPulseLen {
header_high: 9000,
header_low: 4500,
repeat_low: 2250,
data_high: 560,
data_zero_low: 560,
data_one_low: 1690,
};
const NEC_SAMSUNG_TIMING: &NecPulseLen = &NecPulseLen {
header_high: 4500,
header_low: 4500,
repeat_low: 2250,
data_zero_low: 560,
data_high: 560,
data_one_low: 1690,
};
#[derive(Copy, Clone)]
pub struct NecPulseLen {
header_high: u32,
header_low: u32,
repeat_low: u32,
data_high: u32,
data_zero_low: u32,
data_one_low: u32,
}