I'm trying to decode a signal of a generic "Car MP3" remote, which apparently uses the NEC protocol.
When using the NecDebug protocol type, I always get the same bits for every button I press.
Am I doing something wrong?
type IrReceiver = infrared::Receiver<
infrared::protocol::Nec,
infrared::receiver::Poll,
infrared::receiver::PinInput<Pin<Gpio3, Input<Floating>>>,
Button<CarMp3>
>;
pub static IR_RECEIVER: Mutex<RefCell<Option<IrReceiver>>> = Mutex::new(RefCell::new(None));
pub static UART: Mutex<RefCell<Option<UartPeripheral<hal::uart::Enabled, pac::UART0>>>> =
Mutex::new(RefCell::new(None));
pub static TIMER: Mutex<RefCell<Option<hal::Timer>>> = Mutex::new(RefCell::new(None));
pub static ALARM: Mutex<RefCell<Option<timer::Alarm0>>> = Mutex::new(RefCell::new(None));
const TIMER_FREQ: u32 = 20_000;
const TIMER_DURATION_US: u32 = 1_000_000 / TIMER_FREQ;
fn main() {
// ...omitted
let ir_pin: IrReceiverPin = pins.gpio3.into_floating_input();
let receiver = IrReceiver::with_pin(TIMER_FREQ, ir_pin);
let mut timer = Timer::new(p.TIMER, &mut p.RESETS);
let alarm = timer.alarm_0().unwrap();
cortex_m::interrupt::free(|cs| {
IR_RECEIVER.borrow(cs).replace(Some(receiver));
TIMER.borrow(cs).replace(Some(timer));
ALARM.borrow(cs).replace(Some(alarm));
let mut alarm = ALARM.borrow(cs).borrow_mut();
let alarm = alarm.as_mut().unwrap();
let mut timer = TIMER.borrow(cs).borrow_mut();
let timer = timer.as_mut().unwrap();
alarm
.schedule(Microseconds::new(TIMER_DURATION_US))
.unwrap();
alarm.enable_interrupt(timer);
});
unsafe {
pac::NVIC::unmask(pac::Interrupt::TIMER_IRQ_0);
}
}
#[allow(non_snake_case)]
#[interrupt]
fn TIMER_IRQ_0() {
cortex_m::interrupt::free(|cs| {
let mut alarm = ALARM.borrow(cs).borrow_mut();
let alarm = alarm.as_mut().unwrap();
let mut timer = TIMER.borrow(cs).borrow_mut();
let timer = timer.as_mut().unwrap();
let mut receiver = IR_RECEIVER.borrow(cs).borrow_mut();
let receiver = receiver.as_mut().unwrap();
if let Ok(Some(cmd)) = receiver.poll() {
let action = cmd.action();
let mut uart = UART.borrow(cs).borrow_mut();
let uart = uart.as_mut().unwrap();
let string = format!(" {}|{:?} ", cmd.command().cmd != 0, action);
uart.write_full_blocking(string.as_bytes());
}
alarm.clear_interrupt(timer);
alarm
.schedule(Microseconds::new(TIMER_DURATION_US))
.unwrap();
});
}
#[derive(Default, Debug)]
pub struct CarMp3;
impl RemoteControlModel for CarMp3 {
const MODEL: &'static str = "Car Mp3";
const DEVTYPE: infrared::remotecontrol::DeviceType = infrared::remotecontrol::DeviceType::Generic;
const PROTOCOL: infrared::ProtocolId = ProtocolId::Nec;
const ADDRESS: u32 = 0;
type Cmd = NecCommand;
const BUTTONS: &'static [(u32, infrared::remotecontrol::Action)] = &[
(0xFFA25D, infrared::remotecontrol::Action::ChannelListPrev),
(0xFF629D, infrared::remotecontrol::Action::ChannelList),
(0xFFE21D, infrared::remotecontrol::Action::ChannelListNext),
(0xFF22DD, infrared::remotecontrol::Action::Prev),
(0xFF02FD, infrared::remotecontrol::Action::Next),
(0xFFC23D, infrared::remotecontrol::Action::Play_Pause),
(0xFFE01F, infrared::remotecontrol::Action::VolumeDown),
(0xFFA857, infrared::remotecontrol::Action::VolumeUp),
(0xFF906F, infrared::remotecontrol::Action::Eq),
(0xFF6897, infrared::remotecontrol::Action::Zero),
//(0xFF9867, infrared::remotecontrol::Action::?),
//(0xFFB04F, infrared::remotecontrol::Action::?),
(0xFF30CF, infrared::remotecontrol::Action::One),
(0xFF18E7, infrared::remotecontrol::Action::Two),
(0xFF7A85, infrared::remotecontrol::Action::Three),
(0xFF10EF, infrared::remotecontrol::Action::Four),
(0xFF38C7, infrared::remotecontrol::Action::Five),
(0xFF5AA5, infrared::remotecontrol::Action::Six),
(0xFF42BD, infrared::remotecontrol::Action::Seven),
(0xFF4AB5, infrared::remotecontrol::Action::Eight),
(0xFF52AD, infrared::remotecontrol::Action::Nine),
];
}