SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.

CR: Sam
This commit is contained in:
Sam Lantinga 2015-09-30 15:39:30 -07:00
parent 8038b8bb7f
commit bf785c766b
7 changed files with 127 additions and 8 deletions

View file

@ -178,6 +178,7 @@ SDL_JoystickOpen(int device_index)
if (joystick->buttons) {
SDL_memset(joystick->buttons, 0, joystick->nbuttons * sizeof(Uint8));
}
joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
/* Add joystick to list */
++joystick->ref_count;
@ -619,10 +620,10 @@ SDL_PrivateJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state)
/* Make sure we're not getting garbage or duplicate events */
if (button >= joystick->nbuttons) {
return 0;
}
if (state == joystick->buttons[button]) {
return 0;
}
}
if (state == joystick->buttons[button]) {
return 0;
}
/* We ignore events if we don't have keyboard focus, except for button
* release. */
@ -825,4 +826,21 @@ SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
}
/* update the power level for this joystick */
void SDL_PrivateJoystickBatteryLevel(SDL_Joystick * joystick, SDL_JoystickPowerLevel ePowerLevel)
{
joystick->epowerlevel = ePowerLevel;
}
/* return its power level */
SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick)
{
if (!SDL_PrivateJoystickValid(joystick)) {
return (SDL_JOYSTICK_POWER_UNKNOWN);
}
return joystick->epowerlevel;
}
/* vi: set ts=4 sw=4 expandtab: */