sdlGetGamepadPowerInfo function

int sdlGetGamepadPowerInfo(
  1. Pointer<SdlGamepad> gamepad,
  2. Pointer<Int32> percent
)

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.1.3.

extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *gamepad, int *percent)

Implementation

int sdlGetGamepadPowerInfo(
    Pointer<SdlGamepad> gamepad, Pointer<Int32> percent) {
  final sdlGetGamepadPowerInfoLookupFunction = libSdl3.lookupFunction<
      Int32 Function(Pointer<SdlGamepad> gamepad, Pointer<Int32> percent),
      int Function(Pointer<SdlGamepad> gamepad,
          Pointer<Int32> percent)>('SDL_GetGamepadPowerInfo');
  return sdlGetGamepadPowerInfoLookupFunction(gamepad, percent);
}