WootingKb / wootility-issues

A place to report issues with the Wootility and help with feedback on existing issues
23 stars 3 forks source link

Issue with Keyboard & Unity Engine #66

Open PastaJ36 opened 3 years ago

PastaJ36 commented 3 years ago

Got this from a user via email:

The Wooting One keyboard generates the following error when using Unity’s new input system:

Layout ‘HID::Wooting WootingOne’ matches existing device ‘Wooting WootingOne (HID)’ but failed to instantiate: System.Exception: State format ‘SBIT’ is not supported as floating-point format

This is very easy to replicate:

Install and run Unity 2020 (any version).
In Unity’s menu bar select: “Windows” -> “Package Manager” to open the Package Manager window.
Select the “Packages: Unity Registry” option in the dropdown.
Search for the “Input System” package and install it.
In Unity’s menu bar select: “Edit” -> “Project Settings” to open the Project Settings window.

In the Project Settings window, select “Player”, and then select “Both” for “Active Input Handling”. Unity will be restarted to enable the New Input System.
As soon as Unity is restarted, check the error in Unity’s Console.

This is not a blocking issue, but you may want to have full support for games using Unity’s new input system.
Rocky04 commented 3 years ago

Without looking into it I would suggest it's because the controller support within Unity is bad. I would assume Unity don't rely on DirectInput because it will support all platforms so it's handling the HID stuff all by its own and not really correctly. So I understand the error message that way that the module has a problem converting a signed integer value to a signed floating point. It wouldn't be the first program which doesn't follow the algorithm provided by the USB Implementers Forum to transforming the discrete values into an abstract unified unit.

Device Class Definition for Human Interface Devices (HID) - 6.2.2.7 Global Items https://www.usb.org/document-library/device-class-definition-hid-111

if ((Physical Maximum == UNDEFINED)
    || (Physical Minimum == UNDEFINED)
    || ((Physical Maximum == 0) && (Physical Minimum == 0)))
{
    Physical Maximum = Logical Maximum;
    Physical Minimum = Logical Minimum;
}

If (Unit Exponent == UNDEFINED)
    Unit Exponent = 0;

Resolution = (Logical Maximum – Logical Minimum) / ((Physical Maximum – Physical Minimum) * (10 Unit Exponent))

To be clear, a specific program can transform the physical boundaries into its own range, like by transforming them into a range from 0 to 1.

So because missing values should be handled as standard it means the resolution is just 1. Or course the app itself need to transform the value into it's own representation, like form 0 to +1 or -1 to +1, or whatever.

So I would guess the problem is the classic gamepad from Wooting (DirectInput analog mode) because for that interface the values for the axis are between -32768 and +32767 with the center on 0 (logical and physical). If that is the case it should help to maybe set the physical minimum to 0 and the physical maximum to 1 or 65535. But maybe both values need to be changed to 0 until 65535 where 32767 is the center.

As far as I know the reports for the Wootings are ok and even I don't think it's good to modify a product because others can't read specifications, it's maybe worth to consider to change the report for the classic controller. There are a few games / engines out there which aren't comply with the HID reports and don't support negative values. I know there was a problem with "Kerbal Space Program" due to this.

I will check if the report structure is really the problem here later on... Can take a few days...

Rocky04 commented 3 years ago

I can confirm that the mentioned input system can't handle negative input values from controller.

The problem isn't the error which is thrown because even after I added the format the engine handles the zero value as a stick press and not as the center where the stick isn't pressed as it should be. I tried to change that but I'm not familiar with Unity and so I didn't found the location to add the support for that.

In the end even I think the problem is only related to Unity a lot of other games / engines are bad too. So it's the best if the report structure of the Wootings are changed (logical and physical values) so that the minimal value is 0, the maximal is 65535 (maybe one less for a center in the perfect middle) and center at 32767.

Rocky04 commented 2 years ago

@peterclemenko This issue should be fixed for a while, in the case you have a Lekker Wooting can you please verify it. It should also work for the older Flaretech keyboards as soon as they are merged to the new Wootility v4.