Skip to content

Commit

Permalink
gamepad: Add macOS support for "2Axes 8Keys".
Browse files Browse the repository at this point in the history
Add support for a generic gamepad controller that reports as
Vendor=0x0079 and Product=0x0011 on macOS. Support for this
controller first landed in chromiumcodereview.appspot.com/12621002
with a mapping only for Windows. These Vendor/Product IDs appear
to be used for several low-end controller clones. The controller
used when verifying this change was the Vilros Retro Classic USB
Gamepad (Sega Genesis version).

  https://vilros.com/products/vilros-retro-gaming-usb-classic-controller-set-of-5

The left/right D-Pad buttons do not work properly on macOS for
the Vilros controller because it maps four buttons to the same
value. A follow-on CL will address this.

```
0x05, 0x01,        // Usage Page (Generic Desktop Ctrls)
0x09, 0x04,        // Usage (Joystick)
0xA1, 0x01,        // Collection (Application)
0xA1, 0x02,        //   Collection (Logical)
0x75, 0x08,        //     Report Size (8)
0x95, 0x05,        //     Report Count (5)
0x15, 0x00,        //     Logical Minimum (0)
0x26, 0xFF, 0x00,  //     Logical Maximum (255)
0x35, 0x00,        //     Physical Minimum (0)
0x46, 0xFF, 0x00,  //     Physical Maximum (255)
0x09, 0x30,        //     Usage (X)
0x09, 0x30,        //     Usage (X)
0x09, 0x30,        //     Usage (X)
0x09, 0x30,        //     Usage (X)
0x09, 0x31,        //     Usage (Y)
0x81, 0x02,        //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x75, 0x04,        //     Report Size (4)
0x95, 0x01,        //     Report Count (1)
0x25, 0x07,        //     Logical Maximum (7)
0x46, 0x3B, 0x01,  //     Physical Maximum (315)
0x65, 0x14,        //     Unit (System: English Rotation, Length: Centimeter)
0x09, 0x00,        //     Usage (Undefined)
0x81, 0x42,        //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,Null State)
0x65, 0x00,        //     Unit (None)
```

Bug: 1234099
Change-Id: I101fbb25a4ddf38c5d795878d43bf4789fb75a24
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3146150
Reviewed-by: Matt Reynolds <mattreynolds@chromium.org>
Commit-Queue: Chris Mumford <cmumford@google.com>
Cr-Commit-Position: refs/heads/main@{#919420}
  • Loading branch information
cmumford authored and Chromium LUCI CQ committed Sep 8, 2021
1 parent 36a9e75 commit e0f53b2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions device/gamepad/gamepad_standard_mappings_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,28 @@ void MapperDragonRiseGeneric(const Gamepad& input, Gamepad* mapped) {
mapped->axes_length = AXIS_INDEX_COUNT;
}

void Mapper2Axes8Keys(const Gamepad& input, Gamepad* mapped) {
*mapped = input;
mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[2];
mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[0];
mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[1]);
mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[1]);
mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[0]);
mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
AxisPositiveAsButton(input.axes[0]);

// Missing buttons
mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = NullButton();
mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = NullButton();
mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = NullButton();
mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = NullButton();

mapped->buttons_length = BUTTON_INDEX_COUNT - 1;
mapped->axes_length = 0;
}

void MapperOnLiveWireless(const Gamepad& input, Gamepad* mapped) {
*mapped = input;
mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
Expand Down Expand Up @@ -698,6 +720,8 @@ void MapperHoripadSwitch(const Gamepad& input, Gamepad* mapped) {
{GamepadId::kBroadcomProduct8502, MapperSnakebyteIDroidCon},
// DragonRise Generic USB
{GamepadId::kDragonRiseProduct0006, MapperDragonRiseGeneric},
// 2Axes 8Keys Game Pad
{GamepadId::kDragonRiseProduct0011, Mapper2Axes8Keys},
// HORIPAD for Nintendo Switch
{GamepadId::kHoriProduct00c1, MapperHoripadSwitch},
// Xbox 360 Wired
Expand Down

0 comments on commit e0f53b2

Please sign in to comment.