diff options
Diffstat (limited to 'mtdev/test.c')
| -rw-r--r-- | mtdev/test.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/mtdev/test.c b/mtdev/test.c new file mode 100644 index 0000000..bbe4829 --- /dev/null +++ b/mtdev/test.c | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | /*************************************************************************** | ||
| 2 | * | ||
| 3 | * Multitouch X driver | ||
| 4 | * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | * | ||
| 20 | **************************************************************************/ | ||
| 21 | |||
| 22 | #include "mtdev-iobuf.h" | ||
| 23 | #include "mtdev.h" | ||
| 24 | #include <fcntl.h> | ||
| 25 | #include <xbypass.h> | ||
| 26 | |||
| 27 | static void print_event(const struct input_event *ev) | ||
| 28 | { | ||
| 29 | static const mstime_t ms = 1000; | ||
| 30 | static int slot; | ||
| 31 | mstime_t evtime = ev->time.tv_usec / ms + ev->time.tv_sec * ms; | ||
| 32 | if (ev->type == EV_ABS && ev->code == ABS_MT_SLOT) | ||
| 33 | slot = ev->value; | ||
| 34 | fprintf(stderr, "%012llx: %04d: %04x %04x %d\n", | ||
| 35 | evtime, slot, ev->type, ev->code, ev->value); | ||
| 36 | } | ||
| 37 | |||
| 38 | static void loop_device(int fd) | ||
| 39 | { | ||
| 40 | struct Capabilities caps; | ||
| 41 | struct IOBuffer iobuf; | ||
| 42 | struct MTDev mtdev; | ||
| 43 | const struct input_event *ev; | ||
| 44 | struct input_event event; | ||
| 45 | if (read_capabilities(&caps, fd)) { | ||
| 46 | fprintf(stderr, "error: could not read device capabilities\n"); | ||
| 47 | return; | ||
| 48 | } | ||
| 49 | output_capabilities(&caps); | ||
| 50 | if (mtdev_init(&mtdev, &caps)) { | ||
| 51 | fprintf(stderr, "error: could not initialize device\n"); | ||
| 52 | return; | ||
| 53 | } | ||
| 54 | init_iobuf(&iobuf); | ||
| 55 | while (ev = get_iobuf_event(&iobuf, fd)) { | ||
| 56 | mtdev_push(&mtdev, &caps, ev); | ||
| 57 | while (!mtdev_empty(&mtdev)) { | ||
| 58 | mtdev_pop(&mtdev, &event); | ||
| 59 | print_event(&event); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | mtdev_destroy(&mtdev); | ||
| 63 | } | ||
| 64 | |||
| 65 | int main(int argc, char *argv[]) | ||
| 66 | { | ||
| 67 | if (argc < 2) { | ||
| 68 | fprintf(stderr, "Usage: test <mtdev>\n"); | ||
| 69 | return -1; | ||
| 70 | } | ||
| 71 | int fd = open(argv[1], O_RDONLY); | ||
| 72 | if (fd < 0) { | ||
| 73 | fprintf(stderr, "error: could not open file\n"); | ||
| 74 | return -1; | ||
| 75 | } | ||
| 76 | loop_device(fd); | ||
| 77 | close(fd); | ||
| 78 | return 0; | ||
| 79 | } | ||
