From 09d1e9defb49e53acefed0d2fd22b3a28584cd8f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 10 Nov 2023 17:09:39 -0800 Subject: [PATCH] Only update the battery status for Bluetooth Switch Pro controllers Controllers that are plugged in are in the wired state --- src/joystick/hidapi/SDL_hidapi_switch.c | 34 +++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c index 46ffc29da3..db52c6f23d 100644 --- a/src/joystick/hidapi/SDL_hidapi_switch.c +++ b/src/joystick/hidapi/SDL_hidapi_switch.c @@ -2035,24 +2035,26 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, ~axis); } - /* High nibble of battery/connection byte is battery level, low nibble is connection status - * LSB of connection nibble is USB/Switch connection status - */ - if (packet->controllerState.ucBatteryAndConnection & 0x1) { - SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_WIRED); - } else { - /* LSB of the battery nibble is used to report charging. - * The battery level is reported from 0(empty)-8(full) + if (ctx->device->is_bluetooth) { + /* High nibble of battery/connection byte is battery level, low nibble is connection status + * LSB of connection nibble is USB/Switch connection status */ - int level = (packet->controllerState.ucBatteryAndConnection & 0xE0) >> 4; - if (level == 0) { - SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_EMPTY); - } else if (level <= 2) { - SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_LOW); - } else if (level <= 6) { - SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_MEDIUM); + if (packet->controllerState.ucBatteryAndConnection & 0x1) { + SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_WIRED); } else { - SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_FULL); + /* LSB of the battery nibble is used to report charging. + * The battery level is reported from 0(empty)-8(full) + */ + int level = (packet->controllerState.ucBatteryAndConnection & 0xE0) >> 4; + if (level == 0) { + SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_EMPTY); + } else if (level <= 2) { + SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_LOW); + } else if (level <= 6) { + SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_MEDIUM); + } else { + SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_FULL); + } } }