summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-08-06 21:11:17 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-06 21:11:17 +0200
commit7db9d8d76ff61c4802ac15559dcea6fa54ff567a (patch)
treeb67e040c0abeb0ab1fca72754a767dc9ab851461 /test
initial bzr repo at rev 27
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am9
-rw-r--r--test/grail-gesture.c111
-rw-r--r--test/grail-touch.c88
3 files changed, 208 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..4ccbe0a
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,9 @@
1bin_PROGRAMS = grail-touch grail-gesture
2
3INCLUDES=-I$(top_srcdir)/include/
4
5grail_touch_SOURCES = grail-touch.c
6grail_touch_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev -lm
7
8grail_gesture_SOURCES = grail-gesture.c
9grail_gesture_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev -lm
diff --git a/test/grail-gesture.c b/test/grail-gesture.c
new file mode 100644
index 0000000..16b33ac
--- /dev/null
+++ b/test/grail-gesture.c
@@ -0,0 +1,111 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include <grail.h>
26#include <string.h>
27#include <stdio.h>
28#include <unistd.h>
29#include <fcntl.h>
30
31static grail_mask_t flag_mask[DIM_GRAIL_TYPE_BYTES];
32
33static int tp_get_clients(struct grail *ge,
34 struct grail_client_info *clients, int max_clients,
35 const struct grail_coord *coords, int num_coords,
36 const grail_mask_t *types, int type_bytes)
37{
38 memset(&clients[0], 0, sizeof(clients[0]));
39 clients[0].id.client = 345;
40 clients[0].id.root = 1;
41 clients[0].id.event = 2;
42 clients[0].id.child = 3;
43 memcpy(clients[0].mask, flag_mask, sizeof(flag_mask));
44 return 1;
45}
46
47static void tp_event(struct grail *ge, const struct input_event *ev)
48{
49 if (!grail_mask_get(flag_mask, GRAIL_TYPE_POINTER))
50 return;
51 fprintf(stderr, "event %d 0x%x %d\n", ev->type, ev->code, ev->value);
52}
53
54static void tp_gesture(struct grail *ge, const struct grail_event *ev)
55{
56 int i;
57 fprintf(stderr, "gesture %d %d %d %d - %f %f %d - %d\n",
58 ev->type, ev->id, ev->client_id.client, ev->client_id.event,
59 ev->pos.x, ev->pos.y, ev->ntouch,
60 ev->status);
61 for (i = 0; i < ev->nprop; i++)
62 fprintf(stderr, "\t%d: %f\n", i, ev->prop[i]);
63}
64
65static void loop_device(struct grail *ge, int fd)
66{
67 while (!grail_idle(ge, fd, 5000))
68 grail_pull(ge, fd);
69}
70
71int main(int argc, char *argv[])
72{
73 struct grail ge;
74 int i, fd;
75
76 if (argc < 3) {
77 fprintf(stderr, "Usage: %s <mask> <device>\n", argv[0]);
78 return -1;
79 }
80
81 memset(&ge, 0, sizeof(ge));
82 ge.get_clients = tp_get_clients;
83 ge.event = tp_event;
84 ge.gesture = tp_gesture;
85
86 unsigned long mask = strtoull(argv[1], 0, 0);
87 for (i = 0; i < DIM_GRAIL_TYPE; i++)
88 if ((mask >> i) & 1)
89 grail_mask_set(flag_mask, i);
90
91 fd = open(argv[2], O_RDONLY | O_NONBLOCK);
92 if (fd < 0) {
93 fprintf(stderr, "error: could not open device\n");
94 return -1;
95 }
96 if (ioctl(fd, EVIOCGRAB, 1)) {
97 fprintf(stderr, "error: could not grab the device\n");
98 return -1;
99 }
100
101 if (grail_open(&ge, fd)) {
102 fprintf(stderr, "error: could not open touch device\n");
103 return -1;
104 }
105 loop_device(&ge, fd);
106 grail_close(&ge, fd);
107
108 ioctl(fd, EVIOCGRAB, 0);
109 close(fd);
110 return 0;
111}
diff --git a/test/grail-touch.c b/test/grail-touch.c
new file mode 100644
index 0000000..bed31c3
--- /dev/null
+++ b/test/grail-touch.c
@@ -0,0 +1,88 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include <grail-touch.h>
26#include <string.h>
27#include <stdio.h>
28#include <unistd.h>
29#include <fcntl.h>
30
31static void tp_event(struct touch_engine *engine,
32 const struct input_event *ev)
33{
34 fprintf(stderr, "event %d 0x%x %d\n", ev->type, ev->code, ev->value);
35}
36
37static void tp_sync(struct touch_engine *engine,
38 const struct input_event *syn)
39{
40 struct touch_frame *frame = &engine->frame;
41 int i, j;
42 for (i = 0; i < frame->nactive; i++) {
43 struct touch *t = frame->active[i];
44 fprintf(stderr, "touch %d %d\n", i, t->slot);
45 for (j = 0; j < DIM_TOUCH_PROP; j++)
46 fprintf(stderr, " %d\n", t->prop[j]);
47 }
48 fprintf(stderr, "sync %d %lld %d %d\n",
49 frame->nactive, frame->time, frame->ncreate, frame->ndestroy);
50}
51
52static void loop_device(struct touch_dev *dev, int fd)
53{
54 struct touch_engine engine;
55 touch_engine_init(&engine, tp_event, tp_sync, 0);
56 touch_engine_attach(&engine, dev);
57 while (!touch_dev_idle(dev, fd, 5000))
58 touch_dev_pull(dev, fd);
59 touch_engine_detach(&engine, dev);
60}
61
62int main(int argc, char *argv[])
63{
64 struct touch_dev dev;
65 int fd;
66 if (argc < 2) {
67 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
68 return -1;
69 }
70 fd = open(argv[1], O_RDONLY | O_NONBLOCK);
71 if (fd < 0) {
72 fprintf(stderr, "error: could not open device\n");
73 return -1;
74 }
75 if (ioctl(fd, EVIOCGRAB, 1)) {
76 fprintf(stderr, "error: could not grab the device\n");
77 return -1;
78 }
79 if (touch_dev_open(&dev, fd)) {
80 fprintf(stderr, "error: could not open touch device\n");
81 return -1;
82 }
83 loop_device(&dev, fd);
84 touch_dev_close(&dev, fd);
85 ioctl(fd, EVIOCGRAB, 0);
86 close(fd);
87 return 0;
88}