Exemple #1
0
        unsafe void UpdateButtons(RawInput *rin, Device stick)
        {
            stick.ClearButtons();

            for (int i = 0; i < stick.ButtonCaps.Count; i++)
            {
                short * usage_list   = stackalloc short[(int)JoystickButton.Last + 1];
                int     usage_length = (int)JoystickButton.Last;
                HIDPage page         = stick.ButtonCaps[i].UsagePage;
                short   collection   = stick.ButtonCaps[i].LinkCollection;

                HidProtocolStatus status = HidProtocol.GetUsages(
                    HidProtocolReportType.Input,
                    page, 0, usage_list, ref usage_length,
                    PreparsedData,
                    new IntPtr((void *)&rin->Data.HID.RawData),
                    rin->Data.HID.Size);

                if (status != HidProtocolStatus.Success)
                {
                    Debug.Print("[WinRawJoystick] HidProtocol.GetUsages() failed with {0}",
                                Marshal.GetLastWin32Error());
                    continue;
                }

                for (int j = 0; j < usage_length; j++)
                {
                    short usage = *(usage_list + j);
                    stick.SetButton(collection, page, usage, true);
                }
            }
        }
        private unsafe void UpdateButtons(RawInput *rin, Device stick)
        {
            stick.ClearButtons();

            for (var i = 0; i < stick.ButtonCaps.Count; i++)
            {
                short *usage_list   = stackalloc short[64];
                var    usage_length = 64;
                var    page         = stick.ButtonCaps[i].UsagePage;
                var    collection   = stick.ButtonCaps[i].LinkCollection;

                var status = HidProtocol.GetUsages(
                    HidProtocolReportType.Input,
                    page, 0, usage_list, ref usage_length,
                    PreparsedData,
                    new IntPtr(&rin->Data.Hid.RawData),
                    (int)rin->Data.Hid.SizeHid
                    );

                if (status != HidProtocolStatus.Success)
                {
                    Debug.Print("[WinRawJoystick] HidProtocol.GetUsages() failed with {0}",
                                Marshal.GetLastWin32Error());
                    continue;
                }

                for (var j = 0; j < usage_length; j++)
                {
                    var usage = *(usage_list + j);
                    stick.SetButton(collection, page, usage, true);
                }
            }
        }