Commit eef4e6c1 authored by Jose Torreguitar's avatar Jose Torreguitar Committed by Commit Bot

Use proper mappings for all Xbox Elite controllers

The modern Xbox Elite Series 2 controller firmware reports on less axes
than the previous firmware. However, the only way to distinguish between
firmware versions is to check the length of the axes reported.

This change updates the mapping function to work for all firmware
versions by checking the axes length. On the older firmware, the axes
are shifted by one after axis 3 because axes 4 and 9 are redundancies.

BUG=1052543
TEST=Testing this requires two Xbox elite series 2 controllers, one with
     modern firmware and one with release firmware. When using them on
     production code users will notice that on pressing the DPAD on
     modern firmware either the triggers or the opposing dpad axis is
     pressed.

Change-Id: Ie51fd897a14180d664463d196b2fe744338c61c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2057624Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Commit-Queue: José Torreguitar <jtguitar@google.com>
Cr-Commit-Position: refs/heads/master@{#742235}
parent a16fcedb
...@@ -129,8 +129,6 @@ void MapperXboxElite2Bluetooth(const Gamepad& input, Gamepad* mapped) { ...@@ -129,8 +129,6 @@ void MapperXboxElite2Bluetooth(const Gamepad& input, Gamepad* mapped) {
mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4]; mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6]; mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7]; mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[6]);
mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]);
// On some systems, the View (back/select) button is interpreted as a media // On some systems, the View (back/select) button is interpreted as a media
// key instead of a gamepad button. When it behaves as a media key, pressing // key instead of a gamepad button. When it behaves as a media key, pressing
// the button causes a back-navigation in the browser. The below mapping is // the button causes a back-navigation in the browser. The below mapping is
...@@ -139,11 +137,25 @@ void MapperXboxElite2Bluetooth(const Gamepad& input, Gamepad* mapped) { ...@@ -139,11 +137,25 @@ void MapperXboxElite2Bluetooth(const Gamepad& input, Gamepad* mapped) {
mapped->buttons[BUTTON_INDEX_START] = input.buttons[11]; mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13]; mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14]; mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[8]); // The modern Xbox Elite Series 2 firmware reports less axes than prior
mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[8]); // versions. However, the only way to distinguish between the versions is
mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[7]); // to check the length of the axes.
//
// In the older firmware, axes 4 and 9 are redundancies, so after axis 3
// the mappings are shifted by 1
int axis_shift = mapped->axes_length > 8 ? 1 : 0;
mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] =
AxisToButton(input.axes[5 + axis_shift]);
mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] =
AxisToButton(input.axes[4 + axis_shift]);
mapped->buttons[BUTTON_INDEX_DPAD_UP] =
AxisNegativeAsButton(input.axes[7 + axis_shift]);
mapped->buttons[BUTTON_INDEX_DPAD_DOWN] =
AxisPositiveAsButton(input.axes[7 + axis_shift]);
mapped->buttons[BUTTON_INDEX_DPAD_LEFT] =
AxisNegativeAsButton(input.axes[6 + axis_shift]);
mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] = mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
AxisPositiveAsButton(input.axes[7]); AxisPositiveAsButton(input.axes[6 + axis_shift]);
// The Xbox (meta) button does not generate an input event for this device. // The Xbox (meta) button does not generate an input event for this device.
mapped->buttons_length = BUTTON_INDEX_COUNT - 1; mapped->buttons_length = BUTTON_INDEX_COUNT - 1;
......
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