Open sonik-br opened 2 years ago
Hi! Can you frame your question/inquiry/report in the terms of this actual library? I have no idea how this "HID Demo" program is associated with HidSharp.
Oh sorry. My bad. I was testing two libs and got confused. I have edited my first.
So maybe you got here from win-hid-dump or similar, looking to see the same HID report descriptor from your C# application, as your device reports it. Unfortunately that's not how Windows works. The Windows OS doesn't expose the HID report descriptor to its userspace, instead it gives a higher level preprocessed property set. HidSharp attempts to reverse engineer the approximate report descriptor from this information (see WinHidDevice.ReportDescriptorReconstructor.cs), but this will never be accurate. What we would need to find out if the OS is mistaking -128 for 0, or HidSharp.
Before we venture into that, I have to ask, do you have the means to change the report descriptor on your USB device? It's not really justifiable to have an asymmetrical range such as [-128, 127], and most devices use [-127, 127] instead.
It's possible to change as it is an arduino based, open source project. But it's used to interface with playstation controllers and I think it is this way to make it easier to map the 256 bit range to it as it will just use the raw bits. Makes sense? signed byte vs unsigned byte.
For the descriptor I used USBlyzer to capture. It installs as a (kernel?) driver and it can capture any kind of usb traffic on windows.
The device descriptor from source code matches the report from USBlyzer.
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x04, // Usage (Joystick)
0xA1, 0x01, // Collection (Application)
0xA1, 0x00, // Collection (Physical)
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (0x01)
0x29, 0x0C, // Usage Maximum (0x0C)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x95, 0x10, // Report Count (16)
0x75, 0x01, // Report Size (1)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x01, // Usage (Pointer)
0xA1, 0x00, // Collection (Physical)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x15, 0x80, // Logical Minimum (-128)
0x25, 0x7F, // Logical Maximum (127)
0x95, 0x02, // Report Count (2)
0x75, 0x08, // Report Size (8)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC0, // End Collection
0x09, 0x37, // Usage (Dial)
0x15, 0x80, // Logical Minimum (-128)
0x25, 0x7F, // Logical Maximum (127)
0x95, 0x01, // Report Count (1)
0x75, 0x08, // Report Size (8)
0x81, 0x06, // Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position)
0x09, 0x38, // Usage (Wheel)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x95, 0x01, // Report Count (1)
0x75, 0x08, // Report Size (8)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x09, 0x39, // Usage (Hat switch)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x07, // Logical Maximum (7)
0x35, 0x00, // Physical Minimum (0)
0x46, 0x3B, 0x01, // Physical Maximum (315)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x65, 0x14, // Unit (System: English Rotation, Length: Centimeter)
0x81, 0x42, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,Null State)
0xC0, // End Collection
0xC0, // End Collection
The GetRawReportDescriptor
method returns the preprocessed windows descriptor?
By parsing it I can see how it messes up from the original.
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x04, // Usage (Joystick)
0xA1, 0x01, // Collection (Application)
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (0x01)
0x29, 0x10, // Usage Maximum (0x10)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x35, 0x00, // Physical Minimum (0)
0x45, 0x01, // Physical Maximum (1)
0x65, 0x00, // Unit (None)
0x55, 0x00, // Unit Exponent (0)
0x75, 0x01, // Report Size (1)
0x95, 0x10, // Report Count (16)
0x81, 0x03, // Input (Const,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x39, // Usage (Hat switch)
0x25, 0x07, // Logical Maximum (7)
0x46, 0x3B, 0x01, // Physical Maximum (315)
0x65, 0x14, // Unit (System: English Rotation, Length: Centimeter)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x09, 0x37, // Usage (Dial)
0x25, 0x7F, // Logical Maximum (127)
0x81, 0x06, // Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position)
0x09, 0x38, // Usage (Wheel)
0x15, 0x00, // Logical Minimum (0)
0x25, 0xFF, // Logical Maximum (-1)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC1, 0x00, // End Collection
At least after calling the win32 method it's returning a signed value
Hi. I'm interfacing with a game controller and it have a "Dial" axis. It's a relative axis and it's value is signed. It works like an mouse wheel (scrolling can be negative or positive). But the lib returns it as unsiged. Lib register it with range of 0 to 127 but the correct is -128 to 127
Windows joy.cpl shows it correctly. By using an HID descriptor viewer (USBlyzer) it shows the range -128 to 127![image](https://user-images.githubusercontent.com/16923826/170490457-85d301ea-badc-4886-b545-6027173be72d.png)
I'm doing something wrong?