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 void DpadFromAxis(WebKit::WebGamepad* mapped, float dir) { | 17 void DpadFromAxis(blink::WebGamepad* mapped, float dir) { |
18 // Dpad is mapped as a direction on one axis, where -1 is up and it | 18 // Dpad is mapped as a direction on one axis, where -1 is up and it |
19 // increases clockwise to 1, which is up + left. It's set to a large (> 1.f) | 19 // increases clockwise to 1, which is up + left. It's set to a large (> 1.f) |
20 // number when nothing is depressed, except on start up, sometimes it's 0.0 | 20 // number when nothing is depressed, except on start up, sometimes it's 0.0 |
21 // for no data, rather than the large number. | 21 // for no data, rather than the large number. |
22 if (dir == 0.0f) { | 22 if (dir == 0.0f) { |
23 mapped->buttons[kButtonDpadUp] = 0.f; | 23 mapped->buttons[kButtonDpadUp] = 0.f; |
24 mapped->buttons[kButtonDpadDown] = 0.f; | 24 mapped->buttons[kButtonDpadDown] = 0.f; |
25 mapped->buttons[kButtonDpadLeft] = 0.f; | 25 mapped->buttons[kButtonDpadLeft] = 0.f; |
26 mapped->buttons[kButtonDpadRight] = 0.f; | 26 mapped->buttons[kButtonDpadRight] = 0.f; |
27 } else { | 27 } else { |
28 mapped->buttons[kButtonDpadUp] = (dir >= -1.f && dir < -0.7f) || | 28 mapped->buttons[kButtonDpadUp] = (dir >= -1.f && dir < -0.7f) || |
29 (dir >= .95f && dir <= 1.f); | 29 (dir >= .95f && dir <= 1.f); |
30 mapped->buttons[kButtonDpadRight] = dir >= -.75f && dir < -.1f; | 30 mapped->buttons[kButtonDpadRight] = dir >= -.75f && dir < -.1f; |
31 mapped->buttons[kButtonDpadDown] = dir >= -.2f && dir < .45f; | 31 mapped->buttons[kButtonDpadDown] = dir >= -.2f && dir < .45f; |
32 mapped->buttons[kButtonDpadLeft] = dir >= .4f && dir <= 1.f; | 32 mapped->buttons[kButtonDpadLeft] = dir >= .4f && dir <= 1.f; |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 void MapperXbox360Gamepad( | 36 void MapperXbox360Gamepad( |
37 const WebKit::WebGamepad& input, | 37 const blink::WebGamepad& input, |
38 WebKit::WebGamepad* mapped) { | 38 blink::WebGamepad* mapped) { |
39 *mapped = input; | 39 *mapped = input; |
40 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[2]); | 40 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[2]); |
41 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[5]); | 41 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[5]); |
42 mapped->buttons[kButtonBackSelect] = input.buttons[9]; | 42 mapped->buttons[kButtonBackSelect] = input.buttons[9]; |
43 mapped->buttons[kButtonStart] = input.buttons[8]; | 43 mapped->buttons[kButtonStart] = input.buttons[8]; |
44 mapped->buttons[kButtonLeftThumbstick] = input.buttons[6]; | 44 mapped->buttons[kButtonLeftThumbstick] = input.buttons[6]; |
45 mapped->buttons[kButtonRightThumbstick] = input.buttons[7]; | 45 mapped->buttons[kButtonRightThumbstick] = input.buttons[7]; |
46 mapped->buttons[kButtonDpadUp] = input.buttons[11]; | 46 mapped->buttons[kButtonDpadUp] = input.buttons[11]; |
47 mapped->buttons[kButtonDpadDown] = input.buttons[12]; | 47 mapped->buttons[kButtonDpadDown] = input.buttons[12]; |
48 mapped->buttons[kButtonDpadLeft] = input.buttons[13]; | 48 mapped->buttons[kButtonDpadLeft] = input.buttons[13]; |
49 mapped->buttons[kButtonDpadRight] = input.buttons[14]; | 49 mapped->buttons[kButtonDpadRight] = input.buttons[14]; |
50 mapped->buttons[kButtonMeta] = input.buttons[10]; | 50 mapped->buttons[kButtonMeta] = input.buttons[10]; |
51 mapped->axes[kAxisRightStickX] = input.axes[3]; | 51 mapped->axes[kAxisRightStickX] = input.axes[3]; |
52 mapped->axes[kAxisRightStickY] = input.axes[4]; | 52 mapped->axes[kAxisRightStickY] = input.axes[4]; |
53 mapped->buttonsLength = kNumButtons; | 53 mapped->buttonsLength = kNumButtons; |
54 mapped->axesLength = kNumAxes; | 54 mapped->axesLength = kNumAxes; |
55 } | 55 } |
56 | 56 |
57 void MapperPlaystationSixAxis( | 57 void MapperPlaystationSixAxis( |
58 const WebKit::WebGamepad& input, | 58 const blink::WebGamepad& input, |
59 WebKit::WebGamepad* mapped) { | 59 blink::WebGamepad* mapped) { |
60 *mapped = input; | 60 *mapped = input; |
61 mapped->buttons[kButtonPrimary] = input.buttons[14]; | 61 mapped->buttons[kButtonPrimary] = input.buttons[14]; |
62 mapped->buttons[kButtonSecondary] = input.buttons[13]; | 62 mapped->buttons[kButtonSecondary] = input.buttons[13]; |
63 mapped->buttons[kButtonTertiary] = input.buttons[15]; | 63 mapped->buttons[kButtonTertiary] = input.buttons[15]; |
64 mapped->buttons[kButtonQuaternary] = input.buttons[12]; | 64 mapped->buttons[kButtonQuaternary] = input.buttons[12]; |
65 mapped->buttons[kButtonLeftShoulder] = input.buttons[10]; | 65 mapped->buttons[kButtonLeftShoulder] = input.buttons[10]; |
66 mapped->buttons[kButtonRightShoulder] = input.buttons[11]; | 66 mapped->buttons[kButtonRightShoulder] = input.buttons[11]; |
67 mapped->buttons[kButtonLeftTrigger] = input.buttons[8]; | 67 mapped->buttons[kButtonLeftTrigger] = input.buttons[8]; |
68 mapped->buttons[kButtonRightTrigger] = input.buttons[9]; | 68 mapped->buttons[kButtonRightTrigger] = input.buttons[9]; |
69 mapped->buttons[kButtonBackSelect] = input.buttons[0]; | 69 mapped->buttons[kButtonBackSelect] = input.buttons[0]; |
70 mapped->buttons[kButtonStart] = input.buttons[3]; | 70 mapped->buttons[kButtonStart] = input.buttons[3]; |
71 mapped->buttons[kButtonLeftThumbstick] = input.buttons[1]; | 71 mapped->buttons[kButtonLeftThumbstick] = input.buttons[1]; |
72 mapped->buttons[kButtonRightThumbstick] = input.buttons[2]; | 72 mapped->buttons[kButtonRightThumbstick] = input.buttons[2]; |
73 mapped->buttons[kButtonDpadUp] = input.buttons[4]; | 73 mapped->buttons[kButtonDpadUp] = input.buttons[4]; |
74 mapped->buttons[kButtonDpadDown] = input.buttons[6]; | 74 mapped->buttons[kButtonDpadDown] = input.buttons[6]; |
75 mapped->buttons[kButtonDpadLeft] = input.buttons[7]; | 75 mapped->buttons[kButtonDpadLeft] = input.buttons[7]; |
76 mapped->buttons[kButtonDpadRight] = input.buttons[5]; | 76 mapped->buttons[kButtonDpadRight] = input.buttons[5]; |
77 mapped->buttons[kButtonMeta] = input.buttons[16]; | 77 mapped->buttons[kButtonMeta] = input.buttons[16]; |
78 mapped->axes[kAxisRightStickY] = input.axes[5]; | 78 mapped->axes[kAxisRightStickY] = input.axes[5]; |
79 | 79 |
80 mapped->buttonsLength = kNumButtons; | 80 mapped->buttonsLength = kNumButtons; |
81 mapped->axesLength = kNumAxes; | 81 mapped->axesLength = kNumAxes; |
82 } | 82 } |
83 | 83 |
84 void MapperDirectInputStyle( | 84 void MapperDirectInputStyle( |
85 const WebKit::WebGamepad& input, | 85 const blink::WebGamepad& input, |
86 WebKit::WebGamepad* mapped) { | 86 blink::WebGamepad* mapped) { |
87 *mapped = input; | 87 *mapped = input; |
88 mapped->buttons[kButtonPrimary] = input.buttons[1]; | 88 mapped->buttons[kButtonPrimary] = input.buttons[1]; |
89 mapped->buttons[kButtonSecondary] = input.buttons[2]; | 89 mapped->buttons[kButtonSecondary] = input.buttons[2]; |
90 mapped->buttons[kButtonTertiary] = input.buttons[0]; | 90 mapped->buttons[kButtonTertiary] = input.buttons[0]; |
91 mapped->axes[kAxisRightStickY] = input.axes[5]; | 91 mapped->axes[kAxisRightStickY] = input.axes[5]; |
92 DpadFromAxis(mapped, input.axes[9]); | 92 DpadFromAxis(mapped, input.axes[9]); |
93 mapped->buttonsLength = kNumButtons - 1; /* no meta */ | 93 mapped->buttonsLength = kNumButtons - 1; /* no meta */ |
94 mapped->axesLength = kNumAxes; | 94 mapped->axesLength = kNumAxes; |
95 } | 95 } |
96 | 96 |
97 void MapperMacallyIShock( | 97 void MapperMacallyIShock( |
98 const WebKit::WebGamepad& input, | 98 const blink::WebGamepad& input, |
99 WebKit::WebGamepad* mapped) { | 99 blink::WebGamepad* mapped) { |
100 enum IShockButtons { | 100 enum IShockButtons { |
101 kButtonC = kNumButtons, | 101 kButtonC = kNumButtons, |
102 kButtonD, | 102 kButtonD, |
103 kButtonE, | 103 kButtonE, |
104 kNumIShockButtons | 104 kNumIShockButtons |
105 }; | 105 }; |
106 | 106 |
107 *mapped = input; | 107 *mapped = input; |
108 mapped->buttons[kButtonPrimary] = input.buttons[6]; | 108 mapped->buttons[kButtonPrimary] = input.buttons[6]; |
109 mapped->buttons[kButtonSecondary] = input.buttons[5]; | 109 mapped->buttons[kButtonSecondary] = input.buttons[5]; |
(...skipping 18 matching lines...) Expand all Loading... |
128 mapped->axes[kAxisLeftStickX] = input.axes[0]; | 128 mapped->axes[kAxisLeftStickX] = input.axes[0]; |
129 mapped->axes[kAxisLeftStickY] = input.axes[1]; | 129 mapped->axes[kAxisLeftStickY] = input.axes[1]; |
130 mapped->axes[kAxisRightStickX] = -input.axes[5]; | 130 mapped->axes[kAxisRightStickX] = -input.axes[5]; |
131 mapped->axes[kAxisRightStickY] = input.axes[6]; | 131 mapped->axes[kAxisRightStickY] = input.axes[6]; |
132 | 132 |
133 mapped->buttonsLength = kNumIShockButtons; | 133 mapped->buttonsLength = kNumIShockButtons; |
134 mapped->axesLength = kNumAxes; | 134 mapped->axesLength = kNumAxes; |
135 } | 135 } |
136 | 136 |
137 void MapperXGEAR( | 137 void MapperXGEAR( |
138 const WebKit::WebGamepad& input, | 138 const blink::WebGamepad& input, |
139 WebKit::WebGamepad* mapped) { | 139 blink::WebGamepad* mapped) { |
140 *mapped = input; | 140 *mapped = input; |
141 mapped->buttons[kButtonPrimary] = input.buttons[2]; | 141 mapped->buttons[kButtonPrimary] = input.buttons[2]; |
142 mapped->buttons[kButtonTertiary] = input.buttons[3]; | 142 mapped->buttons[kButtonTertiary] = input.buttons[3]; |
143 mapped->buttons[kButtonQuaternary] = input.buttons[0]; | 143 mapped->buttons[kButtonQuaternary] = input.buttons[0]; |
144 mapped->buttons[kButtonLeftShoulder] = input.buttons[6]; | 144 mapped->buttons[kButtonLeftShoulder] = input.buttons[6]; |
145 mapped->buttons[kButtonRightShoulder] = input.buttons[7]; | 145 mapped->buttons[kButtonRightShoulder] = input.buttons[7]; |
146 mapped->buttons[kButtonLeftTrigger] = input.buttons[4]; | 146 mapped->buttons[kButtonLeftTrigger] = input.buttons[4]; |
147 mapped->buttons[kButtonRightTrigger] = input.buttons[5]; | 147 mapped->buttons[kButtonRightTrigger] = input.buttons[5]; |
148 DpadFromAxis(mapped, input.axes[9]); | 148 DpadFromAxis(mapped, input.axes[9]); |
149 mapped->axes[kAxisRightStickX] = input.axes[5]; | 149 mapped->axes[kAxisRightStickX] = input.axes[5]; |
150 mapped->axes[kAxisRightStickY] = input.axes[2]; | 150 mapped->axes[kAxisRightStickY] = input.axes[2]; |
151 mapped->buttonsLength = kNumButtons - 1; /* no meta */ | 151 mapped->buttonsLength = kNumButtons - 1; /* no meta */ |
152 mapped->axesLength = kNumAxes; | 152 mapped->axesLength = kNumAxes; |
153 } | 153 } |
154 | 154 |
155 void MapperSmartJoyPLUS( | 155 void MapperSmartJoyPLUS( |
156 const WebKit::WebGamepad& input, | 156 const blink::WebGamepad& input, |
157 WebKit::WebGamepad* mapped) { | 157 blink::WebGamepad* mapped) { |
158 *mapped = input; | 158 *mapped = input; |
159 mapped->buttons[kButtonPrimary] = input.buttons[2]; | 159 mapped->buttons[kButtonPrimary] = input.buttons[2]; |
160 mapped->buttons[kButtonTertiary] = input.buttons[3]; | 160 mapped->buttons[kButtonTertiary] = input.buttons[3]; |
161 mapped->buttons[kButtonQuaternary] = input.buttons[0]; | 161 mapped->buttons[kButtonQuaternary] = input.buttons[0]; |
162 mapped->buttons[kButtonStart] = input.buttons[8]; | 162 mapped->buttons[kButtonStart] = input.buttons[8]; |
163 mapped->buttons[kButtonBackSelect] = input.buttons[9]; | 163 mapped->buttons[kButtonBackSelect] = input.buttons[9]; |
164 mapped->buttons[kButtonLeftShoulder] = input.buttons[6]; | 164 mapped->buttons[kButtonLeftShoulder] = input.buttons[6]; |
165 mapped->buttons[kButtonRightShoulder] = input.buttons[7]; | 165 mapped->buttons[kButtonRightShoulder] = input.buttons[7]; |
166 mapped->buttons[kButtonLeftTrigger] = input.buttons[4]; | 166 mapped->buttons[kButtonLeftTrigger] = input.buttons[4]; |
167 mapped->buttons[kButtonRightTrigger] = input.buttons[5]; | 167 mapped->buttons[kButtonRightTrigger] = input.buttons[5]; |
168 DpadFromAxis(mapped, input.axes[9]); | 168 DpadFromAxis(mapped, input.axes[9]); |
169 mapped->axes[kAxisRightStickY] = input.axes[5]; | 169 mapped->axes[kAxisRightStickY] = input.axes[5]; |
170 mapped->buttonsLength = kNumButtons - 1; /* no meta */ | 170 mapped->buttonsLength = kNumButtons - 1; /* no meta */ |
171 mapped->axesLength = kNumAxes; | 171 mapped->axesLength = kNumAxes; |
172 } | 172 } |
173 | 173 |
174 void MapperDragonRiseGeneric( | 174 void MapperDragonRiseGeneric( |
175 const WebKit::WebGamepad& input, | 175 const blink::WebGamepad& input, |
176 WebKit::WebGamepad* mapped) { | 176 blink::WebGamepad* mapped) { |
177 *mapped = input; | 177 *mapped = input; |
178 DpadFromAxis(mapped, input.axes[9]); | 178 DpadFromAxis(mapped, input.axes[9]); |
179 mapped->axes[kAxisLeftStickX] = input.axes[0]; | 179 mapped->axes[kAxisLeftStickX] = input.axes[0]; |
180 mapped->axes[kAxisLeftStickY] = input.axes[1]; | 180 mapped->axes[kAxisLeftStickY] = input.axes[1]; |
181 mapped->axes[kAxisRightStickX] = input.axes[2]; | 181 mapped->axes[kAxisRightStickX] = input.axes[2]; |
182 mapped->axes[kAxisRightStickY] = input.axes[5]; | 182 mapped->axes[kAxisRightStickY] = input.axes[5]; |
183 mapped->buttonsLength = kNumButtons - 1; /* no meta */ | 183 mapped->buttonsLength = kNumButtons - 1; /* no meta */ |
184 mapped->axesLength = kNumAxes; | 184 mapped->axesLength = kNumAxes; |
185 } | 185 } |
186 | 186 |
(...skipping 23 matching lines...) Expand all Loading... |
210 const base::StringPiece& product_id) { | 210 const base::StringPiece& product_id) { |
211 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { | 211 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { |
212 MappingData& item = AvailableMappings[i]; | 212 MappingData& item = AvailableMappings[i]; |
213 if (vendor_id == item.vendor_id && product_id == item.product_id) | 213 if (vendor_id == item.vendor_id && product_id == item.product_id) |
214 return item.function; | 214 return item.function; |
215 } | 215 } |
216 return NULL; | 216 return NULL; |
217 } | 217 } |
218 | 218 |
219 } // namespace content | 219 } // namespace content |
OLD | NEW |