Fixed setting the GUID for Bluetooth joysticks
authorSam Lantinga <slouken@libsdl.org>
Fri, 01 Feb 2013 17:09:01 -0800
changeset 6831935b871e1ffe
parent 6830 0cd3e2e9b2c5
child 6832 156e608ec4ef
Fixed setting the GUID for Bluetooth joysticks
src/joystick/linux/SDL_sysjoystick.c
     1.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Thu Jan 31 08:45:30 2013 -0800
     1.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Fri Feb 01 17:09:01 2013 -0800
     1.3 @@ -217,16 +217,27 @@
     1.4          return 0;
     1.5      }
     1.6  
     1.7 +#ifdef DEBUG_JOYSTICK
     1.8 +    printf("Joystick: %s, bustype = %d, vendor = 0x%x, product = 0x%x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version);
     1.9 +#endif
    1.10 +
    1.11 +    SDL_memset(guid->data, 0, sizeof(guid->data));
    1.12 +
    1.13      /* We only need 16 bits for each of these; space them out to fill 128. */
    1.14      /* Byteswap so devices get same GUID on little/big endian platforms. */
    1.15      *(guid16++) = SDL_SwapLE16(inpid.bustype);
    1.16      *(guid16++) = 0;
    1.17 -    *(guid16++) = SDL_SwapLE16(inpid.vendor);
    1.18 -    *(guid16++) = 0;
    1.19 -    *(guid16++) = SDL_SwapLE16(inpid.product);
    1.20 -    *(guid16++) = 0;
    1.21 -    *(guid16++) = SDL_SwapLE16(inpid.version);
    1.22 -    *(guid16++) = 0;
    1.23 +
    1.24 +    if (inpid.vendor && inpid.product && inpid.version) {
    1.25 +        *(guid16++) = SDL_SwapLE16(inpid.vendor);
    1.26 +        *(guid16++) = 0;
    1.27 +        *(guid16++) = SDL_SwapLE16(inpid.product);
    1.28 +        *(guid16++) = 0;
    1.29 +        *(guid16++) = SDL_SwapLE16(inpid.version);
    1.30 +        *(guid16++) = 0;
    1.31 +    } else {
    1.32 +        SDL_strlcpy((char*)guid16, namebuf, sizeof(guid->data) - 4);
    1.33 +    }
    1.34  
    1.35      return 1;
    1.36  }