Slion / SharpLibHid

C# HID Library using Windows Raw Input.
http://publish.slions.net/HidDemo/
58 stars 19 forks source link

PS3 controller multiple axis with same usage reports wrong value #15

Open sonik-br opened 2 years ago

sonik-br commented 2 years ago

Hi. I'm interfacing with a game controller and it have two "Slider" axis. The report is correct on windows (joy.cpl) In the HID Demo one of the sliders report is duplicate on the other. The second one don't generate any report.

The descriptor: (I added the "DataIndex" property on the list). image

And the event log. image

Here it's possible to see that the Sliders both are sharing the same values.

I try to debug but could not find the problem. Looks like it ignores the DataIndex if the axis is duplicate?

If you can at least point me in the right direction so I can try to fix.

Thanks.

Slion commented 2 years ago

Been a while since I had a look at that code but if I had to take a guess it probably does a look-up for the Slider and take the first one it finds, not expecting you can have multiple of them. It could be tricky to fix too. Can you not reassign one of the Sliders to another axis somehow? Do you mind me asking what kind of device is that?

sonik-br commented 2 years ago

I'm interfacing with some gamepads and gamepad adapters. This one is not an adapter, but an Playstation 3 controller directly connected to windows using the driver provided by Sony (maker of the device). It's not really required to fix for this device but would be good to have it working for others. I understand if it's something hard to track down and not worth to fix.

Slion commented 2 years ago

I'm just now starting to understand that issue. I don't have a PS3 controller but I do have a PS4 controller so I guess I'll try to reproduce it with that one. Thanks again for taking the time to report it.

The thing is I don't think I'm myself using that DataIndex to fetch the values. It's done in HidEvent.GetUsageValues using HidP_GetUsageValue. I wonder if that could be a Windows bug. Need to take a closer look though.

I can't reproduce the issue with the PS4 controller cause it does not have multiple axis with the same usage…

Slion commented 2 years ago

I have the means to test that here apparently by configuring my Virpil joystick. However when I try to configure it with multiple axes having the same name it gives out a warning message: image

Just saying it looks like this is something to be avoided in general.

Slion commented 2 years ago

It does work in the control panel, it's showing two sliders, both are working nicely. image

Slion commented 2 years ago

And I can reproduce the issue in HID Demo. I'll try to debug that later today.

Slion commented 2 years ago

The issue it seems is indeed due to HidP_GetUsageValue. It looks like they even describe the problem in the docs remarks section.

Basically to support that we should use HidP_GetUsageValueArray instead off HidP_GetUsageValue.

Slion commented 2 years ago

We should switch to Microsoft.Windows.CsWin32 to gain access to HidP_GetUsageValueArray

Slion commented 2 years ago

Except that our ReportCount is not above one so that array function might not be what we need here. I'm still missing a piece of the puzzle.

I'm guessing I still need to experiment with HidP_GetUsageValueArray to see if I can get it to work somehow.

sonik-br commented 2 years ago

Nice! Thanks for taking a shot at it.

The PS3 controller have some unique features... It's buttons are "pressure sensitive"! So the driver them as button bits and also as sliders. That's why it does have a bunch of sliders.

Slion commented 2 years ago

As feared using HidP_GetUsageValueArray does not work it returns HIDP_STATUS_NOT_VALUE_ARRAY. More investigation is needed to work that one out. I'll put on the ice for now however.

Slion commented 2 years ago

UCR can pick up both Slider axes properly through SharpDX DirectInput. However this is done through DirectInput which is a higher level API so it won't help us here.

Slion commented 2 years ago

@sonik-br Could you build and run the latest HID Demo? I'm just curious to see what kind of friendly name your PS3 controller is now reporting. Hopefully I did not break anything.

Slion commented 2 years ago

I could try to use API Monitor see how Joy.cpl gets the axis value. Though I reckon it's using the DirectInput API rather than the HID API.

sonik-br commented 2 years ago

Tested it with the current code from repo. Working the same way with the PS3 controller. Sliders are sharing the same value.

I can try to see how UCR work and use SharpDX.

BTW got it "working" with IntergatedCircuits/HidSharp Sliders works independently but it does have another problem. It's not handling signed/unsigned values correctly :(

Slion commented 2 years ago

In the HID Demo, is it still displaying VID_054C as the name of the device?

sonik-br commented 2 years ago

It changed...

On windows panel: image

And on HID Demo: image

Slion commented 2 years ago

Thanks, still the wrong one though. Interesting that the control panel get it correct.

sonik-br commented 2 years ago

Control Panel gets the info from windows register I think. I've seen this happen with arduino based devices. On a clean windows install if you connect an customized arduino, windows will cache it's "name". Then later if you connect an default arduino, it will still show the cached name and not what is being reported by the new device. This off course when using devices with same VID/PID.