I'm using LIRCd to capture the keys I press on my remote control, with the proper configuration file.
According to the documentation, I have to wait for the blocking function lirc_nextcode()
to return and I get a nice line to decode, like this:
0000000080bf4bb4 00 CURSOR_DOWN myremote
First number is the key value, next is the amount of repeats that this key was pressed (here 0, since I only pressed it and released it), then the key name and my remote's name.
Anyway, what I'd like to do is detect the key up of my remote.
If I press a button for a certain amount of time, this is what I get (new line every ~ 200ms):
0000000080bf4bb4 00 CURSOR_DOWN myremote
0000000080bf4bb4 01 CURSOR_DOWN myremote
0000000080bf4bb4 02 CURSOR_DOWN myremote
0000000080bf4bb4 03 CURSOR_DOWN myremote
0000000080bf4bb4 04 CURSOR_DOWN myremote
0000000080bf4bb4 05 CURSOR_DOWN myremote
0000000080bf4bb4 06 CURSOR_DOWN myremote
0000000080bf4bb4 07 CURSOR_DOWN myremote
0000000080bf4bb4 08 CURSOR_DOWN myremote
0000000080bf4bb4 09 CURSOR_DOWN myremote
0000000080bf4bb4 0a CURSOR_DOWN myremote
// I let go for 1s and press it again:
0000000080bf4bb4 00 CURSOR_DOWN myremote
So the second number increments whenever I long-press a key, but once I release it and press it again, it resets to 0.
What I want is be able to detect the moment when the repeat stops.
Now, I can see how I could implement a key up detection: if lirc_nextcode()
doesn't crack after a certain amount of time, I can consider that the key has been released.
What I'm asking you is: is there another (more proper) way to do that?
By configuring LIRCd maybe?
Or, if there's no other way to do it than with a timer, what's the best implementation?
Indeed, the lirc_getcode()
is blocking, so whenever a timer cracks, I need it to return!
edit: btw, no lirc
or lircd
tag, would be nice to have!
I'll do it by storing last code received and compare with new one, if codes are different then stored key was released. For what I see in your post, seems that code length is fixed, so you should'nt have much problems implementing it as I've said, just ignore last byte (repeat count).
IR transmitters works by repeating same code while holding key, so you'll need to know "guard time", that is delay between repeats. You sould test for this delay to see if no repeats are comming, if nothing comes after that delay, you could assume that user released key (KEY UP).
In short: