From b48f3e14ddaf601a4e8e325d97e0d04fd287b46d Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 29 Dec 2007 19:45:09 +0000 Subject: [PATCH] Fixed bug #478 Take the min and max values into account. --- src/joystick/darwin/SDL_sysjoystick.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index 60755d17b..84706f65f 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -770,7 +770,7 @@ 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. */ @@ -818,10 +818,11 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) 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: