| Index: content/browser/gamepad/gamepad_standard_mappings_win.cc
|
| diff --git a/content/browser/gamepad/gamepad_standard_mappings_win.cc b/content/browser/gamepad/gamepad_standard_mappings_win.cc
|
| index 07adb9b82ad466131aaad5dbdd011b8f861b5e2d..16f6d90d27c02384f7ff3102208118b78203600f 100644
|
| --- a/content/browser/gamepad/gamepad_standard_mappings_win.cc
|
| +++ b/content/browser/gamepad/gamepad_standard_mappings_win.cc
|
| @@ -10,6 +10,10 @@ namespace content {
|
|
|
| namespace {
|
|
|
| +float AxisToButton(float input) {
|
| + return (input + 1.f) / 2.f;
|
| +}
|
| +
|
| // Maps 0..65535 to -1..1.
|
| float NormalizeDirectInputAxis(long value) {
|
| return (value * 1.f / 32767.5f) - 1.f;
|
| @@ -23,6 +27,25 @@ float AxisPositiveAsButton(long value) {
|
| return (value > 32767) ? 1.f : 0.f;
|
| }
|
|
|
| +void DpadFromAxis(blink::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 MapperDragonRiseGeneric(
|
| const blink::WebGamepad& input,
|
| blink::WebGamepad* mapped) {
|
| @@ -96,16 +119,52 @@ void Mapper2Axes8Keys(
|
| mapped->axesLength = 0;
|
| }
|
|
|
| +void MapperDualshock4(
|
| + const blink::WebGamepad& input,
|
| + blink::WebGamepad* mapped) {
|
| + enum Dualshock4Buttons {
|
| + kTouchpadButton = kNumButtons,
|
| + kNumDualshock4Buttons
|
| + };
|
| +
|
| + *mapped = input;
|
| + mapped->buttons[kButtonPrimary] = input.buttons[1];
|
| + mapped->buttons[kButtonSecondary] = input.buttons[2];
|
| + mapped->buttons[kButtonTertiary] = input.buttons[0];
|
| + mapped->buttons[kButtonQuaternary] = input.buttons[3];
|
| + mapped->buttons[kButtonLeftShoulder] = input.buttons[4];
|
| + mapped->buttons[kButtonRightShoulder] = input.buttons[5];
|
| + mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[3]);
|
| + mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[4]);
|
| + mapped->buttons[kButtonBackSelect] = input.buttons[8];
|
| + mapped->buttons[kButtonStart] = input.buttons[9];
|
| + mapped->buttons[kButtonLeftThumbstick] = input.buttons[10];
|
| + mapped->buttons[kButtonRightThumbstick] = input.buttons[11];
|
| + mapped->buttons[kButtonMeta] = input.buttons[12];
|
| + mapped->buttons[kTouchpadButton] = input.buttons[13];
|
| + mapped->axes[kAxisRightStickY] = input.axes[5];
|
| + DpadFromAxis(mapped, input.axes[9]);
|
| +
|
| + mapped->buttonsLength = kNumDualshock4Buttons;
|
| + mapped->axesLength = kNumAxes;
|
| +}
|
| +
|
| struct MappingData {
|
| const char* const vendor_id;
|
| const char* const product_id;
|
| GamepadStandardMappingFunction function;
|
| } AvailableMappings[] = {
|
| // http://www.linux-usb.org/usb.ids
|
| + { "054c", "05c4", MapperDualshock4 }, // Playstation Dualshock 4
|
| +
|
| + // Untested DirectInput mappings. May not match Raw Input layout.
|
| + // TODO: Test and re-enable
|
| + /*
|
| { "0079", "0006", MapperDragonRiseGeneric }, // DragonRise Generic USB
|
| { "046d", "c216", MapperLogitechDualAction }, // Logitech DualAction
|
| { "046d", "c21a", MapperLogitechPrecision }, // Logitech Precision
|
| { "12bd", "d012", Mapper2Axes8Keys }, // 2Axes 8Keys Game Pad
|
| + */
|
| };
|
|
|
| } // namespace
|
|
|