update-inputattach.patch 23 KB

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