[Commits] SDL: Fixed creating an Android game controller mapping for HIDAP...

libsdl.org revision control commits-owner at libsdl.org
Mon Sep 17 11:36:46 PDT 2018


details:   https://hg.libsdl.org/SDL/rev/f03ca3ab9b30
changeset: 12192:f03ca3ab9b30
user:      Sam Lantinga <slouken at libsdl.org>
date:      Mon Sep 17 11:35:22 2018 -0700
description:
Fixed creating an Android game controller mapping for HIDAPI devices on initialization

diffstat:

 src/joystick/SDL_gamecontroller.c |   8 ++++----
 src/joystick/SDL_joystick.c       |  14 +++++++++++++-
 src/joystick/SDL_joystick_c.h     |   6 ++++++
 3 files changed, 23 insertions(+), 5 deletions(-)

diffs (76 lines):

diff -r 3c9c784e85bb -r f03ca3ab9b30 src/joystick/SDL_gamecontroller.c
--- a/src/joystick/SDL_gamecontroller.c	Sat Sep 15 14:28:10 2018 +0300
+++ b/src/joystick/SDL_gamecontroller.c	Mon Sep 17 11:35:22 2018 -0700
@@ -432,12 +432,12 @@
         pSupportedController = pSupportedController->next;
     }
     if (!exact_match) {
-        if (guid->data[14] == 'h') {
+        if (SDL_IsJoystickHIDAPI(*guid)) {
             /* This is a HIDAPI device */
             return s_pHIDAPIMapping;
         }
 #if SDL_JOYSTICK_XINPUT
-        if (guid->data[14] == 'x') {
+        if (SDL_IsJoystickXInput(*guid)) {
             /* This is an XInput device */
             return s_pXInputMapping;
         }
@@ -1026,8 +1026,8 @@
         }
     }
 #ifdef __ANDROID__
-    if (!mapping) {
-        mapping = SDL_CreateMappingForAndroidController(name, guid);
+    if (!mapping && name && !SDL_IsJoystickHIDAPI(guid)) {
+		mapping = SDL_CreateMappingForAndroidController(name, guid);
     }
 #endif
     if (!mapping) {
diff -r 3c9c784e85bb -r f03ca3ab9b30 src/joystick/SDL_joystick.c
--- a/src/joystick/SDL_joystick.c	Sat Sep 15 14:28:10 2018 +0300
+++ b/src/joystick/SDL_joystick.c	Mon Sep 17 11:35:22 2018 -0700
@@ -1157,6 +1157,18 @@
     return (GuessControllerType(vendor, product) == k_eControllerType_XBoxOneController);
 }
 
+SDL_bool
+SDL_IsJoystickXInput(SDL_JoystickGUID guid)
+{
+    return (guid.data[14] == 'x') ? SDL_TRUE : SDL_FALSE;
+}
+
+SDL_bool
+SDL_IsJoystickHIDAPI(SDL_JoystickGUID guid)
+{
+    return (guid.data[14] == 'h') ? SDL_TRUE : SDL_FALSE;
+}
+
 static SDL_bool SDL_IsJoystickProductWheel(Uint32 vidpid)
 {
     static Uint32 wheel_joysticks[] = {
@@ -1222,7 +1234,7 @@
     Uint16 product;
     Uint32 vidpid;
 
-    if (guid.data[14] == 'x') {
+    if (SDL_IsJoystickXInput(guid)) {
         /* XInput GUID, get the type based on the XInput device subtype */
         switch (guid.data[15]) {
         case 0x01:  /* XINPUT_DEVSUBTYPE_GAMEPAD */
diff -r 3c9c784e85bb -r f03ca3ab9b30 src/joystick/SDL_joystick_c.h
--- a/src/joystick/SDL_joystick_c.h	Sat Sep 15 14:28:10 2018 +0300
+++ b/src/joystick/SDL_joystick_c.h	Mon Sep 17 11:35:22 2018 -0700
@@ -62,6 +62,12 @@
 /* Function to return whether a joystick is an Xbox One controller */
 extern SDL_bool SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id);
 
+/* Function to return whether a joystick guid comes from the XInput driver */
+extern SDL_bool SDL_IsJoystickXInput(SDL_JoystickGUID guid);
+
+/* Function to return whether a joystick guid comes from the HIDAPI driver */
+extern SDL_bool SDL_IsJoystickHIDAPI(SDL_JoystickGUID guid);
+
 /* Function to return whether a joystick should be ignored */
 extern SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid);
 


More information about the commits mailing list