w3c / gamepad

Gamepad
https://w3c.github.io/gamepad/
Other
138 stars 49 forks source link

Axes value stuck at +/- Infinity or zero #150

Closed eugenexlin closed 3 years ago

eugenexlin commented 3 years ago

I have gamepads that are not the standard gamepad, (e.g. rhythm game controllers, custom axis behavior) In windows joystick tester, the axis works fine, goes from left to right and wraps around, but in the browser I am only getting -Infinity, 0, or Infinity.

I would assume what is happening is it is dividing by zero when converting the axis value to a number between 0.0~1.0 I am guessing standard joysticks report what their max axis values are and the gamepad lib just reads it and divides. And if a gamepad is not aware of this field or maybe this gamepad is explicitly and incorrectly returning zero then this problem happens.

Is it possible to just expose the raw axis value + the "reported" max axis value in addition to the current calculated 0.0~1.0 so that in the rare cases that we are stuck with niche hardware reporting max value 0, we have a means of working around it?

Also how can I help get this done

nondebug commented 3 years ago

Are you seeing this on Chrome for Windows? Can you link to product pages for the devices you'd like to see supported?

If it's a HID device you may be able to use WebHID to access the raw input reports, for example here's a page that reads inputs from a DualSense controller: https://nondebug.github.io/dualsense/dualsense-explorer.html

eugenexlin commented 3 years ago

Are you seeing this on Chrome for Windows? Can you link to product pages for the devices you'd like to see supported?

If it's a HID device you may be able to use WebHID to access the raw input reports, for example here's a page that reads inputs from a DualSense controller: https://nondebug.github.io/dualsense/dualsense-explorer.html

Yes, I am using Chrome on windows.

The dualsense page did not find my devices, but that was an interesting suggestion, thanks!

So the controller I am currently testing on is this https://www.dj-dao.com/en/ezmax It actually has complicated firmware which you can change modes so it is optimized for specific different rhythm games. Some modes of this emulate official Bemani rhythm game controllers and Bemani has a history of purposely doing unconventional stuff to be detected as official product in game... haha This producer of 3rd party controllers is likely very custom and scrappy, and I understand if it is difficult to "support" this device!

sharing screenshot of device name for fun image

nondebug commented 3 years ago

I suspect the turntable inputs are implemented in HID as relative inputs, which would explain the wrapping behavior in Windows joystick tester.

In Chrome on Windows, axis inputs are read using HidP_GetScaledUsageValue or HidP_GetUsageValue and then normalized using the physical bounds (for scaled usages) or the logical bounds. I'm guessing there's something wrong with either the physical or logical bounds reported by the device that's causing Chrome to divide by zero during normalization. If you can capture the HID report descriptor from the device then I can take look and see what's going wrong. (If you can't get the raw HID report descriptor, connect to the device in WebHID Explorer and copy the "Device info" text box.)

Currently, the Gamepad API spec only considers joystick-like inputs. For joystick axes, we need to know their minimum and maximum values in order to normalize to the Standard Gamepad's [-1.0,+1.0] axis range. On some platforms, bounds information may not be available for relative inputs. (For instance, on Linux relative axes are delivered as EV_REL input events which have no associated bounds information.)

We also need to recognize when the axis is reporting an "at rest" value so we can detect when the user is not interacting with the axis. For a relative axis with no recentering behavior, the axis could report any value at rest so we need to watch for changes in the input.

I filed https://crbug.com/1213273 to document the ID and axis issues in Chrome.

eugenexlin commented 3 years ago

HID Explorer is nice tool. Here is the device info

productName: 0000000000000000 vendorId: 0x1CCF (7375) productId: 0x8048 (32840) opened: false collections[0] Usage 0001:0004 Input reports: 0x00 Input report 0x00 8 bits (bits 0 to 7) Data,Var,Abs Usage: 0001:0030 (Generic Desktop > X) Logical bounds: -127 to 127 8 bits (bits 8 to 15) Data,Var,Abs Usage: 0001:0031 (Generic Desktop > Y) Logical bounds: -127 to 127 16 values * 1 bits (bits 16 to 31) Data,Var,Abs Usages: 0009:0001 (Button Button 1) to 0009:0010 (Button Button 16) Logical bounds: 0 to 0 8 bits (bits 32 to 39) Cnst,Ary,Abs Logical bounds: 0 to 0

Physical Bounds are just not specified here. Thanks for all the deep info about Gamepad API. I learned a lot!

nondebug commented 3 years ago

Thanks! Actually, it looks like both turntables use Absolute inputs with reasonable Logical bounds. Physical bounds aren't required and usually aren't provided for joystick axes.

I think it's just a bug in Chrome. See https://crbug.com/1213273#c1

I'm closing this issue since there aren't any spec-related changes required to support this device.