Merge pull request #568 from leezer3/JoystickPatch2

Fix: Some joystick hats not returning centered correctly on Windows HID
This commit is contained in:
Jarl Gullberg 2017-07-11 13:52:21 +02:00 committed by GitHub
commit 1c5643f703

View file

@ -341,15 +341,44 @@ namespace OpenTK.Platform.Windows
HatPosition GetHatPosition(uint value, HidProtocolValueCaps caps) HatPosition GetHatPosition(uint value, HidProtocolValueCaps caps)
{ {
if (caps.LogicalMax == 8) if (value > caps.LogicalMax)
return (HatPosition)value;
else if (caps.LogicalMax == 7)
{ {
//Return zero if our value is out of bounds ==> e.g.
//Thrustmaster T-Flight Hotas X returns 15 for the centered position
return HatPosition.Centered;
}
if (caps.LogicalMax == 3)
{
//4-way hat switch as per the example in Appendix C
//http://www.usb.org/developers/hidpage/Hut1_12v2.pdf
switch (value)
{
case 0:
return HatPosition.Left;
case 1:
return HatPosition.Up;
case 2:
return HatPosition.Right;
case 3:
return HatPosition.Down;
}
}
if (caps.LogicalMax == 8)
{
//Hat states are represented as a plain number from 0-8
//with centered being zero
//Padding should have already been stripped out, so just cast
return (HatPosition)value;
}
if (caps.LogicalMax == 7)
{
//Hat states are represented as a plain number from 0-7
//with centered being 8
value++; value++;
value %= 9; value %= 9;
return (HatPosition)value; return (HatPosition)value;
} }
else //The HID report length is unsupported
return HatPosition.Centered; return HatPosition.Centered;
} }