From baf35a3b761172aeeefd7e761b7e29995a37a9e8 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Thu, 19 Aug 2010 21:17:42 +0200 Subject: 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 --- include/grail.h | 38 ++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 1 + src/grail-event.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/grail-gesture.c | 12 +++++++++++- 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/grail-event.c 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 { float x, y; }; +/** + * struct grail_contact - MT event information in bounding box units + * @id: Contact tracking id + * @tool_type: Tool type (ABS_MT_TOOL_TYPE) + * @pos: Position of contact (bbox units) + * @touch_major: Major axis of contact shape (bbox units) + * @touch_minor: Minor axis of contact shape (bbox units) + * @width_major: Major axis of perimeter (bbox units) + * @width_minor: Minor axis of perimeter (bbox units) + * @angle: Angle of orientation (vertical: 0 horizontal: +-M_PI_2) + * @pressure: Pressure of contact (min: 0 max: 1) + * + * Depending on the native support of the underlying device, some or all of + * the listed properties may be computed. + */ +struct grail_contact { + int id; + int tool_type; + struct grail_coord pos; + float touch_major; + float touch_minor; + float width_major; + float width_minor; + float angle; + float pressure; +}; /** * struct grail_client_id - Gesture client information @@ -228,4 +254,16 @@ void grail_filter_abs_events(struct grail *ge, int usage); void grail_get_units(const struct grail *ge, struct grail_coord *min, struct grail_coord *max); +/** + * grail_get_contacts - get current contact state + * @ge: the grail device in use + * @touch: array of contacts to be filled in + * @max_touch: maximum number of contacts supported by the array + * + * Extract the contact state as currently seen by grail. + * + */ +int grail_get_contacts(const struct grail *ge, + struct grail_contact *touch, int max_touch); + #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 = \ gestures-tapping.c \ grail-recognizer.c \ grail-recognizer.h \ + grail-event.c \ grail-api.c AM_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 @@ +/***************************************************************************** + * + * grail - Gesture Recognition And Instantiation Library + * + * Copyright (C) 2010 Canonical Ltd. + * Copyright (C) 2010 Henrik Rydberg + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + ****************************************************************************/ + +#include "grail-inserter.h" +#include "grail-impl.h" +#include + +int grail_get_contacts(const struct grail *ge, + struct grail_contact *touch, int max_touch) +{ + const struct touch_dev *dev = &ge->impl->dev; + const struct gesture_inserter *gin = ge->gin; + const struct touch_frame *frame = &dev->frame; + int i; + if (frame->nactive < max_touch) + max_touch = frame->nactive; + for (i = 0; i < max_touch; i++) { + struct grail_contact *t = &touch[i]; + const struct touch *ct = frame->active[i]; + t->id = ct->id; + t->tool_type = ct->tool_type; + t->pos.x = gin_prop_x(gin, ct->x); + t->pos.y = gin_prop_y(gin, ct->y); + t->touch_major = gin->scale_r * ct->touch_major; + t->touch_minor = gin->scale_r * ct->touch_minor; + t->width_major = gin->scale_r * ct->width_major; + t->width_minor = gin->scale_r * ct->width_minor; + t->angle = touch_angle(dev, ct->orientation); + t->pressure = touch_pressure(dev, ct->pressure); + } + return max_touch; +} 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) static void tp_gesture(struct grail *ge, const struct grail_event *ev) { - int i; + struct grail_contact touch[32]; + int i, ntouch; fprintf(stderr, "gesture %d %d %d %d - %f %f %d - %d\n", ev->type, ev->id, ev->client_id.client, ev->client_id.event, ev->pos.x, ev->pos.y, ev->ntouch, ev->status); + ntouch = grail_get_contacts(ge, touch, 32); + for (i = 0; i < ntouch; i++) { + const struct grail_contact *t = &touch[i]; + fprintf(stderr, "\t%d: %d %d\n", i, t->id, t->tool_type); + fprintf(stderr, "\t %f %f\n", t->pos.x, t->pos.y); + fprintf(stderr, "\t %f %f %f %f\n", t->touch_major, + t->touch_minor, t->width_major, t->width_minor); + fprintf(stderr, "\t %f %f\n", t->angle, t->pressure); + } for (i = 0; i < ev->nprop; i++) fprintf(stderr, "\t%d: %f\n", i, ev->prop[i]); } -- cgit v1.2.3