Separate joystick power state into battery status and percentage

This allows you to see battery percentage while the controller is charging
This commit is contained in:
Sam Lantinga
2024-03-30 10:55:13 -07:00
parent 5e624c2083
commit 8847b35244
42 changed files with 596 additions and 1001 deletions

View File

@@ -3427,14 +3427,27 @@ Uint64 SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad)
return handle;
}
SDL_JoystickPowerLevel SDL_GetGamepadPowerLevel(SDL_Gamepad *gamepad)
SDL_JoystickConnectionState SDL_GetGamepadConnectionState(SDL_Gamepad *gamepad)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (!joystick) {
return SDL_JOYSTICK_POWER_UNKNOWN;
return SDL_JOYSTICK_CONNECTION_INVALID;
}
return SDL_GetJoystickPowerLevel(joystick);
return SDL_GetJoystickConnectionState(joystick);
}
SDL_PowerState SDL_GetGamepadPowerInfo(SDL_Gamepad *gamepad, int *percent)
{
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (percent) {
*percent = -1;
}
if (!joystick) {
return SDL_POWERSTATE_ERROR;
}
return SDL_GetJoystickPowerInfo(joystick, percent);
}
/*