Make GameCube controllers only rumble if both USB cables are connected
authorZack Middleton <zack@cloemail.com>
Wed, 19 Jun 2019 06:43:36 -0700
changeset 12894e0980413763c
parent 12893 a600274d78f4
child 12895 ae044ecb144f
Make GameCube controllers only rumble if both USB cables are connected
The Nintendo USB GameCube Adapter has two USB connectors. Black for data
and grey for additional power for rumble. The Wii U and other software
require both cables to use rumble. The rumble is weaker without the
second USB cable. Other than that I don't know if there is any negative
side affects from using rumble with only one cable.
src/joystick/hidapi/SDL_hidapi_gamecube.c
     1.1 --- a/src/joystick/hidapi/SDL_hidapi_gamecube.c	Wed Jun 19 06:43:04 2019 -0700
     1.2 +++ b/src/joystick/hidapi/SDL_hidapi_gamecube.c	Wed Jun 19 06:43:36 2019 -0700
     1.3 @@ -37,6 +37,7 @@
     1.4  
     1.5  typedef struct {
     1.6      SDL_JoystickID joysticks[4];
     1.7 +    Uint8 rumbleAllowed[4];
     1.8      Uint8 rumble[5];
     1.9      Uint32 rumbleExpiration[4];
    1.10      /* Without this variable, hid_write starts to lag a TON */
    1.11 @@ -99,6 +100,9 @@
    1.12          /* Go through all 4 slots */
    1.13          curSlot = packet + 1;
    1.14          for (i = 0; i < 4; i += 1, curSlot += 9) {
    1.15 +            /* Only allow rumble if the adapter's second USB cable is connected */
    1.16 +            ctx->rumbleAllowed[i] = (curSlot[0] & 0x04) != 0;
    1.17 +
    1.18              if (curSlot[0] & 0x30) { /* 0x10 - Wired, 0x20 - Wireless */
    1.19                  if (ctx->joysticks[i] == -1) {
    1.20                      ctx->joysticks[i] = SDL_GetNextJoystickInstanceID();
    1.21 @@ -168,6 +172,9 @@
    1.22          /* Go through all 4 slots */
    1.23          curSlot = packet + 1;
    1.24          for (i = 0; i < 4; i += 1, curSlot += 9) {
    1.25 +            /* Only allow rumble if the adapter's second USB cable is connected */
    1.26 +            ctx->rumbleAllowed[i] = (curSlot[0] & 0x04) != 0;
    1.27 +
    1.28              if (curSlot[0] & 0x30) { /* 0x10 - Wired, 0x20 - Wireless */
    1.29                  if (ctx->joysticks[i] == -1) {
    1.30                      ctx->joysticks[i] = SDL_GetNextJoystickInstanceID();
    1.31 @@ -238,7 +245,7 @@
    1.32      now = SDL_GetTicks();
    1.33      for (i = 0; i < 4; i += 1) {
    1.34          if (ctx->rumbleExpiration[i] > 0) {
    1.35 -            if (SDL_TICKS_PASSED(now, ctx->rumbleExpiration[i])) {
    1.36 +            if (SDL_TICKS_PASSED(now, ctx->rumbleExpiration[i]) || !ctx->rumbleAllowed[i]) {
    1.37                  ctx->rumble[i + 1] = 0;
    1.38                  ctx->rumbleExpiration[i] = 0;
    1.39                  ctx->rumbleUpdate = 1;
    1.40 @@ -325,6 +332,9 @@
    1.41      Uint8 i, val;
    1.42      for (i = 0; i < 4; i += 1) {
    1.43          if (instance == ctx->joysticks[i]) {
    1.44 +            if (!ctx->rumbleAllowed[i]) {
    1.45 +                return SDL_SetError("Second USB cable for WUP-028 not connected");
    1.46 +            }
    1.47              val = (low_frequency_rumble > 0 || high_frequency_rumble > 0);
    1.48              if (val != ctx->rumble[i + 1]) {
    1.49                  ctx->rumble[i + 1] = val;
    1.50 @@ -338,7 +348,7 @@
    1.51              return 0;
    1.52          }
    1.53      }
    1.54 -    return -1;
    1.55 +    return -1; /* Should never get here! */
    1.56  }
    1.57  
    1.58  SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube =