0

Use uint16_t integer types for device IDs and HID usages

Vendor and product IDs are 16-bit values used to identify USB and
Bluetooth devices. Depending on the platform, they may be reported
as integers or strings. This CL modifies all places in Gamepad where
device IDs are stored as strings or signed integers to instead store
them in a minimum-width integer unsigned type (uint16_t).

Similarly, HID usage pages and usage numbers are defined to be
16-bit values. The constants holding these values are changed
to uint16_t.

In a future CL, Gamepad device ID and HID constants will be pulled
out of the platform-specific data fetcher implementations and placed
in a common header.

BUG=786250

Change-Id: I30a0841db91008802331939a86a7b6c3c5f58586
Reviewed-on: https://chromium-review.googlesource.com/1102099
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594495}
This commit is contained in:
Matt Reynolds
2018-09-26 22:09:30 +00:00
committed by Commit Bot
parent 6f5978f29f
commit 717ca900fb
18 changed files with 216 additions and 200 deletions

@ -5,9 +5,9 @@
#include "device/gamepad/dualshock4_controller_base.h"
namespace {
const uint32_t kVendorSony = 0x054c;
const uint32_t kProductDualshock4 = 0x05c4;
const uint32_t kProductDualshock4Slim = 0x9cc;
const uint16_t kVendorSony = 0x054c;
const uint16_t kProductDualshock4 = 0x05c4;
const uint16_t kProductDualshock4Slim = 0x9cc;
const uint8_t kRumbleMagnitudeMax = 0xff;
enum ControllerType {
@ -16,7 +16,8 @@ enum ControllerType {
DUALSHOCK4_SLIM_CONTROLLER
};
ControllerType ControllerTypeFromDeviceIds(int vendor_id, int product_id) {
ControllerType ControllerTypeFromDeviceIds(uint16_t vendor_id,
uint16_t product_id) {
if (vendor_id == kVendorSony) {
switch (product_id) {
case kProductDualshock4:
@ -37,7 +38,8 @@ namespace device {
Dualshock4ControllerBase::~Dualshock4ControllerBase() = default;
// static
bool Dualshock4ControllerBase::IsDualshock4(int vendor_id, int product_id) {
bool Dualshock4ControllerBase::IsDualshock4(uint16_t vendor_id,
uint16_t product_id) {
return ControllerTypeFromDeviceIds(vendor_id, product_id) !=
UNKNOWN_CONTROLLER;
}

@ -14,7 +14,7 @@ class Dualshock4ControllerBase : public AbstractHapticGamepad {
Dualshock4ControllerBase() = default;
~Dualshock4ControllerBase() override;
static bool IsDualshock4(int vendor_id, int product_id);
static bool IsDualshock4(uint16_t vendor_id, uint16_t product_id);
void SetVibration(double strong_magnitude, double weak_magnitude) override;

@ -164,6 +164,16 @@ bool StartOrStopEffect(int fd, int effect_id, bool do_start) {
return nbytes == sizeof(start_stop);
}
uint16_t HexStringToUInt16WithDefault(base::StringPiece input,
uint16_t default_value) {
uint32_t out = 0;
if (!base::HexStringToUInt(input, &out) ||
out > std::numeric_limits<uint16_t>::max()) {
return default_value;
}
return static_cast<uint16_t>(out);
}
} // namespace
GamepadDeviceLinux::GamepadDeviceLinux(const std::string& syspath_prefix)
@ -338,9 +348,8 @@ bool GamepadDeviceLinux::ReadEvdevSpecialKeys(Gamepad* pad) {
}
GamepadStandardMappingFunction GamepadDeviceLinux::GetMappingFunction() const {
return GetGamepadStandardMappingFunction(vendor_id_.c_str(),
product_id_.c_str(),
version_number_.c_str(), bus_type_);
return GetGamepadStandardMappingFunction(vendor_id_, product_id_,
version_number_, bus_type_);
}
bool GamepadDeviceLinux::IsSameDevice(const UdevGamepadLinux& pad_info) {
@ -370,10 +379,9 @@ bool GamepadDeviceLinux::OpenJoydevNode(const UdevGamepadLinux& pad_info,
const char* name = udev_device_get_sysattr_value(parent_device, "name");
std::string name_string(name ? name : "");
int vendor_id_int = 0;
int product_id_int = 0;
base::HexStringToInt(vendor_id, &vendor_id_int);
base::HexStringToInt(product_id, &product_id_int);
uint16_t vendor_id_int = HexStringToUInt16WithDefault(vendor_id, 0);
uint16_t product_id_int = HexStringToUInt16WithDefault(product_id, 0);
uint16_t version_number_int = HexStringToUInt16WithDefault(version_number, 0);
// In many cases the information the input subsystem contains isn't
// as good as the information that the device bus has, walk up further
@ -402,9 +410,9 @@ bool GamepadDeviceLinux::OpenJoydevNode(const UdevGamepadLinux& pad_info,
}
joydev_index_ = pad_info.index;
vendor_id_ = vendor_id ? vendor_id : "";
product_id_ = product_id ? product_id : "";
version_number_ = version_number ? version_number : "";
vendor_id_ = vendor_id_int;
product_id_ = product_id_int;
version_number_ = version_number_int;
name_ = name_string;
return true;
@ -416,9 +424,9 @@ void GamepadDeviceLinux::CloseJoydevNode() {
joydev_fd_ = -1;
}
joydev_index_ = -1;
vendor_id_.clear();
product_id_.clear();
version_number_.clear();
vendor_id_ = 0;
product_id_ = 0;
version_number_ = 0;
name_.clear();
// Button indices must be recomputed once the joydev node is closed.

@ -41,9 +41,9 @@ class GamepadDeviceLinux : public AbstractHapticGamepad {
bool IsEmpty() const;
int GetJoydevIndex() const { return joydev_index_; }
std::string GetVendorId() const { return vendor_id_; }
std::string GetProductId() const { return product_id_; }
std::string GetVersionNumber() const { return version_number_; }
uint16_t GetVendorId() const { return vendor_id_; }
uint16_t GetProductId() const { return product_id_; }
uint16_t GetVersionNumber() const { return version_number_; }
std::string GetName() const { return name_; }
std::string GetSyspathPrefix() const { return syspath_prefix_; }
GamepadBusType GetBusType() const { return bus_type_; }
@ -119,13 +119,13 @@ class GamepadDeviceLinux : public AbstractHapticGamepad {
std::vector<bool> button_indices_used_;
// The vendor ID of the device.
std::string vendor_id_;
uint16_t vendor_id_;
// The product ID of the device.
std::string product_id_;
uint16_t product_id_;
// The version number of the device.
std::string version_number_;
uint16_t version_number_;
// A string identifying the manufacturer and model of the device.
std::string name_;

@ -63,16 +63,15 @@ void GamepadPlatformDataFetcherLinux::GetGamepadData(bool) {
// static
void GamepadPlatformDataFetcherLinux::UpdateGamepadStrings(
const std::string& name,
const std::string& vendor_id,
const std::string& product_id,
uint16_t vendor_id,
uint16_t product_id,
bool has_standard_mapping,
Gamepad* pad) {
// Set the ID string. The ID contains the device name, vendor and product IDs,
// and an indication of whether the standard mapping is in use.
std::string id =
base::StringPrintf("%s (%sVendor: %s Product: %s)", name.c_str(),
has_standard_mapping ? "STANDARD GAMEPAD " : "",
vendor_id.c_str(), product_id.c_str());
std::string id = base::StringPrintf(
"%s (%sVendor: %04x Product: %04x)", name.c_str(),
has_standard_mapping ? "STANDARD GAMEPAD " : "", vendor_id, product_id);
base::TruncateUTF8ToByteSize(id, Gamepad::kIdLengthCap - 1, &id);
base::string16 tmp16 = base::UTF8ToUTF16(id);
memset(pad->id, 0, sizeof(pad->id));

@ -54,8 +54,8 @@ class DEVICE_GAMEPAD_EXPORT GamepadPlatformDataFetcherLinux
private:
// Updates the ID and mapper strings in |pad| with new device info.
static void UpdateGamepadStrings(const std::string& name,
const std::string& vendor_id,
const std::string& product_id,
uint16_t vendor_id,
uint16_t product_id,
bool has_standard_mapping,
Gamepad* pad);

@ -19,13 +19,13 @@ namespace device {
namespace {
// http://www.usb.org/developers/hidpage
const uint32_t kGenericDesktopUsagePage = 0x01;
const uint32_t kJoystickUsageNumber = 0x04;
const uint32_t kGameUsageNumber = 0x05;
const uint32_t kMultiAxisUsageNumber = 0x08;
const uint16_t kGenericDesktopUsagePage = 0x01;
const uint16_t kJoystickUsageNumber = 0x04;
const uint16_t kGameUsageNumber = 0x05;
const uint16_t kMultiAxisUsageNumber = 0x08;
const int kVendorSteelSeries = 0x1038;
const int kProductNimbus = 0x1420;
const uint16_t kVendorSteelSeries = 0x1038;
const uint16_t kProductNimbus = 0x1420;
void CopyNSStringAsUTF16LittleEndian(NSString* src,
UChar* dest,
@ -192,9 +192,9 @@ void GamepadPlatformDataFetcherMac::DeviceAdd(IOHIDDeviceRef device) {
IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVersionNumberKey))));
NSString* product = CFToNSCast(CFCastStrict<CFStringRef>(
IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey))));
int vendor_int = [vendor_id intValue];
int product_int = [product_id intValue];
int version_int = [version_number intValue];
uint16_t vendor_int = [vendor_id intValue];
uint16_t product_int = [product_id intValue];
uint16_t version_int = [version_number intValue];
// The SteelSeries Nimbus and other Made for iOS gamepads should be handled
// through the GameController interface. Blacklist it here so it doesn't
@ -206,12 +206,8 @@ void GamepadPlatformDataFetcherMac::DeviceAdd(IOHIDDeviceRef device) {
if (!state)
return; // No available slot for this device
char vendor_as_str[5], product_as_str[5], version_as_str[5];
snprintf(vendor_as_str, sizeof(vendor_as_str), "%04x", vendor_int);
snprintf(product_as_str, sizeof(product_as_str), "%04x", product_int);
snprintf(version_as_str, sizeof(version_as_str), "%04x", version_int);
state->mapper = GetGamepadStandardMappingFunction(
vendor_as_str, product_as_str, version_as_str, GAMEPAD_BUS_UNKNOWN);
vendor_int, product_int, version_int, GAMEPAD_BUS_UNKNOWN);
NSString* ident =
[NSString stringWithFormat:@"%@ (%sVendor: %04x Product: %04x)", product,

@ -24,9 +24,9 @@ typedef void (*GamepadStandardMappingFunction)(const Gamepad& original,
Gamepad* mapped);
GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
const base::StringPiece& vendor_id,
const base::StringPiece& product_id,
const base::StringPiece& version_number,
const uint16_t vendor_id,
const uint16_t product_id,
const uint16_t version_number,
GamepadBusType bus_type);
// This defines our canonical mapping order for gamepad-like devices. If these

@ -5,6 +5,7 @@
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "device/gamepad/gamepad_standard_mappings.h"
namespace device {
@ -20,10 +21,20 @@ enum SwitchProButtons {
// axes are capable of, and as a result the received axis values only use about
// 70% of the total range. We renormalize the axis values to cover the full
// range. The axis extents were determined experimentally.
const static float kSwitchProAxisXMin = -0.7f;
const static float kSwitchProAxisXMax = 0.7f;
const static float kSwitchProAxisYMin = -0.65f;
const static float kSwitchProAxisYMax = 0.75f;
const float kSwitchProAxisXMin = -0.7f;
const float kSwitchProAxisXMax = 0.7f;
const float kSwitchProAxisYMin = -0.65f;
const float kSwitchProAxisYMax = 0.75f;
// The hid-sony driver in newer kernels uses an alternate mapping for Sony
// Playstation 3 and Playstation 4 gamepads than in older kernels. To allow
// applications to distinguish between the old mapping and the new mapping,
// hid-sony sets the high bit of the device's version number.
// Dualshock 4 devices are patched in 4.10:
// https://github.com/torvalds/linux/commit/9131f8cc2b4eaf7c08d402243429e0bfba9aa0d6
// Dualshock 3 and SIXAXIS devices are patched in 4.12:
// https://github.com/torvalds/linux/commit/e19a267b9987135c00155a51e683e434b9abb56b
const uint16_t kDualshockPatchedVersion = 0x8111;
void MapperXInputStyleGamepad(const Gamepad& input, Gamepad* mapped) {
*mapped = input;
@ -535,61 +546,62 @@ void MapperLogitechDInput(const Gamepad& input, Gamepad* mapped) {
}
struct MappingData {
const char* const vendor_id;
const char* const product_id;
const uint16_t vendor_id;
const uint16_t product_id;
GamepadStandardMappingFunction function;
} AvailableMappings[] = {
// http://www.linux-usb.org/usb.ids
{"0079", "0006", MapperDragonRiseGeneric}, // DragonRise Generic USB
{"045e", "028e", MapperXInputStyleGamepad}, // Xbox 360 Wired
{"045e", "028f", MapperXInputStyleGamepad}, // Xbox 360 Wireless
{"045e", "02a1", MapperXInputStyleGamepad}, // Xbox 360 Wireless
{"045e", "0291", MapperXInputStyleGamepad}, // Xbox 360 Wireless
{"045e", "02d1", MapperXInputStyleGamepad}, // Xbox One Wired
{"045e", "02dd", MapperXInputStyleGamepad}, // Xbox One Wired (2015 FW)
{"045e", "02e0", MapperXboxOneS}, // Xbox One S (Bluetooth)
{"045e", "02e3", MapperXInputStyleGamepad}, // Xbox One Elite Wired
{"045e", "02ea", MapperXInputStyleGamepad}, // Xbox One S (USB)
{"045e", "02fd", MapperXboxOneS2016Firmware}, // Xbox One S (Bluetooth)
{"045e", "0719", MapperXInputStyleGamepad}, // Xbox 360 Wireless
{"046d", "c216", MapperLogitechDInput}, // Logitech F310 D-mode
{"046d", "c218", MapperLogitechDInput}, // Logitech F510 D-mode
{"046d", "c219", MapperLogitechDInput}, // Logitech F710 D-mode
{"046d", "c21d", MapperXInputStyleGamepad}, // Logitech F310 X-mode
{"046d", "c21e", MapperXInputStyleGamepad}, // Logitech F510 X-mode
{"046d", "c21f", MapperXInputStyleGamepad}, // Logitech F710 X-mode
{"04e8", "a000", MapperSamsung_EI_GP20}, // Samsung Gamepad EI-GP20
{"054c", "0268", MapperDualshock3SixAxis}, // Dualshock 3 / SIXAXIS
{"054c", "05c4", MapperDualshock4}, // Playstation Dualshock 4
{"054c", "09cc", MapperDualshock4}, // Dualshock 4 (PS4 Slim)
{"054c", "0ba0", MapperDualshock4}, // Dualshock 4 USB receiver
{"057e", "2009", MapperSwitchProUsb}, // Switch Pro Controller
{"0583", "2060", MapperIBuffalo}, // iBuffalo Classic
{"0925", "0005", MapperLakeviewResearch}, // SmartJoy PLUS Adapter
{"0925", "8866", MapperLakeviewResearch}, // WiseGroup MP-8866
{"0955", "7210", MapperNvShield}, // Nvidia Shield gamepad (2015)
{"0955", "7214", MapperNvShield2017}, // Nvidia Shield gamepad (2017)
{"0b05", "4500", MapperADT1}, // Nexus Player Controller
{"0e8f", "0003", MapperXGEAR}, // XFXforce XGEAR PS2 Controller
{"1038", "1412", MapperSteelSeries}, // Zeemote: SteelSeries FREE
{"1532", "0900", MapperRazerServal}, // Razer Serval Controller
{"18d1", "2c40", MapperADT1}, // ADT-1 Controller
{"20d6", "6271", MapperMoga}, // Moga Pro Controller (HID mode)
{"20d6", "89e5", MapperMoga}, // Moga 2 HID
{"2378", "1008", MapperOnLiveWireless}, // OnLive Controller (Bluetooth)
{"2378", "100a", MapperOnLiveWireless}, // OnLive Controller (Wired)
{"2836", "0001", MapperOUYA}, // OUYA Controller
{0x0079, 0x0006, MapperDragonRiseGeneric}, // DragonRise Generic USB
{0x045e, 0x028e, MapperXInputStyleGamepad}, // Xbox 360 Wired
{0x045e, 0x028f, MapperXInputStyleGamepad}, // Xbox 360 Wireless
{0x045e, 0x02a1, MapperXInputStyleGamepad}, // Xbox 360 Wireless
{0x045e, 0x0291, MapperXInputStyleGamepad}, // Xbox 360 Wireless
{0x045e, 0x02d1, MapperXInputStyleGamepad}, // Xbox One Wired
{0x045e, 0x02dd, MapperXInputStyleGamepad}, // Xbox One Wired (2015 FW)
{0x045e, 0x02e0, MapperXboxOneS}, // Xbox One S (Bluetooth)
{0x045e, 0x02e3, MapperXInputStyleGamepad}, // Xbox One Elite Wired
{0x045e, 0x02ea, MapperXInputStyleGamepad}, // Xbox One S (USB)
{0x045e, 0x02fd, MapperXboxOneS2016Firmware}, // Xbox One S (Bluetooth)
{0x045e, 0x0719, MapperXInputStyleGamepad}, // Xbox 360 Wireless
{0x046d, 0xc216, MapperLogitechDInput}, // Logitech F310 D-mode
{0x046d, 0xc218, MapperLogitechDInput}, // Logitech F510 D-mode
{0x046d, 0xc219, MapperLogitechDInput}, // Logitech F710 D-mode
{0x046d, 0xc21d, MapperXInputStyleGamepad}, // Logitech F310 X-mode
{0x046d, 0xc21e, MapperXInputStyleGamepad}, // Logitech F510 X-mode
{0x046d, 0xc21f, MapperXInputStyleGamepad}, // Logitech F710 X-mode
{0x04e8, 0xa000, MapperSamsung_EI_GP20}, // Samsung Gamepad EI-GP20
{0x054c, 0x0268, MapperDualshock3SixAxis}, // Dualshock 3 / SIXAXIS
{0x054c, 0x05c4, MapperDualshock4}, // Playstation Dualshock 4
{0x054c, 0x09cc, MapperDualshock4}, // Dualshock 4 (PS4 Slim)
{0x054c, 0x0ba0, MapperDualshock4}, // Dualshock 4 USB receiver
{0x057e, 0x2009, MapperSwitchProUsb}, // Switch Pro Controller
{0x0583, 0x2060, MapperIBuffalo}, // iBuffalo Classic
{0x0925, 0x0005, MapperLakeviewResearch}, // SmartJoy PLUS Adapter
{0x0925, 0x8866, MapperLakeviewResearch}, // WiseGroup MP-8866
{0x0955, 0x7210, MapperNvShield}, // Nvidia Shield gamepad (2015)
{0x0955, 0x7214, MapperNvShield2017}, // Nvidia Shield gamepad (2017)
{0x0b05, 0x4500, MapperADT1}, // Nexus Player Controller
{0x0e8f, 0x0003, MapperXGEAR}, // XFXforce XGEAR PS2 Controller
{0x1038, 0x1412, MapperSteelSeries}, // Zeemote: SteelSeries FREE
{0x1532, 0x0900, MapperRazerServal}, // Razer Serval Controller
{0x18d1, 0x2c40, MapperADT1}, // ADT-1 Controller
{0x20d6, 0x6271, MapperMoga}, // Moga Pro Controller (HID mode)
{0x20d6, 0x89e5, MapperMoga}, // Moga 2 HID
{0x2378, 0x1008, MapperOnLiveWireless}, // OnLive Controller (Bluetooth)
{0x2378, 0x100a, MapperOnLiveWireless}, // OnLive Controller (Wired)
{0x2836, 0x0001, MapperOUYA}, // OUYA Controller
};
const size_t kAvailableMappingsLen = base::size(AvailableMappings);
} // namespace
GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
const base::StringPiece& vendor_id,
const base::StringPiece& product_id,
const base::StringPiece& version_number,
const uint16_t vendor_id,
const uint16_t product_id,
const uint16_t version_number,
GamepadBusType bus_type) {
GamepadStandardMappingFunction mapper = nullptr;
for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
for (size_t i = 0; i < kAvailableMappingsLen; ++i) {
MappingData& item = AvailableMappings[i];
if (vendor_id == item.vendor_id && product_id == item.product_id) {
mapper = item.function;
@ -600,9 +612,11 @@ GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
// The Linux kernel was updated in version 4.10 to better support Dualshock 4
// and Dualshock 3/SIXAXIS gamepads. The driver patches the hardware version
// when using the new mapping to allow downstream users to distinguish them.
if (mapper == MapperDualshock4 && version_number == "8111") {
if (mapper == MapperDualshock4 &&
version_number == kDualshockPatchedVersion) {
mapper = MapperDualshock4New;
} else if (mapper == MapperDualshock3SixAxis && version_number == "8111") {
} else if (mapper == MapperDualshock3SixAxis &&
version_number == kDualshockPatchedVersion) {
mapper = MapperDualshock3SixAxisNew;
}

@ -5,6 +5,7 @@
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "device/gamepad/gamepad_standard_mappings.h"
namespace device {
@ -393,56 +394,57 @@ void MapperMogaPro(const Gamepad& input, Gamepad* mapped) {
}
struct MappingData {
const char* const vendor_id;
const char* const product_id;
const uint16_t vendor_id;
const uint16_t product_id;
GamepadStandardMappingFunction function;
} AvailableMappings[] = {
// http://www.linux-usb.org/usb.ids
{"0079", "0006", MapperDragonRiseGeneric}, // DragonRise Generic USB
{"045e", "028e", MapperXbox360Gamepad}, // Xbox 360 Wired
{"045e", "028f", MapperXbox360Gamepad}, // Xbox 360 Wireless
{"045e", "02d1", MapperXbox360Gamepad}, // Xbox One Wired
{"045e", "02dd", MapperXbox360Gamepad}, // Xbox One Wired (2015 FW)
{"045e", "02e0", MapperXboxOneS}, // Xbox One S (Bluetooth)
{"045e", "02e3", MapperXbox360Gamepad}, // Xbox One Elite Wired
{"045e", "02ea", MapperXbox360Gamepad}, // Xbox One S (USB)
{"045e", "02fd", MapperXboxOneS2016Firmware}, // Xbox One S (Bluetooth)
{"045e", "0719", MapperXbox360Gamepad}, // Xbox 360 Wireless
{"046d", "c216", MapperDirectInputStyle}, // Logitech F310, D mode
{"046d", "c218", MapperDirectInputStyle}, // Logitech F510, D mode
{"046d", "c219", MapperDirectInputStyle}, // Logitech F710, D mode
{"054c", "0268", MapperPlaystationSixAxis}, // Playstation SIXAXIS
{"054c", "05c4", MapperDualshock4}, // Playstation Dualshock 4
{"054c", "09cc", MapperDualshock4}, // Dualshock 4 (PS4 Slim)
{"054c", "0ba0", MapperDualshock4}, // Dualshock 4 USB receiver
{"0583", "2060", MapperIBuffalo}, // iBuffalo Classic
{"0925", "0005", MapperSmartJoyPLUS}, // SmartJoy PLUS Adapter
{"0955", "7210", MapperNvShield}, // Nvidia Shield gamepad (2015)
{"0b05", "4500", MapperADT1}, // Nexus Player Controller
{"0e8f", "0003", MapperXGEAR}, // XFXforce XGEAR PS2 Controller
{"1532", "0900", MapperRazerServal}, // Razer Serval Controller
{"18d1", "2c40", MapperADT1}, // ADT-1 Controller
{"20d6", "6271", MapperMogaPro}, // Moga Pro Controller (HID mode)
{"2222", "0060", MapperDirectInputStyle}, // Macally iShockX, analog mode
{"2222", "4010", MapperMacallyIShock}, // Macally iShock
{"2378", "1008", MapperOnLiveWireless}, // OnLive Controller (Bluetooth)
{"2378", "100a", MapperOnLiveWireless}, // OnLive Controller (Wired)
{"2836", "0001", MapperOUYA}, // OUYA Controller
{0x0079, 0x0006, MapperDragonRiseGeneric}, // DragonRise Generic USB
{0x045e, 0x028e, MapperXbox360Gamepad}, // Xbox 360 Wired
{0x045e, 0x028f, MapperXbox360Gamepad}, // Xbox 360 Wireless
{0x045e, 0x02d1, MapperXbox360Gamepad}, // Xbox One Wired
{0x045e, 0x02dd, MapperXbox360Gamepad}, // Xbox One Wired (2015 FW)
{0x045e, 0x02e0, MapperXboxOneS}, // Xbox One S (Bluetooth)
{0x045e, 0x02e3, MapperXbox360Gamepad}, // Xbox One Elite Wired
{0x045e, 0x02ea, MapperXbox360Gamepad}, // Xbox One S (USB)
{0x045e, 0x02fd, MapperXboxOneS2016Firmware}, // Xbox One S (Bluetooth)
{0x045e, 0x0719, MapperXbox360Gamepad}, // Xbox 360 Wireless
{0x046d, 0xc216, MapperDirectInputStyle}, // Logitech F310, D mode
{0x046d, 0xc218, MapperDirectInputStyle}, // Logitech F510, D mode
{0x046d, 0xc219, MapperDirectInputStyle}, // Logitech F710, D mode
{0x054c, 0x0268, MapperPlaystationSixAxis}, // Playstation SIXAXIS
{0x054c, 0x05c4, MapperDualshock4}, // Playstation Dualshock 4
{0x054c, 0x09cc, MapperDualshock4}, // Dualshock 4 (PS4 Slim)
{0x054c, 0x0ba0, MapperDualshock4}, // Dualshock 4 USB receiver
{0x0583, 0x2060, MapperIBuffalo}, // iBuffalo Classic
{0x0925, 0x0005, MapperSmartJoyPLUS}, // SmartJoy PLUS Adapter
{0x0955, 0x7210, MapperNvShield}, // Nvidia Shield gamepad (2015)
{0x0b05, 0x4500, MapperADT1}, // Nexus Player Controller
{0x0e8f, 0x0003, MapperXGEAR}, // XFXforce XGEAR PS2 Controller
{0x1532, 0x0900, MapperRazerServal}, // Razer Serval Controller
{0x18d1, 0x2c40, MapperADT1}, // ADT-1 Controller
{0x20d6, 0x6271, MapperMogaPro}, // Moga Pro Controller (HID mode)
{0x2222, 0x0060, MapperDirectInputStyle}, // Macally iShockX, analog mode
{0x2222, 0x4010, MapperMacallyIShock}, // Macally iShock
{0x2378, 0x1008, MapperOnLiveWireless}, // OnLive Controller (Bluetooth)
{0x2378, 0x100a, MapperOnLiveWireless}, // OnLive Controller (Wired)
{0x2836, 0x0001, MapperOUYA}, // OUYA Controller
};
const size_t kAvailableMappingsLen = base::size(AvailableMappings);
} // namespace
GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
const base::StringPiece& vendor_id,
const base::StringPiece& product_id,
const base::StringPiece& version_number,
const uint16_t vendor_id,
const uint16_t product_id,
const uint16_t version_number,
GamepadBusType bus_type) {
for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
for (size_t i = 0; i < kAvailableMappingsLen; ++i) {
MappingData& item = AvailableMappings[i];
if (vendor_id == item.vendor_id && product_id == item.product_id)
return item.function;
}
return NULL;
return nullptr;
}
} // namespace device

@ -5,6 +5,7 @@
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "device/gamepad/gamepad_standard_mappings.h"
namespace device {
@ -261,43 +262,44 @@ void MapperMogaPro(const Gamepad& input, Gamepad* mapped) {
}
struct MappingData {
const char* const vendor_id;
const char* const product_id;
const uint16_t vendor_id;
const uint16_t product_id;
GamepadStandardMappingFunction function;
} AvailableMappings[] = {
// http://www.linux-usb.org/usb.ids
{"0079", "0011", Mapper2Axes8Keys}, // 2Axes 8Keys Game Pad
{"046d", "c216", MapperLogitechDInput}, // Logitech F310, D-mode
{"046d", "c218", MapperLogitechDInput}, // Logitech F510, D-mode
{"046d", "c219", MapperLogitechDInput}, // Logitech F710, D-mode
{"054c", "05c4", MapperDualshock4}, // Playstation Dualshock 4
{"054c", "09cc", MapperDualshock4}, // Dualshock 4 (PS4 Slim)
{"054c", "0ba0", MapperDualshock4}, // Dualshock 4 USB receiver
{"0583", "2060", MapperIBuffalo}, // iBuffalo Classic
{"0955", "7210", MapperNvShield}, // Nvidia Shield gamepad (2015)
{"0955", "7214", MapperNvShield2017}, // Nvidia Shield gamepad (2017)
{"0b05", "4500", MapperADT1}, // Nexus Player Controller
{"1532", "0900", MapperRazerServal}, // Razer Serval Controller
{"18d1", "2c40", MapperADT1}, // ADT-1 Controller
{"20d6", "6271", MapperMogaPro}, // Moga Pro Controller (HID mode)
{"2378", "1008", MapperOnLiveWireless}, // OnLive Controller (Bluetooth)
{"2378", "100a", MapperOnLiveWireless}, // OnLive Controller (Wired)
{"2836", "0001", MapperOUYA}, // OUYA Controller
{0x0079, 0x0011, Mapper2Axes8Keys}, // 2Axes 8Keys Game Pad
{0x046d, 0xc216, MapperLogitechDInput}, // Logitech F310, D-mode
{0x046d, 0xc218, MapperLogitechDInput}, // Logitech F510, D-mode
{0x046d, 0xc219, MapperLogitechDInput}, // Logitech F710, D-mode
{0x054c, 0x05c4, MapperDualshock4}, // Playstation Dualshock 4
{0x054c, 0x09cc, MapperDualshock4}, // Dualshock 4 (PS4 Slim)
{0x054c, 0x0ba0, MapperDualshock4}, // Dualshock 4 USB receiver
{0x0583, 0x2060, MapperIBuffalo}, // iBuffalo Classic
{0x0955, 0x7210, MapperNvShield}, // Nvidia Shield gamepad (2015)
{0x0955, 0x7214, MapperNvShield2017}, // Nvidia Shield gamepad (2017)
{0x0b05, 0x4500, MapperADT1}, // Nexus Player Controller
{0x1532, 0x0900, MapperRazerServal}, // Razer Serval Controller
{0x18d1, 0x2c40, MapperADT1}, // ADT-1 Controller
{0x20d6, 0x6271, MapperMogaPro}, // Moga Pro Controller (HID mode)
{0x2378, 0x1008, MapperOnLiveWireless}, // OnLive Controller (Bluetooth)
{0x2378, 0x100a, MapperOnLiveWireless}, // OnLive Controller (Wired)
{0x2836, 0x0001, MapperOUYA}, // OUYA Controller
};
const size_t kAvailableMappingsLen = base::size(AvailableMappings);
} // namespace
GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
const base::StringPiece& vendor_id,
const base::StringPiece& product_id,
const base::StringPiece& version_number,
const uint16_t vendor_id,
const uint16_t product_id,
const uint16_t version_number,
GamepadBusType bus_type) {
for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
for (size_t i = 0; i < kAvailableMappingsLen; ++i) {
MappingData& item = AvailableMappings[i];
if (vendor_id == item.vendor_id && product_id == item.product_id)
return item.function;
}
return NULL;
return nullptr;
}
} // namespace device

@ -196,11 +196,8 @@ void RawInputDataFetcher::EnumerateDevices() {
const int version_number = device->GetVersionNumber();
const std::wstring product_string = device->GetProductString();
const std::string vendor = base::StringPrintf("%04x", vendor_int);
const std::string product = base::StringPrintf("%04x", product_int);
const std::string version = base::StringPrintf("%04x", version_number);
state->mapper = GetGamepadStandardMappingFunction(
vendor, product, version, GAMEPAD_BUS_UNKNOWN);
vendor_int, product_int, version_number, GAMEPAD_BUS_UNKNOWN);
state->axis_mask = 0;
state->button_mask = 0;

@ -109,8 +109,6 @@ void RawInputGamepadDeviceWin::UpdateGamepad(RAWINPUT* input) {
DCHECK(hid_functions_->IsValid());
NTSTATUS status;
report_id_++;
// Query button state.
if (buttons_length_ > 0) {
// Clear the button state
@ -291,9 +289,9 @@ bool RawInputGamepadDeviceWin::QueryHidInfo() {
reinterpret_cast<RID_DEVICE_INFO*>(buffer.get());
DCHECK_EQ(device_info->dwType, static_cast<DWORD>(RIM_TYPEHID));
vendor_id_ = device_info->hid.dwVendorId;
product_id_ = device_info->hid.dwProductId;
version_number_ = device_info->hid.dwVersionNumber;
vendor_id_ = static_cast<uint16_t>(device_info->hid.dwVendorId);
product_id_ = static_cast<uint16_t>(device_info->hid.dwProductId);
version_number_ = static_cast<uint16_t>(device_info->hid.dwVersionNumber);
usage_ = device_info->hid.usUsage;
return true;

@ -38,9 +38,9 @@ class RawInputGamepadDeviceWin : public AbstractHapticGamepad {
static bool IsGamepadUsageId(uint16_t usage);
int GetSourceId() const { return source_id_; }
int GetVendorId() const { return vendor_id_; }
int GetVersionNumber() const { return version_number_; }
int GetProductId() const { return product_id_; }
uint16_t GetVendorId() const { return vendor_id_; }
uint16_t GetVersionNumber() const { return version_number_; }
uint16_t GetProductId() const { return product_id_; }
std::wstring GetDeviceName() const { return name_; }
std::wstring GetProductString() const { return product_string_; }
@ -111,13 +111,9 @@ class RawInputGamepadDeviceWin : public AbstractHapticGamepad {
// Functions loaded from hid.dll. Not owned.
HidDllFunctionsWin* hid_functions_ = nullptr;
// The report ID incremented each time an input message is received for this
// device. It is included in the pad info in place of a timestamp.
uint32_t report_id_ = 0;
uint32_t vendor_id_ = 0;
uint32_t product_id_ = 0;
uint32_t version_number_ = 0;
uint16_t vendor_id_ = 0;
uint16_t product_id_ = 0;
uint16_t version_number_ = 0;
uint16_t usage_ = 0;
std::wstring name_;
std::wstring product_string_;

@ -10,8 +10,8 @@
#include "device/gamepad/gamepad_standard_mappings.h"
namespace {
const uint32_t kVendorNintendo = 0x057e;
const uint32_t kProductSwitchProController = 0x2009;
const uint16_t kVendorNintendo = 0x057e;
const uint16_t kProductSwitchProController = 0x2009;
const uint8_t kRumbleMagnitudeMax = 0xff;
@ -59,7 +59,8 @@ struct ControllerDataReport {
};
#pragma pack(pop)
ControllerType ControllerTypeFromDeviceIds(int vendor_id, int product_id) {
ControllerType ControllerTypeFromDeviceIds(uint16_t vendor_id,
uint16_t product_id) {
if (vendor_id == kVendorNintendo) {
switch (product_id) {
case kProductSwitchProController:
@ -178,7 +179,8 @@ namespace device {
SwitchProControllerBase::~SwitchProControllerBase() = default;
// static
bool SwitchProControllerBase::IsSwitchPro(int vendor_id, int product_id) {
bool SwitchProControllerBase::IsSwitchPro(uint16_t vendor_id,
uint16_t product_id) {
return ControllerTypeFromDeviceIds(vendor_id, product_id) !=
UNKNOWN_CONTROLLER;
}

@ -18,7 +18,7 @@ class SwitchProControllerBase : public AbstractHapticGamepad {
SwitchProControllerBase() = default;
~SwitchProControllerBase() override;
static bool IsSwitchPro(int vendor_id, int product_id);
static bool IsSwitchPro(uint16_t vendor_id, uint16_t product_id);
void DoShutdown() override;

@ -25,12 +25,12 @@ namespace device {
class XboxControllerMac {
public:
static const int kVendorMicrosoft = 0x045e;
static const int kProductXbox360Controller = 0x028e;
static const int kProductXboxOneController2013 = 0x02d1;
static const int kProductXboxOneController2015 = 0x02dd;
static const int kProductXboxOneEliteController = 0x02e3;
static const int kProductXboxOneSController = 0x02ea;
static const uint16_t kVendorMicrosoft = 0x045e;
static const uint16_t kProductXbox360Controller = 0x028e;
static const uint16_t kProductXboxOneController2013 = 0x02d1;
static const uint16_t kProductXboxOneController2015 = 0x02dd;
static const uint16_t kProductXboxOneEliteController = 0x02e3;
static const uint16_t kProductXboxOneSController = 0x02ea;
enum ControllerType {
UNKNOWN_CONTROLLER,
@ -114,8 +114,8 @@ class XboxControllerMac {
mojom::GamepadHapticsManager::ResetVibrationActuatorCallback callback);
UInt32 location_id() { return location_id_; }
int GetVendorId() const;
int GetProductId() const;
uint16_t GetVendorId() const;
uint16_t GetProductId() const;
ControllerType GetControllerType() const;
std::string GetControllerTypeString() const;
std::string GetIdString() const;

@ -277,8 +277,8 @@ void NormalizeXboxOneButtonData(const XboxOneButtonData& data,
&normalized_data->axes[2], &normalized_data->axes[3]);
}
XboxControllerMac::ControllerType ControllerTypeFromIds(int vendor_id,
int product_id) {
XboxControllerMac::ControllerType ControllerTypeFromIds(uint16_t vendor_id,
uint16_t product_id) {
if (vendor_id == XboxControllerMac::kVendorMicrosoft) {
switch (product_id) {
case XboxControllerMac::kProductXbox360Controller:
@ -438,12 +438,12 @@ XboxControllerMac::OpenDeviceResult XboxControllerMac::OpenDevice(
if (!SUCCEEDED(res) || !device_)
return OPEN_FAILED;
UInt16 vendor_id;
uint16_t vendor_id;
kr = (*device_)->GetDeviceVendor(device_, &vendor_id);
if (kr != KERN_SUCCESS || vendor_id != kVendorMicrosoft)
return OPEN_FAILED;
UInt16 product_id;
uint16_t product_id;
kr = (*device_)->GetDeviceProduct(device_, &product_id);
if (kr != KERN_SUCCESS)
return OPEN_FAILED;
@ -633,7 +633,7 @@ void XboxControllerMac::SetLEDPattern(LEDPattern pattern) {
}
}
int XboxControllerMac::GetVendorId() const {
uint16_t XboxControllerMac::GetVendorId() const {
switch (controller_type_) {
case XBOX_360_CONTROLLER:
case XBOX_ONE_CONTROLLER_2013:
@ -646,7 +646,7 @@ int XboxControllerMac::GetVendorId() const {
}
}
int XboxControllerMac::GetProductId() const {
uint16_t XboxControllerMac::GetProductId() const {
switch (controller_type_) {
case XBOX_360_CONTROLLER:
return kProductXbox360Controller;