src/joystick/darwin/SDL_sysjoystick.c
changeset 617 86e0385b8f96
parent 594 a71ce390adeb
child 620 92080b127f82
equal deleted inserted replaced
616:12c746afbc27 617:86e0385b8f96
   750 	while (element)
   750 	while (element)
   751 	{
   751 	{
   752 		Uint8 pos = 0;
   752 		Uint8 pos = 0;
   753 
   753 
   754 		value = HIDGetElementValue(device, element);
   754 		value = HIDGetElementValue(device, element);
       
   755 		if (element->max == 3) /* 4 position hatswitch - scale up value */
       
   756 			value *= 2;
       
   757 		else if (element->max != 7) /* Neither a 4 nor 8 positions - fall back to default position (centered) */
       
   758 			value = -1;
   755 		switch(value)
   759 		switch(value)
   756 		{
   760 		{
   757 			case 0:
   761 			case 0:
   758 				pos = SDL_HAT_CENTERED;
   762 				pos = SDL_HAT_UP;
   759 				break;
   763 				break;
   760 			case 1:
   764 			case 1:
   761 				pos = SDL_HAT_UP;
   765 				pos = SDL_HAT_RIGHTUP;
   762 				break;
   766 				break;
   763 			case 2:
   767 			case 2:
   764 				pos = SDL_HAT_RIGHTUP;
   768 				pos = SDL_HAT_RIGHT;
   765 				break;
   769 				break;
   766 			case 3:
   770 			case 3:
   767 				pos = SDL_HAT_RIGHT;
   771 				pos = SDL_HAT_RIGHTDOWN;
   768 				break;
   772 				break;
   769 			case 4:
   773 			case 4:
   770 				pos = SDL_HAT_RIGHTDOWN;
   774 				pos = SDL_HAT_DOWN;
   771 				break;
   775 				break;
   772 			case 5:
   776 			case 5:
   773 				pos = SDL_HAT_DOWN;
   777 				pos = SDL_HAT_LEFTDOWN;
   774 				break;
   778 				break;
   775 			case 6:
   779 			case 6:
   776 				pos = SDL_HAT_LEFTDOWN;
   780 				pos = SDL_HAT_LEFT;
   777 				break;
   781 				break;
   778 			case 7:
   782 			case 7:
   779 				pos = SDL_HAT_LEFT;
   783 				pos = SDL_HAT_LEFTUP;
   780 				break;
   784 				break;
   781 			case 8:
   785 			default:
   782 				pos = SDL_HAT_LEFTUP;
   786 				/* Every other value is mapped to center. We do that because some
       
   787 				 * joysticks use 8 and some 15 for this value, and apparently
       
   788 				 * there are even more variants out there - so we try to be generous.
       
   789 				 */
       
   790 				pos = SDL_HAT_CENTERED;
   783 				break;
   791 				break;
   784 		}
   792 		}
   785 		if ( pos != joystick->hats[i] )
   793 		if ( pos != joystick->hats[i] )
   786 			SDL_PrivateJoystickHat(joystick, i, pos);
   794 			SDL_PrivateJoystickHat(joystick, i, pos);
   787 		element = element->pNext;
   795 		element = element->pNext;