예제 #1
0
        private static bool GetDeviceCaps(Device stick, byte[] preparsed_data, out HidProtocolCaps caps)
        {
            // Query joystick capabilities
            caps = new HidProtocolCaps();
            if (HidProtocol.GetCaps(preparsed_data, ref caps) != HidProtocolStatus.Success)
            {
                Debug.Print("[WinRawJoystick] HidProtocol.GetCaps() failed with {0}",
                            Marshal.GetLastWin32Error());
                return(false);
            }

            // Make sure our caps arrays are big enough
            HidProtocolValueCaps[]  axis_caps   = new HidProtocolValueCaps[caps.NumberInputValueCaps];
            HidProtocolButtonCaps[] button_caps = new HidProtocolButtonCaps[caps.NumberInputButtonCaps];

            // Axis capabilities
            ushort axis_count = (ushort)axis_caps.Length;

            if (HidProtocol.GetValueCaps(HidProtocolReportType.Input,
                                         axis_caps, ref axis_count, preparsed_data) !=
                HidProtocolStatus.Success)
            {
                Debug.Print("[WinRawJoystick] HidProtocol.GetValueCaps() failed with {0}",
                            Marshal.GetLastWin32Error());
                return(false);
            }

            // Button capabilities
            ushort button_count = (ushort)button_caps.Length;

            if (HidProtocol.GetButtonCaps(HidProtocolReportType.Input,
                                          button_caps, ref button_count, preparsed_data) !=
                HidProtocolStatus.Success)
            {
                Debug.Print("[WinRawJoystick] HidProtocol.GetButtonCaps() failed with {0}",
                            Marshal.GetLastWin32Error());
                return(false);
            }

            stick.AxisCaps.Clear();
            stick.AxisCaps.AddRange(axis_caps);

            stick.ButtonCaps.Clear();
            stick.ButtonCaps.AddRange(button_caps);

            return(true);
        }
예제 #2
0
        private HatPosition GetHatPosition(uint value, HidProtocolValueCaps caps)
        {
            if (value > caps.LogicalMax)
            {
                //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 %= 9;
                return((HatPosition)value);
            }
            //The HID report length is unsupported
            return(HatPosition.Centered);
        }