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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/gamepad/gamepad_standard_mappings_win.cc
diff --git a/content/browser/gamepad/gamepad_standard_mappings_win.cc b/content/browser/gamepad/gamepad_standard_mappings_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2c1bd62f9f03546ae8cc0f50a9b36de3b989b0f8
--- /dev/null
+++ b/content/browser/gamepad/gamepad_standard_mappings_win.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/gamepad/gamepad_standard_mappings.h"
+
+#include "content/common/gamepad_hardware_buffer.h"
+
+namespace content {
+
+namespace {
+
+// Maps 0..65535 to -1..1.
+float NormalizeDirectInputAxis(long value) {
+ return (value * 1.f / 32767.5f) - 1.f;
+}
+
+void MapperDragonRiseGeneric(
+ const WebKit::WebGamepad& input,
+ WebKit::WebGamepad* mapped) {
+ *mapped = input;
+ mapped->buttons[0] = input.buttons[1];
+ mapped->buttons[1] = input.buttons[2];
+ mapped->buttons[2] = input.buttons[0];
+ mapped->buttons[12] = input.buttons[16];
+ mapped->buttons[13] = input.buttons[17];
+ mapped->buttons[14] = input.buttons[18];
+ mapped->buttons[15] = input.buttons[19];
+ mapped->buttonsLength = 16;
+ mapped->axes[0] = NormalizeDirectInputAxis(input.axes[0]);
+ mapped->axes[1] = NormalizeDirectInputAxis(input.axes[1]);
+ mapped->axes[2] = NormalizeDirectInputAxis(input.axes[2]);
+ mapped->axes[3] = NormalizeDirectInputAxis(input.axes[5]);
+ mapped->axesLength = 4;
+}
+
+struct MappingData {
+ const char* const vendor_id;
+ const char* const product_id;
+ GamepadStandardMappingFunction function;
+} AvailableMappings[] = {
+ // http://www.linux-usb.org/usb.ids
+ { "0079", "0006", MapperDragonRiseGeneric }, // DragonRise Generic USB
+};
+
+} // namespace
+
+GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
+ const base::StringPiece& vendor_id,
+ const base::StringPiece& product_id) {
+ for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
+ MappingData& item = AvailableMappings[i];
+ if (vendor_id == item.vendor_id && product_id == item.product_id)
+ return item.function;
+ }
+ return NULL;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698