diff options
| author | Henrik Rydberg <rydberg@bitmath.org> | 2010-07-29 15:54:31 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-08-05 22:48:38 +0200 |
| commit | e0eb1015bf30fd0913db571b000ba6a83ea22660 (patch) | |
| tree | a3d62152066cfb8521c80806596a4fb0fe322014 /test | |
| parent | b76660d71e2ea77752025089bd71deffad64e325 (diff) | |
Split the code into recognizer and inserter
Refactor code to make more room for gesture recognition. Also simplify
public headers.
Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'test')
| -rw-r--r-- | test/Makefile.am | 5 | ||||
| -rw-r--r-- | test/evlink.c | 96 | ||||
| -rw-r--r-- | test/grail.c | 154 |
3 files changed, 36 insertions, 219 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index a24f615..c8404f8 100644 --- a/test/Makefile.am +++ b/test/Makefile.am | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | noinst_PROGRAMS = touch grail evlink | 1 | noinst_PROGRAMS = touch grail |
| 2 | 2 | ||
| 3 | INCLUDES=-I$(top_srcdir)/include/ | 3 | INCLUDES=-I$(top_srcdir)/include/ |
| 4 | 4 | ||
| @@ -7,6 +7,3 @@ touch_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev | |||
| 7 | 7 | ||
| 8 | grail_SOURCES = grail.c | 8 | grail_SOURCES = grail.c |
| 9 | grail_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev | 9 | grail_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev |
| 10 | |||
| 11 | evlink_SOURCES = evlink.c | ||
| 12 | evlink_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev | ||
diff --git a/test/evlink.c b/test/evlink.c deleted file mode 100644 index bef5e22..0000000 --- a/test/evlink.c +++ /dev/null | |||
| @@ -1,96 +0,0 @@ | |||
| 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 | |||
| 31 | static int tp_get_clients(int x, int y, int screen, | ||
| 32 | grail_clientid_t *clients, int nclients) | ||
| 33 | { | ||
| 34 | return 0; | ||
| 35 | } | ||
| 36 | |||
| 37 | static void tp_event(struct grail *ge, const struct input_event *ev) | ||
| 38 | { | ||
| 39 | fprintf(stderr, "event %d %d %d\n", ev->type, ev->code, ev->value); | ||
| 40 | } | ||
| 41 | |||
| 42 | static void tp_gesture(struct grail *ge, const struct grail_event *ev) | ||
| 43 | { | ||
| 44 | fprintf(stderr, "gesture %d %d\n", ev->type, ev->id); | ||
| 45 | } | ||
| 46 | |||
| 47 | static void loop_device(struct grail *ge, int fd) | ||
| 48 | { | ||
| 49 | while (!grail_idle(ge, fd, 5000)) | ||
| 50 | grail_pull(ge, fd); | ||
| 51 | } | ||
| 52 | |||
| 53 | #if 0 | ||
| 54 | void grail_add_client(struct grail *ge, grail_clientid_t id, | ||
| 55 | const int *types, const int *priority, int ntypes); | ||
| 56 | void grail_remove_client(struct grail *ge, grail_clientid_t id); | ||
| 57 | |||
| 58 | #endif | ||
| 59 | |||
| 60 | |||
| 61 | int main(int argc, char *argv[]) | ||
| 62 | { | ||
| 63 | struct grail ge; | ||
| 64 | int fd; | ||
| 65 | |||
| 66 | if (argc < 2) { | ||
| 67 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); | ||
| 68 | return -1; | ||
| 69 | } | ||
| 70 | |||
| 71 | memset(&ge, 0, sizeof(ge)); | ||
| 72 | ge.get_clients = tp_get_clients; | ||
| 73 | ge.event = tp_event; | ||
| 74 | ge.gesture = tp_gesture; | ||
| 75 | |||
| 76 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | ||
| 77 | if (fd < 0) { | ||
| 78 | fprintf(stderr, "error: could not open device\n"); | ||
| 79 | return -1; | ||
| 80 | } | ||
| 81 | if (ioctl(fd, EVIOCGRAB, 1)) { | ||
| 82 | fprintf(stderr, "error: could not grab the device\n"); | ||
| 83 | return -1; | ||
| 84 | } | ||
| 85 | |||
| 86 | if (grail_open(&ge, fd)) { | ||
| 87 | fprintf(stderr, "error: could not open touch device\n"); | ||
| 88 | return -1; | ||
| 89 | } | ||
| 90 | loop_device(&ge, fd); | ||
| 91 | grail_close(&ge, fd); | ||
| 92 | |||
| 93 | ioctl(fd, EVIOCGRAB, 0); | ||
| 94 | close(fd); | ||
| 95 | return 0; | ||
| 96 | } | ||
diff --git a/test/grail.c b/test/grail.c index e22ffd8..85c5bd4 100644 --- a/test/grail.c +++ b/test/grail.c | |||
| @@ -22,146 +22,60 @@ | |||
| 22 | * | 22 | * |
| 23 | ****************************************************************************/ | 23 | ****************************************************************************/ |
| 24 | 24 | ||
| 25 | #include <grail-gesture.h> | 25 | #include <grail.h> |
| 26 | #include <string.h> | 26 | #include <string.h> |
| 27 | #include <stdio.h> | 27 | #include <stdio.h> |
| 28 | #include <unistd.h> | 28 | #include <unistd.h> |
| 29 | #include <fcntl.h> | 29 | #include <fcntl.h> |
| 30 | 30 | ||
| 31 | struct gesture_handler { | 31 | static int tp_get_clients(struct grail *ge, |
| 32 | struct touch_frame frame; | 32 | struct grail_client_info *clients, int max_clients, |
| 33 | struct gesture_client client; | 33 | const struct grail_coord *coords, int num_coords, |
| 34 | struct gesture_dev dev; | 34 | const grail_mask_t *types) |
| 35 | touch_time_t last_scroll; | ||
| 36 | }; | ||
| 37 | |||
| 38 | static void gh_gesture(struct gesture_client *client, | ||
| 39 | const struct gesture_event *ev) | ||
| 40 | { | ||
| 41 | int i; | ||
| 42 | fprintf(stderr, "gesture %d %lld\n", | ||
| 43 | ev->type, ev->time); | ||
| 44 | switch (ev->type) { | ||
| 45 | case GE_MOVE: | ||
| 46 | fprintf(stderr, " %d\n", ev->prop[0]); | ||
| 47 | fprintf(stderr, " %d\n", ev->prop[1]); | ||
| 48 | break; | ||
| 49 | case GE_VSCROLL: | ||
| 50 | fprintf(stderr, " %d\n", ev->prop[0]); | ||
| 51 | break; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | static void gh_init(struct gesture_handler *gh) | ||
| 56 | { | 35 | { |
| 57 | memset(gh, 0, sizeof(*gh)); | 36 | memset(&clients[0], 0, sizeof(clients[0])); |
| 58 | gedev_init(&gh->dev, 0); | 37 | clients[0].id.client = 345; |
| 59 | client_init(&gh->client, gh); | 38 | clients[0].id.root = 1; |
| 60 | gh->client.gesture = gh_gesture; | 39 | clients[0].id.event = 2; |
| 61 | gh->client.priority[GE_MOVE] = 1; | 40 | clients[0].id.child = 3; |
| 62 | gh->client.priority[GE_VSCROLL] = 2; | 41 | clients[0].mask[0] = 3; |
| 63 | gedev_attach_client(&gh->dev, &gh->client); | 42 | return 1; |
| 64 | } | 43 | } |
| 65 | 44 | ||
| 66 | static void gh_handle(struct gesture_handler *gh, | 45 | static void tp_event(struct grail *ge, const struct input_event *ev) |
| 67 | const struct touch_frame *frame, | ||
| 68 | touch_time_t time) | ||
| 69 | { | 46 | { |
| 70 | struct gesture_flag flag; | 47 | fprintf(stderr, "event %d %d %d\n", ev->type, ev->code, ev->value); |
| 71 | struct gesture_event ev; | ||
| 72 | if (frame->ntouch == 1 || frame->ntouch == 2) { | ||
| 73 | flag.type = GE_MOVE; | ||
| 74 | flag.time = time; | ||
| 75 | flag.state = GS_BEGIN; | ||
| 76 | gedev_flag(&gh->dev, &flag); | ||
| 77 | |||
| 78 | ev.type = GE_MOVE; | ||
| 79 | ev.time = time; | ||
| 80 | ev.prop[0] = | ||
| 81 | frame->touch[0].prop[TP_POS_X] - | ||
| 82 | gh->frame.touch[0].prop[TP_POS_X]; | ||
| 83 | ev.prop[1] = | ||
| 84 | frame->touch[0].prop[TP_POS_Y] - | ||
| 85 | gh->frame.touch[0].prop[TP_POS_Y]; | ||
| 86 | if (ev.prop[0] || ev.prop[1]) | ||
| 87 | gedev_event(&gh->dev, &ev); | ||
| 88 | |||
| 89 | flag.time = time + 1; | ||
| 90 | flag.state = GS_END; | ||
| 91 | gedev_flag(&gh->dev, &flag); | ||
| 92 | } | ||
| 93 | if (frame->ntouch == 2) { | ||
| 94 | flag.type = GE_VSCROLL; | ||
| 95 | flag.time = time; | ||
| 96 | flag.state = GS_BEGIN; | ||
| 97 | gedev_flag(&gh->dev, &flag); | ||
| 98 | |||
| 99 | ev.type = GE_VSCROLL; | ||
| 100 | ev.time = time; | ||
| 101 | ev.prop[0] = | ||
| 102 | frame->touch[0].prop[TP_POS_Y] - | ||
| 103 | gh->frame.touch[0].prop[TP_POS_Y]; | ||
| 104 | |||
| 105 | if (ev.prop[0]) | ||
| 106 | gedev_event(&gh->dev, &ev); | ||
| 107 | |||
| 108 | if (time > gh->last_scroll + 100) { | ||
| 109 | flag.time = time + 1; | ||
| 110 | flag.state = GS_END; | ||
| 111 | gedev_flag(&gh->dev, &flag); | ||
| 112 | gh->last_scroll = time; | ||
| 113 | } | ||
| 114 | } else { | ||
| 115 | flag.type = GE_VSCROLL; | ||
| 116 | flag.time = time; | ||
| 117 | flag.state = GS_CANCEL; | ||
| 118 | gedev_flag(&gh->dev, &flag); | ||
| 119 | } | ||
| 120 | gedev_sync(&gh->dev); | ||
| 121 | gh->frame = *frame; | ||
| 122 | } | 48 | } |
| 123 | 49 | ||
| 124 | static void gh_destroy(struct gesture_handler *gh) | 50 | static void tp_gesture(struct grail *ge, const struct grail_event *ev) |
| 125 | { | 51 | { |
| 126 | gedev_detach_client(&gh->dev, &gh->client); | 52 | fprintf(stderr, "gesture %d %d %d %d: %d %d\n", |
| 127 | client_destroy(&gh->client); | 53 | ev->type, ev->id, |
| 128 | gedev_destroy(&gh->dev); | 54 | ev->client_id.client, ev->client_id.event, |
| 55 | ev->prop[0], ev->prop[1]); | ||
| 129 | } | 56 | } |
| 130 | 57 | ||
| 131 | static void tp_event(struct touch_engine *engine, | 58 | static void loop_device(struct grail *ge, int fd) |
| 132 | const struct input_event *ev) | ||
| 133 | { | 59 | { |
| 134 | } | 60 | while (!grail_idle(ge, fd, 5000)) |
| 135 | 61 | grail_pull(ge, fd); | |
| 136 | static void tp_sync(struct touch_engine *engine, | ||
| 137 | const struct input_event *syn) | ||
| 138 | { | ||
| 139 | struct gesture_handler *gh = engine->priv; | ||
| 140 | struct touch_frame *frame = &engine->frame; | ||
| 141 | gh_handle(gh, frame, frame->time); | ||
| 142 | } | ||
| 143 | |||
| 144 | static void loop_device(struct touch_dev *dev, int fd) | ||
| 145 | { | ||
| 146 | struct gesture_handler gh; | ||
| 147 | struct touch_engine engine; | ||
| 148 | gh_init(&gh); | ||
| 149 | touch_engine_init(&engine, tp_event, tp_sync, &gh); | ||
| 150 | touch_engine_attach(&engine, dev); | ||
| 151 | while (!touch_dev_idle(dev, fd, 5000)) | ||
| 152 | touch_dev_pull(dev, fd); | ||
| 153 | touch_engine_detach(&engine, dev); | ||
| 154 | gh_destroy(&gh); | ||
| 155 | } | 62 | } |
| 156 | 63 | ||
| 157 | int main(int argc, char *argv[]) | 64 | int main(int argc, char *argv[]) |
| 158 | { | 65 | { |
| 159 | struct touch_dev dev; | 66 | struct grail ge; |
| 160 | int fd; | 67 | int fd; |
| 68 | |||
| 161 | if (argc < 2) { | 69 | if (argc < 2) { |
| 162 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); | 70 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); |
| 163 | return -1; | 71 | return -1; |
| 164 | } | 72 | } |
| 73 | |||
| 74 | memset(&ge, 0, sizeof(ge)); | ||
| 75 | ge.get_clients = tp_get_clients; | ||
| 76 | ge.event = tp_event; | ||
| 77 | ge.gesture = tp_gesture; | ||
| 78 | |||
| 165 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | 79 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); |
| 166 | if (fd < 0) { | 80 | if (fd < 0) { |
| 167 | fprintf(stderr, "error: could not open device\n"); | 81 | fprintf(stderr, "error: could not open device\n"); |
| @@ -171,12 +85,14 @@ int main(int argc, char *argv[]) | |||
| 171 | fprintf(stderr, "error: could not grab the device\n"); | 85 | fprintf(stderr, "error: could not grab the device\n"); |
| 172 | return -1; | 86 | return -1; |
| 173 | } | 87 | } |
| 174 | if (touch_dev_open(&dev, fd)) { | 88 | |
| 89 | if (grail_open(&ge, fd)) { | ||
| 175 | fprintf(stderr, "error: could not open touch device\n"); | 90 | fprintf(stderr, "error: could not open touch device\n"); |
| 176 | return -1; | 91 | return -1; |
| 177 | } | 92 | } |
| 178 | loop_device(&dev, fd); | 93 | loop_device(&ge, fd); |
| 179 | touch_dev_close(&dev, fd); | 94 | grail_close(&ge, fd); |
| 95 | |||
| 180 | ioctl(fd, EVIOCGRAB, 0); | 96 | ioctl(fd, EVIOCGRAB, 0); |
| 181 | close(fd); | 97 | close(fd); |
| 182 | return 0; | 98 | return 0; |
