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

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

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 void DpadFromAxis(blink::WebGamepad* mapped, float dir) {
18 // Dpad is mapped as a direction on one axis, where -1 is up and it
19 // increases clockwise to 1, which is up + left. It's set to a large (> 1.f)
20 // number when nothing is depressed, except on start up, sometimes it's 0.0
21 // for no data, rather than the large number.
22 if (dir == 0.0f) {
23 mapped->buttons[kButtonDpadUp] = 0.f;
24 mapped->buttons[kButtonDpadDown] = 0.f;
25 mapped->buttons[kButtonDpadLeft] = 0.f;
26 mapped->buttons[kButtonDpadRight] = 0.f;
27 } else {
28 mapped->buttons[kButtonDpadUp] = (dir >= -1.f && dir < -0.7f) ||
29 (dir >= .95f && dir <= 1.f);
30 mapped->buttons[kButtonDpadRight] = dir >= -.75f && dir < -.1f;
31 mapped->buttons[kButtonDpadDown] = dir >= -.2f && dir < .45f;
32 mapped->buttons[kButtonDpadLeft] = dir >= .4f && dir <= 1.f;
33 }
34 }
35
36 void MapperXbox360Gamepad( 11 void MapperXbox360Gamepad(
37 const blink::WebGamepad& input, 12 const blink::WebGamepad& input,
38 blink::WebGamepad* mapped) { 13 blink::WebGamepad* mapped) {
39 *mapped = input; 14 *mapped = input;
40 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[2]); 15 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[2]);
41 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[5]); 16 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[5]);
42 mapped->buttons[kButtonBackSelect] = input.buttons[9]; 17 mapped->buttons[kButtonBackSelect] = input.buttons[9];
43 mapped->buttons[kButtonStart] = input.buttons[8]; 18 mapped->buttons[kButtonStart] = input.buttons[8];
44 mapped->buttons[kButtonLeftThumbstick] = input.buttons[6]; 19 mapped->buttons[kButtonLeftThumbstick] = input.buttons[6];
45 mapped->buttons[kButtonRightThumbstick] = input.buttons[7]; 20 mapped->buttons[kButtonRightThumbstick] = input.buttons[7];
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 const base::StringPiece& product_id) { 243 const base::StringPiece& product_id) {
269 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { 244 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
270 MappingData& item = AvailableMappings[i]; 245 MappingData& item = AvailableMappings[i];
271 if (vendor_id == item.vendor_id && product_id == item.product_id) 246 if (vendor_id == item.vendor_id && product_id == item.product_id)
272 return item.function; 247 return item.function;
273 } 248 }
274 return NULL; 249 return NULL;
275 } 250 }
276 251
277 } // namespace content 252 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gamepad/gamepad_standard_mappings_linux.cc ('k') | content/browser/gamepad/gamepad_standard_mappings_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698