The InfraredPlug class in the Ports library has been extended with a decoder which tries to recognize the incoming IR pulse trains. Remember that the data is returned as a list of on/off times, returned as multiple of the “slot size” given to the InfraredPort constructor on setup.
I merely added a new “decoder()” member:
It currently only recognizes the NEC protocol, which is what three of my remotes here use. The NEC packets have 32 bits of payload (or no bits at all in the case of a “repeat” packet).
Here’s is how the ir_recv.pde sketch calls this new decoder:
Sample output from three different buttons on three different remotes each:
The first remote (starting with 246) shows a “classical” NEC remote, where each second byte is the 1’s complement of the one before it.
The second remote (starting with 162) uses 1’s complement only on the command bytes at the end.
The third remote (starting with 119) is an Apple Remote which uses the extended NEC format, and presumably another way to check the validity of received packets.
Full details about the NEC and other protocols can be found on San Bergman’s page.