From ee74a229e064ec4579a8d7993da10d66c883b211 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 29 Dec 2007 19:44:02 +0000 Subject: [PATCH] Fixed bug #478 Take the min and max values into account. --- docs.html | 3 +++ src/joystick/darwin/SDL_sysjoystick.c | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs.html b/docs.html index 941d2c668..5dda06d8f 100644 --- a/docs.html +++ b/docs.html @@ -79,6 +79,9 @@

Mac OS X Notes

Improved trackpad scrolling support.

+

+ Fixed joystick hat reporting for certain joysticks. +

[separator] diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index ec2751daa..4901436f6 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -727,7 +727,7 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) { 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 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) { 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) {