#![allow(missing_docs)]
#![no_std]
#![no_main]

use core::convert::Infallible;
use defmt::info;
use defmt_rtt as _;
use device_envoy::Result;
use device_envoy::ir::{Ir, IrEvent, IrStatic};
use embassy_executor::Spawner;
use panic_probe as _;

#[embassy_executor::main]
async fn main(spawner: Spawner) -> ! {
    let err = inner_main(spawner).await.unwrap_err();
    core::panic!("{err}");
}

async fn inner_main(spawner: Spawner) -> Result<Infallible> {
    let p = embassy_rp::init(Default::default());

    info!("IR NEC decoder example starting...");

    static IR_STATIC: IrStatic = Ir::new_static();
    let ir = Ir::new(&IR_STATIC, p.PIN_15, p.PIO0, spawner)?;

    info!("IR receiver initialized on GP15");

    // Main loop: process IR events
    loop {
        let event = ir.wait_for_press().await;
        match event {
            IrEvent::Press { addr, cmd } => {
                info!("IR Button Press - addr=0x{:04X} cmd=0x{:02X}", addr, cmd);
            }
        }
    }
}
