コード例 #1
0
            private static int MakeKey(short collection, HidPage page, short usage)
            {
                var coll_byte = unchecked ((byte)collection);
                var page_byte = unchecked ((byte)((((ushort)page & 0xff00) >> 8) | ((ushort)page & 0xff)));

                return((coll_byte << 24) | (page_byte << 16) | unchecked ((ushort)usage));
            }
コード例 #2
0
 private RawInputDevice(ushort usage, RawInputDeviceFlags flags, IntPtr target, HidPage usagePage)
 {
     Usage     = usage;
     Flags     = flags;
     Target    = target;
     UsagePage = usagePage;
 }
コード例 #3
0
            private JoystickHat GetHat(short collection, HidPage page, short usage)
            {
                var key = MakeKey(collection, page, usage);

                if (!hats.ContainsKey(key))
                {
                    hats.Add(key, JoystickHat.Hat0 + hats.Count);
                }

                return(hats[key]);
            }
コード例 #4
0
            private int GetButton(short collection, HidPage page, short usage)
            {
                var key = MakeKey(collection, page, usage);

                if (!buttons.ContainsKey(key))
                {
                    buttons.Add(key, buttons.Count);
                }

                return(buttons[key]);
            }
コード例 #5
0
ファイル: HidHelper.cs プロジェクト: Kinaetron/opentk-1
        /// <summary>
        /// Translates a generic HID usage value to a specific joystick axis for the specified <see cref="HidPage"/>.
        /// </summary>
        /// <param name="page">The HID usage page.</param>
        /// <param name="usage">The generic usage value.</param>
        /// <returns>An <see cref="int"/> that maps the HID usage value to a joystick axis.</returns>
        public static int TranslateJoystickAxis(HidPage page, int usage)
        {
            switch (page)
            {
            case HidPage.GenericDesktop:
                switch ((HidGenericDesktopUsage)usage)
                {
                case HidGenericDesktopUsage.X:
                    return(0);

                case HidGenericDesktopUsage.Y:
                    return(1);

                case HidGenericDesktopUsage.Z:
                    return(2);

                case HidGenericDesktopUsage.RotationZ:
                    return(3);

                case HidGenericDesktopUsage.RotationX:
                    return(4);

                case HidGenericDesktopUsage.RotationY:
                    return(5);

                case HidGenericDesktopUsage.Slider:
                    return(6);

                case HidGenericDesktopUsage.Dial:
                    return(7);

                case HidGenericDesktopUsage.Wheel:
                    return(8);
                }

                break;

            case HidPage.Simulation:
                switch ((HidSimulationUsage)usage)
                {
                case HidSimulationUsage.Rudder:
                    return(9);

                case HidSimulationUsage.Throttle:
                    return(10);
                }

                break;
            }

            Debug.Print($"[Input] Unknown axis with HID page/usage {page}/{usage}");
            return(0);
        }
コード例 #6
0
            private int GetAxis(short collection, HidPage page, short usage)
            {
                var key = MakeKey(collection, page, usage);

                if (!axes.ContainsKey(key))
                {
                    var axis = HidHelper.TranslateJoystickAxis(page, usage);
                    axes.Add(key, axis);
                }

                return(axes[key]);
            }
コード例 #7
0
 public void SetAxis(short collection, HidPage page, short usage, short value)
 {
     // set axis only when HidPage is known by HidHelper.TranslateJoystickAxis() to avoid axis0 to be overwritten by unknown HidPage
     if (page == HidPage.GenericDesktop || page == HidPage.Simulation)
     {
         //Certain joysticks (Speedlink Black Widow, PS3 pad connected via USB)
         //return an invalid HID page of 1, so
         if (usage != 1)
         {
             var axis = GetAxis(collection, page, usage);
             State.SetAxis(axis, value);
         }
     }
 }
コード例 #8
0
            public void SetHat(short collection, HidPage page, short usage, HatPosition pos)
            {
                var hat = GetHat(collection, page, usage);

                State.SetHat(hat, new JoystickHatState(pos));
            }
コード例 #9
0
            public void SetButton(short collection, HidPage page, short usage, bool value)
            {
                var button = GetButton(collection, page, usage);

                State.SetButton(button, value);
            }
コード例 #10
0
 public static extern HidProtocolStatus GetUsageValue(HidProtocolReportType type,
                                                      HidPage usage_page, short link_collection, short usage, ref uint usage_value,
                                                      [In] byte[] preparsed_data, IntPtr report, int report_length);
コード例 #11
0
 public static extern unsafe HidProtocolStatus GetUsages(HidProtocolReportType type,
                                                         HidPage usage_page, short link_collection, short *usage_list, ref int usage_length,
                                                         [In] byte[] preparsed_data, IntPtr report, int report_length);
コード例 #12
0
 public static extern HidProtocolStatus GetSpecificButtonCaps(HidProtocolReportType ReportType,
                                                              HidPage UsagePage, ushort LinkCollection, ushort Usage,
                                                              [Out] HidProtocolButtonCaps[] ButtonCaps, ref ushort ButtonCapsLength,
                                                              [In] byte[] PreparsedData);