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

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 void MapperDragonRiseGeneric(
19 const WebKit::WebGamepad& input,
20 WebKit::WebGamepad* mapped) {
21 *mapped = input;
22 mapped->buttons[0] = input.buttons[1];
23 mapped->buttons[1] = input.buttons[2];
24 mapped->buttons[2] = input.buttons[0];
25 mapped->buttons[12] = input.buttons[16];
26 mapped->buttons[13] = input.buttons[17];
27 mapped->buttons[14] = input.buttons[18];
28 mapped->buttons[15] = input.buttons[19];
29 mapped->buttonsLength = 16;
30 mapped->axes[0] = NormalizeDirectInputAxis(input.axes[0]);
31 mapped->axes[1] = NormalizeDirectInputAxis(input.axes[1]);
32 mapped->axes[2] = NormalizeDirectInputAxis(input.axes[2]);
33 mapped->axes[3] = NormalizeDirectInputAxis(input.axes[5]);
34 mapped->axesLength = 4;
35 }
36
37 void MapperLogitechDualAction(
38 const WebKit::WebGamepad& input,
39 WebKit::WebGamepad* mapped) {
40 *mapped = input;
41 mapped->buttons[0] = input.buttons[1];
42 mapped->buttons[1] = input.buttons[2];
43 mapped->buttons[2] = input.buttons[0];
44 mapped->buttons[12] = input.buttons[16];
45 mapped->buttons[13] = input.buttons[17];
46 mapped->buttons[14] = input.buttons[18];
47 mapped->buttons[15] = input.buttons[19];
48 mapped->buttonsLength = 16;
49 mapped->axes[0] = NormalizeDirectInputAxis(input.axes[0]);
50 mapped->axes[1] = NormalizeDirectInputAxis(input.axes[1]);
51 mapped->axes[2] = NormalizeDirectInputAxis(input.axes[2]);
52 mapped->axes[3] = NormalizeDirectInputAxis(input.axes[5]);
53 mapped->axesLength = 4;
54 }
55
56 struct MappingData {
57 const char* const vendor_id;
58 const char* const product_id;
59 GamepadStandardMappingFunction function;
60 } AvailableMappings[] = {
61 // http://www.linux-usb.org/usb.ids
62 { "0079", "0006", MapperDragonRiseGeneric }, // DragonRise Generic USB
scottmg 2013/02/19 18:50:52 nit; two spaces after code before comment
teravest 2013/02/19 20:53:37 Done.
63 { "046d", "c216", MapperLogitechDualAction }, // Logitech DualAction
64 };
65
66 } // namespace
67
68 GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
69 const base::StringPiece& vendor_id,
70 const base::StringPiece& product_id) {
71 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
72 MappingData& item = AvailableMappings[i];
73 if (vendor_id == item.vendor_id && product_id == item.product_id)
74 return item.function;
75 }
76 return NULL;
77 }
78
79 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698