From: <sk...@us...> - 2010-09-23 11:44:12
|
Revision: 2386 http://linuxconsole.svn.sourceforge.net/linuxconsole/?rev=2386&view=rev Author: skitt Date: 2010-09-23 11:44:06 +0000 (Thu, 23 Sep 2010) Log Message: ----------- Improve jitter tolerance; patch provided by Johann Walles, see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=144768 Modified Paths: -------------- trunk/utils/jscal.c Modified: trunk/utils/jscal.c =================================================================== --- trunk/utils/jscal.c 2010-09-23 11:41:12 UTC (rev 2385) +++ trunk/utils/jscal.c 2010-09-23 11:44:06 UTC (rev 2386) @@ -202,6 +202,7 @@ void calibrate() { int i, j, t, b; + int axis, pos; for (i=0; i<MAX_AXES; i++) { corr[i].type = JS_CORR_NONE; @@ -232,13 +233,19 @@ do { wait_for_event(fd, &js); for(i=0; i < axes; i++) { - if (amin[i] > js.axis[i]) amin[i] = js.axis[i]; - if (amax[i] < js.axis[i]) amax[i] = js.axis[i]; + if (amin[i] > js.axis[i]) { + amin[i] = js.axis[i]; + t = get_time(); + } + if (amax[i] < js.axis[i]) { + amax[i] = js.axis[i]; + t = get_time(); + } printf("Axis %d:%5d,%5d ", i, amin[i], amax[i]); } printf("\r"); fflush(stdout); - } while (get_time() < t+2000); + } while (get_time() < t+4000); printf("Done. Precision is: \n"); @@ -254,30 +261,36 @@ b = js.buttons; - for (j = 0; j < axes; j++) - for (i = 0; i < NUM_POS; i++) { - while(b ^ js.buttons) wait_for_event(fd, &js); - printf("Move axis %d to %s position and push any button.\n", j, pos_name[i]); + for (axis = 0; axis < axes; axis++) + for (pos = 0; pos < NUM_POS; pos++) { + while(b ^ js.buttons) wait_for_event(fd, &js); + printf("Move axis %d to %s position and push any button.\n", axis, pos_name[pos]); - while (!(b ^ js.buttons)) { - print_position(j, js.axis[j]); - wait_for_event(fd, &js); - } + while (!(b ^ js.buttons)) { + print_position(axis, js.axis[axis]); + wait_for_event(fd, &js); + } - putcs("Hold ... "); + putcs("Hold ... "); - corda[j].cmin[i] = js.axis[j]; - corda[j].cmax[i] = js.axis[j]; + corda[axis].cmin[pos] = js.axis[axis]; + corda[axis].cmax[pos] = js.axis[axis]; - t = get_time(); + t = get_time(); - while (get_time() < t + 2000 && (b ^ js.buttons)) { - if (js.axis[j] < corda[j].cmin[i]) corda[j].cmin[i] = js.axis[j]; - if (js.axis[j] > corda[j].cmax[i]) corda[j].cmax[i] = js.axis[j]; - wait_for_event(fd, &js); + while (get_time() < t + 2000 && (b ^ js.buttons)) { + if (js.axis[axis] < corda[axis].cmin[pos]) { + corda[axis].cmin[pos] = js.axis[axis]; + t = get_time(); + } + if (js.axis[axis] > corda[axis].cmax[pos]) { + corda[axis].cmax[pos] = js.axis[axis]; + t = get_time(); + } + wait_for_event(fd, &js); + } + puts("OK."); } - puts("OK."); - } puts(""); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2010-09-23 11:45:50
|
Revision: 2387 http://linuxconsole.svn.sourceforge.net/linuxconsole/?rev=2387&view=rev Author: skitt Date: 2010-09-23 11:45:44 +0000 (Thu, 23 Sep 2010) Log Message: ----------- Add axis and button remapping. Patch provided by Dr. L?\195?\161szl?\195?\179 Kaj?\195?\161n; see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=444142 Modified Paths: -------------- trunk/utils/jscal.c Modified: trunk/utils/jscal.c =================================================================== --- trunk/utils/jscal.c 2010-09-23 11:44:06 UTC (rev 2386) +++ trunk/utils/jscal.c 2010-09-23 11:45:44 UTC (rev 2387) @@ -61,6 +61,8 @@ int fd; struct js_corr corr[MAX_AXES]; +__u8 axmap[ABS_MAX + 1]; +__u16 buttonmap[(KEY_MAX - BTN_MISC + 1)]; char axes, buttons, fuzz; int version; struct correction_data corda[MAX_AXES]; @@ -163,6 +165,12 @@ puts(" -V --version Prints the version numbers"); puts(" -p --print-correction Prints the current settings as a jscal"); puts(" command line"); + puts(" -q --print-mappings Print the current axis and button"); + puts(" mappings as a jscal command line"); + puts(" -u <n_of_axes,axmap1,axmap2,...,"); + puts(" n_of_buttons,btnmap1,btnmap2,"); + puts(" ...> --set-mappings Sets axis and button mappings to the"); + puts(" specified values"); putchar('\n'); } @@ -329,6 +337,42 @@ (version >> 8) & 0xff, version & 0xff); } +void print_mappings(char *devicename) +{ + int i; + + if (ioctl(fd, JSIOCGAXES, &axes)) { + perror("jscal: error getting axes"); + exit(1); + } + if (ioctl(fd, JSIOCGBUTTONS, &buttons)) { + perror("jscal: error getting buttons"); + exit(1); + } + if (ioctl(fd, JSIOCGAXMAP, &axmap)) { + perror("jscal: error getting axis map"); + exit(1); + } + if (ioctl(fd, JSIOCGBTNMAP, &buttonmap)) { + perror("jscal: error getting button map"); + exit(1); + } + + printf("jscal -u %d", axes); + for (i = 0; i < axes; i++) + { + printf( ",%d", axmap[i]); + } + + printf(",%d", buttons); + for (i = 0; i < buttons; i++) + { + printf( ",%d", buttonmap[i]); + } + + printf(" %s\n",devicename); +} + void print_settings(char *devicename) { int i,j; @@ -355,6 +399,107 @@ printf(" %s\n",devicename); } +// n axes n buttons +// 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 +void set_mappings(char *p) +{ + int i; + int axes_on_cl = 0; + int btns_on_cl = 0; + int axis_mapping = 0; + int btn_mapping = 0; + + if (ioctl(fd, JSIOCGAXES, &axes)) { + perror("jscal: error getting axes"); + exit(1); + } + if (ioctl(fd, JSIOCGBUTTONS, &buttons)) { + perror("jscal: error getting buttons"); + exit(1); + } + + if (axes > MAX_AXES) axes = MAX_AXES; + + if (!p) { + fprintf(stderr, "jscal: missing argument for --set-mappings\n"); + exit(1); + } + + //axes + sscanf(p, "%d", &axes_on_cl); + p = strstr(p, ","); + + if (axes_on_cl != axes) { + fprintf(stderr, "jscal: joystick has %d axes and not %d as specified on command line\n", + axes, axes_on_cl); + exit(1); + } + + + for (i = 0; i < axes; i++) + { + if (!p) { + fprintf(stderr, "jscal: missing mapping for axis %d\n", i); + exit(1); + } + sscanf(++p, "%d", &axis_mapping); + p = strstr(p, ","); + + + if (axis_mapping > ABS_MAX + 1) { + fprintf(stderr, "jscal: invalid axis mapping for axis %d (max is %d)\n", i, ABS_MAX + 1); + exit(1); + } + axmap[i] = axis_mapping; + } + + //buttons + sscanf(++p, "%d", &btns_on_cl); + p = strstr(p, ","); + + if (btns_on_cl != buttons) { + fprintf(stderr, "jscal: joystick has %d buttons and not %d as specified on command line\n", + buttons, btns_on_cl); + exit(1); + } + + + for (i = 0; i < buttons; i++) + { + if (!p) { + fprintf(stderr, "jscal: missing mapping for button %d\n", i); + exit(1); + } + sscanf(++p, "%d", &btn_mapping); + p = strstr(p, ","); + + + if (btn_mapping > KEY_MAX) { + fprintf(stderr, "jscal: invalid button mapping for button %d (max is %d)\n", i, KEY_MAX); + exit(1); + } + if (btn_mapping < BTN_MISC) { + fprintf(stderr, "jscal: invalid button mapping for button %d (min is %d)\n", i, BTN_MISC); + exit(1); + } + buttonmap[i] = btn_mapping; + } + + if (p) { + fprintf(stderr, "jscal: too many values\n"); + exit(1); + } + + if (ioctl(fd, JSIOCSAXMAP, &axmap)) { + perror("jscal: error setting axis map"); + exit(1); + } + if (ioctl(fd, JSIOCSBTNMAP, &buttonmap)) { + perror("jscal: error setting button map"); + exit(1); + } +} + void set_correction(char *p) { int i,j; @@ -474,14 +619,18 @@ char *parameter = NULL; int t; + // /usr/include/getopt.h static struct option long_options[] = { {"calibrate", no_argument, NULL, 'c'}, {"help", no_argument, NULL, 'h'}, {"set-correction", required_argument, NULL, 's'}, + {"set-mappings", required_argument, NULL, 'u'}, {"test-center", no_argument, NULL, 't'}, {"version", no_argument, NULL, 'V'}, - {"print-correction", no_argument, NULL, 'p'} + {"print-correction", no_argument, NULL, 'p'}, + {"print-mappings", no_argument, NULL, 'q'}, + {NULL, no_argument, NULL, 0 } }; if (argc == 1) { @@ -490,10 +639,12 @@ } do { - t = getopt_long(argc, argv, "chps:vVt", long_options, &option_index); + t = getopt_long(argc, argv, "chpqu:s:vVt", long_options, &option_index); switch (t) { case 'p': + case 'q': case 's': + case 'u': case 'c': case 't': case 'V': @@ -553,9 +704,15 @@ case 'p': print_settings(argv[argc -1]); break; + case 'q': + print_mappings(argv[argc -1]); + break; case 's': set_correction(parameter); break; + case 'u': + set_mappings(parameter); + break; case 't': test_center(); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2010-09-23 11:56:41
|
Revision: 2392 http://linuxconsole.svn.sourceforge.net/linuxconsole/?rev=2392&view=rev Author: skitt Date: 2010-09-23 11:56:32 +0000 (Thu, 23 Sep 2010) Log Message: ----------- When applying an axis map, carry calibration data over to the new axis assignments. Patch provided by Krzysztof A. Sobiecki; see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=529865 Modified Paths: -------------- trunk/utils/jscal.c Modified: trunk/utils/jscal.c =================================================================== --- trunk/utils/jscal.c 2010-09-23 11:54:38 UTC (rev 2391) +++ trunk/utils/jscal.c 2010-09-23 11:56:32 UTC (rev 2392) @@ -62,6 +62,7 @@ int fd; struct js_corr corr[MAX_AXES]; __u8 axmap[ABS_MAX + 1]; +__u8 axmap2[ABS_MAX + 1]; __u16 buttonmap[(KEY_MAX - BTN_MISC + 1)]; char axes, buttons, fuzz; int version; @@ -354,8 +355,7 @@ exit(1); } if (ioctl(fd, JSIOCGBTNMAP, &buttonmap)) { - perror("jscal: error getting button map"); - exit(1); + buttons=0; } printf("jscal -u %d", axes); @@ -373,6 +373,48 @@ printf(" %s\n",devicename); } + +void get_axmap2(void) +{ + if (ioctl(fd, JSIOCGAXMAP, &axmap2)) { + perror("jscal: error getting axis map"); + exit(1); + } +} + +/* + * Remap the calibration data to fit the (potentially) new axis map. + * axmap2 stores the original axis map, axmap the new one. + */ +void correct_axes(void) +{ + int axmes[ABS_MAX + 1]; + struct js_corr corr_tmp[MAX_AXES]; + int i; + int ax[axes]; + //Create remapping table + for(i=0;i<axes;++i){ + axmes[(axmap2[i])]=i; + } + for(i=0;i<axes;++i){ + ax[i]=axmes[(axmap[i])]; + } + //Read again current callibration settings + if (ioctl(fd, JSIOCGCORR, &corr)) { + perror("jscal: error getting correction"); + exit(1); + } + //Remap callibration settings + for (i = 0; i < axes; i++) { + corr_tmp[i]=corr[(ax[i])]; + } + if (ioctl(fd, JSIOCSCORR, &corr_tmp)) { + perror("jscal: error setting correction"); + exit(1); + } + +} + void print_settings(char *devicename) { int i,j; @@ -425,7 +467,7 @@ exit(1); } - //axes + //axes sscanf(p, "%d", &axes_on_cl); p = strstr(p, ","); @@ -457,15 +499,15 @@ sscanf(++p, "%d", &btns_on_cl); p = strstr(p, ","); - if (btns_on_cl != buttons) { + if ((btns_on_cl != buttons)&&(btns_on_cl!=0)) { fprintf(stderr, "jscal: joystick has %d buttons and not %d as specified on command line\n", buttons, btns_on_cl); exit(1); } - for (i = 0; i < buttons; i++) - { + for (i = 0; i < btns_on_cl; i++) + { if (!p) { fprintf(stderr, "jscal: missing mapping for button %d\n", i); exit(1); @@ -483,21 +525,31 @@ exit(1); } buttonmap[i] = btn_mapping; - } + } if (p) { fprintf(stderr, "jscal: too many values\n"); exit(1); } + + // Save the current axis map + get_axmap2(); + // Apply the new axis map if (ioctl(fd, JSIOCSAXMAP, &axmap)) { perror("jscal: error setting axis map"); exit(1); } - if (ioctl(fd, JSIOCSBTNMAP, &buttonmap)) { - perror("jscal: error setting button map"); - exit(1); - } + + // Move the calibration data accordingly + correct_axes(); + + if (btns_on_cl!=0){ + if (ioctl(fd, JSIOCSBTNMAP, &buttonmap)) { + perror("jscal: error setting button map"); + exit(1); + } + } } void set_correction(char *p) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2010-09-27 05:14:27
|
Revision: 2397 http://linuxconsole.svn.sourceforge.net/linuxconsole/?rev=2397&view=rev Author: skitt Date: 2010-09-27 05:14:20 +0000 (Mon, 27 Sep 2010) Log Message: ----------- As encountered on https://bugs.launchpad.net/ubuntu/+source/joystick/+bug/595767, some "joystick" type devices support more than 16 axes. The kernel actually supports ABS_MAX + 1 axes, so handle that many. Modified Paths: -------------- trunk/utils/jscal.c Modified: trunk/utils/jscal.c =================================================================== --- trunk/utils/jscal.c 2010-09-27 05:13:40 UTC (rev 2396) +++ trunk/utils/jscal.c 2010-09-27 05:14:20 UTC (rev 2397) @@ -47,7 +47,6 @@ #define PIT_HZ 1193180L #define NUM_POS 3 -#define MAX_AXES 16 #define MAX_CORR 1 const char *pos_name[] = {"minimum", "center", "maximum"}; @@ -60,17 +59,17 @@ }; int fd; -struct js_corr corr[MAX_AXES]; +struct js_corr corr[ABS_MAX + 1]; __u8 axmap[ABS_MAX + 1]; __u8 axmap2[ABS_MAX + 1]; __u16 buttonmap[(KEY_MAX - BTN_MISC + 1)]; char axes, buttons, fuzz; int version; -struct correction_data corda[MAX_AXES]; +struct correction_data corda[ABS_MAX + 1]; struct js_info { int buttons; - int axis[MAX_AXES]; + int axis[ABS_MAX + 1]; } js; void print_position(int i, int a) @@ -213,7 +212,7 @@ int i, j, t, b; int axis, pos; - for (i=0; i<MAX_AXES; i++) { + for (i=0; i<ABS_MAX + 1; i++) { corr[i].type = JS_CORR_NONE; corr[i].prec = 0; } @@ -226,7 +225,7 @@ { int i; - int amax[MAX_AXES], amin[MAX_AXES]; + int amax[ABS_MAX + 1], amin[ABS_MAX + 1]; puts("Calibrating precision: wait and don't touch the joystick."); @@ -389,7 +388,7 @@ void correct_axes(void) { int axmes[ABS_MAX + 1]; - struct js_corr corr_tmp[MAX_AXES]; + struct js_corr corr_tmp[ABS_MAX + 1]; int i; int ax[axes]; //Create remapping table @@ -460,7 +459,7 @@ exit(1); } - if (axes > MAX_AXES) axes = MAX_AXES; + if (axes > ABS_MAX + 1) axes = ABS_MAX + 1; if (!p) { fprintf(stderr, "jscal: missing argument for --set-mappings\n"); @@ -562,7 +561,7 @@ exit(1); } - if (axes > MAX_AXES) axes = MAX_AXES; + if (axes > ABS_MAX + 1) axes = ABS_MAX + 1; if (!p) { fprintf(stderr, "jscal: missing number of axes\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |