mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-03 00:18:28 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user