Standardized the format of the SDL joystick GUID and added functions to retrieve the USB VID/PID from a joystick and game controller.

This commit is contained in:
Sam Lantinga 2016-11-10 17:19:34 -08:00
parent 2898ada338
commit ac74e16cde
13 changed files with 294 additions and 76 deletions

View file

@ -81,7 +81,7 @@ static int
IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
{
struct input_id inpid;
Uint16 *guid16 = (Uint16 *) ((char *) &guid->data);
Uint16 *guid16 = (Uint16 *)guid->data;
#if !SDL_USE_LIBUDEV
/* When udev is enabled we only get joystick devices here, so there's no need to test them */
@ -110,23 +110,23 @@ IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *gui
}
#ifdef DEBUG_JOYSTICK
printf("Joystick: %s, bustype = %d, vendor = 0x%x, product = 0x%x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version);
printf("Joystick: %s, bustype = %d, vendor = 0x%.4x, product = 0x%.4x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version);
#endif
SDL_memset(guid->data, 0, sizeof(guid->data));
/* We only need 16 bits for each of these; space them out to fill 128. */
/* Byteswap so devices get same GUID on little/big endian platforms. */
*(guid16++) = SDL_SwapLE16(inpid.bustype);
*(guid16++) = 0;
*guid16++ = SDL_SwapLE16(inpid.bustype);
*guid16++ = 0;
if (inpid.vendor && inpid.product && inpid.version) {
*(guid16++) = SDL_SwapLE16(inpid.vendor);
*(guid16++) = 0;
*(guid16++) = SDL_SwapLE16(inpid.product);
*(guid16++) = 0;
*(guid16++) = SDL_SwapLE16(inpid.version);
*(guid16++) = 0;
if (inpid.vendor && inpid.product) {
*guid16++ = SDL_SwapLE16(inpid.vendor);
*guid16++ = 0;
*guid16++ = SDL_SwapLE16(inpid.product);
*guid16++ = 0;
*guid16++ = SDL_SwapLE16(inpid.version);
*guid16++ = 0;
} else {
SDL_strlcpy((char*)guid16, namebuf, sizeof(guid->data) - 4);
}