Skip to content

Commit

Permalink
Add Microsoft.Windows.CsWin32 dependency
Browse files Browse the repository at this point in the history
Add commented out code to try fix #15.
  • Loading branch information
Slion committed Jun 14, 2022
1 parent b863182 commit 8264655
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Project/Hid/Hid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.1-beta">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SharpLibWin32" Version="0.2.1" />
</ItemGroup>

Expand Down
28 changes: 26 additions & 2 deletions Project/Hid/HidEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ private void ProcessInputReport(byte[] aInputReport)
/// Typically fetches values of a joystick/gamepad axis and dpad directions.
/// </summary>
/// <param name="aInputReport"></param>
private void GetUsageValues(byte[] aInputReport)
private /*unsafe*/ void GetUsageValues(byte[] aInputReport)
{
if (Device.InputValueCapabilities == null)
{
Expand All @@ -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)
{
Expand Down
5 changes: 5 additions & 0 deletions Project/Hid/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


HidP_GetUsageValueArray


0 comments on commit 8264655

Please sign in to comment.