diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2010-07-19 13:09:10 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-07-19 13:09:10 +0200 |
| commit | d2a8e0bfda364730ba5c06be4adc783f9a889073 (patch) | |
| tree | 30d57c0a2db51bfd4e4e36bc1f26539df9e13239 /test/mtdev.c | |
| parent | a6f1a4dd2c14908c6602c4c2438ef4b5cb86de99 (diff) | |
Change test program name to mtdev-test
In order to simplify packaging, rename the current mtdev
device test program to mtdev-test.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'test/mtdev.c')
| -rw-r--r-- | test/mtdev.c | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/test/mtdev.c b/test/mtdev.c deleted file mode 100644 index b8e56d5..0000000 --- a/test/mtdev.c +++ /dev/null | |||
| @@ -1,97 +0,0 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * mtdev - Multitouch Protocol Translation Library (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.h> | ||
| 30 | #include <stdio.h> | ||
| 31 | #include <unistd.h> | ||
| 32 | #include <fcntl.h> | ||
| 33 | |||
| 34 | /* year-proof millisecond event time */ | ||
| 35 | typedef __u64 mstime_t; | ||
| 36 | |||
| 37 | static int use_event(const struct input_event *ev) | ||
| 38 | { | ||
| 39 | #if 0 | ||
| 40 | return ev->type == EV_ABS && mtdev_is_absmt(ev->code); | ||
| 41 | #else | ||
| 42 | return 1; | ||
| 43 | #endif | ||
| 44 | } | ||
| 45 | |||
| 46 | static void print_event(const struct input_event *ev) | ||
| 47 | { | ||
| 48 | static const mstime_t ms = 1000; | ||
| 49 | static int slot; | ||
| 50 | mstime_t evtime = ev->time.tv_usec / ms + ev->time.tv_sec * ms; | ||
| 51 | if (ev->type == EV_ABS && ev->code == ABS_MT_SLOT) | ||
| 52 | slot = ev->value; | ||
| 53 | fprintf(stderr, "%012llx %02d %01d %04x %d\n", | ||
| 54 | evtime, slot, ev->type, ev->code, ev->value); | ||
| 55 | } | ||
| 56 | |||
| 57 | static void loop_device(int fd) | ||
| 58 | { | ||
| 59 | struct mtdev dev; | ||
| 60 | struct input_event ev; | ||
| 61 | int ret = mtdev_open(&dev, fd); | ||
| 62 | if (ret) { | ||
| 63 | fprintf(stderr, "error: could not open device: %d\n", ret); | ||
| 64 | return; | ||
| 65 | } | ||
| 66 | /* while the device has not been inactive for five seconds */ | ||
| 67 | while (!mtdev_idle(&dev, fd, 5000)) { | ||
| 68 | /* extract all available processed events */ | ||
| 69 | while (mtdev_get(&dev, fd, &ev, 1) > 0) { | ||
| 70 | if (use_event(&ev)) | ||
| 71 | print_event(&ev); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | mtdev_close(&dev); | ||
| 75 | } | ||
| 76 | |||
| 77 | int main(int argc, char *argv[]) | ||
| 78 | { | ||
| 79 | int fd; | ||
| 80 | if (argc < 2) { | ||
| 81 | fprintf(stderr, "Usage: mtdev <device>\n"); | ||
| 82 | return -1; | ||
| 83 | } | ||
| 84 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | ||
| 85 | if (fd < 0) { | ||
| 86 | fprintf(stderr, "error: could not open device\n"); | ||
| 87 | return -1; | ||
| 88 | } | ||
| 89 | if (ioctl(fd, EVIOCGRAB, 1)) { | ||
| 90 | fprintf(stderr, "error: could not grab the device\n"); | ||
| 91 | return -1; | ||
| 92 | } | ||
| 93 | loop_device(fd); | ||
| 94 | ioctl(fd, EVIOCGRAB, 0); | ||
| 95 | close(fd); | ||
| 96 | return 0; | ||
| 97 | } | ||
