#include "nec_receive.h"
#include "nec_transmit_pio.h"
#include <stdio.h>
#include <stdlib.h>
#define RX_PIN 28
#define TX_PIN 16
#define PIO_INSTANCE pio0
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr)[0])
uint32_t remote_codes[] = {
0x5da2ff00, //POWER
0xdd22ff00, //TEST
0xfd02ff00, //PLUS
0x3dc2ff00, //BACK
0x1de2ff00, //MENU
0x6f90ff00, //NEXT
0x57a8ff00, //PLAY
0x1fe0ff00, //PREV
0x9768ff00, //0
0x6798ff00, //MINUS
0x4fb0ff00, //C
0x857aff00, //3
0xe718ff00, //2
0xcf30ff00, //1
0xef10ff00, //4
0xc738ff00, //5
0xa55aff00, //6
0xad52ff00, //9
0xb54aff00, //8
0xbd42ff00, //7
};
// Infrared loopback example ('NEC' format)
//
// Need to connect an IR LED to GPIO 14 via a suitable series resistor (e.g. 1.5k)
// and an active-low IR detector to GPIO 15 (e.g. VS1838b)
//
// Output is sent to stdout
int main() {
stdio_init_all();
PIO pio = pio0;
// configure and enable the state machines
int rx_sm = nec_rx_init(pio, RX_PIN);
uint tx_offset = pio_add_program(PIO_INSTANCE, &nec_program);
int tx_sm = pio_claim_unused_sm(PIO_INSTANCE, true);
nec_transmit_program_init(PIO_INSTANCE, tx_sm , tx_offset, TX_PIN);
while (true) {
pio_sm_put_blocking(PIO_INSTANCE, tx_sm,
remote_codes[rand() % ARRAY_SIZE(remote_codes)]);
// display any frames in the receive FIFO
while (!pio_sm_is_rx_fifo_empty(pio, rx_sm)) {
uint32_t rx_frame = pio_sm_get(pio, rx_sm);
nec_print_frame(rx_frame);
}
sleep_ms(500);
}
}