0002-add_finddef_and_inputattach_utils.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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
  4. @@ -12,7 +12,7 @@
  5. AM_CFLAGS = $(DEBUGFLAGS)
  6. INCLUDES = -I$(top_srcdir)/src
  7. -bin_PROGRAMS = ts_test ts_calibrate ts_print ts_print_raw ts_harvest
  8. +bin_PROGRAMS = ts_test ts_calibrate ts_print ts_print_raw ts_harvest ts_finddev inputattach
  9. ts_test_SOURCES = ts_test.c fbutils.c fbutils.h font_8x8.c font_8x16.c font.h
  10. ts_test_LDADD = $(top_builddir)/src/libts.la
  11. @@ -27,4 +27,10 @@
  12. ts_calibrate_LDADD = $(top_builddir)/src/libts.la
  13. ts_harvest_SOURCES = ts_harvest.c fbutils.c fbutils.h testutils.c testutils.h font_8x8.c font_8x16.c font.h
  14. -ts_harvest_LDADD = $(top_builddir)/src/libts.la
  15. +ts_harvest_LDADD = $(top_builddir)/src/libts.la
  16. +
  17. +ts_finddev_SOURCES = ts_finddev.c
  18. +ts_finddev_LDADD = $(top_builddir)/src/libts.la
  19. +
  20. +inputattach_SOURCES = inputattach.c
  21. +inputattach_LDADD =
  22. diff -Naur tslib-org/tests/inputattach.c tslib-1.0/tests/inputattach.c
  23. --- tslib-org/tests/inputattach.c 1970-01-01 02:00:00.000000000 +0200
  24. +++ tslib-1.0/tests/inputattach.c 2007-05-07 17:36:37.000000000 +0300
  25. @@ -0,0 +1,611 @@
  26. +/*
  27. + * $Id: inputattach.c,v 1.24 2006/02/08 12:19:31 vojtech Exp $
  28. + *
  29. + * Copyright (c) 1999-2000 Vojtech Pavlik
  30. + *
  31. + * Sponsored by SuSE
  32. + *
  33. + * Twiddler support Copyright (c) 2001 Arndt Schoenewald
  34. + * Sponsored by Quelltext AG (http://www.quelltext-ag.de), Dortmund, Germany
  35. + */
  36. +
  37. +/*
  38. + * Input line discipline attach program
  39. + */
  40. +
  41. +/*
  42. + * This program is free software; you can redistribute it and/or modify
  43. + * it under the terms of the GNU General Public License as published by
  44. + * the Free Software Foundation; either version 2 of the License, or
  45. + * (at your option) any later version.
  46. + *
  47. + * This program is distributed in the hope that it will be useful,
  48. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  49. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  50. + * GNU General Public License for more details.
  51. + *
  52. + * You should have received a copy of the GNU General Public License
  53. + * along with this program; if not, write to the Free Software
  54. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  55. + *
  56. + * Should you need to contact me, the author, you can do so either by
  57. + * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  58. + * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  59. + */
  60. +
  61. +/* softa note:
  62. +cvs version is here:
  63. +http://cvs.sourceforge.net/viewcvs.py/ *checkout* /linuxconsole/ruby/utils/inputattach.c
  64. +*/
  65. +
  66. +#include <linux/serio.h>
  67. +
  68. +#include <sys/types.h>
  69. +#include <sys/stat.h>
  70. +#include <sys/ioctl.h>
  71. +#include <sys/time.h>
  72. +
  73. +#include <stdio.h>
  74. +#include <stdlib.h>
  75. +#include <unistd.h>
  76. +#include <fcntl.h>
  77. +#include <termios.h>
  78. +#include <string.h>
  79. +#include <assert.h>
  80. +#include <ctype.h>
  81. +
  82. +// softa patch!
  83. +/*
  84. + * Serio types
  85. + */
  86. +#ifndef SERIO_UNKNOWN
  87. + #define SERIO_UNKNOWN 0x00
  88. +#endif
  89. +#ifndef SERIO_MSC
  90. + #define SERIO_MSC 0x01
  91. +#endif
  92. +#ifndef SERIO_SUN
  93. + #define SERIO_SUN 0x02
  94. +#endif
  95. +#ifndef SERIO_MS
  96. + #define SERIO_MS 0x03
  97. +#endif
  98. +#ifndef SERIO_MP
  99. + #define SERIO_MP 0x04
  100. +#endif
  101. +#ifndef SERIO_MZ
  102. + #define SERIO_MZ 0x05
  103. +#endif
  104. +#ifndef SERIO_MZP
  105. + #define SERIO_MZP 0x06
  106. +#endif
  107. +#ifndef SERIO_MZPP
  108. + #define SERIO_MZPP 0x07
  109. +#endif
  110. +#ifndef SERIO_VSXXXAA
  111. + #define SERIO_VSXXXAA 0x08
  112. +#endif
  113. +#ifndef SERIO_SUNKBD
  114. + #define SERIO_SUNKBD 0x10
  115. +#endif
  116. +#ifndef SERIO_WARRIOR
  117. + #define SERIO_WARRIOR 0x18
  118. +#endif
  119. +#ifndef SERIO_SPACEORB
  120. + #define SERIO_SPACEORB 0x19
  121. +#endif
  122. +#ifndef SERIO_MAGELLAN
  123. + #define SERIO_MAGELLAN 0x1a
  124. +#endif
  125. +#ifndef SERIO_SPACEBALL
  126. + #define SERIO_SPACEBALL 0x1b
  127. +#endif
  128. +#ifndef SERIO_GUNZE
  129. + #define SERIO_GUNZE 0x1c
  130. +#endif
  131. +#ifndef SERIO_IFORCE
  132. + #define SERIO_IFORCE 0x1d
  133. +#endif
  134. +#ifndef SERIO_STINGER
  135. + #define SERIO_STINGER 0x1e
  136. +#endif
  137. +#ifndef SERIO_NEWTON
  138. + #define SERIO_NEWTON 0x1f
  139. +#endif
  140. +#ifndef SERIO_STOWAWAY
  141. + #define SERIO_STOWAWAY 0x20
  142. +#endif
  143. +#ifndef SERIO_H3600
  144. + #define SERIO_H3600 0x21
  145. +#endif
  146. +#ifndef SERIO_PS2SER
  147. + #define SERIO_PS2SER 0x22
  148. +#endif
  149. +#ifndef SERIO_TWIDKBD
  150. + #define SERIO_TWIDKBD 0x23
  151. +#endif
  152. +#ifndef SERIO_TWIDJOY
  153. + #define SERIO_TWIDJOY 0x24
  154. +#endif
  155. +#ifndef SERIO_HIL
  156. + #define SERIO_HIL 0x25
  157. +#endif
  158. +#ifndef SERIO_SNES232
  159. + #define SERIO_SNES232 0x26
  160. +#endif
  161. +#ifndef SERIO_SEMTECH
  162. + #define SERIO_SEMTECH 0x27
  163. +#endif
  164. +#ifndef SERIO_LKKBD
  165. + #define SERIO_LKKBD 0x28
  166. +#endif
  167. +#ifndef SERIO_ELO
  168. + #define SERIO_ELO 0x29
  169. +#endif
  170. +#ifndef SERIO_MICROTOUCH
  171. + #define SERIO_MICROTOUCH 0x30
  172. +#endif
  173. +#ifndef SERIO_PENMOUNT
  174. + #define SERIO_PENMOUNT 0x31
  175. +#endif
  176. +#ifndef SERIO_TOUCHRIGHT
  177. + #define SERIO_TOUCHRIGHT 0x32
  178. +#endif
  179. +#ifndef SERIO_TOUCHWIN
  180. + #define SERIO_TOUCHWIN 0x33
  181. +#endif
  182. +// end softa patch!
  183. +
  184. +int readchar(int fd, unsigned char *c, int timeout)
  185. +{
  186. + struct timeval tv;
  187. + fd_set set;
  188. +
  189. + tv.tv_sec = 0;
  190. + tv.tv_usec = timeout * 1000;
  191. +
  192. + FD_ZERO(&set);
  193. + FD_SET(fd, &set);
  194. +
  195. + if (!select(fd+1, &set, NULL, NULL, &tv)) return -1;
  196. + if (read(fd, c, 1) != 1) return -1;
  197. +
  198. + return 0;
  199. +}
  200. +
  201. +
  202. +
  203. +void setline(int fd, int flags, int speed)
  204. +{
  205. + struct termios t;
  206. +
  207. + tcgetattr(fd, &t);
  208. +
  209. + t.c_cflag = flags | CREAD | HUPCL | CLOCAL;
  210. + t.c_iflag = IGNBRK | IGNPAR;
  211. + t.c_oflag = 0;
  212. + t.c_lflag = 0;
  213. + t.c_cc[VMIN ] = 1;
  214. + t.c_cc[VTIME] = 0;
  215. +
  216. + cfsetispeed(&t, speed);
  217. + cfsetospeed(&t, speed);
  218. +
  219. + tcsetattr(fd, TCSANOW, &t);
  220. +}
  221. +
  222. +int logitech_command(int fd, char *c)
  223. +{
  224. + int i;
  225. + unsigned char d;
  226. + for (i = 0; c[i]; i++) {
  227. + write(fd, c + i, 1);
  228. + if (readchar(fd, &d, 1000))
  229. + return -1;
  230. + if (c[i] != d)
  231. + return -1;
  232. + }
  233. + return 0;
  234. +}
  235. +
  236. +int magellan_init(int fd, long *id, long *extra)
  237. +{
  238. + write(fd, "m3\rpBB\rz\r", 9);
  239. + return 0;
  240. +}
  241. +
  242. +int warrior_init(int fd, long *id, long *extra)
  243. +{
  244. + if (logitech_command(fd, "*S")) return -1;
  245. + setline(fd, CS8, B4800);
  246. + return 0;
  247. +}
  248. +
  249. +int spaceball_waitchar(int fd, unsigned char c, unsigned char *d, int timeout)
  250. +{
  251. + unsigned char b = 0;
  252. +
  253. + while (!readchar(fd, &b, timeout)) {
  254. + if (b == 0x0a) continue;
  255. + *d++ = b;
  256. + if (b == c) break;
  257. + }
  258. +
  259. + *d = 0;
  260. +
  261. + return -(b != c);
  262. +}
  263. +
  264. +int spaceball_waitcmd(int fd, char c, char *d)
  265. +{
  266. + int i;
  267. +
  268. + for (i = 0; i < 8; i++) {
  269. + if (spaceball_waitchar(fd, 0x0d, d, 1000))
  270. + return -1;
  271. + if (d[0] == c)
  272. + return 0;
  273. + }
  274. +
  275. + return -1;
  276. +}
  277. +
  278. +int spaceball_cmd(int fd, char *c, char *d)
  279. +{
  280. + int i;
  281. +
  282. + for (i = 0; c[i]; i++)
  283. + write(fd, c + i, 1);
  284. + write(fd, "\r", 1);
  285. +
  286. + i = spaceball_waitcmd(fd, toupper(c[0]), d);
  287. +
  288. + return i;
  289. +}
  290. +
  291. +#define SPACEBALL_1003 1
  292. +#define SPACEBALL_2003B 3
  293. +#define SPACEBALL_2003C 4
  294. +#define SPACEBALL_3003C 7
  295. +#define SPACEBALL_4000FLX 8
  296. +#define SPACEBALL_4000FLX_L 9
  297. +
  298. +int spaceball_init(int fd, long *id, long *extra)
  299. +{
  300. + char r[64];
  301. +
  302. + if (spaceball_waitchar(fd, 0x11, r, 4000) ||
  303. + spaceball_waitchar(fd, 0x0d, r, 1000))
  304. + return -1;
  305. +
  306. + if (spaceball_waitcmd(fd, '@', r))
  307. + return -1;
  308. +
  309. + if (strncmp("@1 Spaceball alive", r, 18))
  310. + return -1;
  311. +
  312. + if (spaceball_waitcmd(fd, '@', r))
  313. + return -1;
  314. +
  315. + if (spaceball_cmd(fd, "hm", r))
  316. + return -1;
  317. +
  318. + if (!strncmp("Hm2003B", r, 7))
  319. + *id = SPACEBALL_2003B;
  320. + if (!strncmp("Hm2003C", r, 7))
  321. + *id = SPACEBALL_2003C;
  322. + if (!strncmp("Hm3003C", r, 7))
  323. + *id = SPACEBALL_3003C;
  324. +
  325. + if (!strncmp("HvFirmware", r, 10)) {
  326. +
  327. + if (spaceball_cmd(fd, "\"", r))
  328. + return -1;
  329. +
  330. + if (strncmp("\"1 Spaceball 4000 FLX", r, 21))
  331. + return -1;
  332. +
  333. + if (spaceball_waitcmd(fd, '"', r))
  334. + return -1;
  335. +
  336. + if (strstr(r, " L "))
  337. + *id = SPACEBALL_4000FLX_L;
  338. + else
  339. + *id = SPACEBALL_4000FLX;
  340. +
  341. + if (spaceball_waitcmd(fd, '"', r))
  342. + return -1;
  343. +
  344. + if (spaceball_cmd(fd, "YS", r))
  345. + return -1;
  346. +
  347. + if (spaceball_cmd(fd, "M", r))
  348. + return -1;
  349. +
  350. + return 0;
  351. + }
  352. +
  353. + if (spaceball_cmd(fd, "P@A@A", r) ||
  354. + spaceball_cmd(fd, "FT@", r) ||
  355. + spaceball_cmd(fd, "MSS", r))
  356. + return -1;
  357. +
  358. + return 0;
  359. +}
  360. +
  361. +int stinger_init(int fd, long *id, long *extra)
  362. +{
  363. + int i;
  364. + unsigned char c;
  365. + unsigned char *response = "\r\n0600520058C272";
  366. +
  367. + if (write(fd, " E5E5", 5) != 5) /* Enable command */
  368. + return -1;
  369. +
  370. + for (i = 0; i < 16; i++) /* Check for Stinger */
  371. + if (readchar(fd, &c, 200) || (c != response[i]))
  372. + return -1;
  373. +
  374. + return 0;
  375. +}
  376. +
  377. +int mzp_init(int fd, long *id, long *extra)
  378. +{
  379. + if (logitech_command(fd, "*X*q")) return -1;
  380. + setline(fd, CS8, B9600);
  381. + return 0;
  382. +}
  383. +
  384. +int newton_init(int fd, long *id, long *extra)
  385. +{
  386. + int i;
  387. + unsigned char c;
  388. + unsigned char response[35] =
  389. + { 0x16, 0x10, 0x02, 0x64, 0x5f, 0x69, 0x64, 0x00,
  390. + 0x00, 0x00, 0x0c, 0x6b, 0x79, 0x62, 0x64, 0x61,
  391. + 0x70, 0x70, 0x6c, 0x00, 0x00, 0x00, 0x01, 0x6e,
  392. + 0x6f, 0x66, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10,
  393. + 0x03, 0xdd, 0xe7 };
  394. +
  395. + for (i = 0; i < 35; i++)
  396. + if (readchar(fd, &c, 400) || (c != response[i]))
  397. + return -1;
  398. +
  399. + return 0;
  400. +}
  401. +
  402. +int twiddler_init(int fd, long *id, long *extra)
  403. +{
  404. + unsigned char c[10];
  405. + int count, line;
  406. +
  407. + /* Turn DTR off, otherwise the Twiddler won't send any data. */
  408. + if (ioctl(fd, TIOCMGET, &line)) return -1;
  409. + line &= ~TIOCM_DTR;
  410. + if (ioctl(fd, TIOCMSET, &line)) return -1;
  411. +
  412. + /* Check whether the device on the serial line is the Twiddler.
  413. + *
  414. + * The Twiddler sends data packets of 5 bytes which have the following
  415. + * properties: the MSB is 0 on the first and 1 on all other bytes, and
  416. + * the high order nibble of the last byte is always 0x8.
  417. + *
  418. + * We read and check two of those 5 byte packets to be sure that we
  419. + * are indeed talking to a Twiddler. */
  420. +
  421. + /* Read at most 5 bytes until we find one with the MSB set to 0 */
  422. + for (count = 0; count < 5; count++) {
  423. + if (readchar(fd, c+0, 500)) return -1;
  424. + if ((c[0] & 0x80) == 0) break;
  425. + }
  426. +
  427. + if (count == 5) {
  428. + /* Could not find header byte in data stream */
  429. + return -1;
  430. + }
  431. +
  432. + /* Read remaining 4 bytes plus the full next data packet */
  433. + for (count = 1; count < 10; count++) {
  434. + if (readchar(fd, c+count, 500)) return -1;
  435. + }
  436. +
  437. + /* Check whether the bytes of both data packets obey the rules */
  438. + for (count = 1; count < 10; count++) {
  439. + if ((count % 5 == 0 && (c[count] & 0x80) != 0)
  440. + || (count % 5 == 4 && (c[count] & 0xF0) != 0x80)
  441. + || (count % 5 != 0 && (c[count] & 0x80) != 0x80)) {
  442. + /* Invalid byte in data packet */
  443. + return -1;
  444. + }
  445. + }
  446. +
  447. + return 0;
  448. +}
  449. +
  450. +int penmount_init(int fd, long *id, long *extra)
  451. +{
  452. + unsigned char init_cmd[5] = { 0xF2, 0x00, 0x00, 0x00, 0x00 };
  453. + unsigned char start_cmd[5] = { 0xF1, 0x00, 0x00, 0x00, 0x00 };
  454. + unsigned char c[10];
  455. + int count;
  456. +
  457. + /* try to initialize device */
  458. + if (write( fd, init_cmd, 5 ) != 5)
  459. + return -1;
  460. +
  461. + /* read the responce */
  462. + for (count = 0; count < 5; count ++) {
  463. + if (readchar(fd, c+0, 500)) return -1;
  464. + if (c[0] == 0xf2) break;
  465. + }
  466. +
  467. + if (readchar(fd, c+1, 500)) return -1;
  468. + if (c[1] != 0xd9) return -1;
  469. +
  470. + if (readchar(fd, c+2, 500)) return -1;
  471. + if (c[2] != 0x0a) return -1;
  472. +
  473. + /* the device is present! start it! */
  474. + if (write( fd, start_cmd, 5 ) != 5)
  475. + return -1;
  476. +
  477. + return 0;
  478. +}
  479. +
  480. +int dump_init(int fd, long *id, long *extra)
  481. +{
  482. + unsigned char c, o = 0;
  483. +
  484. + c = 0x80;
  485. +
  486. + if (write(fd, &c, 1) != 1) /* Enable command */
  487. + return -1;
  488. +
  489. + while (1)
  490. + if (!readchar(fd, &c, 1)) {
  491. + printf("%02x (%c) ", c, ((c > 32) && (c < 127)) ? c : 'x');
  492. + o = 1;
  493. + } else {
  494. + if (o) {
  495. + printf("\n");
  496. + o = 0;
  497. + }
  498. + }
  499. +}
  500. +
  501. +struct input_types {
  502. + char name[16];
  503. + char name2[16];
  504. + int speed;
  505. + int flags;
  506. + unsigned long type;
  507. + unsigned long id;
  508. + unsigned long extra;
  509. + int flush;
  510. + int (*init)(int fd, long *id, long *extra);
  511. +};
  512. +
  513. +struct input_types input_types[] = {
  514. +
  515. +{ "--sunkbd", "-skb", B1200, CS8, SERIO_SUNKBD, 0, 0, 1, NULL },
  516. +{ "--lkkbd", "-lk", B4800, CS8|CSTOPB, SERIO_LKKBD, 0, 0, 1, NULL },
  517. +{ "--vsxxx-aa", "-vs", B4800, CS8|CSTOPB|PARENB|PARODD,SERIO_VSXXXAA, 0, 0, 1, NULL },
  518. +{ "--spaceorb", "-orb", B9600, CS8, SERIO_SPACEORB, 0, 0, 1, NULL },
  519. +{ "--spaceball", "-sbl", B9600, CS8, SERIO_SPACEBALL,0, 0, 0, spaceball_init },
  520. +{ "--magellan", "-mag", B9600, CS8 | CSTOPB | CRTSCTS, SERIO_MAGELLAN, 0, 0, 1, magellan_init },
  521. +{ "--warrior", "-war", B1200, CS7 | CSTOPB, SERIO_WARRIOR, 0, 0, 1, warrior_init },
  522. +{ "--stinger", "-sting", B1200, CS8, SERIO_STINGER, 0, 0, 1, stinger_init },
  523. +{ "--mousesystems", "-msc", B1200, CS8, SERIO_MSC, 0, 0x01, 1, NULL },
  524. +{ "--sunmouse", "-sun", B1200, CS8, SERIO_SUN, 0, 0x01, 1, NULL },
  525. +{ "--microsoft", "-bare", B1200, CS7, SERIO_MS, 0, 0, 1, NULL },
  526. +{ "--mshack", "-ms", B1200, CS7, SERIO_MS, 0, 0x01, 1, NULL },
  527. +{ "--mouseman", "-mman", B1200, CS7, SERIO_MP, 0, 0x01, 1, NULL },
  528. +{ "--intellimouse", "-ms3", B1200, CS7, SERIO_MZ, 0, 0x11, 1, NULL },
  529. +{ "--mmwheel", "-mmw", B1200, CS7 | CSTOPB, SERIO_MZP, 0, 0x13, 1, mzp_init },
  530. +{ "--iforce", "-ifor", B38400, CS8, SERIO_IFORCE, 0, 0, 0, NULL },
  531. +{ "--newtonkbd", "-newt", B9600, CS8, SERIO_NEWTON, 0, 0, 0, newton_init },
  532. +{ "--h3600ts", "-ipaq", B115200, CS8, SERIO_H3600, 0, 0, 0, NULL },
  533. +{ "--stowawaykbd", "-ipaqkbd", B115200, CS8, SERIO_STOWAWAY, 0, 0, 0, NULL },
  534. +{ "--ps2serkbd", "-ps2ser", B1200, CS8, SERIO_PS2SER, 0, 0, 1, NULL },
  535. +{ "--twiddler", "-twid", B2400, CS8, SERIO_TWIDKBD, 0, 0, 0, twiddler_init },
  536. +{ "--twiddler-joy", "-twidjoy", B2400, CS8, SERIO_TWIDJOY, 0, 0, 0, twiddler_init },
  537. +{ "--elotouch", "-elo", B9600, CS8 | CRTSCTS, SERIO_ELO, 0, 0, 0, NULL },
  538. +{ "--elo4002", "-elo6b", B9600, CS8 | CRTSCTS, SERIO_ELO, 1, 0, 0, NULL },
  539. +{ "--elo271-140", "-elo4b", B9600, CS8 | CRTSCTS, SERIO_ELO, 2, 0, 0, NULL },
  540. +{ "--elo261-280", "-elo3b", B9600, CS8 | CRTSCTS, SERIO_ELO, 3, 0, 0, NULL },
  541. +{ "--dump", "-dump", B2400, CS8, 0, 0, 0, 0, dump_init },
  542. +{ "--dmc9000", "-dmc", B19200, CS8, SERIO_PENMOUNT, 0, 0, 0, penmount_init },
  543. +{ "", "", 0, 0 }
  544. +
  545. +};
  546. +
  547. +int main(int argc, char **argv)
  548. +{
  549. + unsigned long devt;
  550. + int ldisc;
  551. + int type;
  552. + long id, extra;
  553. + int fd;
  554. + char c;
  555. +
  556. + if (argc < 2 || argc > 3 || !strcmp("--help", argv[1])) {
  557. + puts("");
  558. + puts("Usage: inputttach <mode> <device>");
  559. + puts("");
  560. + puts("Modes:");
  561. + puts(" --sunkbd -skb Sun Type 4 and Type 5 keyboards");
  562. + puts(" --lkkbd -lk DEC LK201 / LK401 keyboards");
  563. + puts(" --vsxxx-aa -vs DEC VSXXX-AA / VSXXX-GA mouse and VSXXX-AB tablet");
  564. + puts(" --spaceorb -orb SpaceOrb 360 / SpaceBall Avenger");
  565. + puts(" --spaceball -sbl SpaceBall 2003 / 3003 / 4000 FLX");
  566. + puts(" --magellan -mag Magellan / SpaceMouse");
  567. + puts(" --warrior -war WingMan Warrior");
  568. + puts(" --stinger -stng Gravis Stinger");
  569. + puts(" --mousesystems -msc 3-button Mouse Systems mice");
  570. + puts(" --sunmouse -sun 3-button Sun mice");
  571. + puts(" --microsoft -bare 2-button Microsoft mice");
  572. + puts(" --mshack -ms 3-button mice in Microsoft mode");
  573. + puts(" --mouseman -mman 3-button Logitech and Genius mice");
  574. + puts(" --intellimouse -ms3 Microsoft IntelliMouse");
  575. + puts(" --mmwheel -mmw Logitech mice with 4-5 buttons or wheel");
  576. + puts(" --iforce -ifor I-Force joysticks and wheels");
  577. + puts(" --h3600ts -ipaq Ipaq h3600 touchscreen");
  578. + puts(" --stowawaykbd -ipaqkbd Stowaway keyboard");
  579. + puts(" --ps2serkbd -ps2ser PS/2 via serial keyboard");
  580. + puts(" --twiddler -twid Handykey Twiddler chording keyboard");
  581. + puts(" --twiddler-joy -twidjoy Handykey Twiddler used as a joystick");
  582. + puts(" --dmc9000 -dmc DMC9000/Penpount touchscreen");
  583. + puts("");
  584. + return 1;
  585. + }
  586. +
  587. + for (type = 0; input_types[type].speed; type++) {
  588. + if (!strncasecmp(argv[1], input_types[type].name, 16) ||
  589. + !strncasecmp(argv[1], input_types[type].name2, 16))
  590. + break;
  591. + }
  592. +
  593. + if (!input_types[type].speed) {
  594. + fprintf(stderr, "inputattach: invalid mode\n");
  595. + return 1;
  596. + }
  597. +
  598. + if ((fd = open(argv[2], O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) {
  599. + perror("inputattach");
  600. + return 1;
  601. + }
  602. +
  603. + setline(fd, input_types[type].flags, input_types[type].speed);
  604. +
  605. + if (input_types[type].flush)
  606. + while (!readchar(fd, &c, 100));
  607. +
  608. + id = input_types[type].id;
  609. + extra = input_types[type].extra;
  610. +
  611. + if (input_types[type].init && input_types[type].init(fd, &id, &extra)) {
  612. + fprintf(stderr, "inputattach: device initialization failed\n");
  613. + return 1;
  614. + }
  615. +
  616. + ldisc = N_MOUSE;
  617. + if(ioctl(fd, TIOCSETD, &ldisc)) {
  618. + fprintf(stderr, "inputattach: can't set line discipline\n");
  619. + return 1;
  620. + }
  621. +
  622. + devt = input_types[type].type | (id << 8) | (extra << 16);
  623. +
  624. + if(ioctl(fd, SPIOCSTYPE, &devt)) {
  625. + fprintf(stderr, "inputattach: can't set device type\n");
  626. + return 1;
  627. + }
  628. +
  629. + read(fd, NULL, 0);
  630. +
  631. + ldisc = 0;
  632. + ioctl(fd, TIOCSETD, &ldisc);
  633. + close(fd);
  634. +
  635. + return 0;
  636. +}
  637. diff -Naur tslib-org/tests/ts_finddev.c tslib-1.0/tests/ts_finddev.c
  638. --- tslib-org/tests/ts_finddev.c 1970-01-01 02:00:00.000000000 +0200
  639. +++ tslib-1.0/tests/ts_finddev.c 2007-05-07 17:36:37.000000000 +0300
  640. @@ -0,0 +1,75 @@
  641. +/*
  642. + * tslib/src/ts_print.c
  643. + *
  644. + * Derived from tslib/src/ts_test.c by Douglas Lowder
  645. + * Just prints touchscreen events -- does not paint them on framebuffer
  646. + *
  647. + * This file is placed under the GPL. Please see the file
  648. + * COPYING for more details.
  649. + *
  650. + * Basic test program for touchscreen library.
  651. + */
  652. +#include <stdio.h>
  653. +#include <stdlib.h>
  654. +#include <signal.h>
  655. +#include <sys/fcntl.h>
  656. +#include <sys/ioctl.h>
  657. +#include <sys/mman.h>
  658. +#include <sys/time.h>
  659. +#include <sys/types.h>
  660. +#include <unistd.h>
  661. +
  662. +#include "tslib.h"
  663. +
  664. +void usage( int argc, char** argv ) {
  665. + printf( "Usage: %s device_name wait_for_sec\n", argv[0] );
  666. + printf( "\tdevice_name - tdevice to probe, example /dev/input/event0\n" );
  667. + printf( "\twait_for_sec - wait seconds for touch event, if 0 - dont wait!\n" );
  668. + printf( "\tReturn codes:\n" );
  669. + printf( "\t 0 - timeout expired without receiving event.\n" );
  670. + printf( "\t But this maybe is TouchScreen.\n" );
  671. + printf( "\t -1 - this is NOT TouchScreen device!\n" );
  672. + printf( "\t 1 - this is TouchScreen for shure!\n" );
  673. + exit(-1);
  674. +}
  675. +
  676. +void alarm_handler( int sig ) {
  677. + // time is expired!
  678. + exit(0);
  679. +}
  680. +
  681. +int main( int argc, char** argv )
  682. +{
  683. + struct tsdev *ts;
  684. + struct ts_sample samp;
  685. + char *tsdevice=NULL;
  686. + int waitsec;
  687. + int ret;
  688. +
  689. + if (argc != 3)
  690. + usage( argc, argv );
  691. +
  692. + tsdevice = argv[1];
  693. + waitsec = atoi( argv[2] );
  694. + if (waitsec < 0)
  695. + usage( argc, argv );
  696. +
  697. + ts = ts_open( tsdevice, 0 );
  698. + if (!ts)
  699. + return -1;
  700. + if (ts_config(ts))
  701. + return -1;
  702. +
  703. + if (!waitsec) {
  704. + return 0;
  705. + }
  706. +
  707. + printf( "Probe device %s, Please Touch Screen Anywhere in %i seconds! ... \n", tsdevice, waitsec );
  708. + signal( SIGALRM, alarm_handler );
  709. + alarm( waitsec );
  710. + ret = ts_read_raw(ts, &samp, 1 );
  711. + if (ret)
  712. + return 1;
  713. +
  714. + return -1;
  715. +}