This is my following code, the problem I'm facing is that with the code I'm able to get that which protocol the remote im using has like NEC or SONY or AEHA but not able to get the code of the actual value that is received by the mBed on press of a button (that is in the buf variable) kindly tell me where could be the possible problem?
#include "mbed.h"
#include "KS0108.h"
#include "Arial12.h"
#include "SystemFont5x7.h"
#include "image.h"
#include "rtos.h"
#include "loading.h"
#include "ReceiverIR.h"
// KS0108 (PinName _RST,PinName _DI, PinName _RW, PinName _E, PinName _CS1, PinName _CS2, PinName DB0, PinName DB1, PinName DB2, PinName DB3, PinName DB4, PinName DB5, PinName DB6, PinName DB7);
KS0108 display(PTC3,PTD6, PTE31, PTA17, PTC5, PTC4, PTA16, PTC17, PTC16, PTC13, PTC12, PTC11, PTC10, PTC6);
ReceiverIR ir_rx(PTA13);
Serial pc(USBTX, USBRX); // tx, rx
void LCD_thread(void const *args)
{
while (true) {
display.FullScreenBMP(load);
//Thread::wait(0.5);
}
}
void led3_thread(void const *args)
{
while (true) {
Thread::wait(0.5);
}
}
int receive(RemoteIR::Format *format, uint8_t *buf, int bufsiz, int timeout = 1000) {
int cnt = 0;
while (ir_rx.getState() != ReceiverIR::Received) {
wait_ms(1);
cnt++;
if (timeout < cnt) {
return -1;
}
}
return ir_rx.getData(format, buf, bufsiz * 8);
}
int main()
{
display.ClearScreen();
display.FullScreenBMP(pic);
wait(2);
display.ClearScreen();
Thread thread(LCD_thread);
Thread thread1(led3_thread);
//display.DrawBitmap(mikro_test,5,5,BLACK);
/*display.GotoXY(5,0);
display.SelectFont(System5x7,BLACK,ReadData);
display.GotoXY(1,16);
display.PrintString("System5x7");
wait(3);
display.GotoXY(2,32);
display.SelectFont(Arial12,BLACK,ReadData);
display.PrintString("Arial 14");
wait(3);*/
RemoteIR::Format format;
uint8_t buf[32];
memset(buf, 0x00, sizeof(buf));
while(1) {
int bitcount;
if (ir_rx.getState() == ReceiverIR::Received) {
bitcount = receive(&format, buf, sizeof(buf));
pc.printf("got>>",buf);
switch (format) {
case RemoteIR::UNKNOWN:
pc.printf("????");
break;
case RemoteIR::NEC:
pc.printf(" NEC");
break;
case RemoteIR::AEHA:
pc.printf("AEHA");
break;
case RemoteIR::SONY:
pc.printf("SONY");
break;
}
}
}
}
This is my following code, the problem I'm facing is that with the code I'm able to get that which protocol the remote im using has like NEC or SONY or AEHA but not able to get the code of the actual value that is received by the mBed on press of a button (that is in the buf variable) kindly tell me where could be the possible problem?
ON press of a button I get "got>>SONY" and no value in the buf variable?
Where can I be wrong?