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

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

Issue 12260011: Support DirectInput gamepads on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 10 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 "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 // Maps 0..65535 to -1..1.
14 float NormalizeDirectInputAxis(long value) {
15 return (value * 1.f / 32767.5f) - 1.f;
16 }
17
18 float AxisNegativeAsButton(long value) {
19 return (value < 32767) ? 1.f : 0.f;
20 }
21
22 float AxisPositiveAsButton(long value) {
23 return (value > 32767) ? 1.f : 0.f;
24 }
25
26 void MapperDragonRiseGeneric(
27 const WebKit::WebGamepad& input,
28 WebKit::WebGamepad* mapped) {
29 *mapped = input;
30 mapped->buttons[0] = input.buttons[1];
31 mapped->buttons[1] = input.buttons[2];
32 mapped->buttons[2] = input.buttons[0];
33 mapped->buttons[12] = input.buttons[16];
34 mapped->buttons[13] = input.buttons[17];
35 mapped->buttons[14] = input.buttons[18];
36 mapped->buttons[15] = input.buttons[19];
37 mapped->buttonsLength = 16;
38 mapped->axes[0] = NormalizeDirectInputAxis(input.axes[0]);
39 mapped->axes[1] = NormalizeDirectInputAxis(input.axes[1]);
40 mapped->axes[2] = NormalizeDirectInputAxis(input.axes[2]);
41 mapped->axes[3] = NormalizeDirectInputAxis(input.axes[5]);
42 mapped->axesLength = 4;
43 }
44
45 void MapperLogitechDualAction(
46 const WebKit::WebGamepad& input,
47 WebKit::WebGamepad* mapped) {
48 *mapped = input;
49 mapped->buttons[0] = input.buttons[1];
50 mapped->buttons[1] = input.buttons[2];
51 mapped->buttons[2] = input.buttons[0];
52 mapped->buttons[12] = input.buttons[16];
53 mapped->buttons[13] = input.buttons[17];
54 mapped->buttons[14] = input.buttons[18];
55 mapped->buttons[15] = input.buttons[19];
56 mapped->buttonsLength = 16;
57 mapped->axes[0] = NormalizeDirectInputAxis(input.axes[0]);
58 mapped->axes[1] = NormalizeDirectInputAxis(input.axes[1]);
59 mapped->axes[2] = NormalizeDirectInputAxis(input.axes[2]);
60 mapped->axes[3] = NormalizeDirectInputAxis(input.axes[5]);
61 mapped->axesLength = 4;
62 }
63
64 void MapperLogitechPrecision(
65 const WebKit::WebGamepad& input,
66 WebKit::WebGamepad* mapped) {
67 *mapped = input;
68 mapped->buttons[0] = input.buttons[1];
69 mapped->buttons[1] = input.buttons[2];
70 mapped->buttons[2] = input.buttons[0];
71 mapped->buttons[10] = 0; // Not present
72 mapped->buttons[11] = 0; // Not present
73 mapped->buttons[12] = AxisNegativeAsButton(input.axes[1]);
74 mapped->buttons[13] = AxisPositiveAsButton(input.axes[1]);
75 mapped->buttons[14] = AxisNegativeAsButton(input.axes[0]);
76 mapped->buttons[15] = AxisPositiveAsButton(input.axes[0]);
77 mapped->buttonsLength = 16;
78 mapped->axesLength = 0;
79 }
80
81 struct MappingData {
82 const char* const vendor_id;
83 const char* const product_id;
84 GamepadStandardMappingFunction function;
85 } AvailableMappings[] = {
86 // http://www.linux-usb.org/usb.ids
87 { "0079", "0006", MapperDragonRiseGeneric }, // DragonRise Generic USB
88 { "046d", "c216", MapperLogitechDualAction }, // Logitech DualAction
89 { "046d", "c21a", MapperLogitechPrecision }, // Logitech Precision
90 };
91
92 } // namespace
93
94 GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
95 const base::StringPiece& vendor_id,
96 const base::StringPiece& product_id) {
97 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
98 MappingData& item = AvailableMappings[i];
99 if (vendor_id == item.vendor_id && product_id == item.product_id)
100 return item.function;
101 }
102 return NULL;
103 }
104
105 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gamepad/gamepad_platform_data_fetcher_win.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698