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

@ -842,16 +842,31 @@ extern DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
extern DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad);
/**
* Get the battery level of a gamepad, if available.
* Get the connection state of a gamepad.
*
* \param gamepad a gamepad identifier previously returned by
* SDL_OpenGamepad()
* \returns the current battery level as SDL_JoystickPowerLevel on success or
* `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown
* \param gamepad the gamepad object to query.
* \returns the connection state on success or `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*/
extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_GetGamepadPowerLevel(SDL_Gamepad *gamepad);
extern DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetGamepadConnectionState(SDL_Gamepad *gamepad);
/**
* Get the battery state of a gamepad.
*
* You should never take a battery status as absolute truth. Batteries
* (especially failing batteries) are delicate hardware, and the values
* reported here are best estimates based on what that hardware reports. It's
* not uncommon for older batteries to lose stored power much faster than it
* reports, or completely drain when reporting it has 20 percent left, etc.
*
* \param gamepad the gamepad object to query.
* \param percent a pointer filled in with the percentage of battery life left, between 0 and 100, or NULL to ignore. This will be filled in with -1 we can't determine a value or there is no battery.
* \returns the current battery state.
*
* \since This function is available since SDL 3.0.0.
*/
extern DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *gamepad, int *percent);
/**
* Check if a gamepad has been opened and is currently connected.