Fixed handling the guide button with both V1 and V2 of the Xbox One Bluetooth wireless protocols
authorSam Lantinga <slouken@libsdl.org>
Wed, 04 Mar 2020 09:42:10 -0800
changeset 135879944a0c7c355
parent 13586 2f5e3f0be62c
child 13588 668a74d2aec1
Fixed handling the guide button with both V1 and V2 of the Xbox One Bluetooth wireless protocols
src/joystick/hidapi/SDL_hidapi_xboxone.c
     1.1 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c	Wed Mar 04 09:42:08 2020 -0800
     1.2 +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c	Wed Mar 04 09:42:10 2020 -0800
     1.3 @@ -105,10 +105,17 @@
     1.4      { 0x0000, 0x0000, 0x045e, 0x0000, xboxone_init6, sizeof(xboxone_init6), { 0x00, 0x00 } },
     1.5  };
     1.6  
     1.7 +typedef enum {
     1.8 +    XBOX_ONE_WIRELESS_PROTOCOL_UNKNOWN,
     1.9 +    XBOX_ONE_WIRELESS_PROTOCOL_V1,
    1.10 +    XBOX_ONE_WIRELESS_PROTOCOL_V2,
    1.11 +} SDL_XboxOneWirelessProtocol;
    1.12 +
    1.13  typedef struct {
    1.14      Uint16 vendor_id;
    1.15      Uint16 product_id;
    1.16      SDL_bool bluetooth;
    1.17 +    SDL_XboxOneWirelessProtocol wireless_protocol;
    1.18      SDL_bool initialized;
    1.19      Uint32 start_time;
    1.20      Uint8 sequence;
    1.21 @@ -489,6 +496,16 @@
    1.22          SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_START, (data[15] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
    1.23          SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_LEFTSTICK, (data[15] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
    1.24          SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_RIGHTSTICK, (data[15] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
    1.25 +        if (ctx->wireless_protocol == XBOX_ONE_WIRELESS_PROTOCOL_UNKNOWN)
    1.26 +        {
    1.27 +            if (data[15] & 0x10) {
    1.28 +                ctx->wireless_protocol = XBOX_ONE_WIRELESS_PROTOCOL_V2;
    1.29 +            }
    1.30 +        }
    1.31 +        if (ctx->wireless_protocol == XBOX_ONE_WIRELESS_PROTOCOL_V2)
    1.32 +        {
    1.33 +            SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (data[15] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
    1.34 +        }
    1.35      }
    1.36  
    1.37      if (ctx->last_state[16] != data[16]) {
    1.38 @@ -566,6 +583,7 @@
    1.39  static void
    1.40  HIDAPI_DriverXboxOneBluetooth_HandleGuidePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverXboxOne_Context *ctx, Uint8 *data, int size)
    1.41  {
    1.42 +    ctx->wireless_protocol = XBOX_ONE_WIRELESS_PROTOCOL_V1;
    1.43      SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (data[1] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
    1.44  }
    1.45