From ac9a1fb697d4b8a69e7619bd19e563a6a6391edb Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Tue, 11 Jul 2017 11:58:04 +0100 Subject: [PATCH] New: Add 4-position hat switches to Windows HID driver --- src/OpenTK/Platform/Windows/WinRawJoystick.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/OpenTK/Platform/Windows/WinRawJoystick.cs b/src/OpenTK/Platform/Windows/WinRawJoystick.cs index 9bbe6b90..5003af44 100644 --- a/src/OpenTK/Platform/Windows/WinRawJoystick.cs +++ b/src/OpenTK/Platform/Windows/WinRawJoystick.cs @@ -341,6 +341,24 @@ namespace OpenTK.Platform.Windows HatPosition GetHatPosition(uint value, HidProtocolValueCaps caps) { + 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; + default: + return HatPosition.Centered; + } + } if (caps.LogicalMax == 8) { //Hat states are represented as a plain number from 0-8