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

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 struct MappingData {
38 const char* const vendor_id;
39 const char* const product_id;
40 GamepadStandardMappingFunction function;
41 } AvailableMappings[] = {
42 // http://www.linux-usb.org/usb.ids
43 { "0079", "0006", MapperDragonRiseGeneric }, // DragonRise Generic USB
44 };
45
46 } // namespace
47
48 GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
49 const base::StringPiece& vendor_id,
50 const base::StringPiece& product_id) {
51 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
52 MappingData& item = AvailableMappings[i];
53 if (vendor_id == item.vendor_id && product_id == item.product_id)
54 return item.function;
55 }
56 return NULL;
57 }
58
59 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698