Commit 3290671a authored by Andrew Walbran's avatar Andrew Walbran Committed by Commit Bot

[gamepad] Add mappings for Snakebyte iDroid:con on Windows and Mac OS.

The iDroid:con gamepad has multiple modes. This CL adds mappings for the
two modes where it reports as a gamepad.

Also use axes_used rather than axes_length for distinguishing modes on
Linux.

BUG=1073130

Change-Id: I2741de8097155f36eb7b6f60f69fc766b1462707
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2204184
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773227}
parent 55bf5b20
...@@ -6,25 +6,31 @@ ...@@ -6,25 +6,31 @@
namespace device { namespace device {
GamepadButton AxisToButton(float input) { namespace {
float value = (input + 1.f) / 2.f;
const float kButtonAxisDeadzone = 0.01f;
GamepadButton ValueToButton(float value) {
bool pressed = value > GamepadButton::kDefaultButtonPressedThreshold; bool pressed = value > GamepadButton::kDefaultButtonPressedThreshold;
bool touched = value > 0.0f; bool touched = value > 0.f;
return GamepadButton(pressed, touched, value); return GamepadButton(pressed, touched, value);
} }
} // namespace
GamepadButton AxisToButton(float input) {
float value = (input + 1.f) / 2.f;
return ValueToButton(value);
}
GamepadButton AxisNegativeAsButton(float input) { GamepadButton AxisNegativeAsButton(float input) {
float value = (input < -0.5f) ? 1.f : 0.f; float value = input < -kButtonAxisDeadzone ? -input : 0.f;
bool pressed = value > GamepadButton::kDefaultButtonPressedThreshold; return ValueToButton(value);
bool touched = value > 0.0f;
return GamepadButton(pressed, touched, value);
} }
GamepadButton AxisPositiveAsButton(float input) { GamepadButton AxisPositiveAsButton(float input) {
float value = (input > 0.5f) ? 1.f : 0.f; float value = input > kButtonAxisDeadzone ? input : 0.f;
bool pressed = value > GamepadButton::kDefaultButtonPressedThreshold; return ValueToButton(value);
bool touched = value > 0.0f;
return GamepadButton(pressed, touched, value);
} }
GamepadButton ButtonFromButtonAndAxis(GamepadButton button, float axis) { GamepadButton ButtonFromButtonAndAxis(GamepadButton button, float axis) {
......
...@@ -772,7 +772,18 @@ void MapperSnakebyteIDroidCon(const Gamepad& input, Gamepad* mapped) { ...@@ -772,7 +772,18 @@ void MapperSnakebyteIDroidCon(const Gamepad& input, Gamepad* mapped) {
mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[5]; mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[5];
mapped->buttons[BUTTON_INDEX_META] = NullButton(); mapped->buttons[BUTTON_INDEX_META] = NullButton();
if (input.axes_length == 7) { if ((input.axes_used & 0b1000000) == 0) {
// "Game controller 1" mode: digital triggers.
mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[8];
mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[9];
mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[5]);
mapped->buttons[BUTTON_INDEX_DPAD_DOWN] =
AxisPositiveAsButton(input.axes[5]);
mapped->buttons[BUTTON_INDEX_DPAD_LEFT] =
AxisNegativeAsButton(input.axes[4]);
mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
AxisPositiveAsButton(input.axes[4]);
} else {
// "Game controller 2" mode: analog triggers. // "Game controller 2" mode: analog triggers.
mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] =
AxisPositiveAsButton(input.axes[2]); AxisPositiveAsButton(input.axes[2]);
...@@ -787,18 +798,8 @@ void MapperSnakebyteIDroidCon(const Gamepad& input, Gamepad* mapped) { ...@@ -787,18 +798,8 @@ void MapperSnakebyteIDroidCon(const Gamepad& input, Gamepad* mapped) {
AxisPositiveAsButton(input.axes[5]); AxisPositiveAsButton(input.axes[5]);
mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3]; mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4]; mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
} else {
// "Game controller 1" mode: digital triggers.
mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[8];
mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[9];
mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[5]);
mapped->buttons[BUTTON_INDEX_DPAD_DOWN] =
AxisPositiveAsButton(input.axes[5]);
mapped->buttons[BUTTON_INDEX_DPAD_LEFT] =
AxisNegativeAsButton(input.axes[4]);
mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
AxisPositiveAsButton(input.axes[4]);
} }
mapped->buttons_length = BUTTON_INDEX_COUNT - 1; // no meta mapped->buttons_length = BUTTON_INDEX_COUNT - 1; // no meta
mapped->axes_length = AXIS_INDEX_COUNT; mapped->axes_length = AXIS_INDEX_COUNT;
} }
......
...@@ -587,6 +587,40 @@ void MapperXboxOneBluetooth(const Gamepad& input, Gamepad* mapped) { ...@@ -587,6 +587,40 @@ void MapperXboxOneBluetooth(const Gamepad& input, Gamepad* mapped) {
mapped->axes_length = AXIS_INDEX_COUNT; mapped->axes_length = AXIS_INDEX_COUNT;
} }
void MapperSnakebyteIDroidCon(const Gamepad& input, Gamepad* mapped) {
*mapped = input;
mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10];
mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[2];
mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[5];
mapped->buttons[BUTTON_INDEX_META] = NullButton();
DpadFromAxis(mapped, input.axes[9]);
// The iDroid:con has two different modes. Distinguish them based on which
// axes are used.
if ((input.axes_used & 0b11000) == 0) {
// "Game controller 1" mode: digital triggers.
mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[8];
mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[9];
mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
} else {
// "Game controller 2" mode: analog triggers.
mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] =
AxisPositiveAsButton(input.axes[2]);
mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] =
AxisNegativeAsButton(input.axes[2]);
mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
}
mapped->buttons_length = BUTTON_INDEX_COUNT - 1; // no meta
mapped->axes_length = AXIS_INDEX_COUNT;
}
void MapperHoripadSwitch(const Gamepad& input, Gamepad* mapped) { void MapperHoripadSwitch(const Gamepad& input, Gamepad* mapped) {
*mapped = input; *mapped = input;
mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1]; mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
...@@ -609,6 +643,8 @@ constexpr struct MappingData { ...@@ -609,6 +643,8 @@ constexpr struct MappingData {
} AvailableMappings[] = { } AvailableMappings[] = {
// PowerA Wireless Controller - Nintendo GameCube style // PowerA Wireless Controller - Nintendo GameCube style
{GamepadId::kPowerALicPro, MapperSwitchPro}, {GamepadId::kPowerALicPro, MapperSwitchPro},
// Snakebyte iDroid:con
{GamepadId::kBroadcomProduct8502, MapperSnakebyteIDroidCon},
// DragonRise Generic USB // DragonRise Generic USB
{GamepadId::kDragonRiseProduct0006, MapperDragonRiseGeneric}, {GamepadId::kDragonRiseProduct0006, MapperDragonRiseGeneric},
// HORIPAD for Nintendo Switch // HORIPAD for Nintendo Switch
......
...@@ -420,6 +420,40 @@ void MapperSwitchComposite(const Gamepad& input, Gamepad* mapped) { ...@@ -420,6 +420,40 @@ void MapperSwitchComposite(const Gamepad& input, Gamepad* mapped) {
mapped->axes_length = AXIS_INDEX_COUNT; mapped->axes_length = AXIS_INDEX_COUNT;
} }
void MapperSnakebyteIDroidCon(const Gamepad& input, Gamepad* mapped) {
*mapped = input;
mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10];
mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[2];
mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[5];
mapped->buttons[BUTTON_INDEX_META] = NullButton();
DpadFromAxis(mapped, input.axes[9]);
// The iDroid:con has two different modes. Distinguish them based on which
// axes are used.
if ((input.axes_used & 0b11000) == 0) {
// "Game controller 1" mode: digital triggers.
mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[8];
mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[9];
mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
} else {
// "Game controller 2" mode: analog triggers.
mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] =
AxisPositiveAsButton(input.axes[2]);
mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] =
AxisNegativeAsButton(input.axes[2]);
mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
}
mapped->buttons_length = BUTTON_INDEX_COUNT - 1; // no meta
mapped->axes_length = AXIS_INDEX_COUNT;
}
void MapperHoripadSwitch(const Gamepad& input, Gamepad* mapped) { void MapperHoripadSwitch(const Gamepad& input, Gamepad* mapped) {
*mapped = input; *mapped = input;
mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1]; mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
...@@ -442,6 +476,8 @@ constexpr struct MappingData { ...@@ -442,6 +476,8 @@ constexpr struct MappingData {
} AvailableMappings[] = { } AvailableMappings[] = {
// PowerA Wireless Controller - Nintendo GameCube style // PowerA Wireless Controller - Nintendo GameCube style
{GamepadId::kPowerALicPro, MapperSwitchPro}, {GamepadId::kPowerALicPro, MapperSwitchPro},
// Snakebyte iDroid:con
{GamepadId::kBroadcomProduct8502, MapperSnakebyteIDroidCon},
// 2Axes 8Keys Game Pad // 2Axes 8Keys Game Pad
{GamepadId::kDragonRiseProduct0011, Mapper2Axes8Keys}, {GamepadId::kDragonRiseProduct0011, Mapper2Axes8Keys},
// HORIPAD for Nintendo Switch // HORIPAD for Nintendo Switch
......
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