is there a way to configure input using joystick name rather than index number?

hey guys!

First the question and then an explanation of what I want to do.

Question: Is there a way to configure the input joystick for players 1-4 using the joystick name, rather than the index (input_playerX_joypad_index)?

What I want to do…

I’m running RetroArch on Linux on a Raspberry Pi (more specifically, the system is RetroPie).

I like to play SNES games with a SNES-like bluetooth controller, NES games with a NES-like bluetooth controller (both are from 8bitdo), and arcade games with an arcade-like controller. And I’m used to change the input using the input_playerX_joypad_index on system’s specific retroarch.cfg.

The problem is that due to the dynamic nature of Bluetooth conections, the index may change. So keeping these configurations hardcoded isn’t that practical.

BTW: to turn the configuration process easier for the n00bs/lazy people, I made an script with some dialog boxes to let the users configure the input joystick for players 1-4. (It can be found on my github: https://github.com/meleu/RetroPie-joystick-selection )

The script gets the joystick indexes and names from a really small C program I wrote (source code at the end of this message). It gets these information using SDL2 functions. During the configuration process the user sees the joystick names, but in the end it uses the index on a retroarch.cfg-like file with input_playerX_joypad_index lines. Then, if the the joystick order changes (adding/removing devices), the user needs to execute the script again.

If I could configure this using the names, it would avoid the need of rerunning the script frequently.

Here is the C code to list the joysticks indexes and names:

/* jslist.c
* This little program just list the joysticks connected to the system.
* The ouput format is "index:JoystickName".
*
* Compile it with: 
* [prompt]$ gcc jslist.c -o jslist $(sdl2-config --cflags --libs)
*/

#include <stdio.h>
#include "SDL.h"

int main(void) {
    int num_joy, i;

    SDL_Init(SDL_INIT_JOYSTICK);

    num_joy = SDL_NumJoysticks();

    for(i = 0; i < num_joy; i++)
        printf("%d:%s
", i, SDL_JoystickNameForIndex(i));

    SDL_Quit();
    return 0;
}