Don't report battery level for disconnected batteries Fixes https://github.com/libsdl-org/SDL/issues/6536
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/src/core/windows/SDL_xinput.h b/src/core/windows/SDL_xinput.h
index 461d99b..5f6d36a 100644
--- a/src/core/windows/SDL_xinput.h
+++ b/src/core/windows/SDL_xinput.h
@@ -133,10 +133,13 @@ using namespace XInputOnGameInput;
#ifndef BATTERY_DEVTYPE_GAMEPAD
#define BATTERY_DEVTYPE_GAMEPAD 0x00
#endif
+
+#ifndef BATTERY_TYPE_DISCONNECTED
+#define BATTERY_TYPE_DISCONNECTED 0x00
+#endif
#ifndef BATTERY_TYPE_WIRED
#define BATTERY_TYPE_WIRED 0x01
#endif
-
#ifndef BATTERY_TYPE_UNKNOWN
#define BATTERY_TYPE_UNKNOWN 0xFF
#endif
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 4b95581..c882a1a 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -2901,7 +2901,7 @@ void SDL_PrivateJoystickBatteryLevel(SDL_Joystick *joystick, SDL_JoystickPowerLe
{
CHECK_JOYSTICK_MAGIC(joystick, );
- SDL_assert(joystick->ref_count); /* make sure we are calling this only for update, not for initialisation */
+ SDL_assert(joystick->ref_count); /* make sure we are calling this only for update, not for initialization */
if (ePowerLevel != joystick->epowerlevel) {
#if !SDL_EVENTS_DISABLED
if (SDL_GetEventState(SDL_JOYBATTERYUPDATED) == SDL_ENABLE) {
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 120a361..fc738b0 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -1775,7 +1775,8 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
}
has_trigger_data = SDL_TRUE;
- if (battery_info->BatteryType != BATTERY_TYPE_UNKNOWN) {
+ if (battery_info->BatteryType != BATTERY_TYPE_UNKNOWN &&
+ battery_info->BatteryType != BATTERY_TYPE_DISCONNECTED) {
SDL_JoystickPowerLevel ePowerLevel = SDL_JOYSTICK_POWER_UNKNOWN;
if (battery_info->BatteryType == BATTERY_TYPE_WIRED) {
ePowerLevel = SDL_JOYSTICK_POWER_WIRED;