Don't use connection state from the Nintendo Switch Pro report

This isn't reliable for third party controllers like the 8BitDo Pro 2.

Fixes https://github.com/libsdl-org/SDL/issues/10862
This commit is contained in:
Sam Lantinga
2024-12-27 13:57:53 -08:00
parent 75a24116b5
commit 9a4d29699d

View File

@@ -2433,7 +2433,7 @@ 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
/* High nibble of battery/connection byte is battery level, low nibble is connection status (always 0 on 8BitDo Pro 2)
* LSB of connection nibble is USB/Switch connection status
* LSB of the battery nibble is used to report charging.
* The battery level is reported from 0(empty)-8(full)
@@ -2443,12 +2443,6 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
int level = (packet->controllerState.ucBatteryAndConnection & 0xE0) >> 4;
int percent = (int)SDL_roundf((level / 8.0f) * 100.0f);
if (packet->controllerState.ucBatteryAndConnection & 0x01) {
joystick->connection_state = SDL_JOYSTICK_CONNECTION_WIRED;
} else {
joystick->connection_state = SDL_JOYSTICK_CONNECTION_WIRELESS;
}
if (charging) {
if (level == 8) {
state = SDL_POWERSTATE_CHARGED;