Closed Bug 1027207 Opened 10 years ago Closed 4 years ago

Firefox reports different PS3 controller button and axis codes than Chrome and the "Standard Gamepad"

Categories

(Core :: DOM: Device Interfaces, defect, P2)

32 Branch
defect

Tracking

()

RESOLVED FIXED
mozilla78
Tracking Status
firefox78 --- fixed

People

(Reporter: samu.agarwal, Assigned: daoshengmu)

References

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:30.0) Gecko/20100101 Firefox/30.0 (Beta/Release)
Build ID: 20140605174243

Steps to reproduce:

Step 1: Open http://www.html5rocks.com/en/tutorials/doodles/gamepad/gamepad-tester/tester.html to test gamepad.
Step 2: Press buttons on gamepad till it conects.
Step 3: Notice that your actions aren't accuratly represented on the screen.



Actual results:

The buttons on the gamepad were mapped wrongly.


Expected results:

The buttons pressed IRL should have been the same ones on screen. For example when I press the "X" on the gamepad, I should see button number 1 pressed.
Note: This was also tested on aurora 32.0a2 (2014-06-18) same computer
We don't currently have any code in place to map buttons to the standard layout, and platform APIs unfortunately don't expose enough information to do this. I have a patch in bug 855364 that adds a table of known controllers which will let us fix this for common controllers.
Depends on: 855364
Component: Untriaged → DOM
Product: Firefox → Core
Component: DOM → DOM: Device Interfaces
Priority: -- → P5

Testing my PS3 DualShock controller with https://html5gamepad.com/, I see that every browser+OS combination of Firefox, Chrome, Windows, and macOS reports different button and axis codes. None of them match the standard's "Standard Gamepad" mapping:

https://w3c.github.io/gamepad/#remapping

Should Firefox match the "Standard Gamepad" mapping or whatever Chrome reports on the same OS? If Chrome went out of its way recognize and remap many different controllers, why wouldn't they return the codes of the "Standard Gamepad"? And why different codes on Windows and macOS?

I made a spreadsheet comparing the html5gamepad.com results for my PS3 controller:

https://docs.google.com/spreadsheets/d/1kidq0YkmLUsUG281dJHNE3Km-tzzmCfohikj6SE7zJI/edit#gid=0

Daosheng says we probably just need to copy Chromium's PS3 remapping from here:

https://source.chromium.org/chromium/chromium/src/+/master:device/gamepad/gamepad_standard_mappings_linux.cc;l=779-780;drc=eef4e6c1a0af148b14aff31488687784f12ef037?originalUrl=https:%2F%2Fcs.chromium.org%2F

https://source.chromium.org/chromium/chromium/src/+/master:device/gamepad/gamepad_standard_mappings_linux.cc;l=185-207;drc=da6ef73266f6110abc5e788457f0e8f9257dd5b6?originalUrl=https:%2F%2Fcs.chromium.org%2F

And add to Gecko's remappings here:

https://searchfox.org/mozilla-central/rev/97cb0a90bd053de87cd1ab7646d5565809166bb1/dom/gamepad/GamepadRemapping.cpp#1601-1603

OS: macOS → All
Hardware: x86 → All
Summary: The mappings of the PS3 gamepad are all wrong(Apart from the Analog sticks) → Firefox reports different PS3 controller button and axis codes than Chrome and the "Standard Gamepad"
Priority: P5 → P2
Assignee: nobody → dmu

Daosheng says we probably just need to copy Chromium's PS3 remapping from here

The Linux PS3 mapping can't be copied directly because the hid-sony kernel module on Linux applies some device-specific fixes that aren't present on Mac. Many buttons on the PS3 controller are pressure-sensitive and report both digital and analog values. However, the report descriptor doesn't have suitable usage IDs for the button pressure fields so this data isn't picked up by Chrome's generic HID gamepad logic. Relevant portion of the report descriptor (39 bytes with usage Generic Desktop / Pointer):

0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x75, 0x08, // Report Size (8)
0x95, 0x27, // Report Count (39)
0x09, 0x01, // Usage (Pointer)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)

This field contains button pressure data, among other things:

byte 4: D-pad up
byte 5: D-pad right
byte 6: D-pad down
byte 7: D-pad left
byte 8: L2
byte 9: R2
byte 10: L1
byte 11: R1
byte 12: Triangle button
byte 13: Circle button
byte 14: Cross button
byte 15: Square button

On Linux, hid-sony pulls out the L2/R2 analog values (bytes 8 and 9) and exposes them as axes Generic Desktop / Z and Generic Desktop / Rz:

https://github.com/torvalds/linux/blob/master/drivers/hid/hid-sony.c#L774

However, there's no logic to expose the other analog button inputs so this data isn't accessible through evdev.

Supporting analog L2/R2 on Mac would require similar device-specific logic to read the analog button data. Ideally we would support analog inputs for all analog buttons, not just L2/R2.

(In reply to Matt Reynolds from comment #7)

Daosheng says we probably just need to copy Chromium's PS3 remapping from here

The Linux PS3 mapping can't be copied directly because the hid-sony kernel module on Linux applies some device-specific fixes that aren't present on Mac. Many buttons on the PS3 controller are pressure-sensitive and report both digital and analog values. However, the report descriptor doesn't have suitable usage IDs for the button pressure fields so this data isn't picked up by Chrome's generic HID gamepad logic. Relevant portion of the report descriptor (39 bytes with usage Generic Desktop / Pointer):

Thanks for sharing this. My fix is only for PS3 Windows and Mac OS. We didn't put resource on Gamepad Linux recently.

Pushed by dmu@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/8df883bbbb5c
Dealing Playstation3 controller btn/axis remapping. r=baku
Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla78

Any particular reason it’s referred to in this patch as Playstation3Controller and not Dualshock3 to match the Dualshock4 entry?

(In reply to Robin Whittleton from comment #11)

Any particular reason it’s referred to in this patch as Playstation3Controller and not Dualshock3 to match the Dualshock4 entry?

That is a good question. I was struggle with if I should use DS3 instead of PS3 for the naming of my class. Some people use sixaxis (in Linux) and some people use DS3. I guess their product id probably are the same, but I don't have a controller on my hand, so I can't tell. Therefore, I just refer the name with the product id 0x0268 from USB HID [1]. We can make a change once someone gives me an evidence that those two product id are the same. My personal preference is using DS3.

[1] https://www.the-sz.com/products/usbid/index.php?v=0x054C

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: