From e24b971a340dbb1f713b3e98efaf1b05dfbedc7b Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 12 Jul 2022 17:53:03 -0700
Subject: [PATCH] Added support for the NVIDIA Shield controller guide button
---
src/joystick/SDL_gamecontroller.c | 2 +-
src/joystick/hidapi/SDL_hidapi_shield.c | 11 +++--------
src/joystick/usb_ids.h | 2 +-
3 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index 3a5c9c7d56d..c5c6d29bece 100644
--- a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -635,7 +635,7 @@ static ControllerMapping_t *SDL_CreateMappingForHIDAPIController(SDL_JoystickGUI
SDL_strlcat(mapping_string, "misc1:b15,", sizeof(mapping_string));
break;
case SDL_CONTROLLER_TYPE_NVIDIA_SHIELD:
- /* The NVIDIA SHIELD controller has a home button between back and start buttons */
+ /* The NVIDIA SHIELD controller has a share button between back and start buttons */
SDL_strlcat(mapping_string, "misc1:b15,", sizeof(mapping_string));
break;
default:
diff --git a/src/joystick/hidapi/SDL_hidapi_shield.c b/src/joystick/hidapi/SDL_hidapi_shield.c
index c6d77de5339..f3ac984aa8d 100644
--- a/src/joystick/hidapi/SDL_hidapi_shield.c
+++ b/src/joystick/hidapi/SDL_hidapi_shield.c
@@ -50,12 +50,6 @@
/* Reports that are too small are dropped over Bluetooth */
#define HID_REPORT_SIZE 33
-enum
-{
- SDL_CONTROLLER_BUTTON_SHIELD_HOME = 15,
- SDL_CONTROLLER_NUM_SHIELD_BUTTONS,
-};
-
typedef struct {
Uint8 seq_num;
@@ -150,7 +144,7 @@ HIDAPI_DriverShield_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
device->context = ctx;
/* Initialize the joystick capabilities */
- joystick->nbuttons = SDL_CONTROLLER_NUM_SHIELD_BUTTONS;
+ joystick->nbuttons = 16;
joystick->naxes = SDL_CONTROLLER_AXIS_MAX;
joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
@@ -317,8 +311,9 @@ HIDAPI_DriverShield_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverShield_C
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, SDL_SwapLE16(*(Sint16*)&data[21]) - 0x8000);
if (ctx->last_state[17] != data[17]) {
- SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_SHIELD_HOME, (data[17] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
+ SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_MISC1, (data[17] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_BACK, (data[17] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
+ SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (data[17] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
}
SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
diff --git a/src/joystick/usb_ids.h b/src/joystick/usb_ids.h
index 0b9102809a3..e93406d1744 100644
--- a/src/joystick/usb_ids.h
+++ b/src/joystick/usb_ids.h
@@ -39,7 +39,6 @@
#define USB_VENDOR_SONY 0x054c
#define USB_VENDOR_VALVE 0x28de
-#define USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER 0x7214
#define USB_PRODUCT_AMAZON_LUNA_CONTROLLER 0x0419
#define USB_PRODUCT_GOOGLE_STADIA_CONTROLLER 0x9400
#define USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER 0x1846
@@ -51,6 +50,7 @@
#define USB_PRODUCT_NINTENDO_N64_CONTROLLER 0x2019
#define USB_PRODUCT_NINTENDO_SEGA_GENESIS_CONTROLLER 0x201e
#define USB_PRODUCT_NINTENDO_SNES_CONTROLLER 0x2017
+#define USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER 0x7214
#define USB_PRODUCT_RAZER_PANTHERA 0x0401
#define USB_PRODUCT_RAZER_PANTHERA_EVO 0x1008
#define USB_PRODUCT_RAZER_ATROX 0x0a00