Added Android SDK conditionals to game controller mappings
authorSam Lantinga
Mon, 17 Feb 2020 14:15:47 -0800
changeset 135382478e1898463
parent 13537 97d093e10ac7
child 13539 0d8343654eef
Added Android SDK conditionals to game controller mappings
The Nintendo Switch Pro controller has a different mapping on Android 10 and newer
src/joystick/SDL_gamecontroller.c
src/joystick/SDL_gamecontrollerdb.h
src/joystick/sort_controllers.py
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Mon Feb 17 13:54:45 2020 -0800
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Mon Feb 17 14:15:47 2020 -0800
     1.3 @@ -42,7 +42,9 @@
     1.4  /* Many controllers turn the center button into an instantaneous button press */
     1.5  #define SDL_MINIMUM_GUIDE_BUTTON_DELAY_MS   250
     1.6  
     1.7 -#define SDL_CONTROLLER_PLATFORM_FIELD "platform:"
     1.8 +#define SDL_CONTROLLER_PLATFORM_FIELD   "platform:"
     1.9 +#define SDL_CONTROLLER_SDKGE_FIELD      "sdk>=:"
    1.10 +#define SDL_CONTROLLER_SDKLE_FIELD      "sdk<=:"
    1.11  
    1.12  /* a list of currently opened game controllers */
    1.13  static SDL_GameController *SDL_gamecontrollers = NULL;
    1.14 @@ -1136,7 +1138,7 @@
    1.15                  }
    1.16              }
    1.17          }
    1.18 -        
    1.19 +
    1.20          line = line_end + 1;
    1.21      }
    1.22  
    1.23 @@ -1162,6 +1164,27 @@
    1.24          return SDL_InvalidParamError("mappingString");
    1.25      }
    1.26  
    1.27 +#ifdef ANDROID
    1.28 +    { /* Extract and verify the SDK version */
    1.29 +        const char *tmp;
    1.30 +
    1.31 +        tmp = SDL_strstr(mappingString, SDL_CONTROLLER_SDKGE_FIELD);
    1.32 +        if (tmp != NULL) {
    1.33 +            tmp += SDL_strlen(SDL_CONTROLLER_SDKGE_FIELD);
    1.34 +            if (!(SDL_GetAndroidSDKVersion() >= SDL_atoi(tmp))) {
    1.35 +                return SDL_SetError("SDK version %d < minimum version %d", SDL_GetAndroidSDKVersion(), SDL_atoi(tmp));
    1.36 +            }
    1.37 +        }
    1.38 +        tmp = SDL_strstr(mappingString, SDL_CONTROLLER_SDKLE_FIELD);
    1.39 +        if (tmp != NULL) {
    1.40 +            tmp += SDL_strlen(SDL_CONTROLLER_SDKLE_FIELD);
    1.41 +            if (!(SDL_GetAndroidSDKVersion() <= SDL_atoi(tmp))) {
    1.42 +                return SDL_SetError("SDK version %d > maximum version %d", SDL_GetAndroidSDKVersion(), SDL_atoi(tmp));
    1.43 +            }
    1.44 +        }
    1.45 +    }
    1.46 +#endif
    1.47 +
    1.48      pchGUID = SDL_PrivateGetControllerGUIDFromMappingString(mappingString);
    1.49      if (!pchGUID) {
    1.50          return SDL_SetError("Couldn't parse GUID from %s", mappingString);
     2.1 --- a/src/joystick/SDL_gamecontrollerdb.h	Mon Feb 17 13:54:45 2020 -0800
     2.2 +++ b/src/joystick/SDL_gamecontrollerdb.h	Mon Feb 17 14:15:47 2020 -0800
     2.3 @@ -635,11 +635,13 @@
     2.4      "050000005509000003720000cf7f3f00,NVIDIA Controller v01.01,a:b0,b:b1,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
     2.5      "050000005509000010720000ffff3f00,NVIDIA Controller v01.03,a:b0,b:b1,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
     2.6      "050000005509000014720000df7f3f00,NVIDIA Controller v01.04,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a4,rightx:a2,righty:a5,start:b6,x:b2,y:b3,",
     2.7 -    "050000007e05000009200000ffff0f00,Nintendo Switch Pro Controller,a:b0,b:b1,back:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b3,leftstick:b4,lefttrigger:b9,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b6,righttrigger:b10,rightx:a2,righty:a3,start:b16,x:b17,y:b2,", /* Extremely slow in Bluetooth mode on Android */
     2.8 +    "050000007e05000009200000ffff0f00,Nintendo Switch Pro Controller,a:b1,b:b0,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:b15,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:b16,rightx:a2,righty:a3,sdk>=:29,start:b6,x:b3,y:b2,",
     2.9 +    "050000007e05000009200000ffff0f00,Nintendo Switch Pro Controller,a:b0,b:b1,back:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b3,leftstick:b4,lefttrigger:b9,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b6,righttrigger:b10,rightx:a2,righty:a3,sdk<=:28,start:b16,x:b17,y:b2,", /* Extremely slow in Bluetooth mode on Android */
    2.10      "050000004c05000068020000dfff3f00,PS3 Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
    2.11      "030000004c050000cc09000000006800,PS4 Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
    2.12      "050000004c050000c4050000fffe3f00,PS4 Controller,a:b1,b:b17,back:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b3,leftstick:b4,lefttrigger:+a3,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b6,righttrigger:+a4,rightx:a2,righty:a5,start:b16,x:b0,y:b2,",
    2.13      "050000004c050000cc090000fffe3f00,PS4 Controller,a:b1,b:b17,back:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b3,leftstick:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b6,righttrigger:a4,rightx:a2,righty:a5,start:b16,x:b0,y:b2,",
    2.14 +    "050000004c050000cc090000ffff3f00,PS4 Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
    2.15      "050000003215000005070000ffff3f00,Razer Raiju Mobile,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
    2.16      "050000003215000007070000ffff3f00,Razer Raiju Mobile,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
    2.17      "050000003215000000090000bf7f3f00,Razer Serval,a:b0,b:b1,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,x:b2,y:b3,",
     3.1 --- a/src/joystick/sort_controllers.py	Mon Feb 17 13:54:45 2020 -0800
     3.2 +++ b/src/joystick/sort_controllers.py	Mon Feb 17 14:15:47 2020 -0800
     3.3 @@ -11,6 +11,7 @@
     3.4  parsing_controllers = False
     3.5  controllers = []
     3.6  controller_guids = {}
     3.7 +sdk_conditionals = []
     3.8  split_pattern = re.compile(r'([^"]*")([^,]*,)([^,]*,)([^"]*)(".*)')
     3.9  
    3.10  def save_controller(line):
    3.11 @@ -24,12 +25,15 @@
    3.12      entry.append(match.group(5))
    3.13      controllers.append(entry)
    3.14  
    3.15 +    if ',sdk' in line:
    3.16 +        sdk_conditionals.append(entry[1])
    3.17 +
    3.18  def write_controllers():
    3.19      global controllers
    3.20      global controller_guids
    3.21      # Check for duplicates
    3.22      for entry in controllers:
    3.23 -        if (entry[1] in controller_guids):
    3.24 +        if (entry[1] in controller_guids and entry[1] not in sdk_conditionals):
    3.25              current_name = entry[2]
    3.26              existing_name = controller_guids[entry[1]][2]
    3.27              print("Warning: entry '%s' is duplicate of entry '%s'" % (current_name, existing_name))