summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/utouch-frame-test-mtdev.c67
1 files changed, 50 insertions, 17 deletions
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 {
36 struct evemu_device *evemu; 36 struct evemu_device *evemu;
37 struct mtdev *mtdev; 37 struct mtdev *mtdev;
38 utouch_frame_handle fh; 38 utouch_frame_handle fh;
39 struct stat fs;
40 FILE *fptest;
41 int fd;
39}; 42};
40 43
41static int init_evemu(struct frame_test *test, int fd) 44static int init_evemu(struct frame_test *test)
42{ 45{
43 test->evemu = evemu_new(NULL); 46 test->evemu = evemu_new(NULL);
44 if (!test->evemu) 47 if (!test->evemu)
45 return -1; 48 return -1;
46 return evemu_extract(test->evemu, fd); 49 if (test->fptest)
50 return evemu_read(test->evemu, test->fptest) <= 0;
51 return evemu_extract(test->evemu, test->fd);
47} 52}
48 53
49static int init_mtdev(struct frame_test *test, int fd) 54static int init_mtdev(struct frame_test *test)
50{ 55{
51 test->mtdev = mtdev_new_open(fd); 56 if (test->fptest)
57 return 0;
58 test->mtdev = mtdev_new_open(test->fd);
52 if (!test->mtdev) 59 if (!test->mtdev)
53 return -1; 60 return -1;
54 return 0; 61 return 0;
55} 62}
56 63
57static int init_frame(struct frame_test *test, int fd) 64static int init_frame(struct frame_test *test)
58{ 65{
59 test->fh = utouch_frame_new_engine(100, 32, 100); 66 test->fh = utouch_frame_new_engine(100, 32, 100);
60 if (!test->fh) 67 if (!test->fh)
@@ -65,46 +72,71 @@ static int init_frame(struct frame_test *test, int fd)
65static void destroy_all(struct frame_test *test) 72static void destroy_all(struct frame_test *test)
66{ 73{
67 utouch_frame_delete_engine(test->fh); 74 utouch_frame_delete_engine(test->fh);
68 mtdev_close_delete(test->mtdev); 75 if (test->mtdev)
76 mtdev_close_delete(test->mtdev);
69 evemu_delete(test->evemu); 77 evemu_delete(test->evemu);
78 if (test->fptest)
79 fclose(test->fptest);
80 else
81 ioctl(test->fd, EVIOCGRAB, 0);
82 close(test->fd);
70 memset(test, 0, sizeof(*test)); 83 memset(test, 0, sizeof(*test));
71} 84}
72 85
73static void loop_device(struct frame_test *test, int fd) 86static void loop_device(struct frame_test *test)
74{ 87{
88 FILE * fp = test->fptest;
75 const struct utouch_frame *frame; 89 const struct utouch_frame *frame;
76 struct input_event ev; 90 struct input_event ev;
77 91
78 while (!mtdev_idle(test->mtdev, fd, 5000)) { 92 if (fp) {
79 while (mtdev_get(test->mtdev, fd, &ev, 1) > 0) { 93 struct timeval evtime;
94 memset(&evtime, 0, sizeof(evtime));
95 while (evemu_read_event_realtime(fp, &ev, &evtime) > 0) {
80 frame = utouch_frame_pump_mtdev(test->fh, &ev); 96 frame = utouch_frame_pump_mtdev(test->fh, &ev);
81 if (frame) 97 if (frame)
82 report_frame(frame); 98 report_frame(frame);
83 } 99 }
100 } else {
101 while (!mtdev_idle(test->mtdev, test->fd, 5000)) {
102 while (mtdev_get(test->mtdev, test->fd, &ev, 1) > 0) {
103 frame = utouch_frame_pump_mtdev(test->fh, &ev);
104 if (frame)
105 report_frame(frame);
106 }
107 }
84 } 108 }
85} 109}
86 110
87int main(int argc, char *argv[]) 111int main(int argc, char *argv[])
88{ 112{
89 struct frame_test test; 113 struct frame_test test;
90 int fd;
91 114
92 if (argc < 2) { 115 if (argc < 2) {
93 fprintf(stderr, "Usage: %s <device>\n", argv[0]); 116 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
94 return -1; 117 return -1;
95 } 118 }
96 119
97 fd = open(argv[1], O_RDONLY | O_NONBLOCK); 120 memset(&test, 0, sizeof(test));
98 if (fd < 0) { 121
122 test.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
123 if (test.fd < 0) {
99 fprintf(stderr, "error: could not open device\n"); 124 fprintf(stderr, "error: could not open device\n");
100 return -1; 125 return -1;
101 } 126 }
102 if (ioctl(fd, EVIOCGRAB, 1)) { 127 if (fstat(test.fd, &test.fs)) {
128 fprintf(stderr, "error: could not stat the device\n");
129 return -1;
130 }
131 if (!test.fs.st_rdev)
132 test.fptest = fdopen(test.fd, "r");
133
134 if (!test.fptest && ioctl(test.fd, EVIOCGRAB, 1)) {
103 fprintf(stderr, "error: could not grab the device\n"); 135 fprintf(stderr, "error: could not grab the device\n");
104 return -1; 136 return -1;
105 } 137 }
106 138
107 if (init_evemu(&test, fd)) { 139 if (init_evemu(&test)) {
108 fprintf(stderr, "error: could not describe device\n"); 140 fprintf(stderr, "error: could not describe device\n");
109 return -1; 141 return -1;
110 } 142 }
@@ -115,19 +147,20 @@ int main(int argc, char *argv[])
115 147
116 fprintf(stderr, "device: %s\n", evemu_get_name(test.evemu)); 148 fprintf(stderr, "device: %s\n", evemu_get_name(test.evemu));
117 149
118 if (init_mtdev(&test, fd)) { 150 if (init_mtdev(&test)) {
119 fprintf(stderr, "error: could not init mtdev\n"); 151 fprintf(stderr, "error: could not init mtdev\n");
120 return -1; 152 return -1;
121 } 153 }
122 if (init_frame(&test, fd)) { 154 if (init_frame(&test)) {
123 fprintf(stderr, "error: could not init frame\n"); 155 fprintf(stderr, "error: could not init frame\n");
124 return -1; 156 return -1;
125 } 157 }
126 158
127 report_device_caps(test.fh); 159 report_device_caps(test.fh);
128 160
129 loop_device(&test, fd); 161 loop_device(&test);
130 162
131 destroy_all(&test); 163 destroy_all(&test);
164
132 return 0; 165 return 0;
133} 166}