使用 LIRCd 检测按键按下

发布于 2024-11-24 18:35:42 字数 1343 浏览 11 评论 0原文

我正在使用 LIRCd 来捕获我在遥控器上按下的按键,并使用正确的配置文件。
根据文档,我必须等待阻塞函数 lirc_nextcode() 返回,然后我会得到一个很好的解码行,如下所示:

0000000080bf4bb4 00 CURSOR_DOWN myremote

第一个数字是键值,下一个是 按下此键的重复次数(此处为 0,因为我只按下并释放它),然后是按键名称和遥控器的名称。

不管怎样,我想做的是检测遥控器的向上键。

如果我按下一个按钮一段时间,这就是我得到的结果(每约 200 毫秒换行一次):

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

因此,每当我长按一个键时,第二个数字就会递增,但一旦我释放它再次按下它,它会重置为 0。

我想要的是能够检测到重复停止的时刻。

现在,我可以看到如何实现密钥释放检测:如果 lirc_nextcode() 在一定时间后没有破解,我可以认为密钥已被释放。

我要问你的是:还有另一种(更正确)的方法吗?
也许通过配置 LIRCd ?

或者,如果除了计时器之外没有其他方法可以做到这一点,那么最好的实现是什么? 事实上,lirc_getcode()阻塞的,所以每当计时器崩溃时,我都需要它返回!

编辑:顺便说一句,如果没有 lirclircd 标签,那就太好了!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谎言 2024-12-01 18:35:42

我将通过存储最后收到的代码并与新代码进行比较来完成此操作,如果代码不同,则释放存储的密钥。对于我在您的帖子中看到的内容,似乎代码长度是固定的,因此正如我所说,您在实现它时应该不会遇到太多问题,只需忽略最后一个字节(重复计数)即可。

红外发射器的工作原理是按住按键时重复相同的代码,因此您需要知道“保护时间”,即重复之间的延迟。您应该测试此延迟,看看是否没有重复出现,如果在该延迟之后没有任何反应,您可以假设用户释放了密钥(KEY UP)。

简而言之:

  1. 读取代码
  2. 将其存储在 var 中以供稍后比较
  3. 轮询端口以获取更多代码,如果没有任何消息并且保护时间到期,则 KEY UP=true
  4. 得到一个代码,与存储的代码进行比较,如果相等则循环标签 3
  5. 如果不同则KEY UP=true,更多循环到标签 2

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
眼前雾蒙蒙 2024-12-01 18:35:42

我之前使用过lirc/lircd几次,据我所知没有官方方法来检测key up事件。

如果您考虑一下这项技术的工作原理,就会发现它没有这种技术是有道理的。遥控器的编程方式是每个按钮仅存储一个代码。因此,当按下按钮 X 时,它将发送代码 X 表示该按钮已按下,而当按下按钮 Y 时,将发送代码 Y。接收此信息的另一端设备(运行 Lircd)无法知道这是按键按下还是按键向上事件,因为这不是通信方式系统有效。它只知道按下了一个按钮。

按住 RC 上的 X 按钮将向另一端的设备发送更多代码,如果您不感兴趣,您就可以丢弃这些重复消息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文