From 8264655c47098253d60f1170e9ab48790b51a411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lenclud?= Date: Tue, 14 Jun 2022 17:16:48 +0200 Subject: [PATCH] Add Microsoft.Windows.CsWin32 dependency Add commented out code to try fix Slion/SharpLibHid#15. --- Project/Hid/Hid.csproj | 4 ++++ Project/Hid/HidEvent.cs | 28 ++++++++++++++++++++++++++-- Project/Hid/NativeMethods.txt | 5 +++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 Project/Hid/NativeMethods.txt diff --git a/Project/Hid/Hid.csproj b/Project/Hid/Hid.csproj index 1f3ef78..914f72f 100644 --- a/Project/Hid/Hid.csproj +++ b/Project/Hid/Hid.csproj @@ -114,6 +114,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Project/Hid/HidEvent.cs b/Project/Hid/HidEvent.cs index ae216cf..8f68b18 100644 --- a/Project/Hid/HidEvent.cs +++ b/Project/Hid/HidEvent.cs @@ -519,7 +519,7 @@ private void ProcessInputReport(byte[] aInputReport) /// Typically fetches values of a joystick/gamepad axis and dpad directions. /// /// - private void GetUsageValues(byte[] aInputReport) + private /*unsafe*/ void GetUsageValues(byte[] aInputReport) { if (Device.InputValueCapabilities == null) { @@ -534,8 +534,32 @@ private void GetUsageValues(byte[] aInputReport) continue; } - //Now fetch and add our usage value uint usageValue = 0; + + + // Was trying to fix: https://github.com/Slion/SharpLibHid/issues/15 + // No joy + // Check report count + /* + if (caps.ReportCount > 1) + { + Trace.TraceWarning("WARNING: Multiple report not supported"); + } + + fixed (byte* report = aInputReport) + { + var res = Windows.Win32.PInvoke.HidP_GetUsageValueArray(Windows.Win32.Devices.HumanInterfaceDevice.HIDP_REPORT_TYPE.HidP_Input, caps.UsagePage, caps.LinkCollection, caps.NotRange.Usage, (byte*)usageValue, sizeof(uint), Device.PreParsedData, report, (uint)aInputReport.Length); + uint err = (uint)res.Value; + Trace.TraceWarning("RES: " + res.Value.ToString("X")); + if (err==(uint)Win32.HidStatus.HIDP_STATUS_NOT_VALUE_ARRAY) + { + Trace.TraceWarning("Not good"); + } + } + */ + + //Now fetch and add our usage value + Win32.HidStatus status = Win32.Function.HidP_GetUsageValue(Win32.HIDP_REPORT_TYPE.HidP_Input, caps.UsagePage, caps.LinkCollection, caps.NotRange.Usage, ref usageValue, Device.PreParsedData, aInputReport, (uint)aInputReport.Length); if (status == Win32.HidStatus.HIDP_STATUS_SUCCESS) { diff --git a/Project/Hid/NativeMethods.txt b/Project/Hid/NativeMethods.txt new file mode 100644 index 0000000..fc28e7d --- /dev/null +++ b/Project/Hid/NativeMethods.txt @@ -0,0 +1,5 @@ + + +HidP_GetUsageValueArray + +