/***************************************************************************** * * utouch-frame - Touch Frame Library * * Copyright (C) 2010-2011 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Henrik Rydberg * ****************************************************************************/ #define MTDEV_NO_LEGACY_API #include #include #include #include #include #include struct frame_test { struct evemu_device *evemu; struct mtdev *mtdev; utouch_frame_handle fh; }; static int init_evemu(struct frame_test *test, int fd) { test->evemu = evemu_new(NULL); if (!test->evemu) return -1; return evemu_extract(test->evemu, fd); } static int init_mtdev(struct frame_test *test, int fd) { test->mtdev = mtdev_new_open(fd); if (!test->mtdev) return -1; return 0; } static int init_frame(struct frame_test *test, int fd) { test->fh = utouch_frame_new_engine(100, 32, 100); if (!test->fh) return -1; return utouch_frame_init_mtdev(test->fh, test->evemu); } static void destroy_all(struct frame_test *test) { utouch_frame_delete_engine(test->fh); mtdev_close_delete(test->mtdev); evemu_delete(test->evemu); memset(test, 0, sizeof(*test)); } static void report_frame(const struct utouch_frame *frame) { int i; for (i = 0; i < frame->num_active; i++) { const struct utouch_contact *t = frame->active[i]; fprintf(stderr, "touch %d\n", i); fprintf(stderr, " slot: %d\n", t->slot); fprintf(stderr, " id: %d\n", t->id); fprintf(stderr, " tool_type: %d\n", t->tool_type); fprintf(stderr, " x: %f\n", t->x); fprintf(stderr, " y: %f\n", t->y); fprintf(stderr, " touch_major: %f\n", t->touch_major); fprintf(stderr, " touch_minor: %f\n", t->touch_minor); fprintf(stderr, " width_major: %f\n", t->width_major); fprintf(stderr, " width_minor: %f\n", t->width_minor); fprintf(stderr, " angle: %f\n", t->orientation); fprintf(stderr, " pressure: %f\n", t->pressure); fprintf(stderr, " distance: %f\n", t->distance); } fprintf(stderr, "sync %d %ld %d %d %d\n", frame->num_active, frame->time, frame->sequence_id, frame->revision, frame->slot_revision); } static void loop_device(struct frame_test *test, int fd) { const struct utouch_frame *frame; struct input_event ev; while (!mtdev_idle(test->mtdev, fd, 5000)) { while (mtdev_get(test->mtdev, fd, &ev, 1) > 0) { frame = utouch_frame_pump_mtdev(test->fh, &ev); if (frame) report_frame(frame); } } } static void report_device_caps(struct frame_test *test) { #ifdef INPUT_PROP_POINTER fprintf(stderr, "device props:\n"); if (evemu_has_prop(test->evemu, INPUT_PROP_POINTER)) fprintf(stderr, "\tpointer\n"); if (evemu_has_prop(test->evemu, INPUT_PROP_DIRECT)) fprintf(stderr, "\tdirect\n"); if (evemu_has_prop(test->evemu, INPUT_PROP_BUTTONPAD)) fprintf(stderr, "\tbuttonpad\n"); if (evemu_has_prop(test->evemu, INPUT_PROP_SEMI_MT)) fprintf(stderr, "\tsemi_mt\n"); #endif fprintf(stderr, "device mt events:\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_SLOT)) fprintf(stderr, "\tslot\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_TOUCH_MAJOR)) fprintf(stderr, "\ttouch_major\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_TOUCH_MINOR)) fprintf(stderr, "\ttouch_minor\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_WIDTH_MAJOR)) fprintf(stderr, "\twidth_major\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_WIDTH_MINOR)) fprintf(stderr, "\twidth_minor\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_ORIENTATION)) fprintf(stderr, "\torientation\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_POSITION_X)) fprintf(stderr, "\tposition_x\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_POSITION_Y)) fprintf(stderr, "\tposition_y\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_TOOL_TYPE)) fprintf(stderr, "\tposition_y\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_TRACKING_ID)) fprintf(stderr, "\ttracking_id\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_PRESSURE)) fprintf(stderr, "\tpressure\n"); if (evemu_has_event(test->evemu, EV_ABS, ABS_MT_DISTANCE)) fprintf(stderr, "\tdistance\n"); } int main(int argc, char *argv[]) { struct frame_test test; int fd; if (argc < 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return -1; } fd = open(argv[1], O_RDONLY | O_NONBLOCK); if (fd < 0) { fprintf(stderr, "error: could not open device\n"); return -1; } if (ioctl(fd, EVIOCGRAB, 1)) { fprintf(stderr, "error: could not grab the device\n"); return -1; } if (init_evemu(&test, fd)) { fprintf(stderr, "error: could not describe device\n"); return -1; } if (!utouch_frame_is_supported_mtdev(test.evemu)) { fprintf(stderr, "error: unsupported device\n"); return -1; } fprintf(stderr, "device: %s\n", evemu_get_name(test.evemu)); if (init_mtdev(&test, fd)) { fprintf(stderr, "error: could not init mtdev\n"); return -1; } if (init_frame(&test, fd)) { fprintf(stderr, "error: could not init frame\n"); return -1; } report_device_caps(&test); loop_device(&test, fd); destroy_all(&test); return 0; }