summaryrefslogtreecommitdiff
path: root/src/touch-engine.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@bitmath.org>2010-07-13 11:26:46 +0200
committerHenrik Rydberg <rydberg@bitmath.org>2010-07-13 11:26:46 +0200
commit3b837806891de6cf77d4d74d04567e7e68c82fc0 (patch)
tree88073a81fa5be071f52a0999134fbd93d2881819 /src/touch-engine.c
Gesture Recognition And Instantiation Library (grail)
The aim of this first commit is to get down to hard testing of concepts, and the library currently has two test programs, touch and grail, which can be run on commandline. Touch tests the touch interface, and grail tests the gesture interface. Expect thinking errors and some glitches. Other than that, the code runs fine. Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'src/touch-engine.c')
-rw-r--r--src/touch-engine.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/touch-engine.c b/src/touch-engine.c
new file mode 100644
index 0000000..b6774f3
--- /dev/null
+++ b/src/touch-engine.c
@@ -0,0 +1,126 @@
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 <touch-engine.h>
26#include <string.h>
27
28static void tp_event(struct touch_dev *dev, const struct input_event *ev)
29{
30}
31
32static void update_frame(struct touch_frame *frame,
33 int slot, int active,
34 const touch_prop_mask_t *mask,
35 const touch_prop_t *prop)
36{
37 struct touch *touch = &frame->touch[slot];
38 touch->active = active;
39 if (mask && prop) {
40 for (int i = 0; i < DIM_TOUCH_PROP; i++)
41 if (has_prop(mask, i))
42 touch->prop[i] = prop[i];
43 }
44}
45
46static void finalize_frame(struct touch_frame *frame)
47{
48 int last = -1;
49 frame->ntouch = 0;
50 frame->slot = -1;
51 for (int i = 0; i < DIM_TOUCH_PROP; i++) {
52 frame->touch[i].next = -1;
53 if (frame->touch[i].active) {
54 if (last < 0)
55 frame->slot = i;
56 else
57 frame->touch[last].next = i;
58 last = i;
59 frame->ntouch++;
60 }
61 }
62}
63
64static void tp_create(struct touch_dev *dev, int slot,
65 const touch_prop_mask_t *mask, const touch_prop_t *prop)
66{
67 struct touch_engine *engine = dev->priv;
68 if (engine)
69 update_frame(&engine->frame, slot, 1, mask, prop);
70}
71
72static void tp_modify(struct touch_dev *dev, int slot,
73 const touch_prop_mask_t *mask, const touch_prop_t *prop)
74{
75 struct touch_engine *engine = dev->priv;
76 if (engine)
77 update_frame(&engine->frame, slot, 1, mask, prop);
78}
79
80static void tp_destroy(struct touch_dev *dev, int slot)
81{
82 struct touch_engine *engine = dev->priv;
83 if (engine)
84 update_frame(&engine->frame, slot, 0, 0, 0);
85}
86
87static void tp_sync(struct touch_dev *dev, touch_time_t time)
88{
89 struct touch_engine *engine = dev->priv;
90 if (engine) {
91 finalize_frame(&engine->frame);
92 if (engine->sync)
93 engine->sync(engine, time);
94 }
95}
96
97void touch_engine_init(struct touch_engine *engine,
98 void (*sync)(struct touch_engine *engine,
99 touch_time_t time),
100 void *priv)
101{
102 memset(engine, 0, sizeof(*engine));
103 engine->sync = sync;
104 engine->priv = priv;
105}
106
107void touch_engine_attach(struct touch_engine *engine, struct touch_dev *dev)
108{
109 dev->priv = engine;
110 dev->event = tp_event;
111 dev->create = tp_create;
112 dev->modify = tp_modify;
113 dev->destroy = tp_destroy;
114 dev->sync = tp_sync;
115}
116
117void touch_engine_detach(struct touch_engine *engine, struct touch_dev *dev)
118{
119 dev->sync = 0;
120 dev->destroy = 0;
121 dev->modify = 0;
122 dev->create = 0;
123 dev->event = 0;
124 dev->priv = 0;
125}
126