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

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

Issue 165983005: Updating Gamepad API to match latest spec (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed typo in GamepadProviderTest Created 6 years, 9 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
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 "content/browser/gamepad/gamepad_standard_mappings.h" 5 #include "content/browser/gamepad/gamepad_standard_mappings.h"
6 6
7 #include "content/common/gamepad_hardware_buffer.h"
8
9 namespace content { 7 namespace content {
10 8
11 namespace { 9 namespace {
12 10
13 float AxisToButton(float input) {
14 return (input + 1.f) / 2.f;
15 }
16
17 float AxisNegativeAsButton(float input) {
18 return (input < -0.5f) ? 1.f : 0.f;
19 }
20
21 float AxisPositiveAsButton(float input) {
22 return (input > 0.5f) ? 1.f : 0.f;
23 }
24
25 void DpadFromAxis(blink::WebGamepad* mapped, float dir) {
26 // Dpad is mapped as a direction on one axis, where -1 is up and it
27 // increases clockwise to 1, which is up + left. It's set to a large (> 1.f)
28 // number when nothing is depressed, except on start up, sometimes it's 0.0
29 // for no data, rather than the large number.
30 if (dir == 0.0f) {
31 mapped->buttons[kButtonDpadUp] = 0.f;
32 mapped->buttons[kButtonDpadDown] = 0.f;
33 mapped->buttons[kButtonDpadLeft] = 0.f;
34 mapped->buttons[kButtonDpadRight] = 0.f;
35 } else {
36 mapped->buttons[kButtonDpadUp] = (dir >= -1.f && dir < -0.7f) ||
37 (dir >= .95f && dir <= 1.f);
38 mapped->buttons[kButtonDpadRight] = dir >= -.75f && dir < -.1f;
39 mapped->buttons[kButtonDpadDown] = dir >= -.2f && dir < .45f;
40 mapped->buttons[kButtonDpadLeft] = dir >= .4f && dir <= 1.f;
41 }
42 }
43
44 void MapperLogitechDualAction( 11 void MapperLogitechDualAction(
45 const blink::WebGamepad& input, 12 const blink::WebGamepad& input,
46 blink::WebGamepad* mapped) { 13 blink::WebGamepad* mapped) {
47 *mapped = input; 14 *mapped = input;
48 mapped->buttons[kButtonPrimary] = input.buttons[1]; 15 mapped->buttons[kButtonPrimary] = input.buttons[1];
49 mapped->buttons[kButtonSecondary] = input.buttons[2]; 16 mapped->buttons[kButtonSecondary] = input.buttons[2];
50 mapped->buttons[kButtonTertiary] = input.buttons[0]; 17 mapped->buttons[kButtonTertiary] = input.buttons[0];
51 mapped->axes[kAxisRightStickY] = input.axes[5]; 18 mapped->axes[kAxisRightStickY] = input.axes[5];
52 DpadFromAxis(mapped, input.axes[9]); 19 DpadFromAxis(mapped, input.axes[9]);
53 20
54 mapped->buttonsLength = kNumButtons; 21 mapped->buttonsLength = kNumButtons;
55 mapped->axesLength = kNumAxes; 22 mapped->axesLength = kNumAxes;
56 } 23 }
57 24
58 void Mapper2Axes8Keys( 25 void Mapper2Axes8Keys(
59 const blink::WebGamepad& input, 26 const blink::WebGamepad& input,
60 blink::WebGamepad* mapped) { 27 blink::WebGamepad* mapped) {
61 *mapped = input; 28 *mapped = input;
62 mapped->buttons[kButtonPrimary] = input.buttons[2]; 29 mapped->buttons[kButtonPrimary] = input.buttons[2];
63 mapped->buttons[kButtonSecondary] = input.buttons[1]; 30 mapped->buttons[kButtonSecondary] = input.buttons[1];
64 mapped->buttons[kButtonTertiary] = input.buttons[3]; 31 mapped->buttons[kButtonTertiary] = input.buttons[3];
65 mapped->buttons[kButtonQuaternary] = input.buttons[0]; 32 mapped->buttons[kButtonQuaternary] = input.buttons[0];
66 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[1]); 33 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[1]);
67 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[1]); 34 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[1]);
68 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[0]); 35 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[0]);
69 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[0]); 36 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[0]);
70 37
71 // Missing buttons 38 // Missing buttons
72 mapped->buttons[kButtonLeftTrigger] = 0; 39 mapped->buttons[kButtonLeftTrigger] = blink::WebGamepadButton();
73 mapped->buttons[kButtonRightTrigger] = 0; 40 mapped->buttons[kButtonRightTrigger] = blink::WebGamepadButton();
74 mapped->buttons[kButtonLeftThumbstick] = 0; 41 mapped->buttons[kButtonLeftThumbstick] = blink::WebGamepadButton();
75 mapped->buttons[kButtonRightThumbstick] = 0; 42 mapped->buttons[kButtonRightThumbstick] = blink::WebGamepadButton();
76 mapped->buttons[kButtonMeta] = 0; 43 mapped->buttons[kButtonMeta] = blink::WebGamepadButton();
77 44
78 mapped->buttonsLength = kNumButtons - 1; 45 mapped->buttonsLength = kNumButtons - 1;
79 mapped->axesLength = 0; 46 mapped->axesLength = 0;
80 } 47 }
81 48
82 void MapperDualshock4( 49 void MapperDualshock4(
83 const blink::WebGamepad& input, 50 const blink::WebGamepad& input,
84 blink::WebGamepad* mapped) { 51 blink::WebGamepad* mapped) {
85 enum Dualshock4Buttons { 52 enum Dualshock4Buttons {
86 kTouchpadButton = kNumButtons, 53 kTouchpadButton = kNumButtons,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 const base::StringPiece& product_id) { 121 const base::StringPiece& product_id) {
155 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { 122 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
156 MappingData& item = AvailableMappings[i]; 123 MappingData& item = AvailableMappings[i];
157 if (vendor_id == item.vendor_id && product_id == item.product_id) 124 if (vendor_id == item.vendor_id && product_id == item.product_id)
158 return item.function; 125 return item.function;
159 } 126 }
160 return NULL; 127 return NULL;
161 } 128 }
162 129
163 } // namespace content 130 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698