Commit 2ec0b0c0 authored by aicommander's avatar aicommander Committed by Commit bot

Gamepad: Improve gamepad mapping code and unknown gamepad heuristics

This CL modifies the GamepadMappings class to use subclasses
for mappings rather than static methods. The advantage is that
the unknown gamepad mapping can keep state around that allows
it to create heuristic mappings at GamepadDevice constrution
time. This allows stable mappings that don't depend on input
to decide correctly. This also means we aren't doing string
parsing on each gamepad event anymore.

With this change, Moga Pro, Nexus Player (ASUS) Gamepad, and Razer
Serval controllers are working correctly without explict mappings.

Before the change, the D-Pad on Moga, Serval, and ASUS Gamepad were
non-functional. The triggers on the Moga didn't work at all, and the
Serval and ASUS Gamepad's triggers were swapped with the shoulder
buttons.

TEST=http://html5gamepad.com/
BUG=615656

Review-Url: https://codereview.chromium.org/2071223002
Cr-Commit-Position: refs/heads/master@{#419372}
parent 3c3a4409
...@@ -35,8 +35,6 @@ class GamepadDevice { ...@@ -35,8 +35,6 @@ class GamepadDevice {
private int mDeviceIndex; private int mDeviceIndex;
// Last time the data for this gamepad was updated. // Last time the data for this gamepad was updated.
private long mTimestamp; private long mTimestamp;
// If this gamepad is mapped to standard gamepad?
private boolean mIsStandardGamepad;
// Array of values for all axes of the gamepad. // Array of values for all axes of the gamepad.
// All axis values must be linearly normalized to the range [-1.0 .. 1.0]. // All axis values must be linearly normalized to the range [-1.0 .. 1.0].
...@@ -59,6 +57,9 @@ class GamepadDevice { ...@@ -59,6 +57,9 @@ class GamepadDevice {
// Array of axes ids. // Array of axes ids.
private int[] mAxes; private int[] mAxes;
// Mappings to canonical gamepad
private GamepadMappings mMappings;
GamepadDevice(int index, InputDevice inputDevice) { GamepadDevice(int index, InputDevice inputDevice) {
mDeviceIndex = index; mDeviceIndex = index;
mDeviceId = inputDevice.getId(); mDeviceId = inputDevice.getId();
...@@ -75,14 +76,14 @@ class GamepadDevice { ...@@ -75,14 +76,14 @@ class GamepadDevice {
mAxes[i++] = axis; mAxes[i++] = axis;
} }
} }
mMappings = GamepadMappings.getMappings(mDeviceName, mAxes);
} }
/** /**
* Updates the axes and buttons maping of a gamepad device to a standard gamepad format. * Updates the axes and buttons maping of a gamepad device to a standard gamepad format.
*/ */
public void updateButtonsAndAxesMapping() { public void updateButtonsAndAxesMapping() {
mIsStandardGamepad = GamepadMappings.mapToStandardGamepad( mMappings.mapToStandardGamepad(mAxisValues, mButtonsValues, mRawAxes, mRawButtons);
mAxisValues, mButtonsValues, mRawAxes, mRawButtons, mDeviceName);
} }
/** /**
...@@ -96,7 +97,7 @@ class GamepadDevice { ...@@ -96,7 +97,7 @@ class GamepadDevice {
* @return Mapping status of the gamepad device. * @return Mapping status of the gamepad device.
*/ */
public boolean isStandardGamepad() { public boolean isStandardGamepad() {
return mIsStandardGamepad; return mMappings.isStandard();
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment