Commit 59c19899 authored by scottmg@chromium.org's avatar scottmg@chromium.org

Add gamepad mapping for XFXforce XGEAR PS2 Controller on OS X

BUG=140828


Review URL: https://chromiumcodereview.appspot.com/10827264

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150963 0039d316-1c4b-4281-b951-d872f2087c98
parent d1917365
......@@ -14,6 +14,25 @@ float AxisToButton(float input) {
return (input + 1.f) / 2.f;
}
void DpadFromAxis(WebKit::WebGamepad* mapped, float dir) {
// Dpad is mapped as a direction on one axis, where -1 is up and it
// increases clockwise to 1, which is up + left. It's set to a large (> 1.f)
// number when nothing is depressed, except on start up, sometimes it's 0.0
// for no data, rather than the large number.
if (dir == 0.0f) {
mapped->buttons[kButtonDpadUp] = 0.f;
mapped->buttons[kButtonDpadDown] = 0.f;
mapped->buttons[kButtonDpadLeft] = 0.f;
mapped->buttons[kButtonDpadRight] = 0.f;
} else {
mapped->buttons[kButtonDpadUp] = (dir >= -1.f && dir < -0.7f) ||
(dir >= .95f && dir <= 1.f);
mapped->buttons[kButtonDpadRight] = dir >= -.75f && dir < -.1f;
mapped->buttons[kButtonDpadDown] = dir >= -.2f && dir < .45f;
mapped->buttons[kButtonDpadLeft] = dir >= .4f && dir <= 1.f;
}
}
void MapperXbox360Gamepad(
const WebKit::WebGamepad& input,
WebKit::WebGamepad* mapped) {
......@@ -70,25 +89,7 @@ void MapperDirectInputStyle(
mapped->buttons[kButtonSecondary] = input.buttons[2];
mapped->buttons[kButtonTertiary] = input.buttons[0];
mapped->axes[kAxisRightStickY] = input.axes[5];
// Dpad is mapped as a direction on one axis, where -1 is up and it
// increases clockwise to 1, which is up + left. It's set to a large (> 1.f)
// number when nothing is depressed, except on start up, sometimes it's 0.0
// for no data, rather than the large number.
float dir = input.axes[9];
if (dir == 0.0f) {
mapped->buttons[kButtonDpadUp] = 0.f;
mapped->buttons[kButtonDpadDown] = 0.f;
mapped->buttons[kButtonDpadLeft] = 0.f;
mapped->buttons[kButtonDpadRight] = 0.f;
} else {
mapped->buttons[kButtonDpadUp] = (dir >= -1.f && dir < -0.7f) ||
(dir >= .95f && dir <= 1.f);
mapped->buttons[kButtonDpadRight] = dir >= -.75f && dir < -.1f;
mapped->buttons[kButtonDpadDown] = dir >= -.2f && dir < .45f;
mapped->buttons[kButtonDpadLeft] = dir >= .4f && dir <= 1.f;
}
DpadFromAxis(mapped, input.axes[9]);
mapped->buttonsLength = kNumButtons - 1; /* no meta */
mapped->axesLength = kNumAxes;
}
......@@ -133,6 +134,24 @@ void MapperMacallyIShock(
mapped->axesLength = kNumAxes;
}
void MapperXGEAR(
const WebKit::WebGamepad& input,
WebKit::WebGamepad* mapped) {
*mapped = input;
mapped->buttons[kButtonPrimary] = input.buttons[2];
mapped->buttons[kButtonTertiary] = input.buttons[3];
mapped->buttons[kButtonQuaternary] = input.buttons[0];
mapped->buttons[kButtonLeftShoulder] = input.buttons[6];
mapped->buttons[kButtonRightShoulder] = input.buttons[7];
mapped->buttons[kButtonLeftTrigger] = input.buttons[4];
mapped->buttons[kButtonRightTrigger] = input.buttons[5];
DpadFromAxis(mapped, input.axes[9]);
mapped->axes[kAxisRightStickX] = input.axes[5];
mapped->axes[kAxisRightStickY] = input.axes[2];
mapped->buttonsLength = kNumButtons - 1; /* no meta */
mapped->axesLength = kNumAxes;
}
struct MappingData {
const char* const vendor_id;
const char* const product_id;
......@@ -145,6 +164,7 @@ struct MappingData {
{ "046d", "c218", MapperDirectInputStyle }, // Logitech F510, D mode
{ "046d", "c219", MapperDirectInputStyle }, // Logitech F710, D mode
{ "054c", "0268", MapperPlaystationSixAxis }, // Playstation SIXAXIS
{ "0e8f", "0003", MapperXGEAR }, // XFXforce XGEAR PS2 Controller
{ "2222", "0060", MapperDirectInputStyle }, // Macally iShockX, analog mode
{ "2222", "4010", MapperMacallyIShock }, // Macally iShock
};
......
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