| 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 #include "content/common/gamepad_hardware_buffer.h" | 7 #include "content/common/gamepad_hardware_buffer.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 float AxisToButton(float input) { | 13 float AxisToButton(float input) { |
| 14 return (input + 1.f) / 2.f; | 14 return (input + 1.f) / 2.f; |
| 15 } | 15 } |
| 16 | 16 |
| 17 float AxisNegativeAsButton(float input) { | 17 float AxisNegativeAsButton(float input) { |
| 18 return (input < -0.5f) ? 1.f : 0.f; | 18 return (input < -0.5f) ? 1.f : 0.f; |
| 19 } | 19 } |
| 20 | 20 |
| 21 float AxisPositiveAsButton(float input) { | 21 float AxisPositiveAsButton(float input) { |
| 22 return (input > 0.5f) ? 1.f : 0.f; | 22 return (input > 0.5f) ? 1.f : 0.f; |
| 23 } | 23 } |
| 24 | 24 |
| 25 void MapperXInputStyleGamepad( | 25 void MapperXInputStyleGamepad( |
| 26 const WebKit::WebGamepad& input, | 26 const blink::WebGamepad& input, |
| 27 WebKit::WebGamepad* mapped) { | 27 blink::WebGamepad* mapped) { |
| 28 *mapped = input; | 28 *mapped = input; |
| 29 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[2]); | 29 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[2]); |
| 30 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[5]); | 30 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[5]); |
| 31 mapped->buttons[kButtonBackSelect] = input.buttons[6]; | 31 mapped->buttons[kButtonBackSelect] = input.buttons[6]; |
| 32 mapped->buttons[kButtonStart] = input.buttons[7]; | 32 mapped->buttons[kButtonStart] = input.buttons[7]; |
| 33 mapped->buttons[kButtonLeftThumbstick] = input.buttons[9]; | 33 mapped->buttons[kButtonLeftThumbstick] = input.buttons[9]; |
| 34 mapped->buttons[kButtonRightThumbstick] = input.buttons[10]; | 34 mapped->buttons[kButtonRightThumbstick] = input.buttons[10]; |
| 35 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[7]); | 35 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[7]); |
| 36 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[7]); | 36 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[7]); |
| 37 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[6]); | 37 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[6]); |
| 38 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[6]); | 38 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[6]); |
| 39 mapped->buttons[kButtonMeta] = input.buttons[8]; | 39 mapped->buttons[kButtonMeta] = input.buttons[8]; |
| 40 mapped->axes[kAxisRightStickX] = input.axes[3]; | 40 mapped->axes[kAxisRightStickX] = input.axes[3]; |
| 41 mapped->axes[kAxisRightStickY] = input.axes[4]; | 41 mapped->axes[kAxisRightStickY] = input.axes[4]; |
| 42 mapped->buttonsLength = kNumButtons; | 42 mapped->buttonsLength = kNumButtons; |
| 43 mapped->axesLength = kNumAxes; | 43 mapped->axesLength = kNumAxes; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void MapperLakeviewResearch( | 46 void MapperLakeviewResearch( |
| 47 const WebKit::WebGamepad& input, | 47 const blink::WebGamepad& input, |
| 48 WebKit::WebGamepad* mapped) { | 48 blink::WebGamepad* mapped) { |
| 49 *mapped = input; | 49 *mapped = input; |
| 50 mapped->buttons[kButtonPrimary] = input.buttons[2]; | 50 mapped->buttons[kButtonPrimary] = input.buttons[2]; |
| 51 mapped->buttons[kButtonTertiary] = input.buttons[3]; | 51 mapped->buttons[kButtonTertiary] = input.buttons[3]; |
| 52 mapped->buttons[kButtonQuaternary] = input.buttons[0]; | 52 mapped->buttons[kButtonQuaternary] = input.buttons[0]; |
| 53 mapped->buttons[kButtonLeftShoulder] = input.buttons[6]; | 53 mapped->buttons[kButtonLeftShoulder] = input.buttons[6]; |
| 54 mapped->buttons[kButtonRightShoulder] = input.buttons[7]; | 54 mapped->buttons[kButtonRightShoulder] = input.buttons[7]; |
| 55 mapped->buttons[kButtonLeftTrigger] = input.buttons[4]; | 55 mapped->buttons[kButtonLeftTrigger] = input.buttons[4]; |
| 56 mapped->buttons[kButtonRightTrigger] = input.buttons[5]; | 56 mapped->buttons[kButtonRightTrigger] = input.buttons[5]; |
| 57 mapped->buttons[kButtonBackSelect] = input.buttons[9]; | 57 mapped->buttons[kButtonBackSelect] = input.buttons[9]; |
| 58 mapped->buttons[kButtonStart] = input.buttons[8]; | 58 mapped->buttons[kButtonStart] = input.buttons[8]; |
| 59 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[5]); | 59 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[5]); |
| 60 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[5]); | 60 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[5]); |
| 61 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[4]); | 61 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[4]); |
| 62 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[4]); | 62 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[4]); |
| 63 mapped->buttonsLength = kNumButtons - 1; // no Meta on this device | 63 mapped->buttonsLength = kNumButtons - 1; // no Meta on this device |
| 64 mapped->axesLength = kNumAxes; | 64 mapped->axesLength = kNumAxes; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void MapperPlaystationSixAxis( | 67 void MapperPlaystationSixAxis( |
| 68 const WebKit::WebGamepad& input, | 68 const blink::WebGamepad& input, |
| 69 WebKit::WebGamepad* mapped) { | 69 blink::WebGamepad* mapped) { |
| 70 *mapped = input; | 70 *mapped = input; |
| 71 mapped->buttons[kButtonPrimary] = input.buttons[14]; | 71 mapped->buttons[kButtonPrimary] = input.buttons[14]; |
| 72 mapped->buttons[kButtonSecondary] = input.buttons[13]; | 72 mapped->buttons[kButtonSecondary] = input.buttons[13]; |
| 73 mapped->buttons[kButtonTertiary] = input.buttons[15]; | 73 mapped->buttons[kButtonTertiary] = input.buttons[15]; |
| 74 mapped->buttons[kButtonQuaternary] = input.buttons[12]; | 74 mapped->buttons[kButtonQuaternary] = input.buttons[12]; |
| 75 mapped->buttons[kButtonLeftShoulder] = input.buttons[10]; | 75 mapped->buttons[kButtonLeftShoulder] = input.buttons[10]; |
| 76 mapped->buttons[kButtonRightShoulder] = input.buttons[11]; | 76 mapped->buttons[kButtonRightShoulder] = input.buttons[11]; |
| 77 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[12]); | 77 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[12]); |
| 78 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[13]); | 78 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[13]); |
| 79 mapped->buttons[kButtonBackSelect] = input.buttons[0]; | 79 mapped->buttons[kButtonBackSelect] = input.buttons[0]; |
| 80 mapped->buttons[kButtonStart] = input.buttons[3]; | 80 mapped->buttons[kButtonStart] = input.buttons[3]; |
| 81 mapped->buttons[kButtonLeftThumbstick] = input.buttons[1]; | 81 mapped->buttons[kButtonLeftThumbstick] = input.buttons[1]; |
| 82 mapped->buttons[kButtonRightThumbstick] = input.buttons[2]; | 82 mapped->buttons[kButtonRightThumbstick] = input.buttons[2]; |
| 83 mapped->buttons[kButtonDpadUp] = AxisToButton(input.axes[8]); | 83 mapped->buttons[kButtonDpadUp] = AxisToButton(input.axes[8]); |
| 84 mapped->buttons[kButtonDpadDown] = AxisToButton(input.axes[10]); | 84 mapped->buttons[kButtonDpadDown] = AxisToButton(input.axes[10]); |
| 85 mapped->buttons[kButtonDpadLeft] = input.buttons[7]; | 85 mapped->buttons[kButtonDpadLeft] = input.buttons[7]; |
| 86 mapped->buttons[kButtonDpadRight] = AxisToButton(input.axes[9]); | 86 mapped->buttons[kButtonDpadRight] = AxisToButton(input.axes[9]); |
| 87 mapped->buttons[kButtonMeta] = input.buttons[16]; | 87 mapped->buttons[kButtonMeta] = input.buttons[16]; |
| 88 | 88 |
| 89 mapped->buttonsLength = kNumButtons; | 89 mapped->buttonsLength = kNumButtons; |
| 90 mapped->axesLength = kNumAxes; | 90 mapped->axesLength = kNumAxes; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void MapperXGEAR( | 93 void MapperXGEAR( |
| 94 const WebKit::WebGamepad& input, | 94 const blink::WebGamepad& input, |
| 95 WebKit::WebGamepad* mapped) { | 95 blink::WebGamepad* mapped) { |
| 96 *mapped = input; | 96 *mapped = input; |
| 97 mapped->buttons[kButtonPrimary] = input.buttons[2]; | 97 mapped->buttons[kButtonPrimary] = input.buttons[2]; |
| 98 mapped->buttons[kButtonSecondary] = input.buttons[1]; | 98 mapped->buttons[kButtonSecondary] = input.buttons[1]; |
| 99 mapped->buttons[kButtonTertiary] = input.buttons[3]; | 99 mapped->buttons[kButtonTertiary] = input.buttons[3]; |
| 100 mapped->buttons[kButtonQuaternary] = input.buttons[0]; | 100 mapped->buttons[kButtonQuaternary] = input.buttons[0]; |
| 101 mapped->buttons[kButtonLeftShoulder] = input.buttons[6]; | 101 mapped->buttons[kButtonLeftShoulder] = input.buttons[6]; |
| 102 mapped->buttons[kButtonRightShoulder] = input.buttons[7]; | 102 mapped->buttons[kButtonRightShoulder] = input.buttons[7]; |
| 103 mapped->buttons[kButtonLeftTrigger] = input.buttons[4]; | 103 mapped->buttons[kButtonLeftTrigger] = input.buttons[4]; |
| 104 mapped->buttons[kButtonRightTrigger] = input.buttons[5]; | 104 mapped->buttons[kButtonRightTrigger] = input.buttons[5]; |
| 105 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[5]); | 105 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[5]); |
| 106 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[5]); | 106 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[5]); |
| 107 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[4]); | 107 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[4]); |
| 108 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[4]); | 108 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[4]); |
| 109 mapped->axes[kAxisRightStickX] = input.axes[3]; | 109 mapped->axes[kAxisRightStickX] = input.axes[3]; |
| 110 mapped->axes[kAxisRightStickY] = input.axes[2]; | 110 mapped->axes[kAxisRightStickY] = input.axes[2]; |
| 111 mapped->buttonsLength = kNumButtons - 1; // no Meta on this device | 111 mapped->buttonsLength = kNumButtons - 1; // no Meta on this device |
| 112 mapped->axesLength = kNumAxes; | 112 mapped->axesLength = kNumAxes; |
| 113 } | 113 } |
| 114 | 114 |
| 115 | 115 |
| 116 void MapperDragonRiseGeneric( | 116 void MapperDragonRiseGeneric( |
| 117 const WebKit::WebGamepad& input, | 117 const blink::WebGamepad& input, |
| 118 WebKit::WebGamepad* mapped) { | 118 blink::WebGamepad* mapped) { |
| 119 *mapped = input; | 119 *mapped = input; |
| 120 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[6]); | 120 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[6]); |
| 121 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[6]); | 121 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[6]); |
| 122 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[5]); | 122 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[5]); |
| 123 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[5]); | 123 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[5]); |
| 124 mapped->axes[kAxisLeftStickX] = input.axes[0]; | 124 mapped->axes[kAxisLeftStickX] = input.axes[0]; |
| 125 mapped->axes[kAxisLeftStickY] = input.axes[1]; | 125 mapped->axes[kAxisLeftStickY] = input.axes[1]; |
| 126 mapped->axes[kAxisRightStickX] = input.axes[3]; | 126 mapped->axes[kAxisRightStickX] = input.axes[3]; |
| 127 mapped->axes[kAxisRightStickY] = input.axes[4]; | 127 mapped->axes[kAxisRightStickY] = input.axes[4]; |
| 128 mapped->buttonsLength = kNumButtons - 1; // no Meta on this device | 128 mapped->buttonsLength = kNumButtons - 1; // no Meta on this device |
| (...skipping 26 matching lines...) Expand all Loading... |
| 155 const base::StringPiece& product_id) { | 155 const base::StringPiece& product_id) { |
| 156 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { | 156 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { |
| 157 MappingData& item = AvailableMappings[i]; | 157 MappingData& item = AvailableMappings[i]; |
| 158 if (vendor_id == item.vendor_id && product_id == item.product_id) | 158 if (vendor_id == item.vendor_id && product_id == item.product_id) |
| 159 return item.function; | 159 return item.function; |
| 160 } | 160 } |
| 161 return NULL; | 161 return NULL; |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace content | 164 } // namespace content |
| OLD | NEW |