summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-08-19 21:17:42 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-19 21:17:42 +0200
commitbaf35a3b761172aeeefd7e761b7e29995a37a9e8 (patch)
tree93c3a4f8e139b70db8c42d8b69e3bbc80e05a6b7
parentbb964fa8bcebee82093cec8da8081eb1366aea96 (diff)
Add grail_contact and a method to retrieve the current contacts
This patch adds the possibility to extract the current set of contacts from the grail state. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
-rw-r--r--include/grail.h38
-rw-r--r--src/Makefile.am1
-rw-r--r--src/grail-event.c51
-rw-r--r--test/grail-gesture.c12
4 files changed, 101 insertions, 1 deletions
diff --git a/include/grail.h b/include/grail.h
index ae3a73f..40cf22f 100644
--- a/include/grail.h
+++ b/include/grail.h
@@ -49,6 +49,32 @@ struct grail_coord {
49 float x, y; 49 float x, y;
50}; 50};
51 51
52/**
53 * struct grail_contact - MT event information in bounding box units
54 * @id: Contact tracking id
55 * @tool_type: Tool type (ABS_MT_TOOL_TYPE)
56 * @pos: Position of contact (bbox units)
57 * @touch_major: Major axis of contact shape (bbox units)
58 * @touch_minor: Minor axis of contact shape (bbox units)
59 * @width_major: Major axis of perimeter (bbox units)
60 * @width_minor: Minor axis of perimeter (bbox units)
61 * @angle: Angle of orientation (vertical: 0 horizontal: +-M_PI_2)
62 * @pressure: Pressure of contact (min: 0 max: 1)
63 *
64 * Depending on the native support of the underlying device, some or all of
65 * the listed properties may be computed.
66 */
67struct grail_contact {
68 int id;
69 int tool_type;
70 struct grail_coord pos;
71 float touch_major;
72 float touch_minor;
73 float width_major;
74 float width_minor;
75 float angle;
76 float pressure;
77};
52 78
53/** 79/**
54 * struct grail_client_id - Gesture client information 80 * struct grail_client_id - Gesture client information
@@ -228,4 +254,16 @@ void grail_filter_abs_events(struct grail *ge, int usage);
228void grail_get_units(const struct grail *ge, 254void grail_get_units(const struct grail *ge,
229 struct grail_coord *min, struct grail_coord *max); 255 struct grail_coord *min, struct grail_coord *max);
230 256
257/**
258 * grail_get_contacts - get current contact state
259 * @ge: the grail device in use
260 * @touch: array of contacts to be filled in
261 * @max_touch: maximum number of contacts supported by the array
262 *
263 * Extract the contact state as currently seen by grail.
264 *
265 */
266int grail_get_contacts(const struct grail *ge,
267 struct grail_contact *touch, int max_touch);
268
231#endif 269#endif
diff --git a/src/Makefile.am b/src/Makefile.am
index eec0eeb..06a33fa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,6 +21,7 @@ libutouch_grail_la_SOURCES = \
21 gestures-tapping.c \ 21 gestures-tapping.c \
22 grail-recognizer.c \ 22 grail-recognizer.c \
23 grail-recognizer.h \ 23 grail-recognizer.h \
24 grail-event.c \
24 grail-api.c 25 grail-api.c
25 26
26AM_CFLAGS = $(CWARNFLAGS) 27AM_CFLAGS = $(CWARNFLAGS)
diff --git a/src/grail-event.c b/src/grail-event.c
new file mode 100644
index 0000000..6479cc0
--- /dev/null
+++ b/src/grail-event.c
@@ -0,0 +1,51 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 ****************************************************************************/
22
23#include "grail-inserter.h"
24#include "grail-impl.h"
25#include <math.h>
26
27int grail_get_contacts(const struct grail *ge,
28 struct grail_contact *touch, int max_touch)
29{
30 const struct touch_dev *dev = &ge->impl->dev;
31 const struct gesture_inserter *gin = ge->gin;
32 const struct touch_frame *frame = &dev->frame;
33 int i;
34 if (frame->nactive < max_touch)
35 max_touch = frame->nactive;
36 for (i = 0; i < max_touch; i++) {
37 struct grail_contact *t = &touch[i];
38 const struct touch *ct = frame->active[i];
39 t->id = ct->id;
40 t->tool_type = ct->tool_type;
41 t->pos.x = gin_prop_x(gin, ct->x);
42 t->pos.y = gin_prop_y(gin, ct->y);
43 t->touch_major = gin->scale_r * ct->touch_major;
44 t->touch_minor = gin->scale_r * ct->touch_minor;
45 t->width_major = gin->scale_r * ct->width_major;
46 t->width_minor = gin->scale_r * ct->width_minor;
47 t->angle = touch_angle(dev, ct->orientation);
48 t->pressure = touch_pressure(dev, ct->pressure);
49 }
50 return max_touch;
51}
diff --git a/test/grail-gesture.c b/test/grail-gesture.c
index 762d3df..d30e713 100644
--- a/test/grail-gesture.c
+++ b/test/grail-gesture.c
@@ -53,11 +53,21 @@ static void tp_event(struct grail *ge, const struct input_event *ev)
53 53
54static void tp_gesture(struct grail *ge, const struct grail_event *ev) 54static void tp_gesture(struct grail *ge, const struct grail_event *ev)
55{ 55{
56 int i; 56 struct grail_contact touch[32];
57 int i, ntouch;
57 fprintf(stderr, "gesture %d %d %d %d - %f %f %d - %d\n", 58 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->type, ev->id, ev->client_id.client, ev->client_id.event,
59 ev->pos.x, ev->pos.y, ev->ntouch, 60 ev->pos.x, ev->pos.y, ev->ntouch,
60 ev->status); 61 ev->status);
62 ntouch = grail_get_contacts(ge, touch, 32);
63 for (i = 0; i < ntouch; i++) {
64 const struct grail_contact *t = &touch[i];
65 fprintf(stderr, "\t%d: %d %d\n", i, t->id, t->tool_type);
66 fprintf(stderr, "\t %f %f\n", t->pos.x, t->pos.y);
67 fprintf(stderr, "\t %f %f %f %f\n", t->touch_major,
68 t->touch_minor, t->width_major, t->width_minor);
69 fprintf(stderr, "\t %f %f\n", t->angle, t->pressure);
70 }
61 for (i = 0; i < ev->nprop; i++) 71 for (i = 0; i < ev->nprop; i++)
62 fprintf(stderr, "\t%d: %f\n", i, ev->prop[i]); 72 fprintf(stderr, "\t%d: %f\n", i, ev->prop[i]);
63} 73}