From 84733b1d7ccee2a8c6d8874c8e5cd8e3d67eba1b Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Tue, 15 Mar 2011 19:57:46 +0100 Subject: Allow replay of device data through utouch-frame This patch adds replay capabilities to test-mtdev. If the specified device points to a valid evemu file, the device properties will be extracted from that file instead. Any appended event data will be replayed in realtime. In practise, test-mtdev can be executed with a test file. Signed-off-by: Henrik Rydberg --- tools/utouch-frame-test-mtdev.c | 67 ++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 17 deletions(-) (limited to 'tools') diff --git a/tools/utouch-frame-test-mtdev.c b/tools/utouch-frame-test-mtdev.c index 4838f84..5253320 100644 --- a/tools/utouch-frame-test-mtdev.c +++ b/tools/utouch-frame-test-mtdev.c @@ -36,25 +36,32 @@ struct frame_test { struct evemu_device *evemu; struct mtdev *mtdev; utouch_frame_handle fh; + struct stat fs; + FILE *fptest; + int fd; }; -static int init_evemu(struct frame_test *test, int fd) +static int init_evemu(struct frame_test *test) { test->evemu = evemu_new(NULL); if (!test->evemu) return -1; - return evemu_extract(test->evemu, fd); + if (test->fptest) + return evemu_read(test->evemu, test->fptest) <= 0; + return evemu_extract(test->evemu, test->fd); } -static int init_mtdev(struct frame_test *test, int fd) +static int init_mtdev(struct frame_test *test) { - test->mtdev = mtdev_new_open(fd); + if (test->fptest) + return 0; + test->mtdev = mtdev_new_open(test->fd); if (!test->mtdev) return -1; return 0; } -static int init_frame(struct frame_test *test, int fd) +static int init_frame(struct frame_test *test) { test->fh = utouch_frame_new_engine(100, 32, 100); if (!test->fh) @@ -65,46 +72,71 @@ static int init_frame(struct frame_test *test, int fd) static void destroy_all(struct frame_test *test) { utouch_frame_delete_engine(test->fh); - mtdev_close_delete(test->mtdev); + if (test->mtdev) + mtdev_close_delete(test->mtdev); evemu_delete(test->evemu); + if (test->fptest) + fclose(test->fptest); + else + ioctl(test->fd, EVIOCGRAB, 0); + close(test->fd); memset(test, 0, sizeof(*test)); } -static void loop_device(struct frame_test *test, int fd) +static void loop_device(struct frame_test *test) { + FILE * fp = test->fptest; 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) { + if (fp) { + struct timeval evtime; + memset(&evtime, 0, sizeof(evtime)); + while (evemu_read_event_realtime(fp, &ev, &evtime) > 0) { frame = utouch_frame_pump_mtdev(test->fh, &ev); if (frame) report_frame(frame); } + } else { + while (!mtdev_idle(test->mtdev, test->fd, 5000)) { + while (mtdev_get(test->mtdev, test->fd, &ev, 1) > 0) { + frame = utouch_frame_pump_mtdev(test->fh, &ev); + if (frame) + report_frame(frame); + } + } } } 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) { + memset(&test, 0, sizeof(test)); + + test.fd = open(argv[1], O_RDONLY | O_NONBLOCK); + if (test.fd < 0) { fprintf(stderr, "error: could not open device\n"); return -1; } - if (ioctl(fd, EVIOCGRAB, 1)) { + if (fstat(test.fd, &test.fs)) { + fprintf(stderr, "error: could not stat the device\n"); + return -1; + } + if (!test.fs.st_rdev) + test.fptest = fdopen(test.fd, "r"); + + if (!test.fptest && ioctl(test.fd, EVIOCGRAB, 1)) { fprintf(stderr, "error: could not grab the device\n"); return -1; } - if (init_evemu(&test, fd)) { + if (init_evemu(&test)) { fprintf(stderr, "error: could not describe device\n"); return -1; } @@ -115,19 +147,20 @@ int main(int argc, char *argv[]) fprintf(stderr, "device: %s\n", evemu_get_name(test.evemu)); - if (init_mtdev(&test, fd)) { + if (init_mtdev(&test)) { fprintf(stderr, "error: could not init mtdev\n"); return -1; } - if (init_frame(&test, fd)) { + if (init_frame(&test)) { fprintf(stderr, "error: could not init frame\n"); return -1; } report_device_caps(test.fh); - loop_device(&test, fd); + loop_device(&test); destroy_all(&test); + return 0; } -- cgit v1.2.3