MacOS X joystick fix
authorSam Lantinga <slouken@libsdl.org>
Sat, 03 May 2003 15:36:10 +0000
changeset 61786e0385b8f96
parent 616 12c746afbc27
child 618 707748c422f8
MacOS X joystick fix
src/joystick/darwin/SDL_sysjoystick.c
     1.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Sat Apr 26 06:40:01 2003 +0000
     1.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Sat May 03 15:36:10 2003 +0000
     1.3 @@ -752,34 +752,42 @@
     1.4  		Uint8 pos = 0;
     1.5  
     1.6  		value = HIDGetElementValue(device, element);
     1.7 +		if (element->max == 3) /* 4 position hatswitch - scale up value */
     1.8 +			value *= 2;
     1.9 +		else if (element->max != 7) /* Neither a 4 nor 8 positions - fall back to default position (centered) */
    1.10 +			value = -1;
    1.11  		switch(value)
    1.12  		{
    1.13  			case 0:
    1.14 -				pos = SDL_HAT_CENTERED;
    1.15 +				pos = SDL_HAT_UP;
    1.16  				break;
    1.17  			case 1:
    1.18 -				pos = SDL_HAT_UP;
    1.19 +				pos = SDL_HAT_RIGHTUP;
    1.20  				break;
    1.21  			case 2:
    1.22 -				pos = SDL_HAT_RIGHTUP;
    1.23 +				pos = SDL_HAT_RIGHT;
    1.24  				break;
    1.25  			case 3:
    1.26 -				pos = SDL_HAT_RIGHT;
    1.27 +				pos = SDL_HAT_RIGHTDOWN;
    1.28  				break;
    1.29  			case 4:
    1.30 -				pos = SDL_HAT_RIGHTDOWN;
    1.31 +				pos = SDL_HAT_DOWN;
    1.32  				break;
    1.33  			case 5:
    1.34 -				pos = SDL_HAT_DOWN;
    1.35 +				pos = SDL_HAT_LEFTDOWN;
    1.36  				break;
    1.37  			case 6:
    1.38 -				pos = SDL_HAT_LEFTDOWN;
    1.39 +				pos = SDL_HAT_LEFT;
    1.40  				break;
    1.41  			case 7:
    1.42 -				pos = SDL_HAT_LEFT;
    1.43 +				pos = SDL_HAT_LEFTUP;
    1.44  				break;
    1.45 -			case 8:
    1.46 -				pos = SDL_HAT_LEFTUP;
    1.47 +			default:
    1.48 +				/* Every other value is mapped to center. We do that because some
    1.49 +				 * joysticks use 8 and some 15 for this value, and apparently
    1.50 +				 * there are even more variants out there - so we try to be generous.
    1.51 +				 */
    1.52 +				pos = SDL_HAT_CENTERED;
    1.53  				break;
    1.54  		}
    1.55  		if ( pos != joystick->hats[i] )