开发者

Detect key up with LIRCd

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 b开发者_运维问答locking 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:

  1. Read a code
  2. Store it in a var to compare later
  3. Poll port for more codes, if nothing comes and guard time expired then KEY UP=true
  4. Got a code, compare with stored one, if equal go looping label 3
  5. If different then KEY UP=true, go more looping to label 2


I have used lirc/lircd a few times before and as far as I know there's no official way to detect the key up event.

If you think about how this technology works, it makes sense that it doesn't have. The remote control is programmed in a way that it stores only one code per button. So when button X is pressed, it will send code X saying that the button was pressed, and when button Y is pressed code Y will be sent. The device on the other side (running Lircd) that is receiving this information has no way to know if this was a key down or key up event because that's not how the communication system works. It only knows that a button was pressed.

Holding down button X on the RC will send more codes at the device on the other end, making it your job to discard these repeat messages if they don't interest you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜