Fixed bug #478 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Sat, 29 Dec 2007 19:44:02 +0000
branchSDL-1.2
changeset 4120d07c60f5e460
parent 4119 98dee075dae0
child 4121 917ca146d901
Fixed bug #478

Take the min and max values into account.
docs.html
src/joystick/darwin/SDL_sysjoystick.c
     1.1 --- a/docs.html	Sat Dec 29 19:01:13 2007 +0000
     1.2 +++ b/docs.html	Sat Dec 29 19:44:02 2007 +0000
     1.3 @@ -79,6 +79,9 @@
     1.4  <P>
     1.5  	Improved trackpad scrolling support.
     1.6  </P>
     1.7 +<P>
     1.8 +	Fixed joystick hat reporting for certain joysticks.
     1.9 +</P>
    1.10  </BLOCKQUOTE>
    1.11  
    1.12  <IMG SRC="docs/images/rainbow.gif" ALT="[separator]" WIDTH="100%">
     2.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Sat Dec 29 19:01:13 2007 +0000
     2.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Sat Dec 29 19:44:02 2007 +0000
     2.3 @@ -727,7 +727,7 @@
     2.4  {
     2.5  	recDevice *device = joystick->hwdata;
     2.6  	recElement *element;
     2.7 -	SInt32 value;
     2.8 +	SInt32 value, range;
     2.9  	int i;
    2.10  
    2.11  	if (device->removed)  /* device was unplugged; ignore it. */
    2.12 @@ -780,10 +780,11 @@
    2.13  	{
    2.14  		Uint8 pos = 0;
    2.15  
    2.16 -		value = HIDGetElementValue(device, element);
    2.17 -		if (element->max == 3) /* 4 position hatswitch - scale up value */
    2.18 +		range = (element->max - element->min + 1);
    2.19 +		value = HIDGetElementValue(device, element) - element->min;
    2.20 +		if (range == 4) /* 4 position hatswitch - scale up value */
    2.21  			value *= 2;
    2.22 -		else if (element->max != 7) /* Neither a 4 nor 8 positions - fall back to default position (centered) */
    2.23 +		else if (range != 8) /* Neither a 4 nor 8 positions - fall back to default position (centered) */
    2.24  			value = -1;
    2.25  		switch(value)
    2.26  		{