Backing out new changes, at Chris Nelson's request.
authorSam Lantinga <slouken@libsdl.org>
Sat, 11 Sep 2004 17:48:41 +0000
changeset 953cb5e1d0cad31
parent 952 6f5c8bd997aa
child 954 3acd16ea0180
Backing out new changes, at Chris Nelson's request.
src/joystick/linux/SDL_sysjoystick.c
     1.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Tue Aug 31 04:21:35 2004 +0000
     1.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Sat Sep 11 17:48:41 2004 +0000
     1.3 @@ -69,98 +69,45 @@
     1.4  
     1.5  #ifndef NO_LOGICAL_JOYSTICKS
     1.6  
     1.7 -/*
     1.8 -   Some USB HIDs show up as a single joystick even though they actually
     1.9 -   control 2 or more joysticks.
    1.10 -*/
    1.11 -/*
    1.12 -   This code handles the MP-8800 (Quad) and MP-8866 (Dual), which can
    1.13 -   be identified by their transparent blue design. It's quite trivial
    1.14 -   to add other joysticks with similar quirky behavior.
    1.15 -   -id
    1.16 -*/
    1.17 -
    1.18 -struct joystick_logical_mapping {
    1.19 +static struct joystick_logical_values {
    1.20          int njoy;
    1.21          int nthing;
    1.22 -};
    1.23 +} joystick_logical_values[] = {
    1.24  
    1.25 -/*
    1.26 -   {logical joy, logical axis},
    1.27 -   {logical joy, logical hat},
    1.28 -   {logical joy, logical ball},
    1.29 -   {logical joy, logical button}
    1.30 -*/
    1.31 +/* +0 */
    1.32 +   /* MP-8800 axes map - map to {logical joystick #, logical axis #} */
    1.33 +   {0,0},{0,1},{0,2},{1,0},{1,1},{0,3},{1,2},{1,3},{2,0},{2,1},{2,2},{2,3},
    1.34 +   {3,0},{3,1},{3,2},{3,3},{0,4},{1,4},{2,4},
    1.35  
    1.36 -static struct joystick_logical_mapping mp88xx_1_logical_axismap[] = {
    1.37 -   {0,0},{0,1},{0,2},{0,3},{0,4},{0,5}
    1.38 -};
    1.39 -static struct joystick_logical_mapping mp88xx_1_logical_buttonmap[] = {
    1.40 -   {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}
    1.41 -};
    1.42 +/* +19 */
    1.43 +   /* MP-8800 hat map - map to {logical joystick #, logical hat #} */
    1.44 +   {0,0},{1,0},{2,0},{3,0},
    1.45  
    1.46 -static struct joystick_logical_mapping mp88xx_2_logical_axismap[] = {
    1.47 -   {0,0},{0,1},{0,2},{1,0},{1,1},{0,3},
    1.48 -   {1,2},{1,3},{0,4},{0,5},{1,4},{1,5}
    1.49 -};
    1.50 -static struct joystick_logical_mapping mp88xx_2_logical_buttonmap[] = {
    1.51 -   {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11},
    1.52 -   {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11}
    1.53 -};
    1.54 -
    1.55 -static struct joystick_logical_mapping mp88xx_3_logical_axismap[] = {
    1.56 -   {0,0},{0,1},{0,2},{1,0},{1,1},{0,3},
    1.57 -   {1,2},{1,3},{2,0},{2,1},{2,2},{2,3},
    1.58 -   {0,4},{0,5},{1,4},{1,5},{2,4},{2,5}
    1.59 -};
    1.60 -static struct joystick_logical_mapping mp88xx_3_logical_buttonmap[] = {
    1.61 -   {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11},
    1.62 -   {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11},
    1.63 -   {2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8},{2,9},{2,10},{2,11}
    1.64 -};
    1.65 -
    1.66 -static struct joystick_logical_mapping mp88xx_4_logical_axismap[] = {
    1.67 -   {0,0},{0,1},{0,2},{1,0},{1,1},{0,3},
    1.68 -   {1,2},{1,3},{2,0},{2,1},{2,2},{2,3},
    1.69 -   {3,0},{3,1},{3,2},{3,3},{0,4},{0,5},
    1.70 -   {1,4},{1,5},{2,4},{2,5},{3,4},{3,5}
    1.71 -};
    1.72 -static struct joystick_logical_mapping mp88xx_4_logical_buttonmap[] = {
    1.73 +/* +23 */
    1.74 +   /* MP-8800 button map - map to {logical joystick #, logical button #} */
    1.75     {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11},
    1.76     {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11},
    1.77     {2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8},{2,9},{2,10},{2,11},
    1.78     {3,0},{3,1},{3,2},{3,3},{3,4},{3,5},{3,6},{3,7},{3,8},{3,9},{3,10},{3,11}
    1.79  };
    1.80  
    1.81 -struct joystick_logical_layout {
    1.82 +static struct joystick_logical_layout {
    1.83          int naxes;
    1.84          int nhats;
    1.85          int nballs;
    1.86          int nbuttons;
    1.87 -};
    1.88 -
    1.89 -static struct joystick_logical_layout mp88xx_1_logical_layout[] = {
    1.90 -        {6, 0, 0, 12}
    1.91 -};
    1.92 -static struct joystick_logical_layout mp88xx_2_logical_layout[] = {
    1.93 -        {6, 0, 0, 12},
    1.94 -        {6, 0, 0, 12}
    1.95 -};
    1.96 -static struct joystick_logical_layout mp88xx_3_logical_layout[] = {
    1.97 -        {6, 0, 0, 12},
    1.98 -        {6, 0, 0, 12},
    1.99 -        {6, 0, 0, 12}
   1.100 -};
   1.101 -static struct joystick_logical_layout mp88xx_4_logical_layout[] = {
   1.102 -        {6, 0, 0, 12},
   1.103 -        {6, 0, 0, 12},
   1.104 -        {6, 0, 0, 12},
   1.105 -        {6, 0, 0, 12}
   1.106 +} joystick_logical_layout[] = {
   1.107 +        /* MP-8800 logical layout */
   1.108 +        {5, 1, 0, 12},
   1.109 +        {5, 1, 0, 12},
   1.110 +        {5, 1, 0, 12},
   1.111 +        {4, 1, 0, 12}
   1.112  };
   1.113  
   1.114  /*
   1.115 -   This array sets up a means of mapping a single physical joystick to
   1.116 -   multiple logical joysticks. (djm)
   1.117 +   Some USB HIDs show up as a single joystick even though they actually
   1.118 +   control 2 or more joysticks.  This array sets up a means of mapping
   1.119 +   a single physical joystick to multiple logical joysticks. (djm)
   1.120                                                                                  
   1.121     njoys
   1.122          the number of logical joysticks
   1.123 @@ -171,78 +118,19 @@
   1.124     axes, hats, balls, buttons
   1.125          arrays that map a physical thingy to a logical thingy
   1.126   */
   1.127 -struct joystick_logicalmap {
   1.128 +static struct joystick_logicalmap {
   1.129          const char *name;
   1.130 -	int nbuttons;
   1.131          int njoys;
   1.132 -        struct joystick_logical_layout *layout;
   1.133 -        struct joystick_logical_mapping *axismap;
   1.134 -        struct joystick_logical_mapping *hatmap;
   1.135 -        struct joystick_logical_mapping *ballmap;
   1.136 -        struct joystick_logical_mapping *buttonmap;
   1.137 -};
   1.138 +        struct joystick_logical_layout *layouts;
   1.139 +        struct joystick_logical_values *axes;
   1.140 +        struct joystick_logical_values *hats;
   1.141 +        struct joystick_logical_values *balls;
   1.142 +        struct joystick_logical_values *buttons;
   1.143  
   1.144 -static struct joystick_logicalmap joystick_logicalmap[] = {
   1.145 -        {
   1.146 -		"WiseGroup.,Ltd MP-8866 Dual USB Joypad",
   1.147 -		12,
   1.148 -		1,
   1.149 -		mp88xx_1_logical_layout,
   1.150 -        	mp88xx_1_logical_axismap,
   1.151 -		NULL,
   1.152 -		NULL,
   1.153 -        	mp88xx_1_logical_buttonmap
   1.154 -	},
   1.155 -        {
   1.156 -		"WiseGroup.,Ltd MP-8866 Dual USB Joypad",
   1.157 -		24,
   1.158 -		2,
   1.159 -		mp88xx_2_logical_layout,
   1.160 -        	mp88xx_2_logical_axismap,
   1.161 -		NULL,
   1.162 -		NULL,
   1.163 -        	mp88xx_2_logical_buttonmap
   1.164 -	},
   1.165 -        {
   1.166 -		"WiseGroup.,Ltd MP-8800 Quad USB Joypad",
   1.167 -		12,
   1.168 -		1,
   1.169 -		mp88xx_1_logical_layout,
   1.170 -        	mp88xx_1_logical_axismap,
   1.171 -		NULL,
   1.172 -		NULL,
   1.173 -        	mp88xx_1_logical_buttonmap
   1.174 -	},
   1.175 -        {
   1.176 -		"WiseGroup.,Ltd MP-8800 Quad USB Joypad",
   1.177 -		24,
   1.178 -		2,
   1.179 -		mp88xx_2_logical_layout,
   1.180 -        	mp88xx_2_logical_axismap,
   1.181 -		NULL,
   1.182 -		NULL,
   1.183 -        	mp88xx_2_logical_buttonmap
   1.184 -	},
   1.185 -        {
   1.186 -		"WiseGroup.,Ltd MP-8800 Quad USB Joypad",
   1.187 -		36,
   1.188 -		3,
   1.189 -		mp88xx_3_logical_layout,
   1.190 -        	mp88xx_3_logical_axismap,
   1.191 -		NULL,
   1.192 -		NULL,
   1.193 -        	mp88xx_3_logical_buttonmap
   1.194 -	},
   1.195 -        {
   1.196 -		"WiseGroup.,Ltd MP-8800 Quad USB Joypad",
   1.197 -		48,
   1.198 -		4,
   1.199 -		mp88xx_4_logical_layout,
   1.200 -        	mp88xx_4_logical_axismap,
   1.201 -		NULL,
   1.202 -		NULL,
   1.203 -        	mp88xx_4_logical_buttonmap
   1.204 -	}
   1.205 +} joystick_logicalmap[] = {
   1.206 +        {"WiseGroup.,Ltd MP-8800 Quad USB Joypad", 4, joystick_logical_layout,
   1.207 +         joystick_logical_values, joystick_logical_values+19, NULL,
   1.208 +         joystick_logical_values+23}
   1.209  };
   1.210  
   1.211  /* find the head of a linked list, given a point in it
   1.212 @@ -318,40 +206,28 @@
   1.213  {
   1.214     register int i, j, k, ret, prev;
   1.215     const char* name;
   1.216 -   int nbuttons, fd;
   1.217 -   unsigned char n;
   1.218  
   1.219     ret = 0;
   1.220  
   1.221     for(i = 0; i < max; i++) {
   1.222        name = SDL_SYS_JoystickName(i);
   1.223 -	
   1.224 -      fd = open(SDL_joylist[i].fname, O_RDONLY, 0);
   1.225 -      if ( fd >= 0 ) {
   1.226 -	 if ( ioctl(fd, JSIOCGBUTTONS, &n) < 0 ) {
   1.227 -	    nbuttons = -1;
   1.228 -	 } else {
   1.229 -            nbuttons = n;
   1.230 -	 }
   1.231 -	 close(fd);
   1.232 -      }
   1.233 -      else {
   1.234 -	 nbuttons=-1;
   1.235 -      }
   1.236  
   1.237        if (name) {
   1.238           for(j = 0; j < SDL_TABLESIZE(joystick_logicalmap); j++) {
   1.239 -            if (!strcmp(name, joystick_logicalmap[j].name) && (nbuttons==-1 || nbuttons==joystick_logicalmap[j].nbuttons)) {
   1.240 +            if (!strcmp(name, joystick_logicalmap[j].name)) {
   1.241 +
   1.242                 prev = i;
   1.243 -               SDL_joylist[prev].map = &(joystick_logicalmap[j]);
   1.244 +               SDL_joylist[prev].map = joystick_logicalmap+j;
   1.245  
   1.246                 for(k = 1; k < joystick_logicalmap[j].njoys; k++) {
   1.247                    SDL_joylist[prev].next = max + ret;
   1.248 -                  SDL_joylist[max+ret].prev = prev;
   1.249 -		  
   1.250 +
   1.251 +                  if (prev != i)
   1.252 +                     SDL_joylist[max+ret].prev = prev;
   1.253 +
   1.254                    prev = max + ret;
   1.255                    SDL_joylist[prev].logicalno = k;
   1.256 -                  SDL_joylist[prev].map = &(joystick_logicalmap[j]);
   1.257 +                  SDL_joylist[prev].map = joystick_logicalmap+j;
   1.258                    ret++;
   1.259                 }
   1.260  
   1.261 @@ -371,7 +247,9 @@
   1.262        "01020304050607080910111213141516171819"
   1.263        "20212223242526272829303132";
   1.264     const char* suffix;
   1.265 +
   1.266     slen = strlen(namebuf);
   1.267 +
   1.268     suffix = NULL;
   1.269  
   1.270     if (logicalno*2<sizeof(suffixs))
   1.271 @@ -541,12 +419,9 @@
   1.272  		}
   1.273  		close(fd);
   1.274  
   1.275 -
   1.276  #ifndef NO_LOGICAL_JOYSTICKS
   1.277 -		if (SDL_joylist[oindex].prev || SDL_joylist[oindex].next || index!=oindex)
   1.278 -		{
   1.279 +		if (SDL_joylist[oindex].prev || SDL_joylist[oindex].next)
   1.280         		   LogicalSuffix(SDL_joylist[oindex].logicalno, namebuf, 128);
   1.281 -		}
   1.282  #endif
   1.283  	}
   1.284  	return name;
   1.285 @@ -780,7 +655,7 @@
   1.286  {
   1.287          struct joystick_logical_layout* layout;
   1.288                                                                                  
   1.289 -        layout = SDL_joylist[joystick->index].map->layout +
   1.290 +        layout = SDL_joylist[joystick->index].map->layouts +
   1.291                  SDL_joylist[joystick->index].logicalno;
   1.292                                                                                  
   1.293          joystick->nbuttons = layout->nbuttons;
   1.294 @@ -856,7 +731,7 @@
   1.295  #ifndef NO_LOGICAL_JOYSTICKS
   1.296  
   1.297  static SDL_Joystick* FindLogicalJoystick(
   1.298 -   SDL_Joystick *joystick, struct joystick_logical_mapping* v)
   1.299 +   SDL_Joystick *joystick, struct joystick_logical_values* v)
   1.300  {
   1.301          SDL_Joystick *logicaljoy;
   1.302          register int i;
   1.303 @@ -885,7 +760,7 @@
   1.304  
   1.305  static int LogicalJoystickButton(
   1.306     SDL_Joystick *joystick, Uint8 button, Uint8 state){
   1.307 -        struct joystick_logical_mapping* buttons;
   1.308 +        struct joystick_logical_values* buttons;
   1.309          SDL_Joystick *logicaljoy = NULL;
   1.310  
   1.311          /* if there's no map then this is just a regular joystick
   1.312 @@ -895,7 +770,7 @@
   1.313  
   1.314          /* get the logical joystick that will receive the event
   1.315           */
   1.316 -        buttons = SDL_joylist[joystick->index].map->buttonmap+button;
   1.317 +        buttons = SDL_joylist[joystick->index].map->buttons+button;
   1.318          logicaljoy = FindLogicalJoystick(joystick, buttons);
   1.319  
   1.320          if (logicaljoy == NULL)
   1.321 @@ -909,7 +784,7 @@
   1.322  static int LogicalJoystickAxis(
   1.323  	SDL_Joystick *joystick, Uint8 axis, Sint16 value)
   1.324  {
   1.325 -        struct joystick_logical_mapping* axes;
   1.326 +        struct joystick_logical_values* axes;
   1.327          SDL_Joystick *logicaljoy = NULL;
   1.328  
   1.329          /* if there's no map then this is just a regular joystick
   1.330 @@ -919,7 +794,7 @@
   1.331  
   1.332          /* get the logical joystick that will receive the event
   1.333           */
   1.334 -        axes = SDL_joylist[joystick->index].map->axismap+axis;
   1.335 +        axes = SDL_joylist[joystick->index].map->axes+axis;
   1.336          logicaljoy = FindLogicalJoystick(joystick, axes);
   1.337  
   1.338          if (logicaljoy == NULL)
   1.339 @@ -941,7 +816,7 @@
   1.340  		{ SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN }
   1.341  	};
   1.342  	SDL_logical_joydecl(SDL_Joystick *logicaljoy = NULL);
   1.343 -	SDL_logical_joydecl(struct joystick_logical_mapping* hats = NULL);
   1.344 +	SDL_logical_joydecl(struct joystick_logical_values* hats = NULL);
   1.345  
   1.346  	the_hat = &stick->hwdata->hats[hat];
   1.347  	if ( value < 0 ) {
   1.348 @@ -963,7 +838,7 @@
   1.349  
   1.350  			/* get the fake joystick that will receive the event
   1.351  			*/
   1.352 -			hats = SDL_joylist[stick->index].map->hatmap+hat;
   1.353 +			hats = SDL_joylist[stick->index].map->hats+hat;
   1.354  			logicaljoy = FindLogicalJoystick(stick, hats);
   1.355  		}
   1.356