#include "mbed.h"
#include "ReceiverIR.h"
ReceiverIR ir_rx(PB_3);
DigitalOut relay(PB_5);
Serial pc(USBTX, USBRX);
/**
* Receive.
*
* @param format Pointer to a format.
* @param buf Pointer to a buffer.
* @param bufsiz Size of the buffer.
*
* @return Bit length of the received data.
*/
int receive(RemoteIR::Format *format, uint8_t *buf, int bufsiz, int timeout = 100)
{ int cnt = 0;
while (ir_rx.getState() != ReceiverIR::Received) {
cnt++;
if (timeout < cnt) {
return -1;
}
}
return ir_rx.getData(format, buf, bufsiz * 8);
}
/**
* Display a current status.
*/
void display_status(char *status, int bitlength)
{
pc.printf("\n\r%s: %02d", status, bitlength);
}
/**
* Display a format of a data.
*/
void display_format(RemoteIR::Format format)
{
switch (format) {
case RemoteIR::UNKNOWN:
pc.printf("\n\rFormat -> ????????");
break;
case RemoteIR::NEC:
pc.printf("\n\rFormat -> NEC ");
break;
case RemoteIR::NEC_REPEAT:
pc.printf("\n\rFormat -> NEC (R)");
break;
case RemoteIR::AEHA:
pc.printf("\n\rFormat -> AEHA ");
break;
case RemoteIR::AEHA_REPEAT:
pc.printf("\n\rFormat -> AEHA (R)");
break;
case RemoteIR::SONY:
pc.printf("\n\rFormat -> SONY ");
break;
}
}
/**
* Display a data.
*
* @param buf Pointer to a buffer.
* @param bitlength Bit length of a data.
*/
void display_data(uint8_t *buf, int bitlength)
{
const int n = bitlength / 8 + (((bitlength % 8) != 0) ? 1 : 0);
pc.printf("\n\rData -> 0x");
for (int i = 0; i < n; i++) {
pc.printf("%02X ", buf[i]);
}
for (int i = 0; i < 8 - n; i++) {
pc.printf("--");
}
}
/**
* Entry point.
*/
int main(void) {
/*
* Splash.
*/
wait(1); //warm up time
pc.printf("\n\rRemoteIR");
/*
* Execute.
*/
while (1) {
uint8_t buf1[32];
//uint8_t buf2[32];
int bitlength1;
//int bitlength2;
RemoteIR::Format format;
memset(buf1, 0x00, sizeof(buf1)); //fill buf1 with 0x00
//memset(buf2, 0x00, sizeof(buf2)); //fill buf2 with 0x00
{
bitlength1 = receive(&format, buf1, sizeof(buf1));
if (bitlength1 < 0) {
continue;
}
display_status("\n\rstatus -> RECV", bitlength1);
display_data(buf1, bitlength1);
display_format(format);
}
/*
#if TEST_LOOP_BACK
wait_ms(100);
{
bitlength1 = transmit(format, buf1, bitlength1);
if (bitlength1 < 0) {
continue;
}
display_status("TRAN", bitlength1);
display_data(buf1, bitlength1);
display_format(format);
}
wait_ms(100);
{
bitlength2 = receive(&format, buf2, sizeof(buf2));
if (bitlength2 < 0) {
continue;
}
display_status("RECV", bitlength2);
display_data(buf2, bitlength2);
display_format(format);
}
wait_ms(100);
{
for (int i = 0; i < sizeof(buf1); i++) {
if (buf1[i] != buf2[i]) {
display_status("CPERR", bitlength2);
wait(1);
continue;
}
}
}
#endif */
}
}
Has anyone tried that IR library before? I don't think it's because of different crystal frequency issues (mbed_cortexM3 -> 96MHz, nucleo F401_cortexM4 -> 84MHz).
Hi,
I've a mbed and nucleo F401 boards and testing IR library from http://mbed.org/users/shintamainjp/notebook/remote_ir_en/. It works perfectly with mbed board but nucleo board. Test program is here
Import programRemoteIR_TestProgram
A test program for RemoteIR library.
Last commit 13 Oct 2010 by Shinichiro Nakamura
Has anyone tried that IR library before? I don't think it's because of different crystal frequency issues (mbed_cortexM3 -> 96MHz, nucleo F401_cortexM4 -> 84MHz).
Regards,
Aung