comparison src/joystick/darwin/SDL_sysjoystick.c @ 4120:d07c60f5e460 SDL-1.2

Fixed bug #478 Take the min and max values into account.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 29 Dec 2007 19:44:02 +0000
parents e3945f84427f
children a1b03ba2fcd0
comparison
equal deleted inserted replaced
4119:98dee075dae0 4120:d07c60f5e460
725 */ 725 */
726 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) 726 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
727 { 727 {
728 recDevice *device = joystick->hwdata; 728 recDevice *device = joystick->hwdata;
729 recElement *element; 729 recElement *element;
730 SInt32 value; 730 SInt32 value, range;
731 int i; 731 int i;
732 732
733 if (device->removed) /* device was unplugged; ignore it. */ 733 if (device->removed) /* device was unplugged; ignore it. */
734 { 734 {
735 if (device->uncentered) 735 if (device->uncentered)
778 i = 0; 778 i = 0;
779 while (element) 779 while (element)
780 { 780 {
781 Uint8 pos = 0; 781 Uint8 pos = 0;
782 782
783 value = HIDGetElementValue(device, element); 783 range = (element->max - element->min + 1);
784 if (element->max == 3) /* 4 position hatswitch - scale up value */ 784 value = HIDGetElementValue(device, element) - element->min;
785 if (range == 4) /* 4 position hatswitch - scale up value */
785 value *= 2; 786 value *= 2;
786 else if (element->max != 7) /* Neither a 4 nor 8 positions - fall back to default position (centered) */ 787 else if (range != 8) /* Neither a 4 nor 8 positions - fall back to default position (centered) */
787 value = -1; 788 value = -1;
788 switch(value) 789 switch(value)
789 { 790 {
790 case 0: 791 case 0:
791 pos = SDL_HAT_UP; 792 pos = SDL_HAT_UP;