button-axis-remapping.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. Add axis and button remapping. Patch provided by Dr. László Kaján; see
  2. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=444142
  3. Note that the patch provided also changed the jscal man page; this part of
  4. the patch is merged directly into the diff.gz to avoid having quilt patches
  5. which change Debian-specific files.
  6. --- joystick-20051019.orig/utils/jscal.c
  7. +++ joystick-20051019/utils/jscal.c
  8. @@ -61,6 +61,8 @@
  9. int fd;
  10. struct js_corr corr[MAX_AXES];
  11. +__u8 axmap[ABS_MAX + 1];
  12. +__u16 buttonmap[(KEY_MAX - BTN_MISC + 1)];
  13. char axes, buttons, fuzz;
  14. int version;
  15. struct correction_data corda[MAX_AXES];
  16. @@ -163,6 +165,12 @@
  17. puts(" -V --version Prints the version numbers");
  18. puts(" -p --print-correction Prints the current settings as a jscal");
  19. puts(" command line");
  20. + puts(" -q --print-mappings Print the current axis and button");
  21. + puts(" mappings as a jscal command line");
  22. + puts(" -u <n_of_axes,axmap1,axmap2,...,");
  23. + puts(" n_of_buttons,btnmap1,btnmap2,");
  24. + puts(" ...> --set-mappings Sets axis and button mappings to the");
  25. + puts(" specified values");
  26. putchar('\n');
  27. }
  28. @@ -329,6 +337,42 @@
  29. (version >> 8) & 0xff, version & 0xff);
  30. }
  31. +void print_mappings(char *devicename)
  32. +{
  33. + int i;
  34. +
  35. + if (ioctl(fd, JSIOCGAXES, &axes)) {
  36. + perror("jscal: error getting axes");
  37. + exit(1);
  38. + }
  39. + if (ioctl(fd, JSIOCGBUTTONS, &buttons)) {
  40. + perror("jscal: error getting buttons");
  41. + exit(1);
  42. + }
  43. + if (ioctl(fd, JSIOCGAXMAP, &axmap)) {
  44. + perror("jscal: error getting axis map");
  45. + exit(1);
  46. + }
  47. + if (ioctl(fd, JSIOCGBTNMAP, &buttonmap)) {
  48. + perror("jscal: error getting button map");
  49. + exit(1);
  50. + }
  51. +
  52. + printf("jscal -u %d", axes);
  53. + for (i = 0; i < axes; i++)
  54. + {
  55. + printf( ",%d", axmap[i]);
  56. + }
  57. +
  58. + printf(",%d", buttons);
  59. + for (i = 0; i < buttons; i++)
  60. + {
  61. + printf( ",%d", buttonmap[i]);
  62. + }
  63. +
  64. + printf(" %s\n",devicename);
  65. +}
  66. +
  67. void print_settings(char *devicename)
  68. {
  69. int i,j;
  70. @@ -355,6 +399,107 @@
  71. printf(" %s\n",devicename);
  72. }
  73. +// n axes n buttons
  74. +// 10,0,1,2,5,6,16,17,40,41,42:13,288,289,290,291,292,293,294,295,296,297,298,299,300
  75. +void set_mappings(char *p)
  76. +{
  77. + int i;
  78. + int axes_on_cl = 0;
  79. + int btns_on_cl = 0;
  80. + int axis_mapping = 0;
  81. + int btn_mapping = 0;
  82. +
  83. + if (ioctl(fd, JSIOCGAXES, &axes)) {
  84. + perror("jscal: error getting axes");
  85. + exit(1);
  86. + }
  87. + if (ioctl(fd, JSIOCGBUTTONS, &buttons)) {
  88. + perror("jscal: error getting buttons");
  89. + exit(1);
  90. + }
  91. +
  92. + if (axes > MAX_AXES) axes = MAX_AXES;
  93. +
  94. + if (!p) {
  95. + fprintf(stderr, "jscal: missing argument for --set-mappings\n");
  96. + exit(1);
  97. + }
  98. +
  99. + //axes
  100. + sscanf(p, "%d", &axes_on_cl);
  101. + p = strstr(p, ",");
  102. +
  103. + if (axes_on_cl != axes) {
  104. + fprintf(stderr, "jscal: joystick has %d axes and not %d as specified on command line\n",
  105. + axes, axes_on_cl);
  106. + exit(1);
  107. + }
  108. +
  109. +
  110. + for (i = 0; i < axes; i++)
  111. + {
  112. + if (!p) {
  113. + fprintf(stderr, "jscal: missing mapping for axis %d\n", i);
  114. + exit(1);
  115. + }
  116. + sscanf(++p, "%d", &axis_mapping);
  117. + p = strstr(p, ",");
  118. +
  119. +
  120. + if (axis_mapping > ABS_MAX + 1) {
  121. + fprintf(stderr, "jscal: invalid axis mapping for axis %d (max is %d)\n", i, ABS_MAX + 1);
  122. + exit(1);
  123. + }
  124. + axmap[i] = axis_mapping;
  125. + }
  126. +
  127. + //buttons
  128. + sscanf(++p, "%d", &btns_on_cl);
  129. + p = strstr(p, ",");
  130. +
  131. + if (btns_on_cl != buttons) {
  132. + fprintf(stderr, "jscal: joystick has %d buttons and not %d as specified on command line\n",
  133. + buttons, btns_on_cl);
  134. + exit(1);
  135. + }
  136. +
  137. +
  138. + for (i = 0; i < buttons; i++)
  139. + {
  140. + if (!p) {
  141. + fprintf(stderr, "jscal: missing mapping for button %d\n", i);
  142. + exit(1);
  143. + }
  144. + sscanf(++p, "%d", &btn_mapping);
  145. + p = strstr(p, ",");
  146. +
  147. +
  148. + if (btn_mapping > KEY_MAX) {
  149. + fprintf(stderr, "jscal: invalid button mapping for button %d (max is %d)\n", i, KEY_MAX);
  150. + exit(1);
  151. + }
  152. + if (btn_mapping < BTN_MISC) {
  153. + fprintf(stderr, "jscal: invalid button mapping for button %d (min is %d)\n", i, BTN_MISC);
  154. + exit(1);
  155. + }
  156. + buttonmap[i] = btn_mapping;
  157. + }
  158. +
  159. + if (p) {
  160. + fprintf(stderr, "jscal: too many values\n");
  161. + exit(1);
  162. + }
  163. +
  164. + if (ioctl(fd, JSIOCSAXMAP, &axmap)) {
  165. + perror("jscal: error setting axis map");
  166. + exit(1);
  167. + }
  168. + if (ioctl(fd, JSIOCSBTNMAP, &buttonmap)) {
  169. + perror("jscal: error setting button map");
  170. + exit(1);
  171. + }
  172. +}
  173. +
  174. void set_correction(char *p)
  175. {
  176. int i,j;
  177. @@ -474,14 +619,18 @@
  178. char *parameter = NULL;
  179. int t;
  180. + // /usr/include/getopt.h
  181. static struct option long_options[] =
  182. {
  183. {"calibrate", no_argument, NULL, 'c'},
  184. {"help", no_argument, NULL, 'h'},
  185. {"set-correction", required_argument, NULL, 's'},
  186. + {"set-mappings", required_argument, NULL, 'u'},
  187. {"test-center", no_argument, NULL, 't'},
  188. {"version", no_argument, NULL, 'V'},
  189. - {"print-correction", no_argument, NULL, 'p'}
  190. + {"print-correction", no_argument, NULL, 'p'},
  191. + {"print-mappings", no_argument, NULL, 'q'},
  192. + {NULL, no_argument, NULL, 0 }
  193. };
  194. if (argc == 1) {
  195. @@ -490,10 +639,12 @@
  196. }
  197. do {
  198. - t = getopt_long(argc, argv, "chps:vVt", long_options, &option_index);
  199. + t = getopt_long(argc, argv, "chpqu:s:vVt", long_options, &option_index);
  200. switch (t) {
  201. case 'p':
  202. + case 'q':
  203. case 's':
  204. + case 'u':
  205. case 'c':
  206. case 't':
  207. case 'V':
  208. @@ -553,9 +704,15 @@
  209. case 'p':
  210. print_settings(argv[argc -1]);
  211. break;
  212. + case 'q':
  213. + print_mappings(argv[argc -1]);
  214. + break;
  215. case 's':
  216. set_correction(parameter);
  217. break;
  218. + case 'u':
  219. + set_mappings(parameter);
  220. + break;
  221. case 't':
  222. test_center();
  223. break;