diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2010-08-06 21:11:17 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-08-06 21:11:17 +0200 |
| commit | 7db9d8d76ff61c4802ac15559dcea6fa54ff567a (patch) | |
| tree | b67e040c0abeb0ab1fca72754a767dc9ab851461 /test/grail-gesture.c | |
initial bzr repo at rev 27
Diffstat (limited to 'test/grail-gesture.c')
| -rw-r--r-- | test/grail-gesture.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/test/grail-gesture.c b/test/grail-gesture.c new file mode 100644 index 0000000..16b33ac --- /dev/null +++ b/test/grail-gesture.c | |||
| @@ -0,0 +1,111 @@ | |||
| 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 grail_mask_t flag_mask[DIM_GRAIL_TYPE_BYTES]; | ||
| 32 | |||
| 33 | static int tp_get_clients(struct grail *ge, | ||
| 34 | struct grail_client_info *clients, int max_clients, | ||
| 35 | const struct grail_coord *coords, int num_coords, | ||
| 36 | const grail_mask_t *types, int type_bytes) | ||
| 37 | { | ||
| 38 | memset(&clients[0], 0, sizeof(clients[0])); | ||
| 39 | clients[0].id.client = 345; | ||
| 40 | clients[0].id.root = 1; | ||
| 41 | clients[0].id.event = 2; | ||
| 42 | clients[0].id.child = 3; | ||
| 43 | memcpy(clients[0].mask, flag_mask, sizeof(flag_mask)); | ||
| 44 | return 1; | ||
| 45 | } | ||
| 46 | |||
| 47 | static void tp_event(struct grail *ge, const struct input_event *ev) | ||
| 48 | { | ||
| 49 | if (!grail_mask_get(flag_mask, GRAIL_TYPE_POINTER)) | ||
| 50 | return; | ||
| 51 | fprintf(stderr, "event %d 0x%x %d\n", ev->type, ev->code, ev->value); | ||
| 52 | } | ||
| 53 | |||
| 54 | static void tp_gesture(struct grail *ge, const struct grail_event *ev) | ||
| 55 | { | ||
| 56 | int i; | ||
| 57 | fprintf(stderr, "gesture %d %d %d %d - %f %f %d - %d\n", | ||
| 58 | ev->type, ev->id, ev->client_id.client, ev->client_id.event, | ||
| 59 | ev->pos.x, ev->pos.y, ev->ntouch, | ||
| 60 | ev->status); | ||
| 61 | for (i = 0; i < ev->nprop; i++) | ||
| 62 | fprintf(stderr, "\t%d: %f\n", i, ev->prop[i]); | ||
| 63 | } | ||
| 64 | |||
| 65 | static void loop_device(struct grail *ge, int fd) | ||
| 66 | { | ||
| 67 | while (!grail_idle(ge, fd, 5000)) | ||
| 68 | grail_pull(ge, fd); | ||
| 69 | } | ||
| 70 | |||
| 71 | int main(int argc, char *argv[]) | ||
| 72 | { | ||
| 73 | struct grail ge; | ||
| 74 | int i, fd; | ||
| 75 | |||
| 76 | if (argc < 3) { | ||
| 77 | fprintf(stderr, "Usage: %s <mask> <device>\n", argv[0]); | ||
| 78 | return -1; | ||
| 79 | } | ||
| 80 | |||
| 81 | memset(&ge, 0, sizeof(ge)); | ||
| 82 | ge.get_clients = tp_get_clients; | ||
| 83 | ge.event = tp_event; | ||
| 84 | ge.gesture = tp_gesture; | ||
| 85 | |||
| 86 | unsigned long mask = strtoull(argv[1], 0, 0); | ||
| 87 | for (i = 0; i < DIM_GRAIL_TYPE; i++) | ||
| 88 | if ((mask >> i) & 1) | ||
| 89 | grail_mask_set(flag_mask, i); | ||
| 90 | |||
| 91 | fd = open(argv[2], O_RDONLY | O_NONBLOCK); | ||
| 92 | if (fd < 0) { | ||
| 93 | fprintf(stderr, "error: could not open device\n"); | ||
| 94 | return -1; | ||
| 95 | } | ||
| 96 | if (ioctl(fd, EVIOCGRAB, 1)) { | ||
| 97 | fprintf(stderr, "error: could not grab the device\n"); | ||
| 98 | return -1; | ||
| 99 | } | ||
| 100 | |||
| 101 | if (grail_open(&ge, fd)) { | ||
| 102 | fprintf(stderr, "error: could not open touch device\n"); | ||
| 103 | return -1; | ||
| 104 | } | ||
| 105 | loop_device(&ge, fd); | ||
| 106 | grail_close(&ge, fd); | ||
| 107 | |||
| 108 | ioctl(fd, EVIOCGRAB, 0); | ||
| 109 | close(fd); | ||
| 110 | return 0; | ||
| 111 | } | ||
