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

Side by Side Diff: ui/events/ozone/gamepad/static_gamepad_mapping.cc

Issue 2926373002: Add static gamepad mapper for Nvidia Shield and Nintendo Switch (Closed)
Patch Set: Add static gamepad mapper for Nvidia Shield and Nintendo Switch Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 <linux/input.h> 5 #include <linux/input.h>
6 #include <cstdint> 6 #include <cstdint>
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 static const AbsMapType abs_mapping = { 124 static const AbsMapType abs_mapping = {
125 TO_ABS(ABS_X, WG_ABS_X), 125 TO_ABS(ABS_X, WG_ABS_X),
126 TO_ABS(ABS_Y, WG_ABS_Y), 126 TO_ABS(ABS_Y, WG_ABS_Y),
127 TO_ABS(ABS_Z, WG_ABS_RX), 127 TO_ABS(ABS_Z, WG_ABS_RX),
128 TO_ABS(ABS_RZ, WG_ABS_RY), 128 TO_ABS(ABS_RZ, WG_ABS_RY),
129 TO_BTN(ABS_MT_TOUCH_MAJOR, WG_BUTTON_LT), 129 TO_BTN(ABS_MT_TOUCH_MAJOR, WG_BUTTON_LT),
130 TO_BTN(ABS_MT_TOUCH_MINOR, WG_BUTTON_RT)}; 130 TO_BTN(ABS_MT_TOUCH_MINOR, WG_BUTTON_RT)};
131 return DO_MAPPING; 131 return DO_MAPPING;
132 } 132 }
133 133
134 bool DualShock4Mapper(uint16_t type,
135 uint16_t code,
136 GamepadEventType* mapped_type,
137 uint16_t* mapped_code) {
138 static const KeyMapType key_mapping = {
139 {BTN_A, WG_BUTTON_A}, {BTN_B, WG_BUTTON_B},
140 {BTN_C, WG_BUTTON_X}, {BTN_X, WG_BUTTON_Y},
141 {BTN_Y, WG_BUTTON_L1}, {BTN_Z, WG_BUTTON_R1},
142 {BTN_TL, WG_BUTTON_LT}, {BTN_TR, WG_BUTTON_RT},
143 {BTN_TL2, WG_BUTTON_SELECT}, {BTN_TR2, WG_BUTTON_START},
144 {BTN_SELECT, WG_BUTTON_THUMBL}, {BTN_START, WG_BUTTON_THUMBR}};
145
146 static const AbsMapType abs_mapping = {
147 TO_ABS(ABS_X, WG_ABS_X), TO_ABS(ABS_Y, WG_ABS_Y),
148 TO_ABS(ABS_RX, WG_BUTTON_LT), TO_ABS(ABS_RY, WG_BUTTON_RT),
149 TO_ABS(ABS_Z, WG_ABS_RX), TO_ABS(ABS_RZ, WG_ABS_RY),
150 TO_BTN(ABS_HAT0X, kHAT_X), TO_BTN(ABS_HAT0Y, kHAT_Y)};
151 return DO_MAPPING;
152 }
153
154 bool NintendoSwitchLeft(uint16_t type,
155 uint16_t code,
156 GamepadEventType* mapped_type,
157 uint16_t* mapped_code) {
158 static const KeyMapType key_mapping = {
159 {BTN_A, WG_BUTTON_A}, {BTN_B, WG_BUTTON_B},
160 {BTN_C, WG_BUTTON_X}, {BTN_X, WG_BUTTON_Y},
161 {BTN_Y, WG_BUTTON_L1}, {BTN_Z, WG_BUTTON_R1},
162 {BTN_TL2, WG_BUTTON_SELECT}, {BTN_THUMBL, WG_BUTTON_START}};
163
164 static const AbsMapType abs_mapping = {TO_BTN(ABS_HAT0X, kHAT_X),
165 TO_BTN(ABS_HAT0Y, kHAT_Y)};
166 return DO_MAPPING;
167 }
168
169 bool NintendoSwitchRight(uint16_t type,
170 uint16_t code,
171 GamepadEventType* mapped_type,
172 uint16_t* mapped_code) {
173 static const KeyMapType key_mapping = {
174 {BTN_A, WG_BUTTON_A}, {BTN_B, WG_BUTTON_B},
175 {BTN_C, WG_BUTTON_X}, {BTN_X, WG_BUTTON_Y},
176 {BTN_Y, WG_BUTTON_L1}, {BTN_Z, WG_BUTTON_R1},
177 {BTN_MODE, WG_BUTTON_SELECT}, {BTN_TR2, WG_BUTTON_START}};
178
179 static const AbsMapType abs_mapping = {TO_BTN(ABS_HAT0X, kHAT_X),
180 TO_BTN(ABS_HAT0Y, kHAT_Y)};
181 return DO_MAPPING;
182 }
183
134 bool IBuffalocClassicMapper(uint16_t type, 184 bool IBuffalocClassicMapper(uint16_t type,
135 uint16_t code, 185 uint16_t code,
136 GamepadEventType* mapped_type, 186 GamepadEventType* mapped_type,
137 uint16_t* mapped_code) { 187 uint16_t* mapped_code) {
138 static const KeyMapType key_mapping = { 188 static const KeyMapType key_mapping = {
139 {BTN_TRIGGER, WG_BUTTON_A}, {BTN_THUMB, WG_BUTTON_B}, 189 {BTN_TRIGGER, WG_BUTTON_A}, {BTN_THUMB, WG_BUTTON_B},
140 {BTN_THUMB2, WG_BUTTON_X}, {BTN_TOP, WG_BUTTON_Y}, 190 {BTN_THUMB2, WG_BUTTON_X}, {BTN_TOP, WG_BUTTON_Y},
141 {BTN_BASE, WG_BUTTON_L1}, {BTN_BASE2, WG_BUTTON_R1}, 191 {BTN_BASE, WG_BUTTON_L1}, {BTN_BASE2, WG_BUTTON_R1},
142 {BTN_TOP2, WG_BUTTON_LT}, {BTN_PINKIE, WG_BUTTON_RT}}; 192 {BTN_TOP2, WG_BUTTON_LT}, {BTN_PINKIE, WG_BUTTON_RT}};
143 193
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 {BTN_TL2, WG_BUTTON_SELECT}, {BTN_TR2, WG_BUTTON_START}, 403 {BTN_TL2, WG_BUTTON_SELECT}, {BTN_TR2, WG_BUTTON_START},
354 {BTN_SELECT, WG_BUTTON_THUMBL}, {BTN_START, WG_BUTTON_THUMBR}}; 404 {BTN_SELECT, WG_BUTTON_THUMBL}, {BTN_START, WG_BUTTON_THUMBR}};
355 405
356 static const AbsMapType abs_mapping = { 406 static const AbsMapType abs_mapping = {
357 TO_ABS(ABS_X, WG_ABS_X), TO_ABS(ABS_Y, WG_ABS_Y), 407 TO_ABS(ABS_X, WG_ABS_X), TO_ABS(ABS_Y, WG_ABS_Y),
358 TO_ABS(ABS_Z, WG_ABS_RX), TO_ABS(ABS_RZ, WG_ABS_RY), 408 TO_ABS(ABS_Z, WG_ABS_RX), TO_ABS(ABS_RZ, WG_ABS_RY),
359 TO_BTN(ABS_HAT0X, kHAT_X), TO_BTN(ABS_HAT0Y, kHAT_Y)}; 409 TO_BTN(ABS_HAT0X, kHAT_X), TO_BTN(ABS_HAT0Y, kHAT_Y)};
360 return DO_MAPPING; 410 return DO_MAPPING;
361 } 411 }
362 412
363 bool DualShock4(uint16_t type, 413 bool NvidiaShieldMapper(uint16_t type,
364 uint16_t code, 414 uint16_t code,
365 GamepadEventType* mapped_type, 415 GamepadEventType* mapped_type,
366 uint16_t* mapped_code) { 416 uint16_t* mapped_code) {
367 static const KeyMapType key_mapping = { 417 static const KeyMapType key_mapping = {
368 {BTN_A, WG_BUTTON_A}, {BTN_B, WG_BUTTON_B}, 418 {BTN_A, WG_BUTTON_A}, {BTN_B, WG_BUTTON_B},
369 {BTN_C, WG_BUTTON_X}, {BTN_X, WG_BUTTON_Y}, 419 {BTN_X, WG_BUTTON_X}, {BTN_Y, WG_BUTTON_Y},
370 {BTN_Y, WG_BUTTON_L1}, {BTN_Z, WG_BUTTON_R1}, 420 {BTN_TL, WG_BUTTON_L1}, {BTN_TR, WG_BUTTON_R1},
371 {BTN_TL, WG_BUTTON_LT}, {BTN_TR, WG_BUTTON_RT}, 421 {KEY_BACK, WG_BUTTON_SELECT}, {BTN_START, WG_BUTTON_START},
372 {BTN_TL2, WG_BUTTON_SELECT}, {BTN_TR2, WG_BUTTON_START}, 422 {KEY_HOMEPAGE, WG_BUTTON_MODE}, {BTN_THUMBL, WG_BUTTON_THUMBL},
373 {BTN_SELECT, WG_BUTTON_THUMBL}, {BTN_START, WG_BUTTON_THUMBR}}; 423 {BTN_THUMBR, WG_BUTTON_THUMBR}};
374 424
375 static const AbsMapType abs_mapping = { 425 static const AbsMapType abs_mapping = {
376 TO_ABS(ABS_X, WG_ABS_X), TO_ABS(ABS_Y, WG_ABS_Y), 426 TO_ABS(ABS_X, WG_ABS_X), TO_ABS(ABS_Y, WG_ABS_Y),
377 TO_ABS(ABS_RX, WG_BUTTON_LT), TO_ABS(ABS_RY, WG_BUTTON_RT), 427 TO_ABS(ABS_Z, WG_ABS_RX), TO_ABS(ABS_RZ, WG_ABS_RY),
378 TO_ABS(ABS_Z, WG_ABS_RX), TO_ABS(ABS_RZ, WG_ABS_RY), 428 TO_BTN(ABS_BRAKE, WG_BUTTON_LT), TO_BTN(ABS_GAS, WG_BUTTON_RT),
379 TO_BTN(ABS_HAT0X, kHAT_X), TO_BTN(ABS_HAT0Y, kHAT_Y)}; 429 TO_BTN(ABS_HAT0X, kHAT_X), TO_BTN(ABS_HAT0Y, kHAT_Y)};
380 return DO_MAPPING; 430 return DO_MAPPING;
381 } 431 }
382 432
383 static const struct MappingData { 433 static const struct MappingData {
384 uint16_t vendor_id; 434 uint16_t vendor_id;
385 uint16_t product_id; 435 uint16_t product_id;
386 GamepadMapperFunction mapper; 436 GamepadMapperFunction mapper;
387 } AvailableMappings[] = { 437 } AvailableMappings[] = {
388 // Xbox style gamepad. 438 // Xbox style gamepad.
389 {0x045e, 0x028e, XInputStyleMapper}, // Xbox 360 wired. 439 {0x045e, 0x028e, XInputStyleMapper}, // Xbox 360 wired.
(...skipping 10 matching lines...) Expand all
400 {0x2378, 0x1008, XInputStyleMapper}, // Onlive controller (bluetooth). 450 {0x2378, 0x1008, XInputStyleMapper}, // Onlive controller (bluetooth).
401 {0x2378, 0x100a, XInputStyleMapper}, // Onlive controller (wired). 451 {0x2378, 0x100a, XInputStyleMapper}, // Onlive controller (wired).
402 {0x1bad, 0xf016, XInputStyleMapper}, // Mad catz gamepad. 452 {0x1bad, 0xf016, XInputStyleMapper}, // Mad catz gamepad.
403 {0x1bad, 0xf023, XInputStyleMapper}, // Mad catz mlg gamepad for Xbox360. 453 {0x1bad, 0xf023, XInputStyleMapper}, // Mad catz mlg gamepad for Xbox360.
404 {0x1bad, 0xf027, XInputStyleMapper}, // Mad catz fps pro. 454 {0x1bad, 0xf027, XInputStyleMapper}, // Mad catz fps pro.
405 {0x1bad, 0xf036, XInputStyleMapper}, // Mad catz generic Xbox controller. 455 {0x1bad, 0xf036, XInputStyleMapper}, // Mad catz generic Xbox controller.
406 {0x1689, 0xfd01, XInputStyleMapper}, // Razer Xbox 360 gamepad. 456 {0x1689, 0xfd01, XInputStyleMapper}, // Razer Xbox 360 gamepad.
407 {0x1689, 0xfe00, XInputStyleMapper}, // Razer sabertooth elite. 457 {0x1689, 0xfe00, XInputStyleMapper}, // Razer sabertooth elite.
408 // Sony gamepads. 458 // Sony gamepads.
409 {0x054c, 0x0268, PlaystationSixAxisMapper}, // Playstation 3. 459 {0x054c, 0x0268, PlaystationSixAxisMapper}, // Playstation 3.
410 {0x054c, 0x05c4, DualShock4}, // Dualshock 4. 460 {0x054c, 0x05c4, DualShock4Mapper}, // Dualshock 4.
461 // Nintendo switch.
462 {0x057e, 0x2006, NintendoSwitchLeft}, // Nintendo switch left.
463 {0x057e, 0x2007, NintendoSwitchRight}, // Nintendo switch right.
411 // NES style gamepad. 464 // NES style gamepad.
412 {0x0583, 0x2060, IBuffalocClassicMapper}, // iBuffalo Classic. 465 {0x0583, 0x2060, IBuffalocClassicMapper}, // iBuffalo Classic.
413 {0x0079, 0x0011, ClassicNESMapper}, // Classic NES controller. 466 {0x0079, 0x0011, ClassicNESMapper}, // Classic NES controller.
414 {0x12bd, 0xd015, SNesRetroMapper}, // Hitgaming SNES retro. 467 {0x12bd, 0xd015, SNesRetroMapper}, // Hitgaming SNES retro.
415 // Android gamepad. 468 // Android gamepad.
416 {0x0b05, 0x4500, ADT1Mapper}, // Nexus player controller (asus gamepad). 469 {0x0b05, 0x4500, ADT1Mapper}, // Nexus player controller (asus gamepad).
417 {0x1532, 0x0900, ADT1Mapper}, // Razer serval. 470 {0x1532, 0x0900, ADT1Mapper}, // Razer serval.
418 {0x18d1, 0x2c40, ADT1Mapper}, // ADT-1 controller (odie). 471 {0x18d1, 0x2c40, ADT1Mapper}, // ADT-1 controller (odie).
419 // Other gamepads. 472 // Other gamepads.
420 {0x1d79, 0x0009, 473 {0x1d79, 0x0009,
421 Vendor_1d79Product_0009Mapper}, // Nyko playpad / Playpad pro. 474 Vendor_1d79Product_0009Mapper}, // Nyko playpad / Playpad pro.
422 {0x046d, 0xb501, Vendor_046dProduct_b501Mapper}, // Logitech redhawk. 475 {0x046d, 0xb501, Vendor_046dProduct_b501Mapper}, // Logitech redhawk.
423 // Logitech dual action controller. 476 // Logitech dual action controller.
424 {0x046d, 0xc216, Vendor_046dProduct_c216Mapper}, 477 {0x046d, 0xc216, Vendor_046dProduct_c216Mapper},
425 // Logitech cordless rumblepad2. 478 // Logitech cordless rumblepad2.
426 {0x046d, 0xc219, Vendor_046dProduct_c219Mapper}, 479 {0x046d, 0xc219, Vendor_046dProduct_c219Mapper},
427 {0x1038, 0x1412, Vendor_1038Product_1412Mapper}, // Steelseries free. 480 {0x1038, 0x1412, Vendor_1038Product_1412Mapper}, // Steelseries free.
428 // Razer onza tournment edition. 481 // Razer onza tournment edition.
429 {0x1689, 0xfd00, Vendor_1689Product_fd00Mapper}, 482 {0x1689, 0xfd00, Vendor_1689Product_fd00Mapper},
430 {0x11c5, 0x5506, JoydevLikeMapper} // HJC Game ZD-V 483 {0x0955, 0x7214, NvidiaShieldMapper}, // Nvidia shield.
484 {0x11c5, 0x5506, JoydevLikeMapper} // HJC Game ZD-V
431 }; 485 };
432 486
433 class StaticGamepadMapper : public GamepadMapper { 487 class StaticGamepadMapper : public GamepadMapper {
434 public: 488 public:
435 StaticGamepadMapper(GamepadMapperFunction fp) : mapper_fp_(fp) {} 489 StaticGamepadMapper(GamepadMapperFunction fp) : mapper_fp_(fp) {}
436 490
437 bool Map(uint16_t type, 491 bool Map(uint16_t type,
438 uint16_t code, 492 uint16_t code,
439 GamepadEventType* mapped_type, 493 GamepadEventType* mapped_type,
440 uint16_t* mapped_code) const override { 494 uint16_t* mapped_code) const override {
441 return mapper_fp_(type, code, mapped_type, mapped_code); 495 return mapper_fp_(type, code, mapped_type, mapped_code);
442 }; 496 };
443 497
444 private: 498 private:
445 GamepadMapperFunction mapper_fp_; 499 GamepadMapperFunction mapper_fp_;
446 }; 500 };
447 501
448 GamepadMapper* GetStaticGamepadMapper(uint16_t vendor_id, uint16_t product_id) { 502 GamepadMapper* GetStaticGamepadMapper(uint16_t vendor_id, uint16_t product_id) {
449 for (size_t i = 0; i < arraysize(AvailableMappings); i++) { 503 for (size_t i = 0; i < arraysize(AvailableMappings); i++) {
450 if (AvailableMappings[i].vendor_id == vendor_id && 504 if (AvailableMappings[i].vendor_id == vendor_id &&
451 AvailableMappings[i].product_id == product_id) { 505 AvailableMappings[i].product_id == product_id) {
452 return new StaticGamepadMapper(AvailableMappings[i].mapper); 506 return new StaticGamepadMapper(AvailableMappings[i].mapper);
453 } 507 }
454 } 508 }
455 return nullptr; 509 return nullptr;
456 } 510 }
457 511
458 } // namespace ui 512 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698