diff options
| author | Henrik Rydberg <rydberg@bitmath.org> | 2010-08-05 19:33:58 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-08-05 22:48:38 +0200 |
| commit | 7559b3d7aa725cd75ee4e6746246205392fe1c0f (patch) | |
| tree | 364e0201c2bb4e853c5aaba0a61e5929fa857de2 /test/grail-touch.c | |
| parent | 8bbf06f8d0056ae30fdfaf260000e763fad2345c (diff) | |
Rename and install test binaries
Install the test programs as grail-touch and grail-gesture.
Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'test/grail-touch.c')
| -rw-r--r-- | test/grail-touch.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/test/grail-touch.c b/test/grail-touch.c new file mode 100644 index 0000000..8893c0d --- /dev/null +++ b/test/grail-touch.c | |||
| @@ -0,0 +1,90 @@ | |||
| 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-touch.h> | ||
| 26 | #include <string.h> | ||
| 27 | #include <stdio.h> | ||
| 28 | #include <unistd.h> | ||
| 29 | #include <fcntl.h> | ||
| 30 | |||
| 31 | static void tp_event(struct touch_engine *engine, | ||
| 32 | const struct input_event *ev) | ||
| 33 | { | ||
| 34 | fprintf(stderr, "event %d 0x%x %d\n", ev->type, ev->code, ev->value); | ||
| 35 | } | ||
| 36 | |||
| 37 | static void tp_sync(struct touch_engine *engine, | ||
| 38 | const struct input_event *syn) | ||
| 39 | { | ||
| 40 | struct touch_frame *frame = &engine->frame; | ||
| 41 | int i, j; | ||
| 42 | for (i = 0; i < frame->nactive; i++) { | ||
| 43 | struct touch *t = frame->active[i]; | ||
| 44 | fprintf(stderr, "touch %d %d\n", i, t->slot); | ||
| 45 | for (j = 0; j < DIM_TOUCH_PROP; j++) | ||
| 46 | fprintf(stderr, " %d\n", t->prop[j]); | ||
| 47 | } | ||
| 48 | fprintf(stderr, "sync %d %lld %d %d\n", | ||
| 49 | frame->nactive, frame->time, frame->ncreate, frame->ndestroy); | ||
| 50 | } | ||
| 51 | |||
| 52 | static void loop_device(struct touch_dev *dev, int fd) | ||
| 53 | { | ||
| 54 | struct touch_engine engine; | ||
| 55 | touch_engine_init(&engine, tp_event, tp_sync, 0); | ||
| 56 | touch_engine_attach(&engine, dev); | ||
| 57 | while (!touch_dev_idle(dev, fd, 5000)) { | ||
| 58 | touch_dev_fetch(dev, fd); | ||
| 59 | touch_dev_process(dev); | ||
| 60 | } | ||
| 61 | touch_engine_detach(&engine, dev); | ||
| 62 | } | ||
| 63 | |||
| 64 | int main(int argc, char *argv[]) | ||
| 65 | { | ||
| 66 | struct touch_dev dev; | ||
| 67 | int fd; | ||
| 68 | if (argc < 2) { | ||
| 69 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); | ||
| 70 | return -1; | ||
| 71 | } | ||
| 72 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | ||
| 73 | if (fd < 0) { | ||
| 74 | fprintf(stderr, "error: could not open device\n"); | ||
| 75 | return -1; | ||
| 76 | } | ||
| 77 | if (ioctl(fd, EVIOCGRAB, 1)) { | ||
| 78 | fprintf(stderr, "error: could not grab the device\n"); | ||
| 79 | return -1; | ||
| 80 | } | ||
| 81 | if (touch_dev_open(&dev, fd)) { | ||
| 82 | fprintf(stderr, "error: could not open touch device\n"); | ||
| 83 | return -1; | ||
| 84 | } | ||
| 85 | loop_device(&dev, fd); | ||
| 86 | touch_dev_close(&dev, fd); | ||
| 87 | ioctl(fd, EVIOCGRAB, 0); | ||
| 88 | close(fd); | ||
| 89 | return 0; | ||
| 90 | } | ||
