Parcourir la source

Removed 100 ms hitch when querying third party Nintendo Switch controllers that don't respond to request for info

Also take advantage of the fact that we know whether the device is connected over Bluetooth now.
Sam Lantinga il y a 2 ans
Parent
commit
214d5daa3c
1 fichiers modifiés avec 11 ajouts et 10 suppressions
  1. 11 10
      src/joystick/hidapi/SDL_hidapi_switch.c

+ 11 - 10
src/joystick/hidapi/SDL_hidapi_switch.c

@@ -992,26 +992,27 @@ static ESwitchDeviceInfoControllerType ReadJoyConControllerType(SDL_HIDAPI_Devic
         ctx->m_bSyncWrite = SDL_TRUE;
         ctx->m_bSyncWrite = SDL_TRUE;
         ctx->m_nMaxWriteAttempts = GetMaxWriteAttempts(device);
         ctx->m_nMaxWriteAttempts = GetMaxWriteAttempts(device);
 
 
-        for (attempts = 0; attempts < MAX_ATTEMPTS; ++attempts) {
-            if (WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_Status, NULL, 0, SDL_TRUE)) {
-                SwitchProprietaryStatusPacket_t *status = (SwitchProprietaryStatusPacket_t *)&ctx->m_rgucReadBuffer[0];
-
-                eControllerType = CalculateControllerType(ctx, (ESwitchDeviceInfoControllerType)status->ucDeviceType);
-            } else {
+        for ( ; ; ) {
+            ++attempts;
+            if (device->is_bluetooth) {
                 SwitchSubcommandInputPacket_t *reply = NULL;
                 SwitchSubcommandInputPacket_t *reply = NULL;
 
 
-                device->is_bluetooth = SDL_TRUE;
                 if (WriteSubcommand(ctx, k_eSwitchSubcommandIDs_RequestDeviceInfo, NULL, 0, &reply)) {
                 if (WriteSubcommand(ctx, k_eSwitchSubcommandIDs_RequestDeviceInfo, NULL, 0, &reply)) {
                     eControllerType = CalculateControllerType(ctx, (ESwitchDeviceInfoControllerType)reply->deviceInfo.ucDeviceType);
                     eControllerType = CalculateControllerType(ctx, (ESwitchDeviceInfoControllerType)reply->deviceInfo.ucDeviceType);
                 }
                 }
+            } else {
+                if (WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_Status, NULL, 0, SDL_TRUE)) {
+                    SwitchProprietaryStatusPacket_t *status = (SwitchProprietaryStatusPacket_t *)&ctx->m_rgucReadBuffer[0];
+
+                    eControllerType = CalculateControllerType(ctx, (ESwitchDeviceInfoControllerType)status->ucDeviceType);
+                }
             }
             }
-            if (eControllerType == k_eSwitchDeviceInfoControllerType_Unknown) {
+            if (eControllerType == k_eSwitchDeviceInfoControllerType_Unknown && attempts < MAX_ATTEMPTS) {
                 /* Wait a bit and try again */
                 /* Wait a bit and try again */
                 SDL_Delay(100);
                 SDL_Delay(100);
                 continue;
                 continue;
-            } else {
-                break;
             }
             }
+            break;
         }
         }
         SDL_free(ctx);
         SDL_free(ctx);
     }
     }