1 diff -Naur tslib-org/tests/Makefile.am tslib-1.0/tests/Makefile.am
2 --- tslib-org/tests/Makefile.am 2006-08-25 00:02:55.000000000 +0300
3 +++ tslib-1.0/tests/Makefile.am 2007-05-07 17:39:54.000000000 +0300
5 AM_CFLAGS = $(DEBUGFLAGS)
6 INCLUDES = -I$(top_srcdir)/src
8 -bin_PROGRAMS = ts_test ts_calibrate ts_print ts_print_raw ts_harvest
9 +bin_PROGRAMS = ts_test ts_calibrate ts_print ts_print_raw ts_harvest ts_finddev inputattach
11 ts_test_SOURCES = ts_test.c fbutils.c fbutils.h font_8x8.c font_8x16.c font.h
12 ts_test_LDADD = $(top_builddir)/src/libts.la
14 ts_calibrate_LDADD = $(top_builddir)/src/libts.la
16 ts_harvest_SOURCES = ts_harvest.c fbutils.c fbutils.h testutils.c testutils.h font_8x8.c font_8x16.c font.h
17 -ts_harvest_LDADD = $(top_builddir)/src/libts.la
18 +ts_harvest_LDADD = $(top_builddir)/src/libts.la
20 +ts_finddev_SOURCES = ts_finddev.c
21 +ts_finddev_LDADD = $(top_builddir)/src/libts.la
23 +inputattach_SOURCES = inputattach.c
25 diff -Naur tslib-org/tests/inputattach.c tslib-1.0/tests/inputattach.c
26 --- tslib-org/tests/inputattach.c 1970-01-01 02:00:00.000000000 +0200
27 +++ tslib-1.0/tests/inputattach.c 2007-05-07 17:36:37.000000000 +0300
30 + * $Id: inputattach.c,v 1.24 2006/02/08 12:19:31 vojtech Exp $
32 + * Copyright (c) 1999-2000 Vojtech Pavlik
36 + * Twiddler support Copyright (c) 2001 Arndt Schoenewald
37 + * Sponsored by Quelltext AG (http://www.quelltext-ag.de), Dortmund, Germany
41 + * Input line discipline attach program
45 + * This program is free software; you can redistribute it and/or modify
46 + * it under the terms of the GNU General Public License as published by
47 + * the Free Software Foundation; either version 2 of the License, or
48 + * (at your option) any later version.
50 + * This program is distributed in the hope that it will be useful,
51 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
52 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53 + * GNU General Public License for more details.
55 + * You should have received a copy of the GNU General Public License
56 + * along with this program; if not, write to the Free Software
57 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
59 + * Should you need to contact me, the author, you can do so either by
60 + * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
61 + * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
66 +http://cvs.sourceforge.net/viewcvs.py/ *checkout* /linuxconsole/ruby/utils/inputattach.c
69 +#include <linux/serio.h>
71 +#include <sys/types.h>
72 +#include <sys/stat.h>
73 +#include <sys/ioctl.h>
74 +#include <sys/time.h>
89 +#ifndef SERIO_UNKNOWN
90 + #define SERIO_UNKNOWN 0x00
93 + #define SERIO_MSC 0x01
96 + #define SERIO_SUN 0x02
99 + #define SERIO_MS 0x03
102 + #define SERIO_MP 0x04
105 + #define SERIO_MZ 0x05
108 + #define SERIO_MZP 0x06
111 + #define SERIO_MZPP 0x07
113 +#ifndef SERIO_VSXXXAA
114 + #define SERIO_VSXXXAA 0x08
116 +#ifndef SERIO_SUNKBD
117 + #define SERIO_SUNKBD 0x10
119 +#ifndef SERIO_WARRIOR
120 + #define SERIO_WARRIOR 0x18
122 +#ifndef SERIO_WARRIOR
123 + #define SERIO_SPACEORB 0x19
125 +#ifndef SERIO_MAGELLAN
126 + #define SERIO_MAGELLAN 0x1a
128 +#ifndef SERIO_SPACEBALL
129 + #define SERIO_SPACEBALL 0x1b
132 + #define SERIO_GUNZE 0x1c
134 +#ifndef SERIO_IFORCE
135 + #define SERIO_IFORCE 0x1d
137 +#ifndef SERIO_STINGER
138 + #define SERIO_STINGER 0x1e
140 +#ifndef SERIO_NEWTON
141 + #define SERIO_NEWTON 0x1f
143 +#ifndef SERIO_STOWAWAY
144 + #define SERIO_STOWAWAY 0x20
147 + #define SERIO_H3600 0x21
149 +#ifndef SERIO_PS2SER
150 + #define SERIO_PS2SER 0x22
152 +#ifndef SERIO_TWIDKBD
153 + #define SERIO_TWIDKBD 0x23
155 +#ifndef SERIO_TWIDJOY
156 + #define SERIO_TWIDJOY 0x24
159 + #define SERIO_HIL 0x25
161 +#ifndef SERIO_SNES232
162 + #define SERIO_SNES232 0x26
164 +#ifndef SERIO_SEMTECH
165 + #define SERIO_SEMTECH 0x27
168 + #define SERIO_LKKBD 0x28
171 + #define SERIO_ELO 0x29
173 +#ifndef SERIO_MICROTOUCH
174 + #define SERIO_MICROTOUCH 0x30
176 +#ifndef SERIO_PENMOUNT
177 + #define SERIO_PENMOUNT 0x31
179 +#ifndef SERIO_TOUCHRIGHT
180 + #define SERIO_TOUCHRIGHT 0x32
182 +#ifndef SERIO_TOUCHWIN
183 + #define SERIO_TOUCHWIN 0x33
187 +int readchar(int fd, unsigned char *c, int timeout)
193 + tv.tv_usec = timeout * 1000;
198 + if (!select(fd+1, &set, NULL, NULL, &tv)) return -1;
199 + if (read(fd, c, 1) != 1) return -1;
206 +void setline(int fd, int flags, int speed)
212 + t.c_cflag = flags | CREAD | HUPCL | CLOCAL;
213 + t.c_iflag = IGNBRK | IGNPAR;
219 + cfsetispeed(&t, speed);
220 + cfsetospeed(&t, speed);
222 + tcsetattr(fd, TCSANOW, &t);
225 +int logitech_command(int fd, char *c)
229 + for (i = 0; c[i]; i++) {
230 + write(fd, c + i, 1);
231 + if (readchar(fd, &d, 1000))
239 +int magellan_init(int fd, long *id, long *extra)
241 + write(fd, "m3\rpBB\rz\r", 9);
245 +int warrior_init(int fd, long *id, long *extra)
247 + if (logitech_command(fd, "*S")) return -1;
248 + setline(fd, CS8, B4800);
252 +int spaceball_waitchar(int fd, unsigned char c, unsigned char *d, int timeout)
254 + unsigned char b = 0;
256 + while (!readchar(fd, &b, timeout)) {
257 + if (b == 0x0a) continue;
267 +int spaceball_waitcmd(int fd, char c, char *d)
271 + for (i = 0; i < 8; i++) {
272 + if (spaceball_waitchar(fd, 0x0d, d, 1000))
281 +int spaceball_cmd(int fd, char *c, char *d)
285 + for (i = 0; c[i]; i++)
286 + write(fd, c + i, 1);
287 + write(fd, "\r", 1);
289 + i = spaceball_waitcmd(fd, toupper(c[0]), d);
294 +#define SPACEBALL_1003 1
295 +#define SPACEBALL_2003B 3
296 +#define SPACEBALL_2003C 4
297 +#define SPACEBALL_3003C 7
298 +#define SPACEBALL_4000FLX 8
299 +#define SPACEBALL_4000FLX_L 9
301 +int spaceball_init(int fd, long *id, long *extra)
305 + if (spaceball_waitchar(fd, 0x11, r, 4000) ||
306 + spaceball_waitchar(fd, 0x0d, r, 1000))
309 + if (spaceball_waitcmd(fd, '@', r))
312 + if (strncmp("@1 Spaceball alive", r, 18))
315 + if (spaceball_waitcmd(fd, '@', r))
318 + if (spaceball_cmd(fd, "hm", r))
321 + if (!strncmp("Hm2003B", r, 7))
322 + *id = SPACEBALL_2003B;
323 + if (!strncmp("Hm2003C", r, 7))
324 + *id = SPACEBALL_2003C;
325 + if (!strncmp("Hm3003C", r, 7))
326 + *id = SPACEBALL_3003C;
328 + if (!strncmp("HvFirmware", r, 10)) {
330 + if (spaceball_cmd(fd, "\"", r))
333 + if (strncmp("\"1 Spaceball 4000 FLX", r, 21))
336 + if (spaceball_waitcmd(fd, '"', r))
339 + if (strstr(r, " L "))
340 + *id = SPACEBALL_4000FLX_L;
342 + *id = SPACEBALL_4000FLX;
344 + if (spaceball_waitcmd(fd, '"', r))
347 + if (spaceball_cmd(fd, "YS", r))
350 + if (spaceball_cmd(fd, "M", r))
356 + if (spaceball_cmd(fd, "P@A@A", r) ||
357 + spaceball_cmd(fd, "FT@", r) ||
358 + spaceball_cmd(fd, "MSS", r))
364 +int stinger_init(int fd, long *id, long *extra)
368 + unsigned char *response = "\r\n0600520058C272";
370 + if (write(fd, " E5E5", 5) != 5) /* Enable command */
373 + for (i = 0; i < 16; i++) /* Check for Stinger */
374 + if (readchar(fd, &c, 200) || (c != response[i]))
380 +int mzp_init(int fd, long *id, long *extra)
382 + if (logitech_command(fd, "*X*q")) return -1;
383 + setline(fd, CS8, B9600);
387 +int newton_init(int fd, long *id, long *extra)
391 + unsigned char response[35] =
392 + { 0x16, 0x10, 0x02, 0x64, 0x5f, 0x69, 0x64, 0x00,
393 + 0x00, 0x00, 0x0c, 0x6b, 0x79, 0x62, 0x64, 0x61,
394 + 0x70, 0x70, 0x6c, 0x00, 0x00, 0x00, 0x01, 0x6e,
395 + 0x6f, 0x66, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10,
396 + 0x03, 0xdd, 0xe7 };
398 + for (i = 0; i < 35; i++)
399 + if (readchar(fd, &c, 400) || (c != response[i]))
405 +int twiddler_init(int fd, long *id, long *extra)
407 + unsigned char c[10];
410 + /* Turn DTR off, otherwise the Twiddler won't send any data. */
411 + if (ioctl(fd, TIOCMGET, &line)) return -1;
412 + line &= ~TIOCM_DTR;
413 + if (ioctl(fd, TIOCMSET, &line)) return -1;
415 + /* Check whether the device on the serial line is the Twiddler.
417 + * The Twiddler sends data packets of 5 bytes which have the following
418 + * properties: the MSB is 0 on the first and 1 on all other bytes, and
419 + * the high order nibble of the last byte is always 0x8.
421 + * We read and check two of those 5 byte packets to be sure that we
422 + * are indeed talking to a Twiddler. */
424 + /* Read at most 5 bytes until we find one with the MSB set to 0 */
425 + for (count = 0; count < 5; count++) {
426 + if (readchar(fd, c+0, 500)) return -1;
427 + if ((c[0] & 0x80) == 0) break;
431 + /* Could not find header byte in data stream */
435 + /* Read remaining 4 bytes plus the full next data packet */
436 + for (count = 1; count < 10; count++) {
437 + if (readchar(fd, c+count, 500)) return -1;
440 + /* Check whether the bytes of both data packets obey the rules */
441 + for (count = 1; count < 10; count++) {
442 + if ((count % 5 == 0 && (c[count] & 0x80) != 0)
443 + || (count % 5 == 4 && (c[count] & 0xF0) != 0x80)
444 + || (count % 5 != 0 && (c[count] & 0x80) != 0x80)) {
445 + /* Invalid byte in data packet */
453 +int penmount_init(int fd, long *id, long *extra)
455 + unsigned char init_cmd[5] = { 0xF2, 0x00, 0x00, 0x00, 0x00 };
456 + unsigned char start_cmd[5] = { 0xF1, 0x00, 0x00, 0x00, 0x00 };
457 + unsigned char c[10];
460 + /* try to initialize device */
461 + if (write( fd, init_cmd, 5 ) != 5)
464 + /* read the responce */
465 + for (count = 0; count < 5; count ++) {
466 + if (readchar(fd, c+0, 500)) return -1;
467 + if (c[0] == 0xf2) break;
470 + if (readchar(fd, c+1, 500)) return -1;
471 + if (c[1] != 0xd9) return -1;
473 + if (readchar(fd, c+2, 500)) return -1;
474 + if (c[2] != 0x0a) return -1;
476 + /* the device is present! start it! */
477 + if (write( fd, start_cmd, 5 ) != 5)
483 +int dump_init(int fd, long *id, long *extra)
485 + unsigned char c, o = 0;
489 + if (write(fd, &c, 1) != 1) /* Enable command */
493 + if (!readchar(fd, &c, 1)) {
494 + printf("%02x (%c) ", c, ((c > 32) && (c < 127)) ? c : 'x');
504 +struct input_types {
509 + unsigned long type;
511 + unsigned long extra;
513 + int (*init)(int fd, long *id, long *extra);
516 +struct input_types input_types[] = {
518 +{ "--sunkbd", "-skb", B1200, CS8, SERIO_SUNKBD, 0, 0, 1, NULL },
519 +{ "--lkkbd", "-lk", B4800, CS8|CSTOPB, SERIO_LKKBD, 0, 0, 1, NULL },
520 +{ "--vsxxx-aa", "-vs", B4800, CS8|CSTOPB|PARENB|PARODD,SERIO_VSXXXAA, 0, 0, 1, NULL },
521 +{ "--spaceorb", "-orb", B9600, CS8, SERIO_SPACEORB, 0, 0, 1, NULL },
522 +{ "--spaceball", "-sbl", B9600, CS8, SERIO_SPACEBALL,0, 0, 0, spaceball_init },
523 +{ "--magellan", "-mag", B9600, CS8 | CSTOPB | CRTSCTS, SERIO_MAGELLAN, 0, 0, 1, magellan_init },
524 +{ "--warrior", "-war", B1200, CS7 | CSTOPB, SERIO_WARRIOR, 0, 0, 1, warrior_init },
525 +{ "--stinger", "-sting", B1200, CS8, SERIO_STINGER, 0, 0, 1, stinger_init },
526 +{ "--mousesystems", "-msc", B1200, CS8, SERIO_MSC, 0, 0x01, 1, NULL },
527 +{ "--sunmouse", "-sun", B1200, CS8, SERIO_SUN, 0, 0x01, 1, NULL },
528 +{ "--microsoft", "-bare", B1200, CS7, SERIO_MS, 0, 0, 1, NULL },
529 +{ "--mshack", "-ms", B1200, CS7, SERIO_MS, 0, 0x01, 1, NULL },
530 +{ "--mouseman", "-mman", B1200, CS7, SERIO_MP, 0, 0x01, 1, NULL },
531 +{ "--intellimouse", "-ms3", B1200, CS7, SERIO_MZ, 0, 0x11, 1, NULL },
532 +{ "--mmwheel", "-mmw", B1200, CS7 | CSTOPB, SERIO_MZP, 0, 0x13, 1, mzp_init },
533 +{ "--iforce", "-ifor", B38400, CS8, SERIO_IFORCE, 0, 0, 0, NULL },
534 +{ "--newtonkbd", "-newt", B9600, CS8, SERIO_NEWTON, 0, 0, 0, newton_init },
535 +{ "--h3600ts", "-ipaq", B115200, CS8, SERIO_H3600, 0, 0, 0, NULL },
536 +{ "--stowawaykbd", "-ipaqkbd", B115200, CS8, SERIO_STOWAWAY, 0, 0, 0, NULL },
537 +{ "--ps2serkbd", "-ps2ser", B1200, CS8, SERIO_PS2SER, 0, 0, 1, NULL },
538 +{ "--twiddler", "-twid", B2400, CS8, SERIO_TWIDKBD, 0, 0, 0, twiddler_init },
539 +{ "--twiddler-joy", "-twidjoy", B2400, CS8, SERIO_TWIDJOY, 0, 0, 0, twiddler_init },
540 +{ "--elotouch", "-elo", B9600, CS8 | CRTSCTS, SERIO_ELO, 0, 0, 0, NULL },
541 +{ "--elo4002", "-elo6b", B9600, CS8 | CRTSCTS, SERIO_ELO, 1, 0, 0, NULL },
542 +{ "--elo271-140", "-elo4b", B9600, CS8 | CRTSCTS, SERIO_ELO, 2, 0, 0, NULL },
543 +{ "--elo261-280", "-elo3b", B9600, CS8 | CRTSCTS, SERIO_ELO, 3, 0, 0, NULL },
544 +{ "--dump", "-dump", B2400, CS8, 0, 0, 0, 0, dump_init },
545 +{ "--dmc9000", "-dmc", B19200, CS8, SERIO_PENMOUNT, 0, 0, 0, penmount_init },
550 +int main(int argc, char **argv)
552 + unsigned long devt;
559 + if (argc < 2 || argc > 3 || !strcmp("--help", argv[1])) {
561 + puts("Usage: inputttach <mode> <device>");
564 + puts(" --sunkbd -skb Sun Type 4 and Type 5 keyboards");
565 + puts(" --lkkbd -lk DEC LK201 / LK401 keyboards");
566 + puts(" --vsxxx-aa -vs DEC VSXXX-AA / VSXXX-GA mouse and VSXXX-AB tablet");
567 + puts(" --spaceorb -orb SpaceOrb 360 / SpaceBall Avenger");
568 + puts(" --spaceball -sbl SpaceBall 2003 / 3003 / 4000 FLX");
569 + puts(" --magellan -mag Magellan / SpaceMouse");
570 + puts(" --warrior -war WingMan Warrior");
571 + puts(" --stinger -stng Gravis Stinger");
572 + puts(" --mousesystems -msc 3-button Mouse Systems mice");
573 + puts(" --sunmouse -sun 3-button Sun mice");
574 + puts(" --microsoft -bare 2-button Microsoft mice");
575 + puts(" --mshack -ms 3-button mice in Microsoft mode");
576 + puts(" --mouseman -mman 3-button Logitech and Genius mice");
577 + puts(" --intellimouse -ms3 Microsoft IntelliMouse");
578 + puts(" --mmwheel -mmw Logitech mice with 4-5 buttons or wheel");
579 + puts(" --iforce -ifor I-Force joysticks and wheels");
580 + puts(" --h3600ts -ipaq Ipaq h3600 touchscreen");
581 + puts(" --stowawaykbd -ipaqkbd Stowaway keyboard");
582 + puts(" --ps2serkbd -ps2ser PS/2 via serial keyboard");
583 + puts(" --twiddler -twid Handykey Twiddler chording keyboard");
584 + puts(" --twiddler-joy -twidjoy Handykey Twiddler used as a joystick");
585 + puts(" --dmc9000 -dmc DMC9000/Penpount touchscreen");
590 + for (type = 0; input_types[type].speed; type++) {
591 + if (!strncasecmp(argv[1], input_types[type].name, 16) ||
592 + !strncasecmp(argv[1], input_types[type].name2, 16))
596 + if (!input_types[type].speed) {
597 + fprintf(stderr, "inputattach: invalid mode\n");
601 + if ((fd = open(argv[2], O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) {
602 + perror("inputattach");
606 + setline(fd, input_types[type].flags, input_types[type].speed);
608 + if (input_types[type].flush)
609 + while (!readchar(fd, &c, 100));
611 + id = input_types[type].id;
612 + extra = input_types[type].extra;
614 + if (input_types[type].init && input_types[type].init(fd, &id, &extra)) {
615 + fprintf(stderr, "inputattach: device initialization failed\n");
620 + if(ioctl(fd, TIOCSETD, &ldisc)) {
621 + fprintf(stderr, "inputattach: can't set line discipline\n");
625 + devt = input_types[type].type | (id << 8) | (extra << 16);
627 + if(ioctl(fd, SPIOCSTYPE, &devt)) {
628 + fprintf(stderr, "inputattach: can't set device type\n");
635 + ioctl(fd, TIOCSETD, &ldisc);
640 diff -Naur tslib-org/tests/ts_finddev.c tslib-1.0/tests/ts_finddev.c
641 --- tslib-org/tests/ts_finddev.c 1970-01-01 02:00:00.000000000 +0200
642 +++ tslib-1.0/tests/ts_finddev.c 2007-05-07 17:36:37.000000000 +0300
645 + * tslib/src/ts_print.c
647 + * Derived from tslib/src/ts_test.c by Douglas Lowder
648 + * Just prints touchscreen events -- does not paint them on framebuffer
650 + * This file is placed under the GPL. Please see the file
651 + * COPYING for more details.
653 + * Basic test program for touchscreen library.
658 +#include <sys/fcntl.h>
659 +#include <sys/ioctl.h>
660 +#include <sys/mman.h>
661 +#include <sys/time.h>
662 +#include <sys/types.h>
667 +void usage( int argc, char** argv ) {
668 + printf( "Usage: %s device_name wait_for_sec\n", argv[0] );
669 + printf( "\tdevice_name - tdevice to probe, example /dev/input/event0\n" );
670 + printf( "\twait_for_sec - wait seconds for touch event, if 0 - dont wait!\n" );
671 + printf( "\tReturn codes:\n" );
672 + printf( "\t 0 - timeout expired without receiving event.\n" );
673 + printf( "\t But this maybe is TouchScreen.\n" );
674 + printf( "\t -1 - this is NOT TouchScreen device!\n" );
675 + printf( "\t 1 - this is TouchScreen for shure!\n" );
679 +void alarm_handler( int sig ) {
680 + // time is expired!
684 +int main( int argc, char** argv )
687 + struct ts_sample samp;
688 + char *tsdevice=NULL;
693 + usage( argc, argv );
695 + tsdevice = argv[1];
696 + waitsec = atoi( argv[2] );
698 + usage( argc, argv );
700 + ts = ts_open( tsdevice, 0 );
710 + printf( "Probe device %s, Please Touch Screen Anywhere in %i seconds! ... \n", tsdevice, waitsec );
711 + signal( SIGALRM, alarm_handler );
713 + ret = ts_read_raw(ts, &samp, 1 );