diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2010-12-30 17:58:01 +0100 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-12-30 17:58:01 +0100 |
| commit | f0aba58c91933a4702a7cc74f7daf4192868f570 (patch) | |
| tree | 648c41fe09adb72344769dd6242638cbad835482 /tools | |
Initial load of utouch-framev1.0.0
Compiles and runs on mtdev. ABI proof.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/Makefile.am | 7 | ||||
| -rw-r--r-- | tools/utouch-frame-test-mtdev.c | 202 |
2 files changed, 209 insertions, 0 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 0000000..6b50897 --- /dev/null +++ b/tools/Makefile.am | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | bin_PROGRAMS = utouch-frame-test-mtdev | ||
| 2 | |||
| 3 | INCLUDES=-I$(top_srcdir)/include/ | ||
| 4 | |||
| 5 | utouch_frame_test_mtdev_SOURCES = utouch-frame-test-mtdev.c | ||
| 6 | utouch_frame_test_mtdev_LDFLAGS = -L$(top_builddir)/src/.libs/ \ | ||
| 7 | -lutouch-frame -lutouch-evemu -lmtdev -lm | ||
diff --git a/tools/utouch-frame-test-mtdev.c b/tools/utouch-frame-test-mtdev.c new file mode 100644 index 0000000..13f5a68 --- /dev/null +++ b/tools/utouch-frame-test-mtdev.c | |||
| @@ -0,0 +1,202 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * utouch-frame - Touch Frame 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 <mtdev.h> | ||
| 29 | #include <string.h> | ||
| 30 | #include <stdio.h> | ||
| 31 | #include <unistd.h> | ||
| 32 | #include <fcntl.h> | ||
| 33 | |||
| 34 | struct frame_test { | ||
| 35 | struct evemu_device *evemu; | ||
| 36 | struct mtdev *mtdev; | ||
| 37 | utouch_frame_handle fh; | ||
| 38 | }; | ||
| 39 | |||
| 40 | static int init_evemu(struct frame_test *test, int fd) | ||
| 41 | { | ||
| 42 | test->evemu = evemu_new(NULL); | ||
| 43 | if (!test->evemu) | ||
| 44 | return -1; | ||
| 45 | return evemu_extract(test->evemu, fd); | ||
| 46 | } | ||
| 47 | |||
| 48 | static int init_mtdev(struct frame_test *test, int fd) | ||
| 49 | { | ||
| 50 | test->mtdev = mtdev_new_open(fd); | ||
| 51 | if (!test->mtdev) | ||
| 52 | return -1; | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | static int init_frame(struct frame_test *test, int fd) | ||
| 57 | { | ||
| 58 | test->fh = utouch_frame_new_engine(100, 32, 100); | ||
| 59 | if (!test->fh) | ||
| 60 | return -1; | ||
| 61 | return utouch_frame_init_mtdev(test->fh, test->evemu); | ||
| 62 | } | ||
| 63 | |||
| 64 | static void destroy_all(struct frame_test *test) | ||
| 65 | { | ||
| 66 | utouch_frame_delete_engine(test->fh); | ||
| 67 | mtdev_close_delete(test->mtdev); | ||
| 68 | evemu_delete(test->evemu); | ||
| 69 | memset(test, 0, sizeof(*test)); | ||
| 70 | } | ||
| 71 | |||
| 72 | static void report_frame(const struct utouch_frame *frame) | ||
| 73 | { | ||
| 74 | int i; | ||
| 75 | |||
| 76 | for (i = 0; i < frame->num_active; i++) { | ||
| 77 | const struct utouch_contact *t = frame->active[i]; | ||
| 78 | |||
| 79 | fprintf(stderr, "touch %d\n", i); | ||
| 80 | fprintf(stderr, " slot: %d\n", t->slot); | ||
| 81 | fprintf(stderr, " id: %d\n", t->id); | ||
| 82 | fprintf(stderr, " tool_type: %d\n", t->tool_type); | ||
| 83 | fprintf(stderr, " x: %f\n", t->x); | ||
| 84 | fprintf(stderr, " y: %f\n", t->y); | ||
| 85 | fprintf(stderr, " touch_major: %f\n", t->touch_major); | ||
| 86 | fprintf(stderr, " touch_minor: %f\n", t->touch_minor); | ||
| 87 | fprintf(stderr, " width_major: %f\n", t->width_major); | ||
| 88 | fprintf(stderr, " width_minor: %f\n", t->width_minor); | ||
| 89 | fprintf(stderr, " angle: %f\n", t->orientation); | ||
| 90 | fprintf(stderr, " pressure: %f\n", t->pressure); | ||
| 91 | fprintf(stderr, " distance: %f\n", t->distance); | ||
| 92 | } | ||
| 93 | |||
| 94 | fprintf(stderr, "sync %d %ld %d %d %d\n", | ||
| 95 | frame->num_active, | ||
| 96 | frame->time, | ||
| 97 | frame->sequence_id, | ||
| 98 | frame->revision, | ||
| 99 | frame->slot_revision); | ||
| 100 | } | ||
| 101 | |||
| 102 | static void loop_device(struct frame_test *test, int fd) | ||
| 103 | { | ||
| 104 | const struct utouch_frame *frame; | ||
| 105 | struct input_event ev; | ||
| 106 | |||
| 107 | while (!mtdev_idle(test->mtdev, fd, 5000)) { | ||
| 108 | while (mtdev_get(test->mtdev, fd, &ev, 1) > 0) { | ||
| 109 | frame = utouch_frame_pump_mtdev(test->fh, &ev); | ||
| 110 | if (frame) | ||
| 111 | report_frame(frame); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | static void report_device_caps(struct frame_test *test) | ||
| 117 | { | ||
| 118 | #ifdef INPUT_PROP_POINTER | ||
| 119 | fprintf(stderr, "device props:\n"); | ||
| 120 | if (evemu_has_prop(test->evemu, INPUT_PROP_POINTER)) | ||
| 121 | fprintf(stderr, "\tpointer\n"); | ||
| 122 | if (evemu_has_prop(test->evemu, INPUT_PROP_DIRECT)) | ||
| 123 | fprintf(stderr, "\tdirect\n"); | ||
| 124 | if (evemu_has_prop(test->evemu, INPUT_PROP_BUTTONPAD)) | ||
| 125 | fprintf(stderr, "\tbuttonpad\n"); | ||
| 126 | if (evemu_has_prop(test->evemu, INPUT_PROP_SEMI_MT)) | ||
| 127 | fprintf(stderr, "\tsemi_mt\n"); | ||
| 128 | #endif | ||
| 129 | fprintf(stderr, "device mt events:\n"); | ||
| 130 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_SLOT)) | ||
| 131 | fprintf(stderr, "\tslot\n"); | ||
| 132 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_TOUCH_MAJOR)) | ||
| 133 | fprintf(stderr, "\ttouch_major\n"); | ||
| 134 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_TOUCH_MINOR)) | ||
| 135 | fprintf(stderr, "\ttouch_minor\n"); | ||
| 136 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_WIDTH_MAJOR)) | ||
| 137 | fprintf(stderr, "\twidth_major\n"); | ||
| 138 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_WIDTH_MINOR)) | ||
| 139 | fprintf(stderr, "\twidth_minor\n"); | ||
| 140 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_ORIENTATION)) | ||
| 141 | fprintf(stderr, "\torientation\n"); | ||
| 142 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_POSITION_X)) | ||
| 143 | fprintf(stderr, "\tposition_x\n"); | ||
| 144 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_POSITION_Y)) | ||
| 145 | fprintf(stderr, "\tposition_y\n"); | ||
| 146 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_TOOL_TYPE)) | ||
| 147 | fprintf(stderr, "\tposition_y\n"); | ||
| 148 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_TRACKING_ID)) | ||
| 149 | fprintf(stderr, "\ttracking_id\n"); | ||
| 150 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_PRESSURE)) | ||
| 151 | fprintf(stderr, "\tpressure\n"); | ||
| 152 | if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_DISTANCE)) | ||
| 153 | fprintf(stderr, "\tdistance\n"); | ||
| 154 | } | ||
| 155 | |||
| 156 | int main(int argc, char *argv[]) | ||
| 157 | { | ||
| 158 | struct frame_test test; | ||
| 159 | int fd; | ||
| 160 | |||
| 161 | if (argc < 2) { | ||
| 162 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); | ||
| 163 | return -1; | ||
| 164 | } | ||
| 165 | |||
| 166 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | ||
| 167 | if (fd < 0) { | ||
| 168 | fprintf(stderr, "error: could not open device\n"); | ||
| 169 | return -1; | ||
| 170 | } | ||
| 171 | if (ioctl(fd, EVIOCGRAB, 1)) { | ||
| 172 | fprintf(stderr, "error: could not grab the device\n"); | ||
| 173 | return -1; | ||
| 174 | } | ||
| 175 | |||
| 176 | if (init_evemu(&test, fd)) { | ||
| 177 | fprintf(stderr, "error: could not describe device\n"); | ||
| 178 | return -1; | ||
| 179 | } | ||
| 180 | if (!utouch_frame_is_supported_mtdev(test.evemu)) { | ||
| 181 | fprintf(stderr, "error: unsupported device\n"); | ||
| 182 | return -1; | ||
| 183 | } | ||
| 184 | |||
| 185 | fprintf(stderr, "device: %s\n", evemu_get_name(test.evemu)); | ||
| 186 | |||
| 187 | if (init_mtdev(&test, fd)) { | ||
| 188 | fprintf(stderr, "error: could not init mtdev\n"); | ||
| 189 | return -1; | ||
| 190 | } | ||
| 191 | if (init_frame(&test, fd)) { | ||
| 192 | fprintf(stderr, "error: could not init frame\n"); | ||
| 193 | return -1; | ||
| 194 | } | ||
| 195 | |||
| 196 | report_device_caps(&test); | ||
| 197 | |||
| 198 | loop_device(&test, fd); | ||
| 199 | |||
| 200 | destroy_all(&test); | ||
| 201 | return 0; | ||
| 202 | } | ||
