I improved my old IR decoder library by adding some new features, without making it any more complicated. What's nice it that this is all done in the interrupt routine, so the library is still non-blocking. Here are the new features:
- It no longer records invalid IR codes, and automatically resets when an invalid code is received (who cares if the code is invalid anyway?).
- It removes the start bits, and the toggle bit from the code, to make it easier to determine what button was pressed on the remote.
- It can determine whether a code is a repeat, or a new button press by the user.
The library can be downloaded here: https://github.com/frodofski/RC5_Decoder_V2
As before, the ir_begin() function starts the decoder, but ir_data() is a little different:
- If there is no valid code present, it will return a 0.
- If there is a new code, it will return the code.
- Finally, if it is receiving a string of codes with each one being a repeat of the previous one, it will return -1 until the string is broken.
Whats nice about the repeat detection, is that you don't have to worry about stuff happening more than once when you hold down a button on the remote. And if you do want something to happen for as long as the button is held down, like a volume control for example, you just need to look for the -1s.