diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/Makefile.am | 2 | ||||
| -rw-r--r-- | tools/grail-test-mtdev.c | 259 |
2 files changed, 260 insertions, 1 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index c7e0a75..667fbb2 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | bin_PROGRAMS = grail-gesture | 1 | bin_PROGRAMS = grail-gesture grail-test-mtdev |
| 2 | 2 | ||
| 3 | INCLUDES=-I$(top_srcdir)/include/ | 3 | INCLUDES=-I$(top_srcdir)/include/ |
| 4 | 4 | ||
diff --git a/tools/grail-test-mtdev.c b/tools/grail-test-mtdev.c new file mode 100644 index 0000000..bc87631 --- /dev/null +++ b/tools/grail-test-mtdev.c | |||
| @@ -0,0 +1,259 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * grail - Gesture Recognition And Instantiation Library | ||
| 4 | * | ||
| 5 | * Copyright (C) 2010-2011 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 | #define MTDEV_NO_LEGACY_API | ||
| 26 | |||
| 27 | #include <utouch/frame-mtdev.h> | ||
| 28 | #include <grail.h> | ||
| 29 | #include <string.h> | ||
| 30 | #include <stdio.h> | ||
| 31 | #include <unistd.h> | ||
| 32 | #include <fcntl.h> | ||
| 33 | #include <math.h> | ||
| 34 | |||
| 35 | struct frame_test { | ||
| 36 | struct evemu_device *evemu; | ||
| 37 | struct mtdev *mtdev; | ||
| 38 | utouch_frame_handle fh; | ||
| 39 | grail_handle ge; | ||
| 40 | }; | ||
| 41 | |||
| 42 | static int init_evemu(struct frame_test *test, FILE *fp, int fd) | ||
| 43 | { | ||
| 44 | test->evemu = evemu_new(NULL); | ||
| 45 | if (!test->evemu) | ||
| 46 | return -1; | ||
| 47 | if (fp) | ||
| 48 | return evemu_read(test->evemu, fp) <= 0; | ||
| 49 | else | ||
| 50 | return evemu_extract(test->evemu, fd); | ||
| 51 | } | ||
| 52 | |||
| 53 | static int init_mtdev(struct frame_test *test, int fd) | ||
| 54 | { | ||
| 55 | test->mtdev = mtdev_new_open(fd); | ||
| 56 | if (!test->mtdev) | ||
| 57 | return -1; | ||
| 58 | return 0; | ||
| 59 | } | ||
| 60 | |||
| 61 | static int init_frame(struct frame_test *test, int fd) | ||
| 62 | { | ||
| 63 | test->fh = utouch_frame_new_engine(100, 32, 100); | ||
| 64 | if (!test->fh) | ||
| 65 | return -1; | ||
| 66 | return utouch_frame_init_mtdev(test->fh, test->evemu); | ||
| 67 | } | ||
| 68 | |||
| 69 | static int init_grail(struct frame_test *test) | ||
| 70 | { | ||
| 71 | struct grail_coord min = { 0, 0 }; | ||
| 72 | struct grail_coord max = { 1, 1 }; | ||
| 73 | test->ge = grail_new(test->fh, 10, 0); | ||
| 74 | if (!test->ge) | ||
| 75 | return -1; | ||
| 76 | grail_set_bbox(test->ge, &min, &max); | ||
| 77 | return 0; | ||
| 78 | } | ||
| 79 | |||
| 80 | static void destroy_all(struct frame_test *test) | ||
| 81 | { | ||
| 82 | grail_delete(test->ge); | ||
| 83 | utouch_frame_delete_engine(test->fh); | ||
| 84 | if (test->mtdev) | ||
| 85 | mtdev_close_delete(test->mtdev); | ||
| 86 | evemu_delete(test->evemu); | ||
| 87 | memset(test, 0, sizeof(*test)); | ||
| 88 | } | ||
| 89 | |||
| 90 | static void report_frame(grail_handle ge, | ||
| 91 | const struct utouch_frame *touch) | ||
| 92 | { | ||
| 93 | const struct grail_frame *frame = grail_pump_frame(ge, touch); | ||
| 94 | int i; | ||
| 95 | |||
| 96 | if (!frame) | ||
| 97 | return; | ||
| 98 | |||
| 99 | fprintf(stderr, "ongoing elements: %d\n", frame->num_ongoing); | ||
| 100 | |||
| 101 | for (i = 0; i < frame->num_ongoing; i++) { | ||
| 102 | const struct grail_element *slot = frame->ongoing[i]; | ||
| 103 | if (!slot->expect_mask) | ||
| 104 | continue; | ||
| 105 | |||
| 106 | fprintf(stderr, " element %d\n", i); | ||
| 107 | fprintf(stderr, " slot: %d\n", slot->slot); | ||
| 108 | fprintf(stderr, " id: %d\n", slot->id); | ||
| 109 | fprintf(stderr, " num_touches: %d\n", slot->num_touches); | ||
| 110 | fprintf(stderr, " expect: %d\n", slot->expect_mask); | ||
| 111 | fprintf(stderr, " active: %d\n", slot->active_mask); | ||
| 112 | fprintf(stderr, " start time: %ld\n", slot->start_time); | ||
| 113 | fprintf(stderr, " center.x: %f\n", slot->center.x); | ||
| 114 | fprintf(stderr, " center.y: %f\n", slot->center.y); | ||
| 115 | fprintf(stderr, " velocity.x: %f\n", slot->velocity.x); | ||
| 116 | fprintf(stderr, " velocity.y: %f\n", slot->velocity.y); | ||
| 117 | fprintf(stderr, " radius2: %f\n", slot->radius2); | ||
| 118 | fprintf(stderr, " %+08f %+08f %+08f\n" | ||
| 119 | " %+08f %+08f %+08f\n" | ||
| 120 | " %+08f %+08f %+08f\n", | ||
| 121 | slot->transform[0], slot->transform[1], | ||
| 122 | slot->transform[2], slot->transform[3], | ||
| 123 | slot->transform[4], slot->transform[5], | ||
| 124 | slot->transform[6], slot->transform[7], | ||
| 125 | slot->transform[8]); | ||
| 126 | fprintf(stderr, " moveness: %f\n", slot->moveness); | ||
| 127 | fprintf(stderr, " pivot.x: %f\n", slot->pivot.x); | ||
| 128 | fprintf(stderr, " pivot.y: %f\n", slot->pivot.y); | ||
| 129 | fprintf(stderr, " drag.x: %f\n", slot->drag.x); | ||
| 130 | fprintf(stderr, " drag.y: %f\n", slot->drag.y); | ||
| 131 | fprintf(stderr, " scale2: %f\n", slot->scale2); | ||
| 132 | fprintf(stderr, " angle: %f\n", slot->angle); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | static void loop_device(struct frame_test *test, FILE *fp, int fd) | ||
| 137 | { | ||
| 138 | const struct utouch_frame *frame; | ||
| 139 | struct input_event ev; | ||
| 140 | |||
| 141 | if (fp) { | ||
| 142 | struct timeval evtime; | ||
| 143 | memset(&evtime, 0, sizeof(evtime)); | ||
| 144 | while (evemu_read_event_realtime(fp, &ev, &evtime) > 0) { | ||
| 145 | frame = utouch_frame_pump_mtdev(test->fh, &ev); | ||
| 146 | if (frame) | ||
| 147 | report_frame(test->ge, frame); | ||
| 148 | } | ||
| 149 | } else { | ||
| 150 | while (!mtdev_idle(test->mtdev, fd, 5000)) { | ||
| 151 | while (mtdev_get(test->mtdev, fd, &ev, 1) > 0) { | ||
| 152 | frame = utouch_frame_pump_mtdev(test->fh, &ev); | ||
| 153 | if (frame) | ||
| 154 | report_frame(test->ge, frame); | ||
| 155 | } | ||
| 156 | } | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 160 | static void report_device_caps(struct frame_test *test) | ||
| 161 | { | ||
| 162 | const struct utouch_surface *s = utouch_frame_get_surface(test->fh); | ||
| 163 | |||
| 164 | fprintf(stderr, "device props:\n"); | ||
| 165 | if (s->needs_pointer) | ||
| 166 | fprintf(stderr, "\tpointer\n"); | ||
| 167 | if (s->is_direct) | ||
| 168 | fprintf(stderr, "\tdirect\n"); | ||
| 169 | if (s->is_buttonpad) | ||
| 170 | fprintf(stderr, "\tbuttonpad\n"); | ||
| 171 | if (s->is_semi_mt) | ||
| 172 | fprintf(stderr, "\tsemi_mt\n"); | ||
| 173 | fprintf(stderr, "device mt events:\n"); | ||
| 174 | if (s->use_touch_major) | ||
| 175 | fprintf(stderr, "\ttouch_major\n"); | ||
| 176 | if (s->use_touch_minor) | ||
| 177 | fprintf(stderr, "\ttouch_minor\n"); | ||
| 178 | if (s->use_width_major) | ||
| 179 | fprintf(stderr, "\twidth_major\n"); | ||
| 180 | if (s->use_width_minor) | ||
| 181 | fprintf(stderr, "\twidth_minor\n"); | ||
| 182 | if (s->use_orientation) | ||
| 183 | fprintf(stderr, "\torientation\n"); | ||
| 184 | if (s->use_pressure) | ||
| 185 | fprintf(stderr, "\tpressure\n"); | ||
| 186 | if (s->use_distance) | ||
| 187 | fprintf(stderr, "\tdistance\n"); | ||
| 188 | |||
| 189 | fprintf(stderr, "touch frames: %d\n", | ||
| 190 | utouch_frame_get_num_frames(test->fh)); | ||
| 191 | fprintf(stderr, "touch slots: %d\n", | ||
| 192 | utouch_frame_get_num_slots(test->fh)); | ||
| 193 | } | ||
| 194 | |||
| 195 | int main(int argc, char *argv[]) | ||
| 196 | { | ||
| 197 | struct frame_test test; | ||
| 198 | struct stat fs; | ||
| 199 | FILE *fp = 0; | ||
| 200 | int fd; | ||
| 201 | |||
| 202 | if (argc < 2) { | ||
| 203 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); | ||
| 204 | return -1; | ||
| 205 | } | ||
| 206 | |||
| 207 | memset(&test, 0, sizeof(test)); | ||
| 208 | |||
| 209 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | ||
| 210 | if (fd < 0) { | ||
| 211 | fprintf(stderr, "error: could not open device\n"); | ||
| 212 | return -1; | ||
| 213 | } | ||
| 214 | if (fstat(fd, &fs)) { | ||
| 215 | fprintf(stderr, "error: could not stat the device\n"); | ||
| 216 | return -1; | ||
| 217 | } | ||
| 218 | if (!fs.st_rdev) | ||
| 219 | fp = fdopen(fd, "r"); | ||
| 220 | |||
| 221 | if (!fp && ioctl(fd, EVIOCGRAB, 1)) { | ||
| 222 | fprintf(stderr, "error: could not grab the device\n"); | ||
| 223 | return -1; | ||
| 224 | } | ||
| 225 | |||
| 226 | if (init_evemu(&test, fp, fd)) { | ||
| 227 | fprintf(stderr, "error: could not describe device\n"); | ||
| 228 | return -1; | ||
| 229 | } | ||
| 230 | if (!utouch_frame_is_supported_mtdev(test.evemu)) { | ||
| 231 | fprintf(stderr, "error: unsupported device\n"); | ||
| 232 | return -1; | ||
| 233 | } | ||
| 234 | |||
| 235 | fprintf(stderr, "device: %s\n", evemu_get_name(test.evemu)); | ||
| 236 | |||
| 237 | if (!fp && init_mtdev(&test, fd)) { | ||
| 238 | fprintf(stderr, "error: could not init mtdev\n"); | ||
| 239 | return -1; | ||
| 240 | } | ||
| 241 | if (init_frame(&test, fd)) { | ||
| 242 | fprintf(stderr, "error: could not init frame\n"); | ||
| 243 | return -1; | ||
| 244 | } | ||
| 245 | if (init_grail(&test)) { | ||
| 246 | fprintf(stderr, "error: could not init grail\n"); | ||
| 247 | return -1; | ||
| 248 | } | ||
| 249 | |||
| 250 | report_device_caps(&test); | ||
| 251 | |||
| 252 | loop_device(&test, fp, fd); | ||
| 253 | |||
| 254 | destroy_all(&test); | ||
| 255 | |||
| 256 | if (fs.st_rdev) | ||
| 257 | ioctl(fd, EVIOCGRAB, 0); | ||
| 258 | return 0; | ||
| 259 | } | ||
