gamepad_standard_mappings.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #ifndef DEVICE_GAMEPAD_GAMEPAD_STANDARD_MAPPINGS_H_
  5. #define DEVICE_GAMEPAD_GAMEPAD_STANDARD_MAPPINGS_H_
  6. #include "base/strings/string_piece.h"
  7. #include "device/gamepad/public/cpp/gamepad.h"
  8. namespace device {
  9. // For a connected gamepad, specify the type of bus through which it is
  10. // connected. This allows for specialized mappings depending on how the device
  11. // is connected. For instance, a gamepad may require different mappers for USB
  12. // and Bluetooth.
  13. enum GamepadBusType {
  14. GAMEPAD_BUS_UNKNOWN,
  15. GAMEPAD_BUS_USB,
  16. GAMEPAD_BUS_BLUETOOTH
  17. };
  18. typedef void (*GamepadStandardMappingFunction)(const Gamepad& original,
  19. Gamepad* mapped);
  20. // Returns the most suitable mapping function for a particular gamepad.
  21. // |vendor_id| and |product_id| are the USB or Bluetooth vendor and product IDs
  22. // reported by the device. |hid_specification_version| is the binary-coded
  23. // decimal representation of the version of the HID specification that the
  24. // device is compliant with (bcdHID). |version_number| is the firmware version
  25. // number reported by the device (bcdDevice). |bus_type| is the transport
  26. // used to connect to this device, or GAMEPAD_BUS_UNKNOWN if unknown.
  27. GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
  28. const base::StringPiece product_name,
  29. const uint16_t vendor_id,
  30. const uint16_t product_id,
  31. const uint16_t hid_specification_version,
  32. const uint16_t version_number,
  33. GamepadBusType bus_type);
  34. // This defines our canonical mapping order for gamepad-like devices. If these
  35. // items cannot all be satisfied, it is a case-by-case judgement as to whether
  36. // it is better to leave the device unmapped, or to partially map it. In
  37. // general, err towards leaving it *unmapped* so that content can handle
  38. // appropriately.
  39. // A Java counterpart will be generated for this enum.
  40. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.device.gamepad
  41. // GENERATED_JAVA_PREFIX_TO_STRIP: BUTTON_INDEX_
  42. enum CanonicalButtonIndex {
  43. BUTTON_INDEX_PRIMARY,
  44. BUTTON_INDEX_SECONDARY,
  45. BUTTON_INDEX_TERTIARY,
  46. BUTTON_INDEX_QUATERNARY,
  47. BUTTON_INDEX_LEFT_SHOULDER,
  48. BUTTON_INDEX_RIGHT_SHOULDER,
  49. BUTTON_INDEX_LEFT_TRIGGER,
  50. BUTTON_INDEX_RIGHT_TRIGGER,
  51. BUTTON_INDEX_BACK_SELECT,
  52. BUTTON_INDEX_START,
  53. BUTTON_INDEX_LEFT_THUMBSTICK,
  54. BUTTON_INDEX_RIGHT_THUMBSTICK,
  55. BUTTON_INDEX_DPAD_UP,
  56. BUTTON_INDEX_DPAD_DOWN,
  57. BUTTON_INDEX_DPAD_LEFT,
  58. BUTTON_INDEX_DPAD_RIGHT,
  59. BUTTON_INDEX_META,
  60. BUTTON_INDEX_COUNT
  61. };
  62. // Xbox Series X has an extra share button.
  63. enum XboxSeriesXButtons {
  64. XBOX_SERIES_X_BUTTON_SHARE = CanonicalButtonIndex::BUTTON_INDEX_COUNT,
  65. XBOX_SERIES_X_BUTTON_COUNT
  66. };
  67. // A Java counterpart will be generated for this enum.
  68. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.device.gamepad
  69. // GENERATED_JAVA_PREFIX_TO_STRIP: AXIS_INDEX_
  70. enum CanonicalAxisIndex {
  71. AXIS_INDEX_LEFT_STICK_X,
  72. AXIS_INDEX_LEFT_STICK_Y,
  73. AXIS_INDEX_RIGHT_STICK_X,
  74. AXIS_INDEX_RIGHT_STICK_Y,
  75. AXIS_INDEX_COUNT
  76. };
  77. // The Switch Pro controller has a Capture button that has no equivalent in the
  78. // Standard Gamepad.
  79. enum SwitchProButtons {
  80. SWITCH_PRO_BUTTON_CAPTURE = BUTTON_INDEX_COUNT,
  81. SWITCH_PRO_BUTTON_COUNT
  82. };
  83. // Common mapping functions
  84. GamepadButton AxisToButton(float input);
  85. GamepadButton AxisNegativeAsButton(float input);
  86. GamepadButton AxisPositiveAsButton(float input);
  87. GamepadButton ButtonFromButtonAndAxis(GamepadButton button, float axis);
  88. GamepadButton NullButton();
  89. void DpadFromAxis(Gamepad* mapped, float dir);
  90. float RenormalizeAndClampAxis(float value, float min, float max);
  91. // Gamepad common mapping functions
  92. void MapperSwitchPro(const Gamepad& input, Gamepad* mapped);
  93. void MapperSwitchJoyCon(const Gamepad& input, Gamepad* mapped);
  94. void MapperSwitchComposite(const Gamepad& input, Gamepad* mapped);
  95. } // namespace device
  96. #endif // DEVICE_GAMEPAD_GAMEPAD_STANDARD_MAPPINGS_H_