comparison src/joystick/darwin/SDL_sysjoystick.c @ 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 2c835d58faad
children dbc6d1893869
comparison
equal deleted inserted replaced
2286:41a6675d8700 2287:15a242fca6c4
768 void 768 void
769 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) 769 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
770 { 770 {
771 recDevice *device = joystick->hwdata; 771 recDevice *device = joystick->hwdata;
772 recElement *element; 772 recElement *element;
773 SInt32 value; 773 SInt32 value, range;
774 int i; 774 int i;
775 775
776 if (device->removed) { /* device was unplugged; ignore it. */ 776 if (device->removed) { /* device was unplugged; ignore it. */
777 if (device->uncentered) { 777 if (device->uncentered) {
778 device->uncentered = 0; 778 device->uncentered = 0;
816 element = device->firstHat; 816 element = device->firstHat;
817 i = 0; 817 i = 0;
818 while (element) { 818 while (element) {
819 Uint8 pos = 0; 819 Uint8 pos = 0;
820 820
821 value = HIDGetElementValue(device, element); 821 range = (element->max - element->min + 1);
822 if (element->max == 3) /* 4 position hatswitch - scale up value */ 822 value = HIDGetElementValue(device, element) - element->min;
823 if (range == 4) /* 4 position hatswitch - scale up value */
823 value *= 2; 824 value *= 2;
824 else if (element->max != 7) /* Neither a 4 nor 8 positions - fall back to default position (centered) */ 825 else if (range != 8) /* Neither a 4 nor 8 positions - fall back to default position (centered) */
825 value = -1; 826 value = -1;
826 switch (value) { 827 switch (value) {
827 case 0: 828 case 0:
828 pos = SDL_HAT_UP; 829 pos = SDL_HAT_UP;
829 break; 830 break;