Package: joystick Version: 20051019-5 Severity: wishlist Tags: patch Patch adds new functionality to -u and -q options of joystick. Remapping axes (-u) will also move their calibration settings with them. It also add option to ignore buttons while touching only axes. Something like this: jscal -u 4,0,1,2,3,0 /dev/input/js0 0 instead of real buttons number will make jscal ignore them.
Changes in printing current mappings (-q) are somewhat more problematic. jscal -q /dev/input/js0 will act the same unless it encounter bug in JSIOCGBTNMAP in this case I set number of buttons to 0 and print something like that: jscal -u 4,0,1,2,3,0 /dev/input/js0 Changing axes mappings still work and buttons can be ignored. Patch is still rough a bit, but I can change it according to feedback.
diff -rup ~joystick-20051019/utils/jscal.c joystick-20051019/utils/jscal.c --- ~joystick-20051019/utils/jscal.c 2009-05-19 12:07:27.000000000 +0200 +++ joystick-20051019/utils/jscal.c 2009-05-21 12:54:32.000000000 +0200 @@ -61,7 +61,9 @@ struct correction_data { int fd; struct js_corr corr[MAX_AXES]; +struct js_corr corr2[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 +356,7 @@ void print_mappings(char *devicename) exit(1); } if (ioctl(fd, JSIOCGBTNMAP, &buttonmap)) { - perror("jscal: error getting button map"); - exit(1); + buttons=0; } printf("jscal -u %d", axes); @@ -373,6 +374,45 @@ void print_mappings(char *devicename) printf(" %s\n",devicename); } + +void get_axmap2(void) +{ + if (ioctl(fd, JSIOCGAXMAP, &axmap2)) { + perror("jscal: error getting axis map"); + exit(1); + } +} + +void correct_axes(void) +{ + int axmes[ABS_MAX + 1]; + int i; + int ax[axes]; + for(i=0;i<axes;++i){ + axmes[(axmap2[i])]=i; + } + for(i=0;i<axes;++i){ + ax[i]=axmes[(axmap[i])]; + } + if (ioctl(fd, JSIOCGAXES, &axes)) { + perror("jscal: error getting axes"); + exit(1); + } + if (ioctl(fd, JSIOCGCORR, &corr2)) { + perror("jscal: error getting correction"); + exit(1); + } + + for (i = 0; i < axes; i++) { + corr[i]=corr2[(ax[i])]; + } + if (ioctl(fd, JSIOCSCORR, &corr)) { + perror("jscal: error setting correction"); + exit(1); + } + +} + void print_settings(char *devicename) { int i,j; @@ -425,7 +465,7 @@ void set_mappings(char *p) exit(1); } - //axes + //axes sscanf(p, "%d", &axes_on_cl); p = strstr(p, ","); @@ -457,15 +497,15 @@ void set_mappings(char *p) 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 +523,27 @@ void set_mappings(char *p) exit(1); } buttonmap[i] = btn_mapping; - } + } if (p) { fprintf(stderr, "jscal: too many values\n"); exit(1); } + get_axmap2(); 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); - } + + correct_axes(); + + + if ((ioctl(fd, JSIOCSBTNMAP, &buttonmap))&&(btns_on_cl!=0)) { + perror("jscal: error setting button map"); + exit(1); + } + } void set_correction(char *p)