mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-04 23:22:48 +02:00
committed by
Sam Lantinga
parent
e29c0661cc
commit
d0bbfdbfb8
@@ -825,20 +825,21 @@ static const char *map_StringForControllerAxis[] = {
|
||||
/*
|
||||
* convert a string to its enum equivalent
|
||||
*/
|
||||
SDL_GameControllerAxis SDL_GameControllerGetAxisFromString(const char *pchString)
|
||||
SDL_GameControllerAxis
|
||||
SDL_GameControllerGetAxisFromString(const char *str)
|
||||
{
|
||||
int entry;
|
||||
|
||||
if (pchString && (*pchString == '+' || *pchString == '-')) {
|
||||
++pchString;
|
||||
}
|
||||
|
||||
if (pchString == NULL || !pchString[0]) {
|
||||
if (str == NULL || str[0] == '\0') {
|
||||
return SDL_CONTROLLER_AXIS_INVALID;
|
||||
}
|
||||
|
||||
if (*str == '+' || *str == '-') {
|
||||
++str;
|
||||
}
|
||||
|
||||
for (entry = 0; map_StringForControllerAxis[entry]; ++entry) {
|
||||
if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry])) {
|
||||
if (SDL_strcasecmp(str, map_StringForControllerAxis[entry]) == 0) {
|
||||
return (SDL_GameControllerAxis)entry;
|
||||
}
|
||||
}
|
||||
@@ -884,15 +885,16 @@ static const char *map_StringForControllerButton[] = {
|
||||
/*
|
||||
* convert a string to its enum equivalent
|
||||
*/
|
||||
SDL_GameControllerButton SDL_GameControllerGetButtonFromString(const char *pchString)
|
||||
SDL_GameControllerButton
|
||||
SDL_GameControllerGetButtonFromString(const char *str)
|
||||
{
|
||||
int entry;
|
||||
if (pchString == NULL || !pchString[0]) {
|
||||
if (str == NULL || str[0] == '\0') {
|
||||
return SDL_CONTROLLER_BUTTON_INVALID;
|
||||
}
|
||||
|
||||
for (entry = 0; map_StringForControllerButton[entry]; ++entry) {
|
||||
if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0) {
|
||||
if (SDL_strcasecmp(str, map_StringForControllerButton[entry]) == 0) {
|
||||
return (SDL_GameControllerButton)entry;
|
||||
}
|
||||
}
|
||||
@@ -902,10 +904,10 @@ SDL_GameControllerButton SDL_GameControllerGetButtonFromString(const char *pchSt
|
||||
/*
|
||||
* convert an enum to its string equivalent
|
||||
*/
|
||||
const char *SDL_GameControllerGetStringForButton(SDL_GameControllerButton axis)
|
||||
const char *SDL_GameControllerGetStringForButton(SDL_GameControllerButton button)
|
||||
{
|
||||
if (axis > SDL_CONTROLLER_BUTTON_INVALID && axis < SDL_CONTROLLER_BUTTON_MAX) {
|
||||
return map_StringForControllerButton[axis];
|
||||
if (button > SDL_CONTROLLER_BUTTON_INVALID && button < SDL_CONTROLLER_BUTTON_MAX) {
|
||||
return map_StringForControllerButton[button];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -1071,7 +1073,7 @@ static void SDL_PrivateLoadButtonMapping(SDL_GameController *gamecontroller, Con
|
||||
gamecontroller->name = pControllerMapping->name;
|
||||
gamecontroller->num_bindings = 0;
|
||||
gamecontroller->mapping = pControllerMapping;
|
||||
if (gamecontroller->joystick->naxes) {
|
||||
if (gamecontroller->joystick->naxes != 0 && gamecontroller->last_match_axis != NULL) {
|
||||
SDL_memset(gamecontroller->last_match_axis, 0, gamecontroller->joystick->naxes * sizeof(*gamecontroller->last_match_axis));
|
||||
}
|
||||
|
||||
@@ -1351,13 +1353,13 @@ static void SDL_PrivateAppendToMappingString(char *mapping_string,
|
||||
SDL_strlcat(mapping_string, ":", mapping_string_len);
|
||||
switch (mapping->kind) {
|
||||
case EMappingKind_Button:
|
||||
SDL_snprintf(buffer, sizeof(buffer), "b%i", mapping->target);
|
||||
(void)SDL_snprintf(buffer, sizeof buffer, "b%i", mapping->target);
|
||||
break;
|
||||
case EMappingKind_Axis:
|
||||
SDL_snprintf(buffer, sizeof(buffer), "a%i", mapping->target);
|
||||
(void)SDL_snprintf(buffer, sizeof buffer, "a%i", mapping->target);
|
||||
break;
|
||||
case EMappingKind_Hat:
|
||||
SDL_snprintf(buffer, sizeof(buffer), "h%i.%i", mapping->target >> 4, mapping->target & 0x0F);
|
||||
(void)SDL_snprintf(buffer, sizeof buffer, "h%i.%i", mapping->target >> 4, mapping->target & 0x0F);
|
||||
break;
|
||||
default:
|
||||
SDL_assert(SDL_FALSE);
|
||||
@@ -1385,7 +1387,7 @@ static ControllerMapping_t *SDL_PrivateGenerateAutomaticControllerMapping(const
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_snprintf(mapping, sizeof(mapping), "none,%s,", name_string);
|
||||
(void)SDL_snprintf(mapping, sizeof mapping, "none,%s,", name_string);
|
||||
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "a", &raw_map->a);
|
||||
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "b", &raw_map->b);
|
||||
SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "x", &raw_map->x);
|
||||
@@ -1677,7 +1679,7 @@ static char *CreateMappingString(ControllerMapping_t *mapping, SDL_JoystickGUID
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
|
||||
(void)SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
|
||||
|
||||
if (!SDL_strstr(mapping->mapping, SDL_CONTROLLER_PLATFORM_FIELD)) {
|
||||
if (mapping->mapping[SDL_strlen(mapping->mapping) - 1] != ',') {
|
||||
@@ -1848,12 +1850,12 @@ int SDL_GameControllerInit(void)
|
||||
* Get the implementation dependent name of a controller
|
||||
*/
|
||||
const char *
|
||||
SDL_GameControllerNameForIndex(int device_index)
|
||||
SDL_GameControllerNameForIndex(int joystick_index)
|
||||
{
|
||||
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
|
||||
if (pSupportedController) {
|
||||
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(joystick_index);
|
||||
if (pSupportedController != NULL) {
|
||||
if (SDL_strcmp(pSupportedController->name, "*") == 0) {
|
||||
return SDL_JoystickNameForIndex(device_index);
|
||||
return SDL_JoystickNameForIndex(joystick_index);
|
||||
} else {
|
||||
return pSupportedController->name;
|
||||
}
|
||||
@@ -1865,11 +1867,11 @@ SDL_GameControllerNameForIndex(int device_index)
|
||||
* Get the implementation dependent path of a controller
|
||||
*/
|
||||
const char *
|
||||
SDL_GameControllerPathForIndex(int device_index)
|
||||
SDL_GameControllerPathForIndex(int joystick_index)
|
||||
{
|
||||
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
|
||||
if (pSupportedController) {
|
||||
return SDL_JoystickPathForIndex(device_index);
|
||||
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(joystick_index);
|
||||
if (pSupportedController != NULL) {
|
||||
return SDL_JoystickPathForIndex(joystick_index);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -1910,7 +1912,7 @@ SDL_GameControllerMappingForDeviceIndex(int joystick_index)
|
||||
SDL_UnlockJoysticks();
|
||||
return NULL;
|
||||
}
|
||||
SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
|
||||
(void)SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
|
||||
}
|
||||
SDL_UnlockJoysticks();
|
||||
return pMappingString;
|
||||
@@ -1933,10 +1935,10 @@ SDL_IsGameControllerNameAndGUID(const char *name, SDL_JoystickGUID guid)
|
||||
* Return 1 if the joystick at this device index is a supported controller
|
||||
*/
|
||||
SDL_bool
|
||||
SDL_IsGameController(int device_index)
|
||||
SDL_IsGameController(int joystick_index)
|
||||
{
|
||||
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
|
||||
if (pSupportedController) {
|
||||
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(joystick_index);
|
||||
if (pSupportedController != NULL) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
return SDL_FALSE;
|
||||
@@ -2042,7 +2044,7 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
|
||||
* This function returns a controller identifier, or NULL if an error occurred.
|
||||
*/
|
||||
SDL_GameController *
|
||||
SDL_GameControllerOpen(int device_index)
|
||||
SDL_GameControllerOpen(int joystick_index)
|
||||
{
|
||||
SDL_JoystickID instance_id;
|
||||
SDL_GameController *gamecontroller;
|
||||
@@ -2053,8 +2055,8 @@ SDL_GameControllerOpen(int device_index)
|
||||
|
||||
gamecontrollerlist = SDL_gamecontrollers;
|
||||
/* If the controller is already open, return it */
|
||||
instance_id = SDL_JoystickGetDeviceInstanceID(device_index);
|
||||
while (gamecontrollerlist) {
|
||||
instance_id = SDL_JoystickGetDeviceInstanceID(joystick_index);
|
||||
while (gamecontrollerlist != NULL) {
|
||||
if (instance_id == gamecontrollerlist->joystick->instance_id) {
|
||||
gamecontroller = gamecontrollerlist;
|
||||
++gamecontroller->ref_count;
|
||||
@@ -2065,9 +2067,9 @@ SDL_GameControllerOpen(int device_index)
|
||||
}
|
||||
|
||||
/* Find a controller mapping */
|
||||
pSupportedController = SDL_PrivateGetControllerMapping(device_index);
|
||||
pSupportedController = SDL_PrivateGetControllerMapping(joystick_index);
|
||||
if (pSupportedController == NULL) {
|
||||
SDL_SetError("Couldn't find mapping for device (%d)", device_index);
|
||||
SDL_SetError("Couldn't find mapping for device (%d)", joystick_index);
|
||||
SDL_UnlockJoysticks();
|
||||
return NULL;
|
||||
}
|
||||
@@ -2081,8 +2083,8 @@ SDL_GameControllerOpen(int device_index)
|
||||
}
|
||||
gamecontroller->magic = &gamecontroller_magic;
|
||||
|
||||
gamecontroller->joystick = SDL_JoystickOpen(device_index);
|
||||
if (!gamecontroller->joystick) {
|
||||
gamecontroller->joystick = SDL_JoystickOpen(joystick_index);
|
||||
if (gamecontroller->joystick == NULL) {
|
||||
SDL_free(gamecontroller);
|
||||
SDL_UnlockJoysticks();
|
||||
return NULL;
|
||||
|
||||
@@ -1881,7 +1881,7 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
|
||||
len = (SDL_strlen(vendor_name) + 1 + SDL_strlen(product_name) + 1);
|
||||
name = (char *)SDL_malloc(len);
|
||||
if (name) {
|
||||
SDL_snprintf(name, len, "%s %s", vendor_name, product_name);
|
||||
(void)SDL_snprintf(name, len, "%s %s", vendor_name, product_name);
|
||||
}
|
||||
} else if (*product_name) {
|
||||
name = SDL_strdup(product_name);
|
||||
@@ -1909,8 +1909,8 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
|
||||
default:
|
||||
len = (6 + 1 + 6 + 1);
|
||||
name = (char *)SDL_malloc(len);
|
||||
if (name) {
|
||||
SDL_snprintf(name, len, "0x%.4x/0x%.4x", vendor, product);
|
||||
if (name != NULL) {
|
||||
(void)SDL_snprintf(name, len, "0x%.4x/0x%.4x", vendor, product);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -519,7 +519,6 @@ static SDL_bool JoystickAlreadyKnown(IOHIDDeviceRef ioHIDDeviceObject)
|
||||
static void JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject)
|
||||
{
|
||||
recDevice *device;
|
||||
int device_index = 0;
|
||||
io_service_t ioservice;
|
||||
|
||||
if (res != kIOReturnSuccess) {
|
||||
@@ -570,12 +569,10 @@ static void JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender
|
||||
recDevice *curdevice;
|
||||
|
||||
curdevice = gpDeviceList;
|
||||
while (curdevice->pNext) {
|
||||
++device_index;
|
||||
while (curdevice->pNext != NULL) {
|
||||
curdevice = curdevice->pNext;
|
||||
}
|
||||
curdevice->pNext = device;
|
||||
++device_index; /* bump by one since we counted by pNext. */
|
||||
}
|
||||
|
||||
SDL_PrivateJoystickAdded(device->instance_id);
|
||||
|
||||
@@ -233,7 +233,7 @@ static void HIDAPI_DriverGameCube_SetDevicePlayerIndex(SDL_HIDAPI_Device *device
|
||||
{
|
||||
}
|
||||
|
||||
static void HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device, SDL_DriverGameCube_Context *ctx, Uint8 *packet, int size)
|
||||
static void HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device, SDL_DriverGameCube_Context *ctx, const Uint8 *packet, int size)
|
||||
{
|
||||
SDL_Joystick *joystick;
|
||||
Uint8 i, v;
|
||||
|
||||
@@ -158,9 +158,9 @@ static SDL_bool HIDAPI_DriverPS3_InitDevice(SDL_HIDAPI_Device *device)
|
||||
/* Set the controller into report mode over USB */
|
||||
{
|
||||
Uint8 data[USB_PACKET_LENGTH];
|
||||
int size;
|
||||
|
||||
if ((size = ReadFeatureReport(device->dev, 0xf2, data, 17)) < 0) {
|
||||
int size = ReadFeatureReport(device->dev, 0xf2, data, 17);
|
||||
if (size < 0) {
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"HIDAPI_DriverPS3_InitDevice(): Couldn't read feature report 0xf2");
|
||||
return SDL_FALSE;
|
||||
@@ -168,7 +168,8 @@ static SDL_bool HIDAPI_DriverPS3_InitDevice(SDL_HIDAPI_Device *device)
|
||||
#ifdef DEBUG_PS3_PROTOCOL
|
||||
HIDAPI_DumpPacket("PS3 0xF2 packet: size = %d", data, size);
|
||||
#endif
|
||||
if ((size = ReadFeatureReport(device->dev, 0xf5, data, 8)) < 0) {
|
||||
size = ReadFeatureReport(device->dev, 0xf5, data, 8);
|
||||
if (size < 0) {
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"HIDAPI_DriverPS3_InitDevice(): Couldn't read feature report 0xf5");
|
||||
return SDL_FALSE;
|
||||
@@ -583,8 +584,8 @@ static SDL_bool HIDAPI_DriverPS3ThirdParty_IsSupportedDevice(SDL_HIDAPI_Device *
|
||||
|
||||
if (SONY_THIRDPARTY_VENDOR(vendor_id)) {
|
||||
if (device && device->dev) {
|
||||
if ((size = ReadFeatureReport(device->dev, 0x03, data, sizeof(data))) == 8 &&
|
||||
data[2] == 0x26) {
|
||||
size = ReadFeatureReport(device->dev, 0x03, data, sizeof data);
|
||||
if (size == 8 && data[2] == 0x26) {
|
||||
/* Supported third party controller */
|
||||
return SDL_TRUE;
|
||||
} else {
|
||||
|
||||
@@ -189,8 +189,8 @@ static SDL_bool HIDAPI_DriverPS4_IsSupportedDevice(SDL_HIDAPI_Device *device, co
|
||||
|
||||
if (SONY_THIRDPARTY_VENDOR(vendor_id)) {
|
||||
if (device && device->dev) {
|
||||
if ((size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
|
||||
data[2] == 0x27) {
|
||||
size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof data);
|
||||
if (size == 48 && data[2] == 0x27) {
|
||||
/* Supported third party controller */
|
||||
return SDL_TRUE;
|
||||
} else {
|
||||
@@ -268,8 +268,8 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
|
||||
if (ctx->is_dongle) {
|
||||
size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdSerialNumber, data, sizeof(data));
|
||||
if (size >= 7 && (data[1] || data[2] || data[3] || data[4] || data[5] || data[6])) {
|
||||
SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
(void)SDL_snprintf(serial, sizeof serial, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
}
|
||||
device->is_bluetooth = SDL_FALSE;
|
||||
ctx->enhanced_mode = SDL_TRUE;
|
||||
@@ -277,8 +277,8 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
|
||||
/* This will fail if we're on Bluetooth */
|
||||
size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdSerialNumber, data, sizeof(data));
|
||||
if (size >= 7 && (data[1] || data[2] || data[3] || data[4] || data[5] || data[6])) {
|
||||
SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
(void)SDL_snprintf(serial, sizeof serial, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
device->is_bluetooth = SDL_FALSE;
|
||||
ctx->enhanced_mode = SDL_TRUE;
|
||||
} else {
|
||||
@@ -308,6 +308,7 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
|
||||
SDL_Log("PS4 dongle = %s, bluetooth = %s\n", ctx->is_dongle ? "TRUE" : "FALSE", device->is_bluetooth ? "TRUE" : "FALSE");
|
||||
#endif
|
||||
|
||||
size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof data);
|
||||
/* Get the device capabilities */
|
||||
if (device->vendor_id == USB_VENDOR_SONY) {
|
||||
ctx->official_controller = SDL_TRUE;
|
||||
@@ -315,8 +316,7 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
|
||||
ctx->lightbar_supported = SDL_TRUE;
|
||||
ctx->vibration_supported = SDL_TRUE;
|
||||
ctx->touchpad_supported = SDL_TRUE;
|
||||
} else if ((size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
|
||||
data[2] == 0x27) {
|
||||
} else if (size == 48 && data[2] == 0x27) {
|
||||
Uint8 capabilities = data[4];
|
||||
Uint8 device_type = data[5];
|
||||
|
||||
@@ -1119,8 +1119,8 @@ static SDL_bool HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
char serial[18];
|
||||
size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdSerialNumber, data, sizeof(data));
|
||||
if (size >= 7 && (data[1] || data[2] || data[3] || data[4] || data[5] || data[6])) {
|
||||
SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
(void)SDL_snprintf(serial, sizeof serial, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
HIDAPI_SetDeviceSerial(device, serial);
|
||||
}
|
||||
HIDAPI_JoystickConnected(device, NULL);
|
||||
|
||||
@@ -275,8 +275,8 @@ static SDL_bool HIDAPI_DriverPS5_IsSupportedDevice(SDL_HIDAPI_Device *device, co
|
||||
|
||||
if (SONY_THIRDPARTY_VENDOR(vendor_id)) {
|
||||
if (device && device->dev) {
|
||||
if ((size = ReadFeatureReport(device->dev, k_EPS5FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
|
||||
data[2] == 0x28) {
|
||||
size = ReadFeatureReport(device->dev, k_EPS5FeatureReportIdCapabilities, data, sizeof data);
|
||||
if (size == 48 && data[2] == 0x28) {
|
||||
/* Supported third party controller */
|
||||
return SDL_TRUE;
|
||||
} else {
|
||||
@@ -400,8 +400,8 @@ static SDL_bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||
This will also enable enhanced reports over Bluetooth
|
||||
*/
|
||||
if (ReadFeatureReport(device->dev, k_EPS5FeatureReportIdSerialNumber, data, sizeof(data)) >= 7) {
|
||||
SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
(void)SDL_snprintf(serial, sizeof serial, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
}
|
||||
|
||||
/* Read the firmware version
|
||||
@@ -412,6 +412,7 @@ static SDL_bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||
}
|
||||
}
|
||||
|
||||
size = ReadFeatureReport(device->dev, k_EPS5FeatureReportIdCapabilities, data, sizeof data);
|
||||
/* Get the device capabilities */
|
||||
if (device->vendor_id == USB_VENDOR_SONY) {
|
||||
ctx->sensors_supported = SDL_TRUE;
|
||||
@@ -419,8 +420,7 @@ static SDL_bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||
ctx->vibration_supported = SDL_TRUE;
|
||||
ctx->playerled_supported = SDL_TRUE;
|
||||
ctx->touchpad_supported = SDL_TRUE;
|
||||
} else if ((size = ReadFeatureReport(device->dev, k_EPS5FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
|
||||
data[2] == 0x28) {
|
||||
} else if (size == 48 && data[2] == 0x28) {
|
||||
Uint8 capabilities = data[4];
|
||||
Uint8 capabilities2 = data[20];
|
||||
Uint8 device_type = data[5];
|
||||
|
||||
@@ -368,7 +368,7 @@ static void HIDAPI_DriverShield_HandleStatePacketV103(SDL_Joystick *joystick, SD
|
||||
#undef clamp
|
||||
#define clamp(val, min, max) (((val) > (max)) ? (max) : (((val) < (min)) ? (min) : (val)))
|
||||
|
||||
static void HIDAPI_DriverShield_HandleTouchPacketV103(SDL_Joystick *joystick, SDL_DriverShield_Context *ctx, Uint8 *data, int size)
|
||||
static void HIDAPI_DriverShield_HandleTouchPacketV103(SDL_Joystick *joystick, SDL_DriverShield_Context *ctx, const Uint8 *data, int size)
|
||||
{
|
||||
Uint8 touchpad_state;
|
||||
float touchpad_x, touchpad_y;
|
||||
|
||||
@@ -244,7 +244,7 @@ static int WriteSegmentToSteamControllerPacketAssembler(SteamControllerPacketAss
|
||||
}
|
||||
|
||||
if (nSegmentLength != MAX_REPORT_SEGMENT_SIZE) {
|
||||
printf("Bad segment size! %d\n", (int)nSegmentLength);
|
||||
printf("Bad segment size! %d\n", nSegmentLength);
|
||||
hexdump(pSegment, nSegmentLength);
|
||||
ResetSteamControllerPacketAssembler(pAssembler);
|
||||
return -1;
|
||||
@@ -365,10 +365,11 @@ static int GetFeatureReport(SDL_hid_device *dev, unsigned char uBuffer[65])
|
||||
HEXDUMP(uSegmentBuffer, nRet);
|
||||
|
||||
// Zero retry counter if we got data
|
||||
if (nRet > 2 && (uSegmentBuffer[ucDataStartOffset + 1] & REPORT_SEGMENT_DATA_FLAG))
|
||||
if (nRet > 2 && (uSegmentBuffer[ucDataStartOffset + 1] & REPORT_SEGMENT_DATA_FLAG)) {
|
||||
nRetries = 0;
|
||||
else
|
||||
} else {
|
||||
nRetries++;
|
||||
}
|
||||
|
||||
if (nRet > 0) {
|
||||
int nPacketLength = WriteSegmentToSteamControllerPacketAssembler(&assembler,
|
||||
@@ -752,19 +753,21 @@ static void FormatStatePacketUntilGyro(SteamControllerStateInternal_t *pState, V
|
||||
RotatePad(&nLeftPadX, &nLeftPadY, -flRotationAngle);
|
||||
RotatePad(&nRightPadX, &nRightPadY, flRotationAngle);
|
||||
|
||||
if (pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK)
|
||||
if (pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK) {
|
||||
nPadOffset = 1000;
|
||||
else
|
||||
} else {
|
||||
nPadOffset = 0;
|
||||
}
|
||||
|
||||
pState->sLeftPadX = clamp(nLeftPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
|
||||
pState->sLeftPadY = clamp(nLeftPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
|
||||
|
||||
nPadOffset = 0;
|
||||
if (pState->ulButtons & STEAM_RIGHTPAD_FINGERDOWN_MASK)
|
||||
if (pState->ulButtons & STEAM_RIGHTPAD_FINGERDOWN_MASK) {
|
||||
nPadOffset = 1000;
|
||||
else
|
||||
} else {
|
||||
nPadOffset = 0;
|
||||
}
|
||||
|
||||
pState->sRightPadX = clamp(nRightPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
|
||||
pState->sRightPadY = clamp(nRightPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
|
||||
@@ -811,10 +814,11 @@ static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, S
|
||||
int nLength = sizeof(pState->sLeftPadX) + sizeof(pState->sLeftPadY);
|
||||
int nPadOffset;
|
||||
SDL_memcpy(&pState->sLeftPadX, pData, nLength);
|
||||
if (pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK)
|
||||
if (pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK) {
|
||||
nPadOffset = 1000;
|
||||
else
|
||||
} else {
|
||||
nPadOffset = 0;
|
||||
}
|
||||
|
||||
RotatePadShort(&pState->sLeftPadX, &pState->sLeftPadY, -flRotationAngle);
|
||||
pState->sLeftPadX = clamp(pState->sLeftPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
|
||||
@@ -827,10 +831,11 @@ static bool UpdateBLESteamControllerState(const uint8_t *pData, int nDataSize, S
|
||||
|
||||
SDL_memcpy(&pState->sRightPadX, pData, nLength);
|
||||
|
||||
if (pState->ulButtons & STEAM_RIGHTPAD_FINGERDOWN_MASK)
|
||||
if (pState->ulButtons & STEAM_RIGHTPAD_FINGERDOWN_MASK) {
|
||||
nPadOffset = 1000;
|
||||
else
|
||||
} else {
|
||||
nPadOffset = 0;
|
||||
}
|
||||
|
||||
RotatePadShort(&pState->sRightPadX, &pState->sRightPadY, flRotationAngle);
|
||||
pState->sRightPadX = clamp(pState->sRightPadX + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16);
|
||||
|
||||
@@ -829,9 +829,9 @@ static SDL_bool LoadIMUCalibration(SDL_DriverSwitch_Context *ctx)
|
||||
}
|
||||
|
||||
/* Accelerometer scale */
|
||||
ctx->m_IMUScaleData.fAccelScaleX = SWITCH_ACCEL_SCALE_MULT / (float)(SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawX) * SDL_STANDARD_GRAVITY;
|
||||
ctx->m_IMUScaleData.fAccelScaleY = SWITCH_ACCEL_SCALE_MULT / (float)(SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawY) * SDL_STANDARD_GRAVITY;
|
||||
ctx->m_IMUScaleData.fAccelScaleZ = SWITCH_ACCEL_SCALE_MULT / (float)(SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawZ) * SDL_STANDARD_GRAVITY;
|
||||
ctx->m_IMUScaleData.fAccelScaleX = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawX) * SDL_STANDARD_GRAVITY;
|
||||
ctx->m_IMUScaleData.fAccelScaleY = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawY) * SDL_STANDARD_GRAVITY;
|
||||
ctx->m_IMUScaleData.fAccelScaleZ = SWITCH_ACCEL_SCALE_MULT / (SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawZ) * SDL_STANDARD_GRAVITY;
|
||||
|
||||
/* Gyro scale */
|
||||
ctx->m_IMUScaleData.fGyroScaleX = SWITCH_GYRO_SCALE_MULT / (float)(SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawX) * (float)M_PI / 180.0f;
|
||||
@@ -1177,13 +1177,13 @@ static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
|
||||
}
|
||||
device->guid.data[15] = ctx->m_eControllerType;
|
||||
|
||||
SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
ctx->m_rgucMACAddress[0],
|
||||
ctx->m_rgucMACAddress[1],
|
||||
ctx->m_rgucMACAddress[2],
|
||||
ctx->m_rgucMACAddress[3],
|
||||
ctx->m_rgucMACAddress[4],
|
||||
ctx->m_rgucMACAddress[5]);
|
||||
(void)SDL_snprintf(serial, sizeof serial, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
ctx->m_rgucMACAddress[0],
|
||||
ctx->m_rgucMACAddress[1],
|
||||
ctx->m_rgucMACAddress[2],
|
||||
ctx->m_rgucMACAddress[3],
|
||||
ctx->m_rgucMACAddress[4],
|
||||
ctx->m_rgucMACAddress[5]);
|
||||
HIDAPI_SetDeviceSerial(device, serial);
|
||||
}
|
||||
|
||||
@@ -1717,7 +1717,8 @@ static void HandleSimpleControllerState(SDL_Joystick *joystick, SDL_DriverSwitch
|
||||
ctx->m_lastSimpleState = *packet;
|
||||
}
|
||||
|
||||
static void SendSensorUpdate(SDL_Joystick *joystick, SDL_DriverSwitch_Context *ctx, SDL_SensorType type, Uint64 timestamp_us, Sint16 *values)
|
||||
static void
|
||||
SendSensorUpdate(SDL_Joystick *joystick, SDL_DriverSwitch_Context *ctx, SDL_SensorType type, Uint64 timestamp_us, const Sint16 *values)
|
||||
{
|
||||
float data[3];
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ static void SetInitState(SDL_DriverXboxOne_Context *ctx, SDL_XboxOneInitState st
|
||||
ctx->init_state = state;
|
||||
}
|
||||
|
||||
static void SendAckIfNeeded(SDL_HIDAPI_Device *device, Uint8 *data, int size)
|
||||
static void SendAckIfNeeded(SDL_HIDAPI_Device *device, const Uint8 *data, int size)
|
||||
{
|
||||
#if defined(__WIN32__) || defined(__WINGDK__)
|
||||
/* The Windows driver is taking care of acks */
|
||||
@@ -812,7 +812,7 @@ static void HIDAPI_DriverXboxOne_HandleStatusPacket(SDL_Joystick *joystick, SDL_
|
||||
}
|
||||
}
|
||||
|
||||
static void HIDAPI_DriverXboxOne_HandleModePacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, Uint8 *data, int size)
|
||||
static void HIDAPI_DriverXboxOne_HandleModePacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)
|
||||
{
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (data[4] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
@@ -820,7 +820,7 @@ static void HIDAPI_DriverXboxOne_HandleModePacket(SDL_Joystick *joystick, SDL_Dr
|
||||
/*
|
||||
* Xbox One S with firmware 3.1.1221 uses a 16 byte packet and the GUIDE button in a separate packet
|
||||
*/
|
||||
static void HIDAPI_DriverXboxOneBluetooth_HandleButtons16(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, Uint8 *data, int size)
|
||||
static void HIDAPI_DriverXboxOneBluetooth_HandleButtons16(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)
|
||||
{
|
||||
if (ctx->last_state[14] != data[14]) {
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_A, (data[14] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
|
||||
@@ -1022,13 +1022,13 @@ static void HIDAPI_DriverXboxOneBluetooth_HandleStatePacket(SDL_Joystick *joysti
|
||||
SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
|
||||
}
|
||||
|
||||
static void HIDAPI_DriverXboxOneBluetooth_HandleGuidePacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, Uint8 *data, int size)
|
||||
static void HIDAPI_DriverXboxOneBluetooth_HandleGuidePacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)
|
||||
{
|
||||
ctx->has_guide_packet = SDL_TRUE;
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (data[1] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
|
||||
static void HIDAPI_DriverXboxOneBluetooth_HandleBatteryPacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, Uint8 *data, int size)
|
||||
static void HIDAPI_DriverXboxOneBluetooth_HandleBatteryPacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)
|
||||
{
|
||||
Uint8 flags = data[1];
|
||||
SDL_bool on_usb = (((flags & 0x0C) >> 2) == 0);
|
||||
|
||||
@@ -105,12 +105,13 @@ void HIDAPI_DumpPacket(const char *prefix, const Uint8 *data, int size)
|
||||
int start = 0, amount = size;
|
||||
|
||||
buffer = (char *)SDL_malloc(length);
|
||||
SDL_snprintf(buffer, length, prefix, size);
|
||||
(void)SDL_snprintf(buffer, length, prefix, size);
|
||||
for (i = start; i < start + amount; ++i) {
|
||||
size_t current_len = SDL_strlen(buffer);
|
||||
if ((i % 8) == 0) {
|
||||
SDL_snprintf(&buffer[SDL_strlen(buffer)], length - SDL_strlen(buffer), "\n%.2d: ", i);
|
||||
(void)SDL_snprintf(&buffer[current_len], length - current_len, "\n%.2d: ", i);
|
||||
}
|
||||
SDL_snprintf(&buffer[SDL_strlen(buffer)], length - SDL_strlen(buffer), " 0x%.2x", data[i]);
|
||||
(void)SDL_snprintf(&buffer[current_len], length - current_len, " 0x%.2x", data[i]);
|
||||
}
|
||||
SDL_strlcat(buffer, "\n", length);
|
||||
SDL_Log("%s", buffer);
|
||||
@@ -384,7 +385,6 @@ static void HIDAPI_SetupDeviceDriver(SDL_HIDAPI_Device *device, SDL_bool *remove
|
||||
|
||||
/* Make sure the device didn't get removed while opening the HID path */
|
||||
for (curr = SDL_HIDAPI_devices; curr && curr != device; curr = curr->next) {
|
||||
continue;
|
||||
}
|
||||
if (curr == NULL) {
|
||||
*removed = SDL_TRUE;
|
||||
@@ -718,7 +718,6 @@ static SDL_HIDAPI_Device *HIDAPI_AddDevice(const struct SDL_hid_device_info *inf
|
||||
SDL_bool removed;
|
||||
|
||||
for (curr = SDL_HIDAPI_devices, last = NULL; curr; last = curr, curr = curr->next) {
|
||||
continue;
|
||||
}
|
||||
|
||||
device = (SDL_HIDAPI_Device *)SDL_calloc(1, sizeof(*device));
|
||||
@@ -985,7 +984,6 @@ check_removed:
|
||||
|
||||
/* See if we can create any combined Joy-Con controllers */
|
||||
while (HIDAPI_CreateCombinedJoyCons()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SDL_UnlockJoysticks();
|
||||
|
||||
@@ -1310,10 +1310,10 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
|
||||
@end
|
||||
|
||||
@interface SDL_RumbleContext : NSObject
|
||||
@property(nonatomic, strong) SDL_RumbleMotor *m_low_frequency_motor;
|
||||
@property(nonatomic, strong) SDL_RumbleMotor *m_high_frequency_motor;
|
||||
@property(nonatomic, strong) SDL_RumbleMotor *m_left_trigger_motor;
|
||||
@property(nonatomic, strong) SDL_RumbleMotor *m_right_trigger_motor;
|
||||
@property(nonatomic, strong) SDL_RumbleMotor *lowFrequencyMotor;
|
||||
@property(nonatomic, strong) SDL_RumbleMotor *highFrequencyMotor;
|
||||
@property(nonatomic, strong) SDL_RumbleMotor *leftTriggerMotor;
|
||||
@property(nonatomic, strong) SDL_RumbleMotor *rightTriggerMotor;
|
||||
@end
|
||||
|
||||
@implementation SDL_RumbleContext
|
||||
@@ -1326,10 +1326,10 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
|
||||
RightTriggerMotor:(SDL_RumbleMotor *)right_trigger_motor
|
||||
{
|
||||
self = [super init];
|
||||
self.m_low_frequency_motor = low_frequency_motor;
|
||||
self.m_high_frequency_motor = high_frequency_motor;
|
||||
self.m_left_trigger_motor = left_trigger_motor;
|
||||
self.m_right_trigger_motor = right_trigger_motor;
|
||||
self.lowFrequencyMotor = low_frequency_motor;
|
||||
self.highFrequencyMotor = high_frequency_motor;
|
||||
self.leftTriggerMotor = left_trigger_motor;
|
||||
self.rightTriggerMotor = right_trigger_motor;
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -1337,8 +1337,8 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
result += [self.m_low_frequency_motor setIntensity:((float)low_frequency_rumble / 65535.0f)];
|
||||
result += [self.m_high_frequency_motor setIntensity:((float)high_frequency_rumble / 65535.0f)];
|
||||
result += [self.lowFrequencyMotor setIntensity:((float)low_frequency_rumble / 65535.0f)];
|
||||
result += [self.highFrequencyMotor setIntensity:((float)high_frequency_rumble / 65535.0f)];
|
||||
return ((result < 0) ? -1 : 0);
|
||||
}
|
||||
|
||||
@@ -1346,9 +1346,9 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (self.m_left_trigger_motor && self.m_right_trigger_motor) {
|
||||
result += [self.m_left_trigger_motor setIntensity:((float)left_rumble / 65535.0f)];
|
||||
result += [self.m_right_trigger_motor setIntensity:((float)right_rumble / 65535.0f)];
|
||||
if (self.leftTriggerMotor && self.rightTriggerMotor) {
|
||||
result += [self.leftTriggerMotor setIntensity:((float)left_rumble / 65535.0f)];
|
||||
result += [self.rightTriggerMotor setIntensity:((float)right_rumble / 65535.0f)];
|
||||
} else {
|
||||
result = SDL_Unsupported();
|
||||
}
|
||||
@@ -1357,8 +1357,8 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
|
||||
|
||||
- (void)cleanup
|
||||
{
|
||||
[self.m_low_frequency_motor cleanup];
|
||||
[self.m_high_frequency_motor cleanup];
|
||||
[self.lowFrequencyMotor cleanup];
|
||||
[self.highFrequencyMotor cleanup];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1675,6 +1675,7 @@ SDL_bool IOS_SupportedHIDDevice(IOHIDDeviceRef device)
|
||||
#endif
|
||||
|
||||
#if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE)
|
||||
/* NOLINTNEXTLINE(readability-non-const-parameter): getCString takes a non-const char* */
|
||||
static void GetAppleSFSymbolsNameForElement(GCControllerElement *element, char *name)
|
||||
{
|
||||
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
|
||||
|
||||
@@ -565,7 +565,7 @@ static void LINUX_InotifyJoystickDetect(void)
|
||||
while (remain > 0) {
|
||||
if (buf.event.len > 0) {
|
||||
if (IsJoystickDeviceNode(buf.event.name)) {
|
||||
SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", buf.event.name);
|
||||
(void)SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", buf.event.name);
|
||||
|
||||
if (buf.event.mask & (IN_CREATE | IN_MOVED_TO | IN_ATTRIB)) {
|
||||
MaybeAddDevice(path);
|
||||
@@ -592,7 +592,7 @@ static int get_event_joystick_index(int event)
|
||||
struct dirent **entries = NULL;
|
||||
char path[PATH_MAX];
|
||||
|
||||
SDL_snprintf(path, SDL_arraysize(path), "/sys/class/input/event%d/device", event);
|
||||
(void)SDL_snprintf(path, SDL_arraysize(path), "/sys/class/input/event%d/device", event);
|
||||
count = scandir(path, &entries, NULL, alphasort);
|
||||
for (i = 0; i < count; ++i) {
|
||||
if (SDL_strncmp(entries[i]->d_name, "js", 2) == 0) {
|
||||
@@ -665,7 +665,7 @@ static void LINUX_FallbackJoystickDetect(void)
|
||||
qsort(entries, count, sizeof(*entries), sort_entries);
|
||||
}
|
||||
for (i = 0; i < count; ++i) {
|
||||
SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", entries[i]->d_name);
|
||||
(void)SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", entries[i]->d_name);
|
||||
MaybeAddDevice(path);
|
||||
|
||||
free(entries[i]); /* This should NOT be SDL_free() */
|
||||
|
||||
@@ -228,7 +228,6 @@ int SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *desc)
|
||||
joystick_hwdata *last;
|
||||
|
||||
for (last = g_VJoys; last->next; last = last->next) {
|
||||
continue;
|
||||
}
|
||||
last->next = hwdata;
|
||||
} else {
|
||||
|
||||
@@ -623,19 +623,19 @@ static BOOL CALLBACK EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE pDeviceObj
|
||||
|
||||
in->type = AXIS;
|
||||
in->num = joystick->naxes;
|
||||
if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_XAxis, sizeof(pDeviceObject->guidType)))
|
||||
if (SDL_memcmp(&pDeviceObject->guidType, &GUID_XAxis, sizeof pDeviceObject->guidType) == 0) {
|
||||
in->ofs = DIJOFS_X;
|
||||
else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_YAxis, sizeof(pDeviceObject->guidType)))
|
||||
} else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_YAxis, sizeof pDeviceObject->guidType) == 0) {
|
||||
in->ofs = DIJOFS_Y;
|
||||
else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_ZAxis, sizeof(pDeviceObject->guidType)))
|
||||
} else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_ZAxis, sizeof pDeviceObject->guidType) == 0) {
|
||||
in->ofs = DIJOFS_Z;
|
||||
else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_RxAxis, sizeof(pDeviceObject->guidType)))
|
||||
} else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_RxAxis, sizeof pDeviceObject->guidType) == 0) {
|
||||
in->ofs = DIJOFS_RX;
|
||||
else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_RyAxis, sizeof(pDeviceObject->guidType)))
|
||||
} else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_RyAxis, sizeof pDeviceObject->guidType) == 0) {
|
||||
in->ofs = DIJOFS_RY;
|
||||
else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_RzAxis, sizeof(pDeviceObject->guidType)))
|
||||
} else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_RzAxis, sizeof pDeviceObject->guidType) == 0) {
|
||||
in->ofs = DIJOFS_RZ;
|
||||
else if (!SDL_memcmp(&pDeviceObject->guidType, &GUID_Slider, sizeof(pDeviceObject->guidType))) {
|
||||
} else if (SDL_memcmp(&pDeviceObject->guidType, &GUID_Slider, sizeof pDeviceObject->guidType) == 0) {
|
||||
in->ofs = DIJOFS_SLIDER(joystick->hwdata->NumSliders);
|
||||
++joystick->hwdata->NumSliders;
|
||||
} else {
|
||||
|
||||
@@ -730,8 +730,8 @@ static void RAWINPUT_AddDevice(HANDLE hDevice)
|
||||
/* Don't take devices handled by HIDAPI */
|
||||
CHECK(!HIDAPI_IsDevicePresent((Uint16)rdi.hid.dwVendorId, (Uint16)rdi.hid.dwProductId, (Uint16)rdi.hid.dwVersionNumber, ""));
|
||||
#endif
|
||||
|
||||
CHECK(device = (SDL_RAWINPUT_Device *)SDL_calloc(1, sizeof(SDL_RAWINPUT_Device)));
|
||||
device = (SDL_RAWINPUT_Device *)SDL_calloc(1, sizeof(SDL_RAWINPUT_Device));
|
||||
CHECK(device);
|
||||
device->hDevice = hDevice;
|
||||
device->vendor_id = (Uint16)rdi.hid.dwVendorId;
|
||||
device->product_id = (Uint16)rdi.hid.dwProductId;
|
||||
@@ -742,7 +742,8 @@ static void RAWINPUT_AddDevice(HANDLE hDevice)
|
||||
/* Get HID Top-Level Collection Preparsed Data */
|
||||
size = 0;
|
||||
CHECK(GetRawInputDeviceInfoA(hDevice, RIDI_PREPARSEDDATA, NULL, &size) != (UINT)-1);
|
||||
CHECK(device->preparsed_data = (PHIDP_PREPARSED_DATA)SDL_calloc(size, sizeof(BYTE)));
|
||||
device->preparsed_data = (PHIDP_PREPARSED_DATA)SDL_calloc(size, sizeof(BYTE));
|
||||
CHECK(device->preparsed_data);
|
||||
CHECK(GetRawInputDeviceInfoA(hDevice, RIDI_PREPARSEDDATA, device->preparsed_data, &size) != (UINT)-1);
|
||||
|
||||
hFile = CreateFileA(dev_name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
@@ -786,7 +787,6 @@ static void RAWINPUT_AddDevice(HANDLE hDevice)
|
||||
/* Add it to the list */
|
||||
RAWINPUT_AcquireDevice(device);
|
||||
for (curr = SDL_RAWINPUT_devices, last = NULL; curr; last = curr, curr = curr->next) {
|
||||
continue;
|
||||
}
|
||||
if (last) {
|
||||
last->next = device;
|
||||
|
||||
@@ -189,7 +189,7 @@ static SDL_bool SDL_IsXInputDevice(Uint16 vendor, Uint16 product)
|
||||
continue;
|
||||
}
|
||||
|
||||
SDL_snprintf(devVidPidString, sizeof(devVidPidString), "VID_%04X&PID_%04X", vendor, product);
|
||||
(void)SDL_snprintf(devVidPidString, sizeof devVidPidString, "VID_%04X&PID_%04X", vendor, product);
|
||||
|
||||
while (CM_Get_Parent(&devNode, devNode, 0) == CR_SUCCESS) {
|
||||
char deviceId[MAX_DEVICE_ID_LEN];
|
||||
@@ -237,7 +237,7 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_QueryInter
|
||||
static ULONG STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_AddRef(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController *This)
|
||||
{
|
||||
RawGameControllerDelegate *self = (RawGameControllerDelegate *)This;
|
||||
return SDL_AtomicAdd(&self->refcount, 1) + 1;
|
||||
return SDL_AtomicAdd(&self->refcount, 1) + 1UL;
|
||||
}
|
||||
|
||||
static ULONG STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_Release(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController *This)
|
||||
@@ -393,6 +393,8 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
|
||||
wgi.controllers = controllers;
|
||||
|
||||
SDL_PrivateJoystickAdded(joystickID);
|
||||
} else {
|
||||
SDL_free(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ static DWORD CALLBACK SDL_DeviceNotificationFunc(HCMNOTIFICATION hNotify, PVOID
|
||||
static void SDL_CleanupDeviceNotificationFunc(void)
|
||||
{
|
||||
if (cfgmgr32_lib_handle) {
|
||||
if (s_DeviceNotificationFuncHandle) {
|
||||
if (s_DeviceNotificationFuncHandle != NULL && CM_Unregister_Notification != NULL) {
|
||||
CM_Unregister_Notification(s_DeviceNotificationFuncHandle);
|
||||
s_DeviceNotificationFuncHandle = NULL;
|
||||
}
|
||||
@@ -294,8 +294,8 @@ static int SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
data->messageWindow = (HWND)CreateWindowEx(0, TEXT("Message"), NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
|
||||
if (!data->messageWindow) {
|
||||
data->messageWindow = CreateWindowEx(0, TEXT("Message"), NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
|
||||
if (data->messageWindow == NULL) {
|
||||
WIN_SetError("Failed to create message window for joystick autodetect");
|
||||
SDL_CleanupDeviceNotification(data);
|
||||
return -1;
|
||||
|
||||
@@ -86,37 +86,37 @@ static const char *GetXInputName(const Uint8 userid, BYTE SubType)
|
||||
static char name[32];
|
||||
|
||||
if (SDL_XInputUseOldJoystickMapping()) {
|
||||
SDL_snprintf(name, sizeof(name), "X360 Controller #%u", 1 + userid);
|
||||
(void)SDL_snprintf(name, sizeof name, "X360 Controller #%u", 1 + userid);
|
||||
} else {
|
||||
switch (SubType) {
|
||||
case XINPUT_DEVSUBTYPE_GAMEPAD:
|
||||
SDL_snprintf(name, sizeof(name), "XInput Controller #%u", 1 + userid);
|
||||
(void)SDL_snprintf(name, sizeof name, "XInput Controller #%u", 1 + userid);
|
||||
break;
|
||||
case XINPUT_DEVSUBTYPE_WHEEL:
|
||||
SDL_snprintf(name, sizeof(name), "XInput Wheel #%u", 1 + userid);
|
||||
(void)SDL_snprintf(name, sizeof name, "XInput Wheel #%u", 1 + userid);
|
||||
break;
|
||||
case XINPUT_DEVSUBTYPE_ARCADE_STICK:
|
||||
SDL_snprintf(name, sizeof(name), "XInput ArcadeStick #%u", 1 + userid);
|
||||
(void)SDL_snprintf(name, sizeof name, "XInput ArcadeStick #%u", 1 + userid);
|
||||
break;
|
||||
case XINPUT_DEVSUBTYPE_FLIGHT_STICK:
|
||||
SDL_snprintf(name, sizeof(name), "XInput FlightStick #%u", 1 + userid);
|
||||
(void)SDL_snprintf(name, sizeof name, "XInput FlightStick #%u", 1 + userid);
|
||||
break;
|
||||
case XINPUT_DEVSUBTYPE_DANCE_PAD:
|
||||
SDL_snprintf(name, sizeof(name), "XInput DancePad #%u", 1 + userid);
|
||||
(void)SDL_snprintf(name, sizeof name, "XInput DancePad #%u", 1 + userid);
|
||||
break;
|
||||
case XINPUT_DEVSUBTYPE_GUITAR:
|
||||
case XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE:
|
||||
case XINPUT_DEVSUBTYPE_GUITAR_BASS:
|
||||
SDL_snprintf(name, sizeof(name), "XInput Guitar #%u", 1 + userid);
|
||||
(void)SDL_snprintf(name, sizeof name, "XInput Guitar #%u", 1 + userid);
|
||||
break;
|
||||
case XINPUT_DEVSUBTYPE_DRUM_KIT:
|
||||
SDL_snprintf(name, sizeof(name), "XInput DrumKit #%u", 1 + userid);
|
||||
(void)SDL_snprintf(name, sizeof name, "XInput DrumKit #%u", 1 + userid);
|
||||
break;
|
||||
case XINPUT_DEVSUBTYPE_ARCADE_PAD:
|
||||
SDL_snprintf(name, sizeof(name), "XInput ArcadePad #%u", 1 + userid);
|
||||
(void)SDL_snprintf(name, sizeof name, "XInput ArcadePad #%u", 1 + userid);
|
||||
break;
|
||||
default:
|
||||
SDL_snprintf(name, sizeof(name), "XInput Device #%u", 1 + userid);
|
||||
(void)SDL_snprintf(name, sizeof name, "XInput Device #%u", 1 + userid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -207,7 +207,7 @@ static void GuessXInputDevice(Uint8 userid, Uint16 *pVID, Uint16 *pPID, Uint16 *
|
||||
/* Steam encodes the real device in the path */
|
||||
int realVID = rdi.hid.dwVendorId;
|
||||
int realPID = rdi.hid.dwProductId;
|
||||
SDL_sscanf(devName, "\\\\.\\pipe\\HID#VID_045E&PID_028E&IG_00#%x&%x&", &realVID, &realPID);
|
||||
(void)SDL_sscanf(devName, "\\\\.\\pipe\\HID#VID_045E&PID_028E&IG_00#%x&%x&", &realVID, &realPID);
|
||||
*pVID = (Uint16)realVID;
|
||||
*pPID = (Uint16)realPID;
|
||||
*pVersion = 0;
|
||||
@@ -279,7 +279,7 @@ static void AddXInputDevice(Uint8 userid, BYTE SubType, JoyStick_DeviceData **pC
|
||||
SDL_free(pNewJoystick);
|
||||
return; /* better luck next time? */
|
||||
}
|
||||
SDL_snprintf(pNewJoystick->path, sizeof(pNewJoystick->path), "XInput#%d", userid);
|
||||
(void)SDL_snprintf(pNewJoystick->path, sizeof pNewJoystick->path, "XInput#%d", userid);
|
||||
if (!SDL_XInputUseOldJoystickMapping()) {
|
||||
GuessXInputDevice(userid, &vendor, &product, &version);
|
||||
|
||||
@@ -434,7 +434,7 @@ static void UpdateXInputJoystickState_OLD(SDL_Joystick *joystick, XINPUT_STATE_E
|
||||
SDL_PrivateJoystickAxis(joystick, 4, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger * 65535 / 255) - 32768));
|
||||
SDL_PrivateJoystickAxis(joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger * 65535 / 255) - 32768));
|
||||
|
||||
for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
|
||||
for (button = 0; button < (Uint8)SDL_arraysize(s_XInputButtons); ++button) {
|
||||
SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ static void UpdateXInputJoystickState(SDL_Joystick *joystick, XINPUT_STATE_EX *p
|
||||
SDL_PrivateJoystickAxis(joystick, 4, ~pXInputState->Gamepad.sThumbRY);
|
||||
SDL_PrivateJoystickAxis(joystick, 5, ((int)pXInputState->Gamepad.bRightTrigger * 257) - 32768);
|
||||
|
||||
for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
|
||||
for (button = 0; button < (Uint8)SDL_arraysize(s_XInputButtons); ++button) {
|
||||
SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user