README
1mtdev - Multitouch Protocol Translation Library (MIT license)
2
3The mtdev library transforms all variants of kernel MT events to the
4slotted type B protocol. The events put into mtdev may be from any MT
5device, specifically type A without contact tracking, type A with
6contact tracking, or type B with contact tracking. See the kernel
7documentation for further details.
8
9http://bitmath.org/code/mtdev/
10Please send patches to: patches@bitmath.org
11
12---
13Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
14Copyright (C) 2010 Canonical Ltd.
15
README.OpenSource
README.md
1# mtdev - Multitouch Protocol Translation Library
2
3The mtdev is a stand-alone library which transforms all variants of kernel MT events to the slotted type B protocol. The events put into mtdev may be from any MT device, specifically type A without contact tracking, type A with contact tracking, or type B with contact tracking.
4
5The bulk of the mtdev code has been out there since 2008, as part of the Multitouch X Driver. With this package, finger tracking and seamless MT protocol handling is available under a free license.
6
7
8## Directory structure
9
10```
11README.md English description
12README_zh.md Chinese description
13include/ API Definition
14src/ Encapsulation layer implementation
15README.OpenSource Open Source Description
16```
17
18## How OpenHarmony integrates mtdev
19### 1.Header file import
20```c
21#include <mtdev.h>
22```
23### 2.BUILD.gn add Reference
24```c
25public_deps += ["//third_party/mtdev:libmtdev"]
26```
27### 3.Example of calling mtdev function
28```c
29//year-proof millisecond event time
30typedef uint64_t mstime_t;
31
32static int use_event(const struct input_event *ev)
33{
34#if 0
35 return ev->type == EV_ABS && mtdev_is_absmt(ev->code);
36#else
37 return 1;
38#endif
39}
40
41//print events
42static void print_event(const struct input_event *ev)
43{
44 static const mstime_t ms = 1000;
45 static int slot;
46 mstime_t evtime = ev->input_event_usec / ms + ev->input_event_sec * ms;
47 if (ev->type == EV_ABS && ev->code == ABS_MT_SLOT)
48 slot = ev->value;
49 fprintf(stderr, "%012llx %02d %01d %04x %d\n",
50 evtime, slot, ev->type, ev->code, ev->value);
51}
52
53#define CHECK(dev, name) \
54 if (mtdev_has_mt_event(dev, name)) \
55 fprintf(stderr, " %s\n", #name)
56
57//check prop
58static void show_props(const struct mtdev *dev)
59{
60 fprintf(stderr, "supported mt events:\n");
61 CHECK(dev, ABS_MT_SLOT);
62 CHECK(dev, ABS_MT_TOUCH_MAJOR);
63 CHECK(dev, ABS_MT_TOUCH_MINOR);
64 CHECK(dev, ABS_MT_WIDTH_MAJOR);
65 CHECK(dev, ABS_MT_WIDTH_MINOR);
66 CHECK(dev, ABS_MT_ORIENTATION);
67 CHECK(dev, ABS_MT_POSITION_X);
68 CHECK(dev, ABS_MT_POSITION_Y);
69 CHECK(dev, ABS_MT_TOOL_TYPE);
70 CHECK(dev, ABS_MT_BLOB_ID);
71 CHECK(dev, ABS_MT_TRACKING_ID);
72 CHECK(dev, ABS_MT_PRESSURE);
73 CHECK(dev, ABS_MT_DISTANCE);
74}
75
76//Create mtdev, check prop, get and print mt events
77static void loop_device(int fd)
78{
79 struct mtdev dev;
80 struct input_event ev;
81 int ret = mtdev_open(&dev, fd);
82 if (ret) {
83 fprintf(stderr, "error: could not open device: %d\n", ret);
84 return;
85 }
86 show_props(&dev);
87 //while the device has not been inactive for five seconds
88 while (!mtdev_idle(&dev, fd, 5000)) {
89 //extract all available processed events
90 while (mtdev_get(&dev, fd, &ev, 1) > 0) {
91 if (use_event(&ev))
92 print_event(&ev);
93 }
94 }
95 mtdev_close(&dev);
96}
97
98//main function
99int main(int argc, char *argv[])
100{
101 int fd;
102 if (argc < 2) {
103 fprintf(stderr, "Usage: mtdev <device>\n");
104 return -1;
105 }
106 fd = open(argv[1], O_RDONLY | O_NONBLOCK);
107 if (fd < 0) {
108 fprintf(stderr, "error: could not open device\n");
109 return -1;
110 }
111 if (ioctl(fd, EVIOCGRAB, 1)) {
112 fprintf(stderr, "error: could not grab the device\n");
113 return -1;
114 }
115 loop_device(fd);
116 ioctl(fd, EVIOCGRAB, 0);
117 close(fd);
118 return 0;
119}
120```
121
122## mtdev Working with documents
123
124
125Official API http://bitmath.org/code/mtdev/
126
127
128## License
129
130见 [LICENSE](MIT(X11)License).
131
132---
133
134The mtdev library was released under the MIT licence in collaboration with Canonical, Ltd.
README_zh.md
1# mtdev - Multitouch Protocol Translation Library
2
3mtdev是一个独立的库,它将内核MT事件的所有变体转换为信号槽类型B协议。归为mtdev的事件可能来自任何MT设备,具体来说,包括无接触跟踪的TypeA设备、带接触跟踪的TypeA或带触点跟踪的TypeB设备。
4
5作为Multitouch X驱动程序的一部分,大部分mtdev代码自2008年以来就已经存在。通过此软件包,手指跟踪和无缝MT协议处理在免费许可下可用。
6
7
8## 目录结构
9
10```
11README.md 英文说明
12README_zh.md 中文说明
13include/ API定义
14src/ 封装层实现
15README.OpenSource 开源说明
16```
17
18## OpenHarmony如何集成mtdev
19### 1.头文件引入
20```c
21#include <mtdev.h>
22```
23### 2.BUILD.gn添加引用
24```c
25public_deps += ["//third_party/mtdev:libmtdev"]
26```
27### 3.调用mtdev函数过程举例
28```c
29//全年毫秒事件时间
30typedef uint64_t mstime_t;
31
32static int use_event(const struct input_event *ev)
33{
34#if 0
35 return ev->type == EV_ABS && mtdev_is_absmt(ev->code);
36#else
37 return 1;
38#endif
39}
40
41//打印事件
42static void print_event(const struct input_event *ev)
43{
44 static const mstime_t ms = 1000;
45 static int slot;
46 mstime_t evtime = ev->input_event_usec / ms + ev->input_event_sec * ms;
47 if (ev->type == EV_ABS && ev->code == ABS_MT_SLOT)
48 slot = ev->value;
49 fprintf(stderr, "%012llx %02d %01d %04x %d\n",
50 evtime, slot, ev->type, ev->code, ev->value);
51}
52
53#define CHECK(dev, name) \
54 if (mtdev_has_mt_event(dev, name)) \
55 fprintf(stderr, " %s\n", #name)
56
57//检查属性
58static void show_props(const struct mtdev *dev)
59{
60 fprintf(stderr, "supported mt events:\n");
61 CHECK(dev, ABS_MT_SLOT);
62 CHECK(dev, ABS_MT_TOUCH_MAJOR);
63 CHECK(dev, ABS_MT_TOUCH_MINOR);
64 CHECK(dev, ABS_MT_WIDTH_MAJOR);
65 CHECK(dev, ABS_MT_WIDTH_MINOR);
66 CHECK(dev, ABS_MT_ORIENTATION);
67 CHECK(dev, ABS_MT_POSITION_X);
68 CHECK(dev, ABS_MT_POSITION_Y);
69 CHECK(dev, ABS_MT_TOOL_TYPE);
70 CHECK(dev, ABS_MT_BLOB_ID);
71 CHECK(dev, ABS_MT_TRACKING_ID);
72 CHECK(dev, ABS_MT_PRESSURE);
73 CHECK(dev, ABS_MT_DISTANCE);
74}
75
76//创建mtdev,检查prop,获取并打印mt事件
77static void loop_device(int fd)
78{
79 struct mtdev dev;
80 struct input_event ev;
81 int ret = mtdev_open(&dev, fd);
82 if (ret) {
83 fprintf(stderr, "error: could not open device: %d\n", ret);
84 return;
85 }
86 show_props(&dev);
87 //当设备五秒钟未处于非活动状态时
88 while (!mtdev_idle(&dev, fd, 5000)) {
89 //提取所有可被处理的事件
90 while (mtdev_get(&dev, fd, &ev, 1) > 0) {
91 if (use_event(&ev))
92 print_event(&ev);
93 }
94 }
95 mtdev_close(&dev);
96}
97
98//主程序
99int main(int argc, char *argv[])
100{
101 int fd;
102 if (argc < 2) {
103 fprintf(stderr, "Usage: mtdev <device>\n");
104 return -1;
105 }
106 fd = open(argv[1], O_RDONLY | O_NONBLOCK);
107 if (fd < 0) {
108 fprintf(stderr, "error: could not open device\n");
109 return -1;
110 }
111 if (ioctl(fd, EVIOCGRAB, 1)) {
112 fprintf(stderr, "error: could not grab the device\n");
113 return -1;
114 }
115 loop_device(fd);
116 ioctl(fd, EVIOCGRAB, 0);
117 close(fd);
118 return 0;
119}
120```
121
122## mtdev使用文档
123
124
125API官方文档 http://bitmath.org/code/mtdev/
126
127
128## License
129
130见 [LICENSE](MIT(X11)License).
131
132---
133
134The mtdev library was released under the MIT licence in collaboration with Canonical, Ltd.