解析/ dev / input / mice数据

时间:2019-02-16 21:57:37

标签: c linux mouse

我正在编写一个C程序,该程序从/ dev / input / mice读取并解释鼠标位置数据,并将其写出。但是我在弄清楚如何解释从/ dev / input / mice读取的数据时遇到了麻烦。当我从读取/ dev / input / mice打印出原始数据时,会得到一长串值。例如,这就是我得到的:

57, 129, 129

此数据是通过触摸左下角的触摸屏生成的。

有人知道如何解析此数据(或可以指向一些文档)吗?这些原始数据是来自HID设备本身,还是来自内核?我还阅读了其他几篇文章,其中只有三个字节的数据:Xpos,Ypos和单击状态。这不是真的。 x和y数据所包含的分辨率都超出了一个字节数据(2 ^ 8)的分辨率,并且从/ dev / input / mice文件读取时,我得到的不仅仅是三个字节。

此外,我知道还有一些与X服务器通信的库,您可以使用它们来读取鼠标数据。我的问题特别是关于/ dev / input / mice中的数据。

如果有问题,我将在具有Raspbian的Raspberry Pi上运行代码。读取值的代码是:

char mouse_data[num_mouse_bytes];
int mouse_directory = open("/dev/input/mice", O_RDONLY);
int bytes_read = read(mouse_directory, mouse_data, num_mouse_bytes);
int byte_index = 0;
while(byte_index < bytes_read){
    printf("%hhu, " mouse_data[byte_index]);
    byte_index++;
}

0 个答案:

没有答案