op_test_inputs: minor validation adjustments
[pandora-misc.git] / op_test_inputs.c
1 /*
2  * Copyright (c) 2010, GraÅžvydas Ignotas
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of the organization nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #define _GNU_SOURCE
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h>
34 #include <sys/mman.h>
35 #include <unistd.h>
36 #include <linux/input.h>
37 #include <tslib.h>
38
39 #include "font.c"
40
41 #define array_size(x) (sizeof(x) / sizeof(x[0]))
42
43 typedef struct {
44         int x, y;
45         int code;
46         unsigned int active:1;
47         unsigned int tested:1;
48         const char *name;
49 } key_item;
50
51 static key_item key_items[] =
52 {
53         {  66,  26, KEY_1, 0, 0, "1" },
54         { 133,  26, KEY_2, 0, 0, "2" },
55         { 200,  26, KEY_3, 0, 0, "3" },
56         { 266,  26, KEY_4, 0, 0, "4" },
57         { 333,  26, KEY_5, 0, 0, "5" },
58         { 400,  26, KEY_6, 0, 0, "6" },
59         { 466,  26, KEY_7, 0, 0, "7" },
60         { 533,  26, KEY_8, 0, 0, "8" },
61         { 600,  26, KEY_9, 0, 0, "9" },
62         { 666,  26, KEY_0, 0, 0, "0" },
63         { 733,  26, KEY_BACKSPACE, 0, 0, "DEL" },
64         //
65         {  10,  55, KEY_RIGHTSHIFT,0, 0, "L" },
66         {  10,  75, KEY_KPPLUS,    0, 0, "L2" },
67         { 758,  55, KEY_RIGHTCTRL, 0, 0, "R" },
68         { 758,  75, KEY_KPMINUS,   0, 0, "R2" },
69         {  10, 220, KEY_POWER,     0, 0, "POWER" },
70         {  10, 240, KEY_COFFEE,    0, 0, "HOLD" },
71         //
72         { 130,  94, KEY_UP,     0, 0, "U" },
73         {  80, 163, KEY_LEFT,   0, 0, "L" },
74         { 180, 163, KEY_RIGHT,  0, 0, "R" },
75         { 130, 232, KEY_DOWN,   0, 0, "D" },
76         { 376,  94, KEY_LEFTALT,0, 0, "ALT" },
77         { 368, 163, KEY_LEFTCTRL,0,0, "CTRL" },
78         { 368, 232, KEY_MENU,   0, 0, "MENU" },
79         { 700,  94, KEY_PAGEUP, 0, 0, "Y" },
80         { 650, 163, KEY_HOME,   0, 0, "A" },
81         { 750, 163, KEY_END,    0, 0, "B" },
82         { 700, 232, KEY_PAGEDOWN,0,0, "X" },
83         //
84         {  92, 300, KEY_Q,      0, 0, "Q" },
85         { 158, 300, KEY_W,      0, 0, "W" },
86         { 225, 300, KEY_E,      0, 0, "E" },
87         { 292, 300, KEY_R,      0, 0, "R" },
88         { 358, 300, KEY_T,      0, 0, "T" },
89         { 425, 300, KEY_Y,      0, 0, "Y" },
90         { 492, 300, KEY_U,      0, 0, "U" },
91         { 558, 300, KEY_I,      0, 0, "I" },
92         { 625, 300, KEY_O,      0, 0, "O" },
93         { 692, 300, KEY_P,      0, 0, "P" },
94         //
95         {  30, 369, KEY_LEFTSHIFT, 0, 0, "SHIFT" },
96         { 133, 369, KEY_A,      0, 0, "A" },
97         { 200, 369, KEY_S,      0, 0, "S" },
98         { 266, 369, KEY_D,      0, 0, "D" },
99         { 333, 369, KEY_F,      0, 0, "F" },
100         { 400, 369, KEY_G,      0, 0, "G" },
101         { 466, 369, KEY_H,      0, 0, "H" },
102         { 533, 369, KEY_J,      0, 0, "J" },
103         { 600, 369, KEY_K,      0, 0, "K" },
104         { 666, 369, KEY_L,      0, 0, "L" },
105         { 710, 369, KEY_ENTER,  0, 0, "ENTER" },
106         //
107         {  25, 437, KEY_COMMA,  0, 0, "," },
108         {  92, 437, KEY_DOT,    0, 0, "." },
109         { 158, 437, KEY_Z,      0, 0, "Z" },
110         { 225, 437, KEY_X,      0, 0, "X" },
111         { 292, 437, KEY_C,      0, 0, "C" },
112         { 358, 437, KEY_V,      0, 0, "V" },
113         { 425, 437, KEY_B,      0, 0, "B" },
114         { 492, 437, KEY_N,      0, 0, "N" },
115         { 558, 437, KEY_M,      0, 0, "M" },
116         { 625, 437, KEY_SPACE,  0, 0, "SPACE" },
117         { 758, 437, KEY_FN,     0, 0, "Fn" },
118 };
119
120 #define KI_COUNT (sizeof(key_items) / sizeof(key_items[0]))
121
122 static int nub_range_hit, all_btns_tested, lid_tested, ts_tested;
123 static int ts_old_x, ts_old_y;
124 static int lid_closed;
125
126 static void draw_ts_cross(unsigned short *fb, unsigned short col, int x, int y)
127 {
128         int i, x1, y1;
129
130         if (y >= 0 && y < 480)
131                 for (x1 = x - 5, i = 0; i < 11; i++, x1++)
132                         if (x1 >= 0 && x1 < 800) fb[y * 800 + x1] = col;
133         
134         if (x >= 0 && x < 800)
135                 for (y1 = y - 5, i = 0; i < 11; i++, y1++)
136                         if (y1 >= 0 && y1 < 480) fb[y1 * 800 + x] = col;
137
138         if (x != ts_old_x && y != ts_old_y)
139                 ts_tested = 1;
140
141         ts_old_x = x;
142         ts_old_y = y;
143 }
144
145 static void text_out16(unsigned short *fb, int x, int y, unsigned short col, const char *text)
146 {
147         int i,l;
148
149         fb = fb + x + y*800;
150
151         for (i = 0; i < strlen(text); i++)
152         {
153                 for (l=0;l<8;l++)
154                 {
155                         #define pix(fdmask,add) \
156                                 if (fontdata8x8[((text[i])*8)+l]&fdmask) \
157                                         fb[l*2*800+add]=fb[l*2*800+add+1]=fb[l*2*800+800+add]=fb[l*2*800+800+add+1]=col
158                         pix(0x80,  0);
159                         pix(0x40,  2);
160                         pix(0x20,  4);
161                         pix(0x10,  6);
162                         pix(0x08,  8);
163                         pix(0x04, 10);
164                         pix(0x02, 12);
165                         pix(0x01, 14);
166                         #undef pix
167                 }
168                 fb += 8*2;
169         }
170 }
171
172 static void text_out16_small(unsigned short *fb, int x, int y, unsigned short col, const char *text)
173 {
174         int i,l;
175
176         fb = fb + x + y*800;
177
178         for (i = 0; i < strlen(text); i++)
179         {
180                 for (l=0;l<8;l++)
181                 {
182                         #define pix(fdmask,add) \
183                                 if (fontdata8x8[((text[i])*8)+l]&fdmask) \
184                                         fb[l*800+add]=fb[l*800+800+add]=col
185                         pix(0x80,  0);
186                         pix(0x40,  1);
187                         pix(0x20,  2);
188                         pix(0x10,  3);
189                         pix(0x08,  4);
190                         pix(0x04,  5);
191                         pix(0x02,  6);
192                         pix(0x01,  7);
193                         #undef pix
194                 }
195                 fb += 8;
196         }
197 }
198
199 static void redraw_nubs(unsigned short *fb, int x1, int y1, int x2, int y2)
200 {
201         char buff[32];
202         int fill = 0, y;
203
204         fb += 90*800;
205
206         if (nub_range_hit == 0xff && all_btns_tested && lid_tested && ts_tested)
207                 fill = 3;
208
209         // clear areas
210         for (y = 0; y < 140; y++) {
211                 memset(fb + 800*y + 200, fill, (64+8)*2*2);
212                 memset(fb + 800*y + 450, fill, (64+8)*2*2);
213         }
214
215         text_out16(fb + 200, 32*2 + x1/8, 32*2 + y1/8, 0x001f, "@");
216         text_out16(fb + 450, 32*2 + x2/8, 32*2 + y2/8, 0x001f, "@");
217
218         if (x1 == -256) nub_range_hit |= 0x01;
219         if (x1 ==  256) nub_range_hit |= 0x02;
220         if (y1 == -256) nub_range_hit |= 0x04;
221         if (y1 ==  256) nub_range_hit |= 0x08;
222         if (x2 == -256) nub_range_hit |= 0x10;
223         if (x2 ==  256) nub_range_hit |= 0x20;
224         if (y2 == -256) nub_range_hit |= 0x40;
225         if (y2 ==  256) nub_range_hit |= 0x80;
226
227         snprintf(buff, sizeof(buff), "%3i", x1/8);
228         text_out16_small(fb, 235, 130, (nub_range_hit & 0x03) == 0x03 ? 0xce6f : 0x7bef, buff);
229         snprintf(buff, sizeof(buff), "%3i", y1/8);
230         text_out16_small(fb, 270, 130, (nub_range_hit & 0x0c) == 0x0c ? 0xce6f : 0x7bef, buff);
231
232         snprintf(buff, sizeof(buff), "%3i", x2/8);
233         text_out16_small(fb, 485, 130, (nub_range_hit & 0x30) == 0x30 ? 0xce6f : 0x7bef, buff);
234         snprintf(buff, sizeof(buff), "%3i", y2/8);
235         text_out16_small(fb, 520, 130, (nub_range_hit & 0xc0) == 0xc0 ? 0xce6f : 0x7bef, buff);
236 }
237
238 static void redraw_keys_lid(unsigned short *fb)
239 {
240         const key_item *key;
241         int i;
242
243         for (i = 0; i < KI_COUNT; i++)
244         {
245                 key = &key_items[i];
246
247                 text_out16(fb, key->x, key->y,
248                         key->active ? 0x07e0 : (key->tested ? 0xce6f : 0x7bef),
249                         key->name);
250         }
251
252         text_out16(fb, 10, 260, lid_closed ? 0x07e0 : (lid_tested ? 0xce6f : 0x7bef), "LID");
253 }
254
255 static void set_key(int code, int val)
256 {
257         key_item *key = NULL;
258         int i;
259
260         for (i = 0; i < KI_COUNT; i++)
261         {
262                 if (key_items[i].code == code)
263                 {
264                         key = &key_items[i];
265                         break;
266                 }
267         }
268
269         if (key == NULL)
270         {
271                 printf("%c unexpected key? (%i)\n", val ? '+' : '-', code);
272         }
273         else
274         {
275                 key->active = !!val;
276                 key->tested |= !!val;
277                 printf("%c %s\n", val ? '+' : '-', key->name);
278         }
279
280         if (all_btns_tested)
281                 return;
282
283         for (i = 0; i < KI_COUNT; i++)
284         {
285                 if (key_items[i].code == KEY_MENU)
286                         continue;
287                 if (key_items[i].code == KEY_KPPLUS || key_items[i].code == KEY_KPMINUS)
288                         continue;
289                 if (!key_items[i].tested)
290                         break;
291         }
292
293         if (i == KI_COUNT)
294                 all_btns_tested = 1;
295 }
296
297 /* sound test */
298 #include <sys/soundcard.h>
299 #include <pthread.h>
300
301 static int snd_test_l, snd_test_r, snd_test_quit;
302 static pthread_cond_t snd_cond = PTHREAD_COND_INITIALIZER;
303 static pthread_mutex_t snd_mutex = PTHREAD_MUTEX_INITIALIZER;
304
305 static void *sound_thread(void *arg)
306 {
307         int i, ret, randfd, dspfd;
308         int frag, bits, stereo, rate;
309         short buf[8*1024];//2*22050 / 10];
310
311         randfd = open("/dev/urandom", O_RDONLY);
312         if (randfd == -1) {
313                 perror("open(\"/dev/urandom\")");
314                 return NULL;
315         }
316
317         dspfd = open("/dev/dsp", O_WRONLY);
318         if (dspfd == -1) {
319                 perror("open(\"/dev/dsp\")");
320                 close(randfd);
321                 return NULL;
322         }
323
324         frag = (2 << 16) | 13;
325         ret = ioctl(dspfd, SNDCTL_DSP_SETFRAGMENT, &frag);
326         if (ret < 0)
327                 perror("SNDCTL_DSP_SETFRAGMENT");
328
329         stereo = 1; bits = 16; rate = 22050;
330         ret = ioctl(dspfd, SNDCTL_DSP_STEREO, &stereo);
331         if (ret == 0)
332                 ret = ioctl(dspfd, SNDCTL_DSP_SETFMT, &bits);
333         if (ret == 0)
334                 ret = ioctl(dspfd, SNDCTL_DSP_SPEED, &rate);
335         if (ret < 0)
336                 perror("failed to set audio format");
337
338         while (1) {
339                 pthread_mutex_lock(&snd_mutex);
340                 if (!snd_test_l && !snd_test_r)
341                         pthread_cond_wait(&snd_cond, &snd_mutex);
342                 pthread_mutex_unlock(&snd_mutex);
343
344                 if (snd_test_quit)
345                         break;
346
347                 ret = read(randfd, buf, sizeof(buf));
348                 if (ret == -1) {
349                         perror("urandom read");
350                         break;
351                 }
352
353                 if (!snd_test_l)
354                         for (i = 0; i < array_size(buf) / 2; i++)
355                                 buf[i * 2] = 0;
356                 if (!snd_test_r)
357                         for (i = 0; i < array_size(buf) / 2; i++)
358                                 buf[i * 2 + 1] = 0;
359
360                 ret = write(dspfd, buf, sizeof(buf));
361                 if (ret == -1) {
362                         perror("dsp write");
363                         break;
364                 }
365         }
366
367         close(randfd);
368         close(dspfd);
369
370         return NULL;
371 }
372
373 static void sound_init(void)
374 {
375         pthread_t tid;
376         int ret;
377
378         ret = pthread_create(&tid, NULL, sound_thread, NULL);
379         if (ret != 0) {
380                 fprintf(stderr, "pthread_create sound_thread: %d\n", ret);
381                 return;
382         }
383         pthread_detach(tid);
384 }
385
386 static void sound_do(int l, int r)
387 {
388         pthread_mutex_lock(&snd_mutex);
389         snd_test_l = l;
390         snd_test_r = r;
391         if (l || r || snd_test_quit)
392                 pthread_cond_signal(&snd_cond);
393         pthread_mutex_unlock(&snd_mutex);
394 }
395
396 enum {
397         DEV_PWRBTN,
398         DEV_KEYPAD,
399         DEV_BUTTONS,
400         DEV_TS,
401         DEV_LNUB,
402         DEV_RNUB,
403         DEVS_TOTAL
404 };
405
406 int main(int argc, char *argv[])
407 {
408         unsigned short *screen;
409         int fbdev, ifd[DEVS_TOTAL] = { -1, -1, -1, -1, -1, -1 };
410         int i, id, imaxfd = 0, ts_x = 0, ts_y = 0;
411         int nubx[2] = {0,0}, nuby[2] = {0,0};
412         int pressed_l = 0, pressed_r = 0;
413         struct tsdev *ts = NULL;
414
415         fbdev = open("/dev/fb0", O_RDWR);
416         if (fbdev == -1)
417         {
418                 perror("open(\"/dev/fb0\") failed");
419                 return 1;
420         }
421
422         screen = mmap(0, 800*480*2, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev, 0);
423         if (screen == MAP_FAILED)
424         {
425                 perror("mmap(fbptr) failed");
426                 return 1;
427         }
428
429         memset(screen, 0, 800*480*2);
430
431         sound_init();
432
433         for (id = 0; ; id++)
434         {
435                 char fname[64];
436                 char name[256] = { 0, };
437                 int fd;
438
439                 snprintf(fname, sizeof(fname), "/dev/input/event%i", id);
440                 fd = open(fname, O_RDONLY);
441                 if (fd == -1)
442                 {
443                         break;
444                 }
445
446                 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
447
448                 if (strcasestr(name, "power") != NULL || strcasestr(name, "pwrbutton") != NULL)
449                 {
450                         ifd[DEV_PWRBTN] = fd;
451                 }
452                 else if (strcasestr(name, "keypad") != NULL)
453                 {
454                         ifd[DEV_KEYPAD] = fd;
455                 }
456                 else if (strcmp(name, "gpio-keys") == 0)
457                 {
458                         ifd[DEV_BUTTONS] = fd;
459                 }
460                 else if (strcasestr(name, "touchscreen") != NULL)
461                 {
462                         close(fd);
463                         ts = ts_open(fname, 0);
464                         if (ts == NULL)
465                         {
466                                 perror("ts_open");
467                                 goto end;
468                         }
469                         if (ts_config(ts))
470                         {
471                                 perror("ts_config");
472                                 goto end;
473                         }
474                         ifd[DEV_TS] = ts_fd(ts);
475                 }
476                 else if (strcmp(name, "nub0") == 0)
477                 {
478                         ifd[DEV_LNUB] = fd;
479                 }
480                 else if (strcmp(name, "nub1") == 0)
481                 {
482                         ifd[DEV_RNUB] = fd;
483                 }
484                 else
485                 {
486                         printf("skipping \"%s\"\n", name);
487                         close(fd);
488                         continue;
489                 }
490                 if (imaxfd < fd) imaxfd = fd;
491         }
492
493         if (ifd[DEV_PWRBTN]  == -1) printf("Warning: couldn't find pwrbutton device\n");
494         if (ifd[DEV_KEYPAD]  == -1) printf("Warning: couldn't find keypad device\n");
495         if (ifd[DEV_BUTTONS] == -1) printf("Warning: couldn't find button device\n");
496         if (ifd[DEV_TS]      == -1) printf("Warning: couldn't find touchscreen device\n");
497         if (ifd[DEV_LNUB]    == -1) printf("Warning: couldn't find nub1 device\n");
498         if (ifd[DEV_RNUB]    == -1) printf("Warning: couldn't find nub2 device\n");
499
500 #ifdef VALIDATION
501         int early_leave_attempt = 0;
502         text_out16_small(screen, 220, 3, 0x7bef,
503                          "press menu/pandora to exit");
504 #else
505         text_out16_small(screen, 320, 3, 0x7bef, "Press L+R to exit");
506 #endif
507
508 #ifdef VALIDATION
509         while (1)
510 #else
511         while (!pressed_l || !pressed_r)
512 #endif
513         {
514                 struct input_event ev[64];
515                 int fd = -1, rd, which, ret;
516                 fd_set fdset;
517
518 #ifdef VALIDATION
519                 if (early_leave_attempt) {
520                         char buff[128];
521                         snprintf(buff, sizeof(buff), "not everything tested (%s%s%s%s), L+R to override",
522                                 nub_range_hit == 0xff ? "" : "nubs", all_btns_tested ? "" : " buttons",
523                                 lid_tested ? "" : " lid_switch", ts_tested ? "" : " touchscreen");
524                         memset(screen, 0, 800*12*2);
525                         if (nub_range_hit == 0xff && all_btns_tested && lid_tested && ts_tested)
526                                 text_out16_small(screen, 220, 3, 0x07c0,
527                                         "press menu/pandora to shutdown, L+Start to exit");
528                         else
529                                 text_out16_small(screen, 4, 3, 0xf800, buff);
530                 }
531 #endif
532                 draw_ts_cross(screen, 0x0000, ts_old_x, ts_old_y);
533                 redraw_keys_lid(screen);
534                 redraw_nubs(screen, nubx[0], nuby[0], nubx[1], nuby[1]);
535                 draw_ts_cross(screen, 0xf800, ts_x, ts_y);
536
537                 FD_ZERO(&fdset);
538                 for (i = 0; i < DEVS_TOTAL; i++)
539                         if (ifd[i] != -1)
540                                 FD_SET(ifd[i], &fdset);
541
542                 ret = select(imaxfd + 1, &fdset, NULL, NULL, NULL);
543                 if (ret == -1)
544                 {
545                         perror("select");
546                         break;
547                 }
548
549                 for (i = 0; i < DEVS_TOTAL; i++)
550                         if (ifd[i] != -1 && FD_ISSET(ifd[i], &fdset))
551                                 fd = ifd[i];
552
553                 /* touch event? */
554                 if (fd == ifd[DEV_TS])
555                 {
556                         struct ts_sample samp;
557
558                         ret = ts_read(ts, &samp, 1);
559                         if (ret < 0) {
560                                 perror("ts_read");
561                                 break;
562                         }
563
564                         if (ret != 1)
565                                 continue;
566
567                         ts_x = samp.x; ts_y = samp.y;
568                         //printf("ts: %6d %6d %6d\n", samp.x, samp.y, samp.pressure);
569                         continue;
570                 }
571
572                 /* buttons or keypad */
573                 rd = read(fd, ev, sizeof(ev));
574                 if (rd < (int) sizeof(ev[0])) {
575                         perror("\nevtest: error reading");
576                         break;
577                 }
578
579                 for (i = 0; i < rd / sizeof(ev[0]); i++)
580                 {
581                         switch (ev[i].type) {
582                         case EV_SYN:
583                                 break;
584                         case EV_KEY:
585                                 set_key(ev[i].code, ev[i].value);
586
587                                 if (ev[i].code == KEY_RIGHTSHIFT)
588                                         pressed_l = !!ev[i].value;
589                                 if (ev[i].code == KEY_RIGHTCTRL)
590                                         pressed_r = !!ev[i].value;
591 #ifdef VALIDATION
592                                 if (ev[i].code == KEY_LEFTALT && !!ev[i].value && pressed_l) {
593                                         // L+Start, legacy code
594                                         if (nub_range_hit == 0xff && all_btns_tested && lid_tested && ts_tested)
595                                                 goto end;
596                                         if (pressed_l && pressed_r)
597                                                 goto end;
598                                         early_leave_attempt = 1;
599                                 }
600                                 if (ev[i].code == KEY_MENU && !!ev[i].value) {
601                                         if ((nub_range_hit == 0xff && all_btns_tested && lid_tested && ts_tested) ||
602                                             (pressed_l && pressed_r)) {
603                                                 sync();
604                                                 //system("poweroff -f");
605                                                 goto end;
606                                         }
607                                         early_leave_attempt = 1;
608                                 }
609 #endif
610                                 if (ev[i].code == KEY_LEFT)
611                                         sound_do(!!ev[i].value, snd_test_r);
612                                 if (ev[i].code == KEY_RIGHT)
613                                         sound_do(snd_test_l, !!ev[i].value);
614                                 break;
615                         case EV_ABS:
616                                 which = (fd == ifd[DEV_LNUB]) ? 0 : 1;
617                                 if (ev[i].code == ABS_X)
618                                         nubx[which] = ev[i].value;
619                                 else if (ev[i].code == ABS_Y)
620                                         nuby[which] = ev[i].value;
621                                 else
622                                         printf("unexpected EV_ABS code: %i\n", ev[i].code);
623                                 break;
624                         case EV_SW:
625                                 if (ev[i].code == SW_LID) {
626                                         lid_closed = ev[i].value;
627                                         lid_tested |= ev[i].value;
628                                 }
629                                 else
630                                         printf("unexpected EV_SW code: %i\n", ev[i].code);
631                                 break;
632                         case EV_MSC:
633                                 if (ev[i].code == MSC_SCAN)
634                                         break;
635                                 /* fallthrough */
636                         default:
637                                 printf("unexpected event: type %i, code %d\n", ev[i].type, ev[i].code);
638                                 break;
639                         }
640                 }
641         }
642
643         snd_test_quit = 1;
644         sound_do(0, 0);
645
646 end:
647         if (ts != NULL)
648                 ts_close(ts);
649         for (i = 0; i < DEVS_TOTAL; i++)
650                 if (i != DEV_TS && ifd[i] != -1)
651                         close(ifd[i]);
652         munmap(screen, 800*480*2);
653         close(fbdev);
654         return 0;
655 }
656