changeset 2287:15a242fca6c4

Fixed bug #478 Take the min and max values into account.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 29 Dec 2007 19:45:09 +0000
parents 41a6675d8700
children e9bcf004c324
files src/joystick/darwin/SDL_sysjoystick.c
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/joystick/darwin/SDL_sysjoystick.c	Sat Dec 29 19:29:20 2007 +0000
+++ b/src/joystick/darwin/SDL_sysjoystick.c	Sat Dec 29 19:45:09 2007 +0000
@@ -770,7 +770,7 @@
 {
     recDevice *device = joystick->hwdata;
     recElement *element;
-    SInt32 value;
+    SInt32 value, range;
     int i;
 
     if (device->removed) {      /* device was unplugged; ignore it. */
@@ -818,10 +818,11 @@
     while (element) {
         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) {
         case 0: