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

Side by Side Diff: content/browser/gamepad/gamepad_standard_mappings_mac.mm

Issue 9270015: Add Mac gamepad input remapper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix linux Created 8 years, 11 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 | Annotate | Revision Log
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 "content/browser/gamepad/gamepad_standard_mappings.h"
6
7 #include "content/common/gamepad_hardware_buffer.h"
8
9 namespace content {
10
11 namespace {
12
13 float AxisToButton(float input) {
14 return (input + 1.f) / 2.f;
15 }
16
17 void MapperXbox360Gamepad(
18 const WebKit::WebGamepad& input,
19 WebKit::WebGamepad* mapped) {
20 *mapped = input;
21 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[2]);
22 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[5]);
23 mapped->buttons[kButtonBackSelect] = input.buttons[9];
24 mapped->buttons[kButtonStart] = input.buttons[8];
25 mapped->buttons[kButtonLeftThumbstick] = input.buttons[6];
26 mapped->buttons[kButtonRightThumbstick] = input.buttons[7];
27 mapped->buttons[kButtonDpadUp] = input.buttons[11];
28 mapped->buttons[kButtonDpadDown] = input.buttons[12];
29 mapped->buttons[kButtonDpadLeft] = input.buttons[13];
30 mapped->buttons[kButtonDpadRight] = input.buttons[14];
31 mapped->buttons[kButtonMeta] = input.buttons[10];
32 mapped->axes[kAxisRightStickX] = input.axes[3];
33 mapped->axes[kAxisRightStickY] = input.axes[4];
34 mapped->buttonsLength = kNumButtons;
35 mapped->axesLength = kNumAxes;
36 }
37
38 void MapperPlaystationSixAxis(
39 const WebKit::WebGamepad& input,
40 WebKit::WebGamepad* mapped) {
41 *mapped = input;
42 mapped->buttons[kButtonPrimary] = input.buttons[14];
43 mapped->buttons[kButtonSecondary] = input.buttons[13];
44 mapped->buttons[kButtonTertiary] = input.buttons[15];
45 mapped->buttons[kButtonQuaternary] = input.buttons[12];
46 mapped->buttons[kButtonLeftShoulder] = input.buttons[10];
47 mapped->buttons[kButtonRightShoulder] = input.buttons[11];
48 mapped->buttons[kButtonLeftTrigger] = input.buttons[8];
49 mapped->buttons[kButtonRightTrigger] = input.buttons[9];
50 mapped->buttons[kButtonBackSelect] = input.buttons[0];
51 mapped->buttons[kButtonStart] = input.buttons[3];
52 mapped->buttons[kButtonLeftThumbstick] = input.buttons[1];
53 mapped->buttons[kButtonRightThumbstick] = input.buttons[2];
54 mapped->buttons[kButtonDpadUp] = input.buttons[4];
55 mapped->buttons[kButtonDpadDown] = input.buttons[6];
56 mapped->buttons[kButtonDpadLeft] = input.buttons[7];
57 mapped->buttons[kButtonDpadRight] = input.buttons[5];
58 mapped->buttons[kButtonMeta] = input.buttons[16];
59 mapped->axes[kAxisRightStickY] = input.axes[5];
60
61 mapped->buttonsLength = kNumButtons;
62 mapped->axesLength = kNumAxes;
63 }
64
65 void MapperMacallyIshock(
66 const WebKit::WebGamepad& input,
67 WebKit::WebGamepad* mapped) {
68 *mapped = input;
69 mapped->buttons[kButtonPrimary] = input.buttons[1];
70 mapped->buttons[kButtonSecondary] = input.buttons[2];
71 mapped->buttons[kButtonTertiary] = input.buttons[0];
72 mapped->axes[kAxisRightStickY] = input.axes[5];
73
74 // Dpad is mapped as a direction on one axis, where -1 is up and it
75 // increases clockwise to 1, which is up + left. It's set to a large (> 1.f)
76 // number when nothing is depressed, except on start up, sometimes it's 0.0
77 // for no data, rather than the large number.
78 float dir = input.axes[9];
79 if (dir == 0.0f) {
80 mapped->buttons[kButtonDpadUp] = 0.f;
81 mapped->buttons[kButtonDpadDown] = 0.f;
82 mapped->buttons[kButtonDpadLeft] = 0.f;
83 mapped->buttons[kButtonDpadRight] = 0.f;
84 } else {
85 mapped->buttons[kButtonDpadUp] = (dir >= -1.f && dir < -0.7f) ||
86 (dir >= .95f && dir <= 1.f);
87 mapped->buttons[kButtonDpadRight] = dir >= -.75f && dir < -.1f;
88 mapped->buttons[kButtonDpadDown] = dir >= -.2f && dir < .45f;
89 mapped->buttons[kButtonDpadLeft] = dir >= .4f && dir <= 1.f;
90 }
91
92 mapped->buttonsLength = kNumButtons - 1; /* no meta */
93 mapped->axesLength = kNumAxes;
94 }
95
96
97 struct MappingData {
98 const char* const vendor_id;
99 const char* const product_id;
100 GamepadStandardMappingFunction function;
101 } AvailableMappings[] = {
102 // http://www.linux-usb.org/usb.ids
103 { "045e", "028e", MapperXbox360Gamepad }, // Xbox 360 Controller
104 { "045e", "028f", MapperXbox360Gamepad }, // Xbox 360 Wireless Controller
105 { "054c", "0268", MapperPlaystationSixAxis }, // Playstation SIXAXIS
106 { "2222", "0060", MapperMacallyIshock }, // Macally iShockX, analog mode
107 };
108
109 } // namespace
110
111 GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
112 const base::StringPiece& vendor_id,
113 const base::StringPiece& product_id) {
114 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
115 MappingData& item = AvailableMappings[i];
116 if (vendor_id == item.vendor_id && product_id == item.product_id)
117 return item.function;
118 }
119 return NULL;
120 }
121
122 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gamepad/gamepad_standard_mappings_linux.cc ('k') | content/browser/gamepad/platform_data_fetcher_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698