infrared/protocol/nec/
apple.rs1use crate::{
4 cmd::{AddressCommand, Command},
5 protocol::nec::{NecCommandVariant, NecPulseLen, NEC_STANDARD_TIMING},
6};
7
8#[derive(Debug, Copy, Clone, PartialEq)]
9#[cfg_attr(feature = "defmt", derive(defmt::Format))]
10pub struct AppleNecCommand {
11 pub command_page: u8,
12 pub command: u8,
13 pub device_id: u8,
14 pub repeat: bool,
15}
16
17impl NecCommandVariant for AppleNecCommand {
18 const PULSE_DISTANCE: &'static NecPulseLen = NEC_STANDARD_TIMING;
19
20 fn validate(bits: u32) -> bool {
21 let vendor = ((bits >> 5) & 0x7FF) as u16;
22 const APPLE_VENDOR_ID: u16 = 0x43f;
23
24 vendor == APPLE_VENDOR_ID &&
25 (bits.count_ones() & 0x1) == 1
27 }
28
29 fn unpack(bits: u32, repeat: bool) -> Option<Self> {
30 if !Self::validate(bits) {
31 return None;
32 }
33 let command_page = (bits & 0x1F) as u8;
35 let _vendor = ((bits >> 5) & 0x7FF) as u16;
37
38 let _parity_bit = (bits >> 16) & 0x1;
40 let command = ((bits >> 17) & 0x7F) as u8;
42 let device_id = ((bits >> 24) & 0xFF) as u8;
44
45 Some(AppleNecCommand {
46 command_page,
47 command,
48 device_id,
49 repeat,
50 })
51 }
52
53 fn pack(&self) -> u32 {
54 unimplemented!()
55 }
56}
57
58impl Command for AppleNecCommand {
59 fn is_repeat(&self) -> bool {
60 self.repeat
61 }
62}
63
64impl AddressCommand for AppleNecCommand {
65 fn address(&self) -> u32 {
66 0
67 }
68
69 fn command(&self) -> u32 {
70 u32::from(self.command_page << 7 | self.command)
71 }
72
73 fn create(_addr: u32, _cmd: u32) -> Option<Self> {
74 None
75 }
76}