Added a second hint SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED to control the Home button LED on Nintendo Joy-Con controllers separately from Nintendo Switch Pro controllers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 9c11eb1..1cb2cc2 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -810,17 +810,28 @@ extern "C" {
#define SDL_HINT_JOYSTICK_HIDAPI_SWITCH "SDL_JOYSTICK_HIDAPI_SWITCH"
/**
- * \brief A variable controlling whether the Home button LED should be turned on when a Nintendo Switch controller is opened
+ * \brief A variable controlling whether the Home button LED should be turned on when a Nintendo Switch Pro controller is opened
*
* This variable can be set to the following values:
* "0" - home button LED is turned off
* "1" - home button LED is turned on
*
- * By default the Home button LED state is not changed.
+ * By default the Home button LED state is not changed. This hint can also be set to a floating point value between 0.0 and 1.0 which controls the brightness of the Home button LED.
*/
#define SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED "SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED"
/**
+ * \brief A variable controlling whether the Home button LED should be turned on when a Nintendo Switch Joy-Con controller is opened
+ *
+ * This variable can be set to the following values:
+ * "0" - home button LED is turned off
+ * "1" - home button LED is turned on
+ *
+ * By default the Home button LED state is not changed. This hint can also be set to a floating point value between 0.0 and 1.0 which controls the brightness of the Home button LED.
+ */
+#define SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED "SDL_JOYSTICK_HIDAPI_JOYCON_HOME_LED"
+
+/**
* \brief A variable controlling whether the player LEDs should be lit to indicate which player is associated with a Nintendo Switch controller.
*
* This variable can be set to the following values:
diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index 29c7dfb..0779e9b 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -249,7 +249,6 @@ typedef struct
typedef struct {
SDL_HIDAPI_Device *device;
SDL_bool m_bInputOnly;
- SDL_bool m_bHasHomeLED;
SDL_bool m_bUsingBluetooth;
SDL_bool m_bIsGameCube;
SDL_bool m_bUseButtonLabels;
@@ -304,8 +303,11 @@ typedef struct {
static SDL_bool
-HasHomeLED(int vendor_id, int product_id)
+HasHomeLED(SDL_DriverSwitch_Context *ctx)
{
+ Uint16 vendor_id = ctx->device->vendor_id;
+ Uint16 product_id = ctx->device->product_id;
+
/* The Power A Nintendo Switch Pro controllers don't have a Home LED */
if (vendor_id == 0 && product_id == 0) {
return SDL_FALSE;
@@ -318,9 +320,7 @@ HasHomeLED(int vendor_id, int product_id)
/* The Nintendo Online classic controllers don't have a Home LED */
if (vendor_id == USB_VENDOR_NINTENDO &&
- (product_id == USB_PRODUCT_NINTENDO_N64_CONTROLLER ||
- product_id == USB_PRODUCT_NINTENDO_SEGA_GENESIS_CONTROLLER ||
- product_id == USB_PRODUCT_NINTENDO_SNES_CONTROLLER)) {
+ ctx->m_eControllerType > k_eSwitchDeviceInfoControllerType_ProController) {
return SDL_FALSE;
}
@@ -1234,8 +1234,6 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
/* Find out whether or not we can send output reports */
ctx->m_bInputOnly = SDL_IsJoystickNintendoSwitchProInputOnly(device->vendor_id, device->product_id);
if (!ctx->m_bInputOnly) {
- ctx->m_bHasHomeLED = HasHomeLED(device->vendor_id, device->product_id);
-
/* Initialize rumble data */
SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[0]);
SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[1]);
@@ -1314,9 +1312,15 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
}
/* Set the LED state */
- if (ctx->m_bHasHomeLED) {
- SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED,
- SDL_HomeLEDHintChanged, ctx);
+ if (HasHomeLED(ctx)) {
+ if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConLeft ||
+ ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED,
+ SDL_HomeLEDHintChanged, ctx);
+ } else {
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED,
+ SDL_HomeLEDHintChanged, ctx);
+ }
}
/* Set the serial number */
@@ -2090,8 +2094,14 @@ HIDAPI_DriverSwitch_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
SDL_DelHintCallback(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS,
SDL_GameControllerButtonReportingHintChanged, ctx);
- SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED,
- SDL_HomeLEDHintChanged, ctx);
+ if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConLeft ||
+ ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
+ SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED,
+ SDL_HomeLEDHintChanged, ctx);
+ } else {
+ SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED,
+ SDL_HomeLEDHintChanged, ctx);
+ }
SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED,
SDL_PlayerLEDHintChanged, ctx);