Skip to content

Latest commit

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Hideous

Ugly stuff made simple, at least.

Hideous is a library for .NET allowing users to interface with HID devices using a simple programming interface that doesn't require them to guess "how the fuck do I use it".

I'm a fuckwit - examples?

So am I, but I get you. Catch.

Enumerating certain HID devices

usingHideous;varcollection=newHidDeviceCollection(vendorId:0x0B05,productId:0x19B6);foreach(vardeviceincollection){Console.WriteLine(device.Properties);}

Enumerating all HID devices

usingHideous;varcollection=newHidDeviceCollection();/* Same as (0, 0) */foreach(vardeviceincollection){Console.WriteLine(device.Properties);}

Looking up a device by usage page

usingHideous;varcollection=newHidDeviceCollection(0x0B05,0x19B6);varmyDevice=collection.FirstOrDefault(x =>x.Properties.UsagePage==0xFF00);

Enumerating reports of a device

usingHideous;varcollection=newHidDeviceCollection(0x0B05,0x19B6);varmyDevice=collection.FirstOrDefault(
x =>x.Properties.UsagePage==0x0001&&x.Properties.UsageId==0x0006);if(myDevice!=null){myDevice.Connect();/* Descriptor only becomes valid AFTER connection was established. */foreach(varreportinmyDevice.Descriptor.Reports){Console.WriteLine(report);}}

Reading a HID input report that has an ID

usingHideous;varcollection=newHidDeviceCollection(0x0B05,0x19B6);varmyDevice=collection.FirstOrDefault(
x =>x.Properties.UsagePage==0xFF31&&x.Properties.UsageId==0x0076);if(myDevice!=null){myDevice.Connect();while(true){varbytes=newbyte[31];/** * 0x01 refers to the report ID, * not its index in the collection. * * By default reads are non-blocking. * To enforce blocking readsset * myDevice.IsReadBlocking to `true`. * * This method doesn't require prefixing * the data bytes with the report ID. * * The output byte array will be trimmed to the * actual count of bytes read from the device. * * Same deal with Feature reports, but they have * Set and Get methods accordingly. **/varreadBytes=myDevice.Descriptor.InputReports[0x5D].Read(bytes);foreach(varbinreadBytes){Console.WriteLine(b.ToString("X2"));}}}

Notes

The library currently supports Windows and Linux only - because of the natives extracted when the library first runs, you will find either hidapi.dll or hidapi.so if not already present.

Requires HidApi >= 0.14.0.

About

A simple, cross-platform C# USB HID abstraction library.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages