changeset 617:86e0385b8f96

MacOS X joystick fix
author Sam Lantinga <slouken@libsdl.org>
date Sat, 03 May 2003 15:36:10 +0000
parents 12c746afbc27
children 707748c422f8
files src/joystick/darwin/SDL_sysjoystick.c
diffstat 1 files changed, 19 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/joystick/darwin/SDL_sysjoystick.c	Sat Apr 26 06:40:01 2003 +0000
+++ b/src/joystick/darwin/SDL_sysjoystick.c	Sat May 03 15:36:10 2003 +0000
@@ -752,34 +752,42 @@
 		Uint8 pos = 0;
 
 		value = HIDGetElementValue(device, element);
+		if (element->max == 3) /* 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) */
+			value = -1;
 		switch(value)
 		{
 			case 0:
-				pos = SDL_HAT_CENTERED;
-				break;
-			case 1:
 				pos = SDL_HAT_UP;
 				break;
-			case 2:
+			case 1:
 				pos = SDL_HAT_RIGHTUP;
 				break;
+			case 2:
+				pos = SDL_HAT_RIGHT;
+				break;
 			case 3:
-				pos = SDL_HAT_RIGHT;
+				pos = SDL_HAT_RIGHTDOWN;
 				break;
 			case 4:
-				pos = SDL_HAT_RIGHTDOWN;
+				pos = SDL_HAT_DOWN;
 				break;
 			case 5:
-				pos = SDL_HAT_DOWN;
+				pos = SDL_HAT_LEFTDOWN;
 				break;
 			case 6:
-				pos = SDL_HAT_LEFTDOWN;
+				pos = SDL_HAT_LEFT;
 				break;
 			case 7:
-				pos = SDL_HAT_LEFT;
+				pos = SDL_HAT_LEFTUP;
 				break;
-			case 8:
-				pos = SDL_HAT_LEFTUP;
+			default:
+				/* Every other value is mapped to center. We do that because some
+				 * joysticks use 8 and some 15 for this value, and apparently
+				 * there are even more variants out there - so we try to be generous.
+				 */
+				pos = SDL_HAT_CENTERED;
 				break;
 		}
 		if ( pos != joystick->hats[i] )