changeset 4120:d07c60f5e460 SDL-1.2

Fixed bug #478 Take the min and max values into account.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 29 Dec 2007 19:44:02 +0000
parents 98dee075dae0
children 917ca146d901
files docs.html src/joystick/darwin/SDL_sysjoystick.c
diffstat 2 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/docs.html	Sat Dec 29 19:01:13 2007 +0000
+++ b/docs.html	Sat Dec 29 19:44:02 2007 +0000
@@ -79,6 +79,9 @@
 <P>
 	Improved trackpad scrolling support.
 </P>
+<P>
+	Fixed joystick hat reporting for certain joysticks.
+</P>
 </BLOCKQUOTE>
 
 <IMG SRC="docs/images/rainbow.gif" ALT="[separator]" WIDTH="100%">
--- a/src/joystick/darwin/SDL_sysjoystick.c	Sat Dec 29 19:01:13 2007 +0000
+++ b/src/joystick/darwin/SDL_sysjoystick.c	Sat Dec 29 19:44:02 2007 +0000
@@ -727,7 +727,7 @@
 {
 	recDevice *device = joystick->hwdata;
 	recElement *element;
-	SInt32 value;
+	SInt32 value, range;
 	int i;
 
 	if (device->removed)  /* device was unplugged; ignore it. */
@@ -780,10 +780,11 @@
 	{
 		Uint8 pos = 0;
 
-		value = HIDGetElementValue(device, element);
-		if (element->max == 3) /* 4 position hatswitch - scale up value */
+		range = (element->max - element->min + 1);
+		value = HIDGetElementValue(device, element) - element->min;
+		if (range == 4) /* 4 position hatswitch - scale up value */
 			value *= 2;
-		else if (element->max != 7) /* Neither a 4 nor 8 positions - fall back to default position (centered) */
+		else if (range != 8) /* Neither a 4 nor 8 positions - fall back to default position (centered) */
 			value = -1;
 		switch(value)
 		{