diff options
Diffstat (limited to 'test/touch.c')
| -rw-r--r-- | test/touch.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/test/touch.c b/test/touch.c new file mode 100644 index 0000000..48b2f12 --- /dev/null +++ b/test/touch.c | |||
| @@ -0,0 +1,80 @@ | |||
| 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 void tp_sync(struct touch_engine *engine, touch_time_t time) | ||
| 32 | { | ||
| 33 | struct touch_frame *frame = &engine->frame; | ||
| 34 | int slot, i; | ||
| 35 | fprintf(stderr, "sync %d %lld\n", frame->ntouch, time); | ||
| 36 | for (slot = frame->slot; slot >= 0; slot = next_slot(frame, slot)) { | ||
| 37 | struct touch *touch = &frame->touch[slot]; | ||
| 38 | fprintf(stderr, "touch %d\n", slot); | ||
| 39 | for (i = 0; i < DIM_TOUCH_PROP; i++) | ||
| 40 | fprintf(stderr, " %d\n", touch->prop[i]); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | static void loop_device(struct touch_dev *dev, int fd) | ||
| 45 | { | ||
| 46 | struct touch_engine engine; | ||
| 47 | touch_engine_init(&engine, tp_sync, 0); | ||
| 48 | touch_engine_attach(&engine, dev); | ||
| 49 | while (!touch_dev_idle(dev, fd, 5000)) | ||
| 50 | touch_dev_pull(dev, fd); | ||
| 51 | touch_engine_detach(&engine, dev); | ||
| 52 | } | ||
| 53 | |||
| 54 | int main(int argc, char *argv[]) | ||
| 55 | { | ||
| 56 | struct touch_dev dev; | ||
| 57 | int fd; | ||
| 58 | if (argc < 2) { | ||
| 59 | fprintf(stderr, "Usage: mtdev <device>\n"); | ||
| 60 | return -1; | ||
| 61 | } | ||
| 62 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | ||
| 63 | if (fd < 0) { | ||
| 64 | fprintf(stderr, "error: could not open device\n"); | ||
| 65 | return -1; | ||
| 66 | } | ||
| 67 | if (ioctl(fd, EVIOCGRAB, 1)) { | ||
| 68 | fprintf(stderr, "error: could not grab the device\n"); | ||
| 69 | return -1; | ||
| 70 | } | ||
| 71 | if (touch_dev_open(&dev, fd)) { | ||
| 72 | fprintf(stderr, "error: could not open touch device\n"); | ||
| 73 | return -1; | ||
| 74 | } | ||
| 75 | loop_device(&dev, fd); | ||
| 76 | touch_dev_close(&dev, fd); | ||
| 77 | ioctl(fd, EVIOCGRAB, 0); | ||
| 78 | close(fd); | ||
| 79 | return 0; | ||
| 80 | } | ||
