从无头程序获取蓝牙事件
我有一台迷你 Linux PC(无头),我想用它作为蓝牙远程 IP 的网关。
我对 IP 方面没有任何问题,我只是对蓝牙方面有点迷茫。
如何从我的代码中获取蓝牙事件?它是基于设备的(意味着我只是 open()
正确的设备)还是有一些 API?
基本上,我想要的是轮询遥控器上的按键,仅此而已。
在伪代码中,这将是这样的:
handle = open_bluetooth();
for event in poll(handle):
do_something_with(event.key)
我有点不确定,因为我找到的大多数文档都是让遥控器像普通键盘一样工作,但因为我想要无头(没有 Xserver,没有 TTY 控制台) ,仅适用于管理员的 SSH)这不是我想要的。
至于语言,我的控制软件是用 ruby 编写的,但如果需要的话,我可以毫无问题地进行 C 扩展。
I have a mini linux PC (headless), and I'd like to use it as a gateway for a bluetooth remote to IP.
I have no problem with the IP side of things, I'm just a little bit in the fog for the bluetooth side of things.
How can I get the bluetooth events from my code? Is it device based (would mean I just open()
the right device) or is there some API?
Basically, what I want is to poll for keypress on the remote and that's it.
In pseudo code, this would be something like:
handle = open_bluetooth();
for event in poll(handle):
do_something_with(event.key)
I'm a bit unsure because most of the documentation I find is to make the remote acts like a regular keyboard, but as I'd like to be headless (no Xserver, no TTY console, only SSH for admin) this is not what I want.
As for the language, my control software is in ruby, but I have no problem making a C extension if needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了怎么做。
其实很简单,只要在字符设备上调用 POSIX
open
,然后读取struct input_event
(一次不止一个,因为一个按键会产生多个事件,你获取 syn、key,有时还有杂项事件)。有关该结构的信息,请查看头文件
linux/input.h
。I figured how to do it.
It's quite simple actually, just call POSIX
open
on the character device, then readstruct input_event
(more than one at a time, because a keypress generates more than one event, you get the syn, the key and sometimes the misc event).For info on the struct, look into header
linux/input.h
.