pub mod kepler;
pub mod mapping;
pub use kepler::{IrKepler, IrKeplerStatic, KEPLER_MAPPING, KeplerKeys};
pub use mapping::{IrMapping, IrMappingStatic};
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::channel::Channel as EmbassyChannel;
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum IrEvent {
Press {
addr: u16,
cmd: u8,
},
}
#[allow(async_fn_in_trait)]
pub trait Ir {
async fn wait_for_press(&self) -> IrEvent;
}
impl<T> Ir for &T
where
T: Ir + ?Sized,
{
async fn wait_for_press(&self) -> IrEvent {
(*self).wait_for_press().await
}
}
#[doc(hidden)]
pub struct IrStatic(EmbassyChannel<CriticalSectionRawMutex, IrEvent, 8>);
impl IrStatic {
#[must_use]
pub const fn new() -> Self {
Self(EmbassyChannel::new())
}
pub async fn send(&self, event: IrEvent) {
self.0.send(event).await;
}
pub async fn receive(&self) -> IrEvent {
self.0.receive().await
}
}
impl Default for IrStatic {
fn default() -> Self {
Self::new()
}
}
#[doc(hidden)]
pub fn decode_nec_frame(frame: u32) -> Option<(u16, u8)> {
let byte0 = (frame & 0xFF) as u8;
let byte1 = ((frame >> 8) & 0xFF) as u8;
let byte2 = ((frame >> 16) & 0xFF) as u8;
let byte3 = ((frame >> 24) & 0xFF) as u8;
if (byte2 ^ byte3) != 0xFF {
return None;
}
if (byte0 ^ byte1) == 0xFF {
return Some((u16::from(byte0), byte2));
}
let addr16 = ((u16::from(byte1)) << 8) | u16::from(byte0);
Some((addr16, byte2))
}