Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: content/browser/gamepad/gamepad_standard_mappings_win.cc

Issue 2081583002: Migrating majority of gamepad from content/browser/ to device/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final tweaks Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include <stddef.h>
6
7 #include "base/macros.h"
8 #include "content/browser/gamepad/gamepad_standard_mappings.h"
9
10 namespace content {
11
12 namespace {
13
14 void MapperLogitechDualAction(const blink::WebGamepad& input,
15 blink::WebGamepad* mapped) {
16 *mapped = input;
17 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
18 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[2];
19 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[0];
20 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
21 DpadFromAxis(mapped, input.axes[9]);
22
23 mapped->buttonsLength = BUTTON_INDEX_COUNT;
24 mapped->axesLength = AXIS_INDEX_COUNT;
25 }
26
27 void Mapper2Axes8Keys(const blink::WebGamepad& input,
28 blink::WebGamepad* mapped) {
29 *mapped = input;
30 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[2];
31 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
32 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
33 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[0];
34 mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[1]);
35 mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[1]);
36 mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[0]);
37 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
38 AxisPositiveAsButton(input.axes[0]);
39
40 // Missing buttons
41 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = blink::WebGamepadButton();
42 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = blink::WebGamepadButton();
43 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = blink::WebGamepadButton();
44 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = blink::WebGamepadButton();
45 mapped->buttons[BUTTON_INDEX_META] = blink::WebGamepadButton();
46
47 mapped->buttonsLength = BUTTON_INDEX_COUNT - 1;
48 mapped->axesLength = 0;
49 }
50
51 void MapperDualshock4(const blink::WebGamepad& input,
52 blink::WebGamepad* mapped) {
53 enum Dualshock4Buttons {
54 DUALSHOCK_BUTTON_TOUCHPAD = BUTTON_INDEX_COUNT,
55 DUALSHOCK_BUTTON_COUNT
56 };
57
58 *mapped = input;
59 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
60 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[2];
61 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[0];
62 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[3];
63 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[4];
64 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[5];
65 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
66 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
67 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[8];
68 mapped->buttons[BUTTON_INDEX_START] = input.buttons[9];
69 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[10];
70 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[11];
71 mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
72 mapped->buttons[DUALSHOCK_BUTTON_TOUCHPAD] = input.buttons[13];
73 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
74 DpadFromAxis(mapped, input.axes[9]);
75
76 mapped->buttonsLength = DUALSHOCK_BUTTON_COUNT;
77 mapped->axesLength = AXIS_INDEX_COUNT;
78 }
79
80 void MapperIBuffalo(const blink::WebGamepad& input, blink::WebGamepad* mapped) {
81 *mapped = input;
82 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
83 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[0];
84 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
85 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[2];
86 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[6];
87 mapped->buttons[BUTTON_INDEX_START] = input.buttons[7];
88 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[4];
89 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[5];
90 mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[1]);
91 mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[1]);
92 mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[0]);
93 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
94 AxisPositiveAsButton(input.axes[0]);
95 mapped->buttonsLength = BUTTON_INDEX_COUNT - 1; /* no meta */
96 mapped->axesLength = 2;
97 }
98
99 void MapperOnLiveWireless(const blink::WebGamepad& input,
100 blink::WebGamepad* mapped) {
101 *mapped = input;
102 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
103 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
104 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
105 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
106 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
107 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
108 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]);
109 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]);
110 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10];
111 mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
112 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
113 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
114 mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
115 mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
116 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
117 DpadFromAxis(mapped, input.axes[9]);
118
119 mapped->buttonsLength = BUTTON_INDEX_COUNT;
120 mapped->axesLength = AXIS_INDEX_COUNT;
121 }
122
123 void MapperADT1(const blink::WebGamepad& input, blink::WebGamepad* mapped) {
124 *mapped = input;
125 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
126 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
127 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
128 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
129 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
130 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
131 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[4]);
132 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[3]);
133 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = NullButton();
134 mapped->buttons[BUTTON_INDEX_START] = NullButton();
135 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
136 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
137 mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
138 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
139 DpadFromAxis(mapped, input.axes[9]);
140
141 mapped->buttonsLength = BUTTON_INDEX_COUNT;
142 mapped->axesLength = AXIS_INDEX_COUNT;
143 }
144
145 void MapperNvShield(const blink::WebGamepad& input, blink::WebGamepad* mapped) {
146 *mapped = input;
147 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
148 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
149 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
150 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
151 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
152 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
153 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[4]);
154 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[3]);
155 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = NullButton();
156 mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
157 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
158 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
159 mapped->buttons[BUTTON_INDEX_META] = input.buttons[8];
160 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
161 DpadFromAxis(mapped, input.axes[9]);
162
163 mapped->buttonsLength = BUTTON_INDEX_COUNT;
164 mapped->axesLength = AXIS_INDEX_COUNT;
165 }
166
167 void MapperOUYA(const blink::WebGamepad& input, blink::WebGamepad* mapped) {
168 *mapped = input;
169 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
170 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[3];
171 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[1];
172 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[2];
173 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[4];
174 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[5];
175 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]);
176 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]);
177 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = NullButton();
178 mapped->buttons[BUTTON_INDEX_START] = NullButton();
179 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[6];
180 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[7];
181 mapped->buttons[BUTTON_INDEX_DPAD_UP] = input.buttons[8];
182 mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = input.buttons[9];
183 mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = input.buttons[10];
184 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] = input.buttons[11];
185 mapped->buttons[BUTTON_INDEX_META] = input.buttons[15];
186 mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
187 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
188
189 mapped->buttonsLength = BUTTON_INDEX_COUNT;
190 mapped->axesLength = AXIS_INDEX_COUNT;
191 }
192
193 void MapperRazerServal(const blink::WebGamepad& input,
194 blink::WebGamepad* mapped) {
195 *mapped = input;
196 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
197 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
198 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
199 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
200 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
201 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
202 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[4]);
203 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[3]);
204 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10];
205 mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
206 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
207 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
208 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
209 DpadFromAxis(mapped, input.axes[9]);
210
211 mapped->buttonsLength = BUTTON_INDEX_COUNT - 1; /* no meta */
212 mapped->axesLength = AXIS_INDEX_COUNT;
213 }
214
215 void MapperMogaPro(const blink::WebGamepad& input, blink::WebGamepad* mapped) {
216 *mapped = input;
217 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
218 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
219 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
220 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
221 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
222 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
223 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[4]);
224 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[3]);
225 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = NullButton();
226 mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
227 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
228 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
229 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
230 DpadFromAxis(mapped, input.axes[9]);
231
232 mapped->buttonsLength = BUTTON_INDEX_COUNT - 1; /* no meta */
233 mapped->axesLength = AXIS_INDEX_COUNT;
234 }
235
236 struct MappingData {
237 const char* const vendor_id;
238 const char* const product_id;
239 GamepadStandardMappingFunction function;
240 } AvailableMappings[] = {
241 // http://www.linux-usb.org/usb.ids
242 {"0079", "0011", Mapper2Axes8Keys}, // 2Axes 8Keys Game Pad
243 {"046d", "c216", MapperLogitechDualAction}, // Logitech DualAction
244 {"054c", "05c4", MapperDualshock4}, // Playstation Dualshock 4
245 {"0583", "2060", MapperIBuffalo}, // iBuffalo Classic
246 {"0955", "7210", MapperNvShield}, // Nvidia Shield gamepad
247 {"0b05", "4500", MapperADT1}, // Nexus Player Controller
248 {"1532", "0900", MapperRazerServal}, // Razer Serval Controller
249 {"18d1", "2c40", MapperADT1}, // ADT-1 Controller
250 {"20d6", "6271", MapperMogaPro}, // Moga Pro Controller (HID mode)
251 {"2378", "1008", MapperOnLiveWireless}, // OnLive Controller (Bluetooth)
252 {"2378", "100a", MapperOnLiveWireless}, // OnLive Controller (Wired)
253 {"2836", "0001", MapperOUYA}, // OUYA Controller
254 };
255
256 } // namespace
257
258 GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
259 const base::StringPiece& vendor_id,
260 const base::StringPiece& product_id) {
261 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
262 MappingData& item = AvailableMappings[i];
263 if (vendor_id == item.vendor_id && product_id == item.product_id)
264 return item.function;
265 }
266 return NULL;
267 }
268
269 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gamepad/gamepad_standard_mappings_mac.mm ('k') | content/browser/gamepad/gamepad_test_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698