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
3 // found in the LICENSE file.
5 #include "content/browser/gamepad/gamepad_standard_mappings.h"
11 void MapperXInputStyleGamepad(const blink::WebGamepad
& input
,
12 blink::WebGamepad
* mapped
) {
14 mapped
->buttons
[BUTTON_INDEX_LEFT_TRIGGER
] = AxisToButton(input
.axes
[2]);
15 mapped
->buttons
[BUTTON_INDEX_RIGHT_TRIGGER
] = AxisToButton(input
.axes
[5]);
16 mapped
->buttons
[BUTTON_INDEX_BACK_SELECT
] = input
.buttons
[6];
17 mapped
->buttons
[BUTTON_INDEX_START
] = input
.buttons
[7];
18 mapped
->buttons
[BUTTON_INDEX_LEFT_THUMBSTICK
] = input
.buttons
[9];
19 mapped
->buttons
[BUTTON_INDEX_RIGHT_THUMBSTICK
] = input
.buttons
[10];
20 mapped
->buttons
[BUTTON_INDEX_DPAD_UP
] = AxisNegativeAsButton(input
.axes
[7]);
21 mapped
->buttons
[BUTTON_INDEX_DPAD_DOWN
] = AxisPositiveAsButton(input
.axes
[7]);
22 mapped
->buttons
[BUTTON_INDEX_DPAD_LEFT
] = AxisNegativeAsButton(input
.axes
[6]);
23 mapped
->buttons
[BUTTON_INDEX_DPAD_RIGHT
] =
24 AxisPositiveAsButton(input
.axes
[6]);
25 mapped
->buttons
[BUTTON_INDEX_META
] = input
.buttons
[8];
26 mapped
->axes
[AXIS_INDEX_RIGHT_STICK_X
] = input
.axes
[3];
27 mapped
->axes
[AXIS_INDEX_RIGHT_STICK_Y
] = input
.axes
[4];
28 mapped
->buttonsLength
= BUTTON_INDEX_COUNT
;
29 mapped
->axesLength
= AXIS_INDEX_COUNT
;
32 void MapperLakeviewResearch(const blink::WebGamepad
& input
,
33 blink::WebGamepad
* mapped
) {
35 mapped
->buttons
[BUTTON_INDEX_PRIMARY
] = input
.buttons
[2];
36 mapped
->buttons
[BUTTON_INDEX_TERTIARY
] = input
.buttons
[3];
37 mapped
->buttons
[BUTTON_INDEX_QUATERNARY
] = input
.buttons
[0];
38 mapped
->buttons
[BUTTON_INDEX_LEFT_SHOULDER
] = input
.buttons
[6];
39 mapped
->buttons
[BUTTON_INDEX_RIGHT_SHOULDER
] = input
.buttons
[7];
40 mapped
->buttons
[BUTTON_INDEX_LEFT_TRIGGER
] = input
.buttons
[4];
41 mapped
->buttons
[BUTTON_INDEX_RIGHT_TRIGGER
] = input
.buttons
[5];
42 mapped
->buttons
[BUTTON_INDEX_BACK_SELECT
] = input
.buttons
[9];
43 mapped
->buttons
[BUTTON_INDEX_START
] = input
.buttons
[8];
44 mapped
->buttons
[BUTTON_INDEX_DPAD_UP
] = AxisNegativeAsButton(input
.axes
[5]);
45 mapped
->buttons
[BUTTON_INDEX_DPAD_DOWN
] = AxisPositiveAsButton(input
.axes
[5]);
46 mapped
->buttons
[BUTTON_INDEX_DPAD_LEFT
] = AxisNegativeAsButton(input
.axes
[4]);
47 mapped
->buttons
[BUTTON_INDEX_DPAD_RIGHT
] =
48 AxisPositiveAsButton(input
.axes
[4]);
49 mapped
->buttonsLength
= BUTTON_INDEX_COUNT
- 1; // no Meta on this device
50 mapped
->axesLength
= AXIS_INDEX_COUNT
;
53 void MapperPlaystationSixAxis(const blink::WebGamepad
& input
,
54 blink::WebGamepad
* mapped
) {
56 mapped
->buttons
[BUTTON_INDEX_PRIMARY
] = input
.buttons
[14];
57 mapped
->buttons
[BUTTON_INDEX_SECONDARY
] = input
.buttons
[13];
58 mapped
->buttons
[BUTTON_INDEX_TERTIARY
] = input
.buttons
[15];
59 mapped
->buttons
[BUTTON_INDEX_QUATERNARY
] = input
.buttons
[12];
60 mapped
->buttons
[BUTTON_INDEX_LEFT_SHOULDER
] = input
.buttons
[10];
61 mapped
->buttons
[BUTTON_INDEX_RIGHT_SHOULDER
] = input
.buttons
[11];
62 mapped
->buttons
[BUTTON_INDEX_LEFT_TRIGGER
] = AxisToButton(input
.axes
[12]);
63 mapped
->buttons
[BUTTON_INDEX_RIGHT_TRIGGER
] = AxisToButton(input
.axes
[13]);
64 mapped
->buttons
[BUTTON_INDEX_BACK_SELECT
] = input
.buttons
[0];
65 mapped
->buttons
[BUTTON_INDEX_START
] = input
.buttons
[3];
66 mapped
->buttons
[BUTTON_INDEX_LEFT_THUMBSTICK
] = input
.buttons
[1];
67 mapped
->buttons
[BUTTON_INDEX_RIGHT_THUMBSTICK
] = input
.buttons
[2];
68 mapped
->buttons
[BUTTON_INDEX_DPAD_UP
] = AxisToButton(input
.axes
[8]);
69 mapped
->buttons
[BUTTON_INDEX_DPAD_DOWN
] = AxisToButton(input
.axes
[10]);
70 mapped
->buttons
[BUTTON_INDEX_DPAD_LEFT
] = input
.buttons
[7];
71 mapped
->buttons
[BUTTON_INDEX_DPAD_RIGHT
] = AxisToButton(input
.axes
[9]);
72 mapped
->buttons
[BUTTON_INDEX_META
] = input
.buttons
[16];
74 mapped
->buttonsLength
= BUTTON_INDEX_COUNT
;
75 mapped
->axesLength
= AXIS_INDEX_COUNT
;
78 void MapperDualshock4(const blink::WebGamepad
& input
,
79 blink::WebGamepad
* mapped
) {
80 enum Dualshock4Buttons
{
81 DUALSHOCK_BUTTON_TOUCHPAD
= BUTTON_INDEX_COUNT
,
82 DUALSHOCK_BUTTON_COUNT
86 mapped
->buttons
[BUTTON_INDEX_PRIMARY
] = input
.buttons
[1];
87 mapped
->buttons
[BUTTON_INDEX_SECONDARY
] = input
.buttons
[2];
88 mapped
->buttons
[BUTTON_INDEX_TERTIARY
] = input
.buttons
[0];
89 mapped
->buttons
[BUTTON_INDEX_QUATERNARY
] = input
.buttons
[3];
90 mapped
->buttons
[BUTTON_INDEX_LEFT_SHOULDER
] = input
.buttons
[4];
91 mapped
->buttons
[BUTTON_INDEX_RIGHT_SHOULDER
] = input
.buttons
[5];
92 mapped
->buttons
[BUTTON_INDEX_LEFT_TRIGGER
] = AxisToButton(input
.axes
[3]);
93 mapped
->buttons
[BUTTON_INDEX_RIGHT_TRIGGER
] = AxisToButton(input
.axes
[4]);
94 mapped
->buttons
[BUTTON_INDEX_BACK_SELECT
] = input
.buttons
[8];
95 mapped
->buttons
[BUTTON_INDEX_START
] = input
.buttons
[9];
96 mapped
->buttons
[BUTTON_INDEX_LEFT_THUMBSTICK
] = input
.buttons
[10];
97 mapped
->buttons
[BUTTON_INDEX_RIGHT_THUMBSTICK
] = input
.buttons
[11];
98 mapped
->buttons
[BUTTON_INDEX_DPAD_UP
] = AxisNegativeAsButton(input
.axes
[7]);
99 mapped
->buttons
[BUTTON_INDEX_DPAD_DOWN
] = AxisPositiveAsButton(input
.axes
[7]);
100 mapped
->buttons
[BUTTON_INDEX_DPAD_LEFT
] = AxisNegativeAsButton(input
.axes
[6]);
101 mapped
->buttons
[BUTTON_INDEX_DPAD_RIGHT
] =
102 AxisPositiveAsButton(input
.axes
[6]);
103 mapped
->buttons
[BUTTON_INDEX_META
] = input
.buttons
[12];
104 mapped
->buttons
[DUALSHOCK_BUTTON_TOUCHPAD
] = input
.buttons
[13];
105 mapped
->axes
[AXIS_INDEX_RIGHT_STICK_Y
] = input
.axes
[5];
107 mapped
->buttonsLength
= DUALSHOCK_BUTTON_COUNT
;
108 mapped
->axesLength
= AXIS_INDEX_COUNT
;
111 void MapperIBuffalo(const blink::WebGamepad
& input
, blink::WebGamepad
* mapped
) {
113 mapped
->buttons
[BUTTON_INDEX_PRIMARY
] = input
.buttons
[1];
114 mapped
->buttons
[BUTTON_INDEX_SECONDARY
] = input
.buttons
[0];
115 mapped
->buttons
[BUTTON_INDEX_TERTIARY
] = input
.buttons
[3];
116 mapped
->buttons
[BUTTON_INDEX_QUATERNARY
] = input
.buttons
[2];
117 mapped
->buttons
[BUTTON_INDEX_BACK_SELECT
] = input
.buttons
[6];
118 mapped
->buttons
[BUTTON_INDEX_START
] = input
.buttons
[7];
119 mapped
->buttons
[BUTTON_INDEX_LEFT_TRIGGER
] = input
.buttons
[4];
120 mapped
->buttons
[BUTTON_INDEX_RIGHT_TRIGGER
] = input
.buttons
[5];
121 mapped
->buttons
[BUTTON_INDEX_DPAD_UP
] = AxisNegativeAsButton(input
.axes
[1]);
122 mapped
->buttons
[BUTTON_INDEX_DPAD_DOWN
] = AxisPositiveAsButton(input
.axes
[1]);
123 mapped
->buttons
[BUTTON_INDEX_DPAD_LEFT
] = AxisNegativeAsButton(input
.axes
[0]);
124 mapped
->buttons
[BUTTON_INDEX_DPAD_RIGHT
] =
125 AxisPositiveAsButton(input
.axes
[0]);
126 mapped
->buttonsLength
= BUTTON_INDEX_COUNT
- 1; /* no meta */
127 mapped
->axesLength
= 2;
131 void MapperXGEAR(const blink::WebGamepad
& input
, blink::WebGamepad
* mapped
) {
133 mapped
->buttons
[BUTTON_INDEX_PRIMARY
] = input
.buttons
[2];
134 mapped
->buttons
[BUTTON_INDEX_SECONDARY
] = input
.buttons
[1];
135 mapped
->buttons
[BUTTON_INDEX_TERTIARY
] = input
.buttons
[3];
136 mapped
->buttons
[BUTTON_INDEX_QUATERNARY
] = input
.buttons
[0];
137 mapped
->buttons
[BUTTON_INDEX_LEFT_SHOULDER
] = input
.buttons
[6];
138 mapped
->buttons
[BUTTON_INDEX_RIGHT_SHOULDER
] = input
.buttons
[7];
139 mapped
->buttons
[BUTTON_INDEX_LEFT_TRIGGER
] = input
.buttons
[4];
140 mapped
->buttons
[BUTTON_INDEX_RIGHT_TRIGGER
] = input
.buttons
[5];
141 mapped
->buttons
[BUTTON_INDEX_DPAD_UP
] = AxisNegativeAsButton(input
.axes
[5]);
142 mapped
->buttons
[BUTTON_INDEX_DPAD_DOWN
] = AxisPositiveAsButton(input
.axes
[5]);
143 mapped
->buttons
[BUTTON_INDEX_DPAD_LEFT
] = AxisNegativeAsButton(input
.axes
[4]);
144 mapped
->buttons
[BUTTON_INDEX_DPAD_RIGHT
] =
145 AxisPositiveAsButton(input
.axes
[4]);
146 mapped
->axes
[AXIS_INDEX_RIGHT_STICK_X
] = input
.axes
[3];
147 mapped
->axes
[AXIS_INDEX_RIGHT_STICK_Y
] = input
.axes
[2];
148 mapped
->buttonsLength
= BUTTON_INDEX_COUNT
- 1; // no Meta on this device
149 mapped
->axesLength
= AXIS_INDEX_COUNT
;
152 void MapperDragonRiseGeneric(const blink::WebGamepad
& input
,
153 blink::WebGamepad
* mapped
) {
155 mapped
->buttons
[BUTTON_INDEX_DPAD_UP
] = AxisNegativeAsButton(input
.axes
[6]);
156 mapped
->buttons
[BUTTON_INDEX_DPAD_DOWN
] = AxisPositiveAsButton(input
.axes
[6]);
157 mapped
->buttons
[BUTTON_INDEX_DPAD_LEFT
] = AxisNegativeAsButton(input
.axes
[5]);
158 mapped
->buttons
[BUTTON_INDEX_DPAD_RIGHT
] =
159 AxisPositiveAsButton(input
.axes
[5]);
160 mapped
->axes
[AXIS_INDEX_LEFT_STICK_X
] = input
.axes
[0];
161 mapped
->axes
[AXIS_INDEX_LEFT_STICK_Y
] = input
.axes
[1];
162 mapped
->axes
[AXIS_INDEX_RIGHT_STICK_X
] = input
.axes
[3];
163 mapped
->axes
[AXIS_INDEX_RIGHT_STICK_Y
] = input
.axes
[4];
164 mapped
->buttonsLength
= BUTTON_INDEX_COUNT
- 1; // no Meta on this device
165 mapped
->axesLength
= AXIS_INDEX_COUNT
;
168 void MapperOnLiveWireless(const blink::WebGamepad
& input
,
169 blink::WebGamepad
* mapped
) {
171 mapped
->buttons
[BUTTON_INDEX_LEFT_TRIGGER
] = AxisToButton(input
.axes
[2]);
172 mapped
->buttons
[BUTTON_INDEX_RIGHT_TRIGGER
] = AxisToButton(input
.axes
[5]);
173 mapped
->buttons
[BUTTON_INDEX_BACK_SELECT
] = input
.buttons
[6];
174 mapped
->buttons
[BUTTON_INDEX_START
] = input
.buttons
[7];
175 mapped
->buttons
[BUTTON_INDEX_LEFT_THUMBSTICK
] = input
.buttons
[9];
176 mapped
->buttons
[BUTTON_INDEX_RIGHT_THUMBSTICK
] = input
.buttons
[10];
177 mapped
->buttons
[BUTTON_INDEX_DPAD_UP
] = AxisNegativeAsButton(input
.axes
[7]);
178 mapped
->buttons
[BUTTON_INDEX_DPAD_DOWN
] = AxisPositiveAsButton(input
.axes
[7]);
179 mapped
->buttons
[BUTTON_INDEX_DPAD_LEFT
] = AxisNegativeAsButton(input
.axes
[6]);
180 mapped
->buttons
[BUTTON_INDEX_DPAD_RIGHT
] =
181 AxisPositiveAsButton(input
.axes
[6]);
182 mapped
->buttons
[BUTTON_INDEX_META
] = input
.buttons
[8];
183 mapped
->axes
[AXIS_INDEX_RIGHT_STICK_X
] = input
.axes
[3];
184 mapped
->axes
[AXIS_INDEX_RIGHT_STICK_Y
] = input
.axes
[4];
186 mapped
->buttonsLength
= BUTTON_INDEX_COUNT
;
187 mapped
->axesLength
= AXIS_INDEX_COUNT
;
190 void MapperADT1(const blink::WebGamepad
& input
, blink::WebGamepad
* mapped
) {
192 mapped
->buttons
[BUTTON_INDEX_LEFT_TRIGGER
] = AxisToButton(input
.axes
[5]);
193 mapped
->buttons
[BUTTON_INDEX_RIGHT_TRIGGER
] = AxisToButton(input
.axes
[4]);
194 mapped
->buttons
[BUTTON_INDEX_BACK_SELECT
] = NullButton();
195 mapped
->buttons
[BUTTON_INDEX_START
] = NullButton();
196 mapped
->buttons
[BUTTON_INDEX_LEFT_THUMBSTICK
] = input
.buttons
[7];
197 mapped
->buttons
[BUTTON_INDEX_RIGHT_THUMBSTICK
] = input
.buttons
[8];
198 mapped
->buttons
[BUTTON_INDEX_DPAD_UP
] = AxisNegativeAsButton(input
.axes
[7]);
199 mapped
->buttons
[BUTTON_INDEX_DPAD_DOWN
] = AxisPositiveAsButton(input
.axes
[7]);
200 mapped
->buttons
[BUTTON_INDEX_DPAD_LEFT
] = AxisNegativeAsButton(input
.axes
[6]);
201 mapped
->buttons
[BUTTON_INDEX_DPAD_RIGHT
] =
202 AxisPositiveAsButton(input
.axes
[6]);
203 mapped
->buttons
[BUTTON_INDEX_META
] = input
.buttons
[6];
205 mapped
->buttonsLength
= BUTTON_INDEX_COUNT
;
206 mapped
->axesLength
= AXIS_INDEX_COUNT
;
209 void MapperNvShield(const blink::WebGamepad
& input
, blink::WebGamepad
* mapped
) {
211 mapped
->buttons
[BUTTON_INDEX_LEFT_TRIGGER
] = AxisToButton(input
.axes
[5]);
212 mapped
->buttons
[BUTTON_INDEX_RIGHT_TRIGGER
] = AxisToButton(input
.axes
[4]);
213 mapped
->buttons
[BUTTON_INDEX_BACK_SELECT
] = NullButton();
214 mapped
->buttons
[BUTTON_INDEX_START
] = input
.buttons
[7];
215 mapped
->buttons
[BUTTON_INDEX_LEFT_THUMBSTICK
] = input
.buttons
[8];
216 mapped
->buttons
[BUTTON_INDEX_RIGHT_THUMBSTICK
] = input
.buttons
[9];
217 mapped
->buttons
[BUTTON_INDEX_DPAD_UP
] = AxisNegativeAsButton(input
.axes
[7]);
218 mapped
->buttons
[BUTTON_INDEX_DPAD_DOWN
] = AxisPositiveAsButton(input
.axes
[7]);
219 mapped
->buttons
[BUTTON_INDEX_DPAD_LEFT
] = AxisNegativeAsButton(input
.axes
[6]);
220 mapped
->buttons
[BUTTON_INDEX_DPAD_RIGHT
] =
221 AxisPositiveAsButton(input
.axes
[6]);
222 mapped
->buttons
[BUTTON_INDEX_META
] = input
.buttons
[6];
224 mapped
->buttonsLength
= BUTTON_INDEX_COUNT
;
225 mapped
->axesLength
= AXIS_INDEX_COUNT
;
229 const char* const vendor_id
;
230 const char* const product_id
;
231 GamepadStandardMappingFunction function
;
232 } AvailableMappings
[] = {
233 // http://www.linux-usb.org/usb.ids
234 {"0079", "0006", MapperDragonRiseGeneric
}, // DragonRise Generic USB
235 {"045e", "028e", MapperXInputStyleGamepad
}, // Xbox 360 Controller
238 MapperXInputStyleGamepad
}, // Xbox 360 Wireless Controller
239 {"046d", "c21d", MapperXInputStyleGamepad
}, // Logitech F310
240 {"046d", "c21e", MapperXInputStyleGamepad
}, // Logitech F510
241 {"046d", "c21f", MapperXInputStyleGamepad
}, // Logitech F710
242 {"054c", "0268", MapperPlaystationSixAxis
}, // Playstation SIXAXIS
243 {"054c", "05c4", MapperDualshock4
}, // Playstation Dualshock 4
244 {"0583", "2060", MapperIBuffalo
}, // iBuffalo Classic
245 {"0925", "0005", MapperLakeviewResearch
}, // SmartJoy PLUS Adapter
246 {"0925", "8866", MapperLakeviewResearch
}, // WiseGroup MP-8866
247 {"0955", "7210", MapperNvShield
}, // Nvidia Shield gamepad
248 {"0e8f", "0003", MapperXGEAR
}, // XFXforce XGEAR PS2 Controller
249 {"18d1", "2c40", MapperADT1
}, // ADT-1 Controller
250 {"2378", "1008", MapperOnLiveWireless
}, // OnLive Controller (Bluetooth)
251 {"2378", "100a", MapperOnLiveWireless
}, // OnLive Controller (Wired)
256 GamepadStandardMappingFunction
GetGamepadStandardMappingFunction(
257 const base::StringPiece
& vendor_id
,
258 const base::StringPiece
& product_id
) {
259 for (size_t i
= 0; i
< arraysize(AvailableMappings
); ++i
) {
260 MappingData
& item
= AvailableMappings
[i
];
261 if (vendor_id
== item
.vendor_id
&& product_id
== item
.product_id
)
262 return item
.function
;
267 } // namespace content