summaryrefslogtreecommitdiff
path: root/mtdev/test.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-10-12 15:38:43 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-10-12 15:38:43 +0200
commitacea9df3381825a634c000a574f58b4ca5293ee8 (patch)
tree3698bd55f137bc377f1b840e4fb5bf9e446e7250 /mtdev/test.c
parent7380af2c93dc83f4f09e293717d46eadf7799e89 (diff)
Same version, but using the mtdev library.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'mtdev/test.c')
-rw-r--r--mtdev/test.c79
1 files changed, 0 insertions, 79 deletions
diff --git a/mtdev/test.c b/mtdev/test.c
deleted file mode 100644
index 9f73fcd..0000000
--- a/mtdev/test.c
+++ /dev/null
@@ -1,79 +0,0 @@
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
27static 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
38static 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_put(&mtdev, &caps, ev);
57 while (!mtdev_empty(&mtdev)) {
58 mtdev_get(&mtdev, &event);
59 print_event(&event);
60 }
61 }
62 mtdev_destroy(&mtdev);
63}
64
65int 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}