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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "content/browser/gamepad/gamepad_standard_mappings.h" | 8 #include "device/gamepad/gamepad_standard_mappings.h" |
9 | 9 |
10 namespace content { | 10 namespace device { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 void MapperXInputStyleGamepad(const blink::WebGamepad& input, | 14 void MapperXInputStyleGamepad(const blink::WebGamepad& input, |
15 blink::WebGamepad* mapped) { | 15 blink::WebGamepad* mapped) { |
16 *mapped = input; | 16 *mapped = input; |
17 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]); | 17 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]); |
18 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]); | 18 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]); |
19 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[6]; | 19 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[6]; |
20 mapped->buttons[BUTTON_INDEX_START] = input.buttons[7]; | 20 mapped->buttons[BUTTON_INDEX_START] = input.buttons[7]; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[5]; | 123 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[5]; |
124 mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[1]); | 124 mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[1]); |
125 mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[1]); | 125 mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[1]); |
126 mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[0]); | 126 mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[0]); |
127 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] = | 127 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] = |
128 AxisPositiveAsButton(input.axes[0]); | 128 AxisPositiveAsButton(input.axes[0]); |
129 mapped->buttonsLength = BUTTON_INDEX_COUNT - 1; /* no meta */ | 129 mapped->buttonsLength = BUTTON_INDEX_COUNT - 1; /* no meta */ |
130 mapped->axesLength = 2; | 130 mapped->axesLength = 2; |
131 } | 131 } |
132 | 132 |
133 | |
134 void MapperXGEAR(const blink::WebGamepad& input, blink::WebGamepad* mapped) { | 133 void MapperXGEAR(const blink::WebGamepad& input, blink::WebGamepad* mapped) { |
135 *mapped = input; | 134 *mapped = input; |
136 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[2]; | 135 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[2]; |
137 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1]; | 136 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1]; |
138 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3]; | 137 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3]; |
139 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[0]; | 138 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[0]; |
140 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6]; | 139 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6]; |
141 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7]; | 140 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7]; |
142 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[4]; | 141 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[4]; |
143 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[5]; | 142 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[5]; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 288 |
290 mapped->buttonsLength = BUTTON_INDEX_COUNT - 1; /* no meta */ | 289 mapped->buttonsLength = BUTTON_INDEX_COUNT - 1; /* no meta */ |
291 mapped->axesLength = AXIS_INDEX_COUNT; | 290 mapped->axesLength = AXIS_INDEX_COUNT; |
292 } | 291 } |
293 | 292 |
294 struct MappingData { | 293 struct MappingData { |
295 const char* const vendor_id; | 294 const char* const vendor_id; |
296 const char* const product_id; | 295 const char* const product_id; |
297 GamepadStandardMappingFunction function; | 296 GamepadStandardMappingFunction function; |
298 } AvailableMappings[] = { | 297 } AvailableMappings[] = { |
299 // http://www.linux-usb.org/usb.ids | 298 // http://www.linux-usb.org/usb.ids |
300 {"0079", "0006", MapperDragonRiseGeneric}, // DragonRise Generic USB | 299 {"0079", "0006", MapperDragonRiseGeneric}, // DragonRise Generic USB |
301 {"045e", "028e", MapperXInputStyleGamepad}, // Xbox 360 Wired | 300 {"045e", "028e", MapperXInputStyleGamepad}, // Xbox 360 Wired |
302 {"045e", "028f", MapperXInputStyleGamepad}, // Xbox 360 Wireless | 301 {"045e", "028f", MapperXInputStyleGamepad}, // Xbox 360 Wireless |
303 {"045e", "0719", MapperXInputStyleGamepad}, // Xbox 360 Wireless | 302 {"045e", "0719", MapperXInputStyleGamepad}, // Xbox 360 Wireless |
304 {"046d", "c21d", MapperXInputStyleGamepad}, // Logitech F310 | 303 {"046d", "c21d", MapperXInputStyleGamepad}, // Logitech F310 |
305 {"046d", "c21e", MapperXInputStyleGamepad}, // Logitech F510 | 304 {"046d", "c21e", MapperXInputStyleGamepad}, // Logitech F510 |
306 {"046d", "c21f", MapperXInputStyleGamepad}, // Logitech F710 | 305 {"046d", "c21f", MapperXInputStyleGamepad}, // Logitech F710 |
307 {"054c", "0268", MapperPlaystationSixAxis}, // Playstation SIXAXIS | 306 {"054c", "0268", MapperPlaystationSixAxis}, // Playstation SIXAXIS |
308 {"054c", "05c4", MapperDualshock4}, // Playstation Dualshock 4 | 307 {"054c", "05c4", MapperDualshock4}, // Playstation Dualshock 4 |
309 {"0583", "2060", MapperIBuffalo}, // iBuffalo Classic | 308 {"0583", "2060", MapperIBuffalo}, // iBuffalo Classic |
310 {"0925", "0005", MapperLakeviewResearch}, // SmartJoy PLUS Adapter | 309 {"0925", "0005", MapperLakeviewResearch}, // SmartJoy PLUS Adapter |
311 {"0925", "8866", MapperLakeviewResearch}, // WiseGroup MP-8866 | 310 {"0925", "8866", MapperLakeviewResearch}, // WiseGroup MP-8866 |
312 {"0955", "7210", MapperNvShield}, // Nvidia Shield gamepad | 311 {"0955", "7210", MapperNvShield}, // Nvidia Shield gamepad |
313 {"0b05", "4500", MapperADT1}, // Nexus Player Controller | 312 {"0b05", "4500", MapperADT1}, // Nexus Player Controller |
314 {"0e8f", "0003", MapperXGEAR}, // XFXforce XGEAR PS2 Controller | 313 {"0e8f", "0003", MapperXGEAR}, // XFXforce XGEAR PS2 Controller |
315 {"1532", "0900", MapperRazerServal}, // Razer Serval Controller | 314 {"1532", "0900", MapperRazerServal}, // Razer Serval Controller |
316 {"18d1", "2c40", MapperADT1}, // ADT-1 Controller | 315 {"18d1", "2c40", MapperADT1}, // ADT-1 Controller |
317 {"20d6", "6271", MapperMogaPro}, // Moga Pro Controller (HID mode) | 316 {"20d6", "6271", MapperMogaPro}, // Moga Pro Controller (HID mode) |
318 {"2378", "1008", MapperOnLiveWireless}, // OnLive Controller (Bluetooth) | 317 {"2378", "1008", MapperOnLiveWireless}, // OnLive Controller (Bluetooth) |
319 {"2378", "100a", MapperOnLiveWireless}, // OnLive Controller (Wired) | 318 {"2378", "100a", MapperOnLiveWireless}, // OnLive Controller (Wired) |
320 {"2836", "0001", MapperOUYA}, // OUYA Controller | 319 {"2836", "0001", MapperOUYA}, // OUYA Controller |
321 }; | 320 }; |
322 | 321 |
323 } // namespace | 322 } // namespace |
324 | 323 |
325 GamepadStandardMappingFunction GetGamepadStandardMappingFunction( | 324 GamepadStandardMappingFunction GetGamepadStandardMappingFunction( |
326 const base::StringPiece& vendor_id, | 325 const base::StringPiece& vendor_id, |
327 const base::StringPiece& product_id) { | 326 const base::StringPiece& product_id) { |
328 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { | 327 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { |
329 MappingData& item = AvailableMappings[i]; | 328 MappingData& item = AvailableMappings[i]; |
330 if (vendor_id == item.vendor_id && product_id == item.product_id) | 329 if (vendor_id == item.vendor_id && product_id == item.product_id) |
331 return item.function; | 330 return item.function; |
332 } | 331 } |
333 return NULL; | 332 return NULL; |
334 } | 333 } |
335 | 334 |
336 } // namespace content | 335 } // namespace device |
OLD | NEW |