Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Enumerate by (vid, pid)[] #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/HidLibrary/HidDevices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ public static IEnumerable<HidDevice> Enumerate(int vendorId, params int[] produc
productIds.Contains(x.Attributes.ProductId));
}

public static IEnumerable<HidDevice> Enumerate(unit.Tuple_VidPid[] vidpids)
{
var Devices = EnumerateDevices().Select(x => new HidDevice(x.Path, x.Description));
List<HidDevice> temp = new List<HidDevice>();
foreach (var d in Devices)
{
if (vidpids.Where(x => x.VendorId == d.Attributes.VendorId && x.ProductId == d.Attributes.ProductId).Any())
{
temp.Add(d);
}
}
return temp;
}

public static IEnumerable<HidDevice> Enumerate(int vendorId, int productId, ushort UsagePage)
{
return EnumerateDevices().Select(x => new HidDevice(x.Path, x.Description)).Where(x => x.Attributes.VendorId == vendorId &&
Expand Down
2 changes: 1 addition & 1 deletion src/HidLibrary/HidLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" PackagePath=""/>
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2' ">
<Reference Include="System" />
Expand Down
8 changes: 8 additions & 0 deletions src/HidLibrary/unit/Tuple_VidPid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace HidLibrary.unit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been away from active open-source C# development for a long time, so I may just be behind on naming conventions. What was the purpose for the "unit" namespace and why did you choose that name for this?

{
public class Tuple_VidPid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really unwieldy name for this class, unless it adheres to a new C# convention I don't know about. It's not actually a tuple, since it's just a regular C# data object. It seems like something along these lines could be useful, but it should probably include a UsageID property and be called something like HidDeviceDescription, and we should use it inside HidDevice as well, possibly as the underlying data storage for the properties it describes.

{
public int VendorId { get; set; }
public int ProductId { get; set; }
}
}