| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/gamepad/gamepad_standard_mappings.h" | 5 #include "content/browser/gamepad/gamepad_standard_mappings.h" |
| 6 | 6 |
| 7 namespace content { | 7 namespace content { |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 void MapperLogitechDualAction( | 11 void MapperLogitechDualAction(const blink::WebGamepad& input, |
| 12 const blink::WebGamepad& input, | 12 blink::WebGamepad* mapped) { |
| 13 blink::WebGamepad* mapped) { | |
| 14 *mapped = input; | 13 *mapped = input; |
| 15 mapped->buttons[kButtonPrimary] = input.buttons[1]; | 14 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1]; |
| 16 mapped->buttons[kButtonSecondary] = input.buttons[2]; | 15 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[2]; |
| 17 mapped->buttons[kButtonTertiary] = input.buttons[0]; | 16 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[0]; |
| 18 mapped->axes[kAxisRightStickY] = input.axes[5]; | 17 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5]; |
| 19 DpadFromAxis(mapped, input.axes[9]); | 18 DpadFromAxis(mapped, input.axes[9]); |
| 20 | 19 |
| 21 mapped->buttonsLength = kNumButtons; | 20 mapped->buttonsLength = BUTTON_INDEX_COUNT; |
| 22 mapped->axesLength = kNumAxes; | 21 mapped->axesLength = AXIS_INDEX_COUNT; |
| 23 } | 22 } |
| 24 | 23 |
| 25 void Mapper2Axes8Keys( | 24 void Mapper2Axes8Keys(const blink::WebGamepad& input, |
| 26 const blink::WebGamepad& input, | 25 blink::WebGamepad* mapped) { |
| 27 blink::WebGamepad* mapped) { | |
| 28 *mapped = input; | 26 *mapped = input; |
| 29 mapped->buttons[kButtonPrimary] = input.buttons[2]; | 27 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[2]; |
| 30 mapped->buttons[kButtonSecondary] = input.buttons[1]; | 28 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1]; |
| 31 mapped->buttons[kButtonTertiary] = input.buttons[3]; | 29 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3]; |
| 32 mapped->buttons[kButtonQuaternary] = input.buttons[0]; | 30 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[0]; |
| 33 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[1]); | 31 mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[1]); |
| 34 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[1]); | 32 mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[1]); |
| 35 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[0]); | 33 mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[0]); |
| 36 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[0]); | 34 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] = |
| 35 AxisPositiveAsButton(input.axes[0]); |
| 37 | 36 |
| 38 // Missing buttons | 37 // Missing buttons |
| 39 mapped->buttons[kButtonLeftTrigger] = blink::WebGamepadButton(); | 38 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = blink::WebGamepadButton(); |
| 40 mapped->buttons[kButtonRightTrigger] = blink::WebGamepadButton(); | 39 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = blink::WebGamepadButton(); |
| 41 mapped->buttons[kButtonLeftThumbstick] = blink::WebGamepadButton(); | 40 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = blink::WebGamepadButton(); |
| 42 mapped->buttons[kButtonRightThumbstick] = blink::WebGamepadButton(); | 41 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = blink::WebGamepadButton(); |
| 43 mapped->buttons[kButtonMeta] = blink::WebGamepadButton(); | 42 mapped->buttons[BUTTON_INDEX_META] = blink::WebGamepadButton(); |
| 44 | 43 |
| 45 mapped->buttonsLength = kNumButtons - 1; | 44 mapped->buttonsLength = BUTTON_INDEX_COUNT - 1; |
| 46 mapped->axesLength = 0; | 45 mapped->axesLength = 0; |
| 47 } | 46 } |
| 48 | 47 |
| 49 void MapperDualshock4( | 48 void MapperDualshock4(const blink::WebGamepad& input, |
| 50 const blink::WebGamepad& input, | 49 blink::WebGamepad* mapped) { |
| 51 blink::WebGamepad* mapped) { | |
| 52 enum Dualshock4Buttons { | 50 enum Dualshock4Buttons { |
| 53 kTouchpadButton = kNumButtons, | 51 DUALSHOCK_BUTTON_TOUCHPAD = BUTTON_INDEX_COUNT, |
| 54 kNumDualshock4Buttons | 52 DUALSHOCK_BUTTON_COUNT |
| 55 }; | 53 }; |
| 56 | 54 |
| 57 *mapped = input; | 55 *mapped = input; |
| 58 mapped->buttons[kButtonPrimary] = input.buttons[1]; | 56 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1]; |
| 59 mapped->buttons[kButtonSecondary] = input.buttons[2]; | 57 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[2]; |
| 60 mapped->buttons[kButtonTertiary] = input.buttons[0]; | 58 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[0]; |
| 61 mapped->buttons[kButtonQuaternary] = input.buttons[3]; | 59 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[3]; |
| 62 mapped->buttons[kButtonLeftShoulder] = input.buttons[4]; | 60 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[4]; |
| 63 mapped->buttons[kButtonRightShoulder] = input.buttons[5]; | 61 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[5]; |
| 64 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[3]); | 62 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]); |
| 65 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[4]); | 63 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]); |
| 66 mapped->buttons[kButtonBackSelect] = input.buttons[8]; | 64 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[8]; |
| 67 mapped->buttons[kButtonStart] = input.buttons[9]; | 65 mapped->buttons[BUTTON_INDEX_START] = input.buttons[9]; |
| 68 mapped->buttons[kButtonLeftThumbstick] = input.buttons[10]; | 66 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[10]; |
| 69 mapped->buttons[kButtonRightThumbstick] = input.buttons[11]; | 67 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[11]; |
| 70 mapped->buttons[kButtonMeta] = input.buttons[12]; | 68 mapped->buttons[BUTTON_INDEX_META] = input.buttons[12]; |
| 71 mapped->buttons[kTouchpadButton] = input.buttons[13]; | 69 mapped->buttons[DUALSHOCK_BUTTON_TOUCHPAD] = input.buttons[13]; |
| 72 mapped->axes[kAxisRightStickY] = input.axes[5]; | 70 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5]; |
| 73 DpadFromAxis(mapped, input.axes[9]); | 71 DpadFromAxis(mapped, input.axes[9]); |
| 74 | 72 |
| 75 mapped->buttonsLength = kNumDualshock4Buttons; | 73 mapped->buttonsLength = DUALSHOCK_BUTTON_COUNT; |
| 76 mapped->axesLength = kNumAxes; | 74 mapped->axesLength = AXIS_INDEX_COUNT; |
| 77 } | 75 } |
| 78 | 76 |
| 79 void MapperOnLiveWireless( | 77 void MapperOnLiveWireless(const blink::WebGamepad& input, |
| 80 const blink::WebGamepad& input, | 78 blink::WebGamepad* mapped) { |
| 81 blink::WebGamepad* mapped) { | |
| 82 *mapped = input; | 79 *mapped = input; |
| 83 mapped->buttons[kButtonPrimary] = input.buttons[0]; | 80 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0]; |
| 84 mapped->buttons[kButtonSecondary] = input.buttons[1]; | 81 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1]; |
| 85 mapped->buttons[kButtonTertiary] = input.buttons[3]; | 82 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3]; |
| 86 mapped->buttons[kButtonQuaternary] = input.buttons[4]; | 83 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4]; |
| 87 mapped->buttons[kButtonLeftShoulder] = input.buttons[6]; | 84 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6]; |
| 88 mapped->buttons[kButtonRightShoulder] = input.buttons[7]; | 85 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7]; |
| 89 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[2]); | 86 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]); |
| 90 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[5]); | 87 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]); |
| 91 mapped->buttons[kButtonBackSelect] = input.buttons[10]; | 88 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10]; |
| 92 mapped->buttons[kButtonStart] = input.buttons[11]; | 89 mapped->buttons[BUTTON_INDEX_START] = input.buttons[11]; |
| 93 mapped->buttons[kButtonLeftThumbstick] = input.buttons[13]; | 90 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13]; |
| 94 mapped->buttons[kButtonRightThumbstick] = input.buttons[14]; | 91 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14]; |
| 95 mapped->buttons[kButtonMeta] = input.buttons[12]; | 92 mapped->buttons[BUTTON_INDEX_META] = input.buttons[12]; |
| 96 mapped->axes[kAxisRightStickX] = input.axes[3]; | 93 mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3]; |
| 97 mapped->axes[kAxisRightStickY] = input.axes[4]; | 94 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4]; |
| 98 DpadFromAxis(mapped, input.axes[9]); | 95 DpadFromAxis(mapped, input.axes[9]); |
| 99 | 96 |
| 100 mapped->buttonsLength = kNumButtons; | 97 mapped->buttonsLength = BUTTON_INDEX_COUNT; |
| 101 mapped->axesLength = kNumAxes; | 98 mapped->axesLength = AXIS_INDEX_COUNT; |
| 102 } | 99 } |
| 103 | 100 |
| 104 void MapperADT1( | 101 void MapperADT1(const blink::WebGamepad& input, blink::WebGamepad* mapped) { |
| 105 const blink::WebGamepad& input, | |
| 106 blink::WebGamepad* mapped) { | |
| 107 *mapped = input; | 102 *mapped = input; |
| 108 mapped->buttons[kButtonPrimary] = input.buttons[0]; | 103 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0]; |
| 109 mapped->buttons[kButtonSecondary] = input.buttons[1]; | 104 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1]; |
| 110 mapped->buttons[kButtonTertiary] = input.buttons[3]; | 105 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3]; |
| 111 mapped->buttons[kButtonQuaternary] = input.buttons[4]; | 106 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4]; |
| 112 mapped->buttons[kButtonLeftShoulder] = input.buttons[6]; | 107 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6]; |
| 113 mapped->buttons[kButtonRightShoulder] = input.buttons[7]; | 108 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7]; |
| 114 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[4]); | 109 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[4]); |
| 115 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[3]); | 110 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[3]); |
| 116 mapped->buttons[kButtonBackSelect] = NullButton(); | 111 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = NullButton(); |
| 117 mapped->buttons[kButtonStart] = NullButton(); | 112 mapped->buttons[BUTTON_INDEX_START] = NullButton(); |
| 118 mapped->buttons[kButtonLeftThumbstick] = input.buttons[13]; | 113 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13]; |
| 119 mapped->buttons[kButtonRightThumbstick] = input.buttons[14]; | 114 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14]; |
| 120 mapped->buttons[kButtonMeta] = input.buttons[12]; | 115 mapped->buttons[BUTTON_INDEX_META] = input.buttons[12]; |
| 121 mapped->axes[kAxisRightStickY] = input.axes[5]; | 116 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5]; |
| 122 DpadFromAxis(mapped, input.axes[9]); | 117 DpadFromAxis(mapped, input.axes[9]); |
| 123 | 118 |
| 124 mapped->buttonsLength = kNumButtons; | 119 mapped->buttonsLength = BUTTON_INDEX_COUNT; |
| 125 mapped->axesLength = kNumAxes; | 120 mapped->axesLength = AXIS_INDEX_COUNT; |
| 126 } | 121 } |
| 127 | 122 |
| 128 struct MappingData { | 123 struct MappingData { |
| 129 const char* const vendor_id; | 124 const char* const vendor_id; |
| 130 const char* const product_id; | 125 const char* const product_id; |
| 131 GamepadStandardMappingFunction function; | 126 GamepadStandardMappingFunction function; |
| 132 } AvailableMappings[] = { | 127 } AvailableMappings[] = { |
| 133 // http://www.linux-usb.org/usb.ids | 128 // http://www.linux-usb.org/usb.ids |
| 134 { "046d", "c216", MapperLogitechDualAction }, // Logitech DualAction | 129 {"046d", "c216", MapperLogitechDualAction}, // Logitech DualAction |
| 135 { "0079", "0011", Mapper2Axes8Keys }, // 2Axes 8Keys Game Pad | 130 {"0079", "0011", Mapper2Axes8Keys}, // 2Axes 8Keys Game Pad |
| 136 { "054c", "05c4", MapperDualshock4 }, // Playstation Dualshock 4 | 131 {"054c", "05c4", MapperDualshock4}, // Playstation Dualshock 4 |
| 137 { "2378", "1008", MapperOnLiveWireless }, // OnLive Controller (Bluetooth) | 132 {"2378", "1008", MapperOnLiveWireless}, // OnLive Controller (Bluetooth) |
| 138 { "2378", "100a", MapperOnLiveWireless }, // OnLive Controller (Wired) | 133 {"2378", "100a", MapperOnLiveWireless}, // OnLive Controller (Wired) |
| 139 { "18d1", "2c40", MapperADT1 }, // ADT-1 Controller | 134 {"18d1", "2c40", MapperADT1}, // ADT-1 Controller |
| 140 }; | 135 }; |
| 141 | 136 |
| 142 } // namespace | 137 } // namespace |
| 143 | 138 |
| 144 GamepadStandardMappingFunction GetGamepadStandardMappingFunction( | 139 GamepadStandardMappingFunction GetGamepadStandardMappingFunction( |
| 145 const base::StringPiece& vendor_id, | 140 const base::StringPiece& vendor_id, |
| 146 const base::StringPiece& product_id) { | 141 const base::StringPiece& product_id) { |
| 147 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { | 142 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { |
| 148 MappingData& item = AvailableMappings[i]; | 143 MappingData& item = AvailableMappings[i]; |
| 149 if (vendor_id == item.vendor_id && product_id == item.product_id) | 144 if (vendor_id == item.vendor_id && product_id == item.product_id) |
| 150 return item.function; | 145 return item.function; |
| 151 } | 146 } |
| 152 return NULL; | 147 return NULL; |
| 153 } | 148 } |
| 154 | 149 |
| 155 } // namespace content | 150 } // namespace content |
| OLD | NEW |