# HG changeset patch # User Sam Lantinga # Date 1051976170 0 # Node ID 86e0385b8f96833959a8daa239294b6f5027f556 # Parent 12c746afbc2733126affca30395cd8aaf6b430d2 MacOS X joystick fix diff -r 12c746afbc27 -r 86e0385b8f96 src/joystick/darwin/SDL_sysjoystick.c --- 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] )