diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/mtdev-mapgen.c | 76 | ||||
| -rw-r--r-- | test/mtdev.c | 95 |
2 files changed, 171 insertions, 0 deletions
diff --git a/test/mtdev-mapgen.c b/test/mtdev-mapgen.c new file mode 100644 index 0000000..823ce96 --- /dev/null +++ b/test/mtdev-mapgen.c | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * mtdev - MT device event converter (MIT license) | ||
| 4 | * | ||
| 5 | * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se> | ||
| 6 | * Copyright (C) 2010 Canonical Ltd. | ||
| 7 | * | ||
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
| 9 | * copy of this software and associated documentation files (the "Software"), | ||
| 10 | * to deal in the Software without restriction, including without limitation | ||
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
| 12 | * and/or sell copies of the Software, and to permit persons to whom the | ||
| 13 | * Software is furnished to do so, subject to the following conditions: | ||
| 14 | * | ||
| 15 | * The above copyright notice and this permission notice (including the next | ||
| 16 | * paragraph) shall be included in all copies or substantial portions of the | ||
| 17 | * Software. | ||
| 18 | * | ||
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| 22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| 25 | * DEALINGS IN THE SOFTWARE. | ||
| 26 | * | ||
| 27 | ****************************************************************************/ | ||
| 28 | |||
| 29 | #include <mtdev-mapping.h> | ||
| 30 | #include <stdio.h> | ||
| 31 | |||
| 32 | #define BIT_DEF(name) \ | ||
| 33 | printf("#define MTDEV_"#name"\t%d\n", \ | ||
| 34 | cabs2mt[ABS_MT_##name] - 1) | ||
| 35 | |||
| 36 | static unsigned int cabs2mt[ABS_CNT]; | ||
| 37 | static unsigned int cmt2abs[MT_ABS_SIZE]; | ||
| 38 | |||
| 39 | void init_caps() | ||
| 40 | { | ||
| 41 | static const int init_abs_map[MT_ABS_SIZE] = MT_SLOT_ABS_EVENTS; | ||
| 42 | int i; | ||
| 43 | for (i = 0; i < MT_ABS_SIZE; i++) { | ||
| 44 | cabs2mt[init_abs_map[i]] = i + 1; | ||
| 45 | cmt2abs[i] = init_abs_map[i]; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | static inline const char *newln(int i, int n) | ||
| 50 | { | ||
| 51 | return i == n - 1 || i % 8 == 7 ? "\n" : ""; | ||
| 52 | } | ||
| 53 | |||
| 54 | int main(int argc, char *argv[]) | ||
| 55 | { | ||
| 56 | int i; | ||
| 57 | init_caps(); | ||
| 58 | printf("static const unsigned int mtdev_map_abs2mt[ABS_CNT] = {\n"); | ||
| 59 | for (i = 0; i < ABS_CNT; i++) | ||
| 60 | printf(" 0x%04x,%s", cabs2mt[i], newln(i, ABS_CNT)); | ||
| 61 | printf("};\n\n"); | ||
| 62 | printf("static const unsigned int mtdev_map_mt2abs[MT_ABS_SIZE] = {\n"); | ||
| 63 | for (i = 0; i < MT_ABS_SIZE; i++) | ||
| 64 | printf(" 0x%04x,%s", cmt2abs[i], newln(i, MT_ABS_SIZE)); | ||
| 65 | printf("};\n\n"); | ||
| 66 | BIT_DEF(TRACKING_ID); | ||
| 67 | BIT_DEF(POSITION_X); | ||
| 68 | BIT_DEF(POSITION_Y); | ||
| 69 | BIT_DEF(TOUCH_MAJOR); | ||
| 70 | BIT_DEF(TOUCH_MINOR); | ||
| 71 | BIT_DEF(WIDTH_MAJOR); | ||
| 72 | BIT_DEF(WIDTH_MINOR); | ||
| 73 | BIT_DEF(ORIENTATION); | ||
| 74 | printf("\n"); | ||
| 75 | return 0; | ||
| 76 | } | ||
diff --git a/test/mtdev.c b/test/mtdev.c new file mode 100644 index 0000000..995a4e2 --- /dev/null +++ b/test/mtdev.c | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * mtdev - MT device event converter (MIT license) | ||
| 4 | * | ||
| 5 | * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se> | ||
| 6 | * Copyright (C) 2010 Canonical Ltd. | ||
| 7 | * | ||
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
| 9 | * copy of this software and associated documentation files (the "Software"), | ||
| 10 | * to deal in the Software without restriction, including without limitation | ||
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
| 12 | * and/or sell copies of the Software, and to permit persons to whom the | ||
| 13 | * Software is furnished to do so, subject to the following conditions: | ||
| 14 | * | ||
| 15 | * The above copyright notice and this permission notice (including the next | ||
| 16 | * paragraph) shall be included in all copies or substantial portions of the | ||
| 17 | * Software. | ||
| 18 | * | ||
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| 22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| 25 | * DEALINGS IN THE SOFTWARE. | ||
| 26 | * | ||
| 27 | ****************************************************************************/ | ||
| 28 | |||
| 29 | #include <mtdev-mapping.h> | ||
| 30 | #include <stdio.h> | ||
| 31 | #include <fcntl.h> | ||
| 32 | |||
| 33 | /* year-proof millisecond event time */ | ||
| 34 | typedef __u64 mstime_t; | ||
| 35 | |||
| 36 | static int use_event(const struct input_event *ev) | ||
| 37 | { | ||
| 38 | #if 0 | ||
| 39 | return ev->type == EV_ABS && mtdev_is_absmt(ev->code); | ||
| 40 | #else | ||
| 41 | return 1; | ||
| 42 | #endif | ||
| 43 | } | ||
| 44 | |||
| 45 | static void print_event(const struct input_event *ev) | ||
| 46 | { | ||
| 47 | static const mstime_t ms = 1000; | ||
| 48 | static int slot; | ||
| 49 | mstime_t evtime = ev->time.tv_usec / ms + ev->time.tv_sec * ms; | ||
| 50 | if (ev->type == EV_ABS && ev->code == ABS_MT_SLOT) | ||
| 51 | slot = ev->value; | ||
| 52 | fprintf(stderr, "%012llx %02d %01d %04x %d\n", | ||
| 53 | evtime, slot, ev->type, ev->code, ev->value); | ||
| 54 | } | ||
| 55 | |||
| 56 | static void loop_device(int fd) | ||
| 57 | { | ||
| 58 | struct mtdev dev; | ||
| 59 | struct input_event ev; | ||
| 60 | int ret = mtdev_open(&dev, fd); | ||
| 61 | if (ret) { | ||
| 62 | fprintf(stderr, "error: could not open device: %d\n", ret); | ||
| 63 | return; | ||
| 64 | } | ||
| 65 | while (mtdev_pull(&dev, fd, 1) > 0) { | ||
| 66 | while (!mtdev_empty(&dev)) { | ||
| 67 | mtdev_get(&dev, &ev); | ||
| 68 | if (use_event(&ev)) | ||
| 69 | print_event(&ev); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | mtdev_close(&dev); | ||
| 73 | } | ||
| 74 | |||
| 75 | int main(int argc, char *argv[]) | ||
| 76 | { | ||
| 77 | int fd; | ||
| 78 | if (argc < 2) { | ||
| 79 | fprintf(stderr, "Usage: mtdev <device>\n"); | ||
| 80 | return -1; | ||
| 81 | } | ||
| 82 | fd = open(argv[1], O_RDONLY); | ||
| 83 | if (fd < 0) { | ||
| 84 | fprintf(stderr, "error: could not open device\n"); | ||
| 85 | return -1; | ||
| 86 | } | ||
| 87 | if (ioctl(fd, EVIOCGRAB, 1)) { | ||
| 88 | fprintf(stderr, "error: could not grab the device\n"); | ||
| 89 | return -1; | ||
| 90 | } | ||
| 91 | loop_device(fd); | ||
| 92 | ioctl(fd, EVIOCGRAB, 0); | ||
| 93 | close(fd); | ||
| 94 | return 0; | ||
| 95 | } | ||
