pub trait Command {
fn construct(addr: u32, data: u32) -> Option<Self>
where
Self: core::marker::Sized;
fn address(&self) -> u32;
fn data(&self) -> u32;
fn protocol(&self) -> Protocol;
fn pulses(&self, buf: &mut [u16]) -> usize;
fn pulses_shift_scaled(&self, buf: &mut [u16], shift: usize) -> usize {
let len = self.pulses(buf);
buf.iter_mut().take(len).for_each(|pulse| *pulse >>= shift);
len
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u8)]
#[non_exhaustive]
pub enum Protocol {
Nec = 1,
Nec16 = 2,
NecSamsung = 3,
Rc5 = 5,
Rc6 = 6,
Sbp = 7,
Unknown = 255,
}
impl From<u8> for Protocol {
fn from(u: u8) -> Self {
match u {
1 => Protocol::Nec,
2 => Protocol::Nec16,
3 => Protocol::NecSamsung,
5 => Protocol::Rc5,
6 => Protocol::Rc6,
7 => Protocol::Sbp,
_ => Protocol::Unknown,
}
}
}