positron96 / rpi-ircontrol

A C++ program for Raspberry Pi that reads data from various IR remote controls via an IR receiver
1 stars 0 forks source link

NEC REMOTE ADDRESS VALIDATION CHOKING #1

Open grene78 opened 7 years ago

grene78 commented 7 years ago

Great code! Thank you, this is going to help me ditch LIRC which has been a pain to try to configure on stretch.

With my NEC remote, I was choking on:

`if(cAddr != (char)~cAddrI ) {
    printf("address validation failed: %1$d(%1$o) != %2$d(%2$o)\n", cAddr, (char)~cAddrI);
    printf("switching to NOTHING\n");
    cState = NOTHING;
    return;
}`

My NEC remote was providing the address and inverse address:

Address: 01100001 Inverse: 10000110

Simple fix:

unsigned char reverse(unsigned char b) {
    b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
    b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
    b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
    return b;
}

if (cAddr != reverse(cAddrI)) {
    printf("address validation failed: %1$d(%1$o) != %2$d(%2$o)\n", cAddr, (char)~cAddrI);
    printf("switching to NOTHING\n");
    cState = NOTHING;
    return;
}

I'm not sure if many NEC remotes do it this way. I know at least one does!

positron96 commented 7 years ago

Thank you! I did not actually think this code would be much use to anyone else! As for ID inversion, I could incorporate your code into project if you don't mind.

grene78 commented 7 years ago

It was/is very helpful. Glad I found it. As for the changes, go for it, that's why I sent it.