diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/Makefile.am | 9 | ||||
| -rw-r--r-- | test/grail-gesture.c | 126 | ||||
| -rw-r--r-- | test/grail-touch.c | 97 |
3 files changed, 0 insertions, 232 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 8ffbe09..e69de29 100644 --- a/test/Makefile.am +++ b/test/Makefile.am | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | bin_PROGRAMS = grail-touch grail-gesture | ||
| 2 | |||
| 3 | INCLUDES=-I$(top_srcdir)/include/ | ||
| 4 | |||
| 5 | grail_touch_SOURCES = grail-touch.c | ||
| 6 | grail_touch_LDFLAGS = -L$(top_builddir)/src/.libs/ -lutouch-grail -lmtdev -lm | ||
| 7 | |||
| 8 | grail_gesture_SOURCES = grail-gesture.c | ||
| 9 | grail_gesture_LDFLAGS = -L$(top_builddir)/src/.libs/ -lutouch-grail -lmtdev -lm | ||
diff --git a/test/grail-gesture.c b/test/grail-gesture.c deleted file mode 100644 index 614bf1a..0000000 --- a/test/grail-gesture.c +++ /dev/null | |||
| @@ -1,126 +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 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 | fprintf(stderr, "%lu.%06u %04x %04x %d\n", | ||
| 50 | ev->time.tv_sec, (unsigned)ev->time.tv_usec, | ||
| 51 | ev->type, ev->code, ev->value); | ||
| 52 | } | ||
| 53 | |||
| 54 | static void tp_gesture(struct grail *ge, const struct grail_event *ev) | ||
| 55 | { | ||
| 56 | struct grail_contact touch[32]; | ||
| 57 | int i, ntouch; | ||
| 58 | fprintf(stderr, "gesture %d %d %d %d - %f %f %d - %d\n", | ||
| 59 | ev->type, ev->id, ev->client_id.client, ev->client_id.event, | ||
| 60 | ev->pos.x, ev->pos.y, ev->ntouch, | ||
| 61 | ev->status); | ||
| 62 | ntouch = grail_get_contacts(ge, touch, 32); | ||
| 63 | for (i = 0; i < ntouch; i++) { | ||
| 64 | const struct grail_contact *t = &touch[i]; | ||
| 65 | fprintf(stderr, "\t%d: %d %d\n", i, t->id, t->tool_type); | ||
| 66 | fprintf(stderr, "\t %f %f\n", t->pos.x, t->pos.y); | ||
| 67 | fprintf(stderr, "\t %f %f %f %f\n", t->touch_major, | ||
| 68 | t->touch_minor, t->width_major, t->width_minor); | ||
| 69 | fprintf(stderr, "\t %f %f\n", t->angle, t->pressure); | ||
| 70 | } | ||
| 71 | for (i = 0; i < ev->nprop; i++) | ||
| 72 | fprintf(stderr, "\t%d: %f\n", i, ev->prop[i]); | ||
| 73 | } | ||
| 74 | |||
| 75 | static void loop_device(struct grail *ge, int fd) | ||
| 76 | { | ||
| 77 | while (!grail_idle(ge, fd, 5000)) | ||
| 78 | grail_pull(ge, fd); | ||
| 79 | } | ||
| 80 | |||
| 81 | int main(int argc, char *argv[]) | ||
| 82 | { | ||
| 83 | struct grail ge; | ||
| 84 | int i, fd; | ||
| 85 | |||
| 86 | if (argc < 3) { | ||
| 87 | fprintf(stderr, "Usage: %s <mask> <device>\n", argv[0]); | ||
| 88 | return -1; | ||
| 89 | } | ||
| 90 | |||
| 91 | memset(&ge, 0, sizeof(ge)); | ||
| 92 | ge.get_clients = tp_get_clients; | ||
| 93 | ge.event = tp_event; | ||
| 94 | ge.gesture = tp_gesture; | ||
| 95 | |||
| 96 | unsigned long mask = strtoull(argv[1], 0, 0); | ||
| 97 | for (i = 0; i < DIM_GRAIL_TYPE; i++) | ||
| 98 | if ((mask >> i) & 1) | ||
| 99 | grail_mask_set(flag_mask, i); | ||
| 100 | |||
| 101 | fd = open(argv[2], O_RDONLY | O_NONBLOCK); | ||
| 102 | if (fd < 0) { | ||
| 103 | fprintf(stderr, "error: could not open device\n"); | ||
| 104 | return -1; | ||
| 105 | } | ||
| 106 | if (ioctl(fd, EVIOCGRAB, 1)) { | ||
| 107 | fprintf(stderr, "error: could not grab the device\n"); | ||
| 108 | return -1; | ||
| 109 | } | ||
| 110 | |||
| 111 | if (grail_open(&ge, fd)) { | ||
| 112 | fprintf(stderr, "error: could not open touch device\n"); | ||
| 113 | return -1; | ||
| 114 | } | ||
| 115 | //grail_filter_abs_events(&ge, 1); | ||
| 116 | |||
| 117 | struct grail_coord min = { -2, -1 }, max = { 2, 1 }; | ||
| 118 | grail_set_bbox(&ge, &min, &max); | ||
| 119 | |||
| 120 | loop_device(&ge, fd); | ||
| 121 | grail_close(&ge, fd); | ||
| 122 | |||
| 123 | ioctl(fd, EVIOCGRAB, 0); | ||
| 124 | close(fd); | ||
| 125 | return 0; | ||
| 126 | } | ||
diff --git a/test/grail-touch.c b/test/grail-touch.c deleted file mode 100644 index c5ecae3..0000000 --- a/test/grail-touch.c +++ /dev/null | |||
| @@ -1,97 +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-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_dev *dev, | ||
| 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_dev *dev, | ||
| 38 | const struct input_event *syn) | ||
| 39 | { | ||
| 40 | struct touch_frame *frame = &dev->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\n", i); | ||
| 45 | fprintf(stderr, " slot: %d\n", t->slot); | ||
| 46 | fprintf(stderr, " id: %d\n", t->id); | ||
| 47 | fprintf(stderr, " tool_type: %d\n", t->tool_type); | ||
| 48 | fprintf(stderr, " x: %d\n", t->x); | ||
| 49 | fprintf(stderr, " y: %d\n", t->y); | ||
| 50 | fprintf(stderr, " touch_major: %d\n", t->touch_major); | ||
| 51 | fprintf(stderr, " touch_minor: %d\n", t->touch_minor); | ||
| 52 | fprintf(stderr, " width_major: %d\n", t->width_major); | ||
| 53 | fprintf(stderr, " width_minor: %d\n", t->width_minor); | ||
| 54 | fprintf(stderr, " angle: %f\n", | ||
| 55 | touch_angle(dev, t->orientation)); | ||
| 56 | fprintf(stderr, " pressure: %f\n", | ||
| 57 | touch_pressure(dev, t->pressure)); | ||
| 58 | } | ||
| 59 | fprintf(stderr, "sync %d %lld %d %d\n", | ||
| 60 | frame->nactive, frame->time, frame->ncreate, frame->ndestroy); | ||
| 61 | } | ||
| 62 | |||
| 63 | static void loop_device(struct touch_dev *dev, int fd) | ||
| 64 | { | ||
| 65 | dev->event = tp_event; | ||
| 66 | dev->sync = tp_sync; | ||
| 67 | while (!touch_dev_idle(dev, fd, 5000)) | ||
| 68 | touch_dev_pull(dev, fd); | ||
| 69 | } | ||
| 70 | |||
| 71 | int main(int argc, char *argv[]) | ||
| 72 | { | ||
| 73 | struct touch_dev dev; | ||
| 74 | int fd; | ||
| 75 | if (argc < 2) { | ||
| 76 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); | ||
| 77 | return -1; | ||
| 78 | } | ||
| 79 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | ||
| 80 | if (fd < 0) { | ||
| 81 | fprintf(stderr, "error: could not open device\n"); | ||
| 82 | return -1; | ||
| 83 | } | ||
| 84 | if (ioctl(fd, EVIOCGRAB, 1)) { | ||
| 85 | fprintf(stderr, "error: could not grab the device\n"); | ||
| 86 | return -1; | ||
| 87 | } | ||
| 88 | if (touch_dev_open(&dev, fd)) { | ||
| 89 | fprintf(stderr, "error: could not open touch device\n"); | ||
| 90 | return -1; | ||
| 91 | } | ||
| 92 | loop_device(&dev, fd); | ||
| 93 | touch_dev_close(&dev, fd); | ||
| 94 | ioctl(fd, EVIOCGRAB, 0); | ||
| 95 | close(fd); | ||
| 96 | return 0; | ||
| 97 | } | ||
