Ver Fonte

Only update the battery status for Bluetooth Switch Pro controllers

Controllers that are plugged in are in the wired state
Sam Lantinga há 1 ano atrás
pai
commit
09d1e9defb
1 ficheiros alterados com 18 adições e 16 exclusões
  1. 18 16
      src/joystick/hidapi/SDL_hidapi_switch.c

+ 18 - 16
src/joystick/hidapi/SDL_hidapi_switch.c

@@ -2035,24 +2035,26 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
         SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, ~axis);
     }
 
-    /* High nibble of battery/connection byte is battery level, low nibble is connection status
-     * LSB of connection nibble is USB/Switch connection status
-     */
-    if (packet->controllerState.ucBatteryAndConnection & 0x1) {
-        SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_WIRED);
-    } else {
-        /* LSB of the battery nibble is used to report charging.
-         * The battery level is reported from 0(empty)-8(full)
+    if (ctx->device->is_bluetooth) {
+        /* High nibble of battery/connection byte is battery level, low nibble is connection status
+         * LSB of connection nibble is USB/Switch connection status
          */
-        int level = (packet->controllerState.ucBatteryAndConnection & 0xE0) >> 4;
-        if (level == 0) {
-            SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_EMPTY);
-        } else if (level <= 2) {
-            SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_LOW);
-        } else if (level <= 6) {
-            SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_MEDIUM);
+        if (packet->controllerState.ucBatteryAndConnection & 0x1) {
+            SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_WIRED);
         } else {
-            SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_FULL);
+            /* LSB of the battery nibble is used to report charging.
+             * The battery level is reported from 0(empty)-8(full)
+             */
+            int level = (packet->controllerState.ucBatteryAndConnection & 0xE0) >> 4;
+            if (level == 0) {
+                SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_EMPTY);
+            } else if (level <= 2) {
+                SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_LOW);
+            } else if (level <= 6) {
+                SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_MEDIUM);
+            } else {
+                SDL_SendJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_FULL);
+            }
         }
     }