RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    [SOLVED] how can I get the connected joypad names?

    Scheduled Pinned Locked Moved Ideas and Development
    retroarchcontrollerinput
    26 Posts 5 Posters 13.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mediamogulM
      mediamogul Global Moderator @meleu
      last edited by mediamogul

      @meleu said in how can I get the connected joypad names?:

      I want to start playing with some bash code to let the user choose what controller will be the player1, player2, etc. (at least with libretro cores).

      Very cool idea. Recalbox does this very thing right inside of the Emulation Station GUI. It's very slick. If you get stuck, you might try looking at how they achieved this.

      RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

      1 Reply Last reply Reply Quote 2
      • RionR
        Rion
        last edited by

        I have the same problem sort of.

        I have two 8bitdo controllers, SFC30 & NES30.

        I want to have the NES30 as player 1 and SFC30 as player 2.

        This works 5 out of 10 times if I do it in this order. Start SFC30 first then NES30.
        But the other 5 times retroarch decide SFC30 is Player 1 and Player 2 is NES30.

        So an emulator specific change for what controller is p1 & p2 would be the best solution using the run command.

        Something like a joystick/gamepad hierarchy.

        Example:
        NES30 is always p1 if it's connected.
        SFC30 is always p2 if it's connected & Nes30 is connected.
        Nes30 is off = SFC30 is p1.

        @herb_fargus was talking about something like this as part of the Retropie Setup in this thread usb-controller-player-order

        FBNeo rom filtering
        Mame2003 Arcade Bezels
        Fba Arcade Bezels
        Fba NeoGeo Bezels

        mediamogulM meleuM 2 Replies Last reply Reply Quote 0
        • mediamogulM
          mediamogul Global Moderator @Rion
          last edited by mediamogul

          @Rion

          Any finer solution to this would be welcome as it seems to be a constant user query on how to achieve this. I personally use the RGui & have the option selected to save on exit, but not everyone likes that approach.

          RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

          1 Reply Last reply Reply Quote 0
          • meleuM
            meleu @Zigurana
            last edited by

            @Zigurana said in how can I get the connected joypad names?:

            What are you trying to achieve?

            My inspiration is the recalbox controller settings.

            I wanna get the controller names and their respective index (js0, js1, js2...) to show a list on a dialog (like the retropie_setup does)and let the user choose what will be the input for player1, player2 and so on (using the input_playerxx_joypad_index variable on retroarch.cfg).

            Currently I don't have enough skill to play with C++. But I think I can do it with bash script.

            mediamogulM 1 Reply Last reply Reply Quote 0
            • mediamogulM
              mediamogul Global Moderator @meleu
              last edited by

              @meleu said in how can I get the connected joypad names?:

              Currently I don't have enough skill to play with C++. But I think I can do it with bash script.

              I'm right there with you. I hope to free up enough time at some point to learn.

              RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

              1 Reply Last reply Reply Quote 0
              • meleuM
                meleu
                last edited by

                I'm thinking on a dialog box like this (or something closer):

                dialog \
                	--title 'Input selection' \
                	--checklist 'What player you want to control with "8Bitdo Zero"' \
                	0 0 0 \
                	player1 '' off \
                	player2 '' off \
                	player3 '' off \
                	player4 '' off
                

                input selection

                Once I get the controller names/indexes and the user selection, I think it's simple to change the input_playerX_joypad_index on retroarch.cfg using the sed command.

                I read in other topics that some users wants to, for example, play NES games with their NES-like controllers, and play SNES games with their SNES-like controller. I think it's also feasible.

                RionR 1 Reply Last reply Reply Quote 1
                • mediamogulM
                  mediamogul Global Moderator
                  last edited by

                  Very nice! Considering multiple use cases like you are will be greatly appreciated.

                  RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                  1 Reply Last reply Reply Quote 0
                  • RionR
                    Rion @meleu
                    last edited by

                    @meleu said in how can I get the connected joypad names?:

                    I'm thinking on a dialog box like this (or something closer):

                    dialog \
                    	--title 'Input selection' \
                    	--checklist 'What player you want to control with "8Bitdo Zero"' \
                    	0 0 0 \
                    	player1 '' off \
                    	player2 '' off \
                    	player3 '' off \
                    	player4 '' off
                    

                    input selection

                    Once I get the controller names/indexes and the user selection, I think it's simple to change the input_playerX_joypad_index on retroarch.cfg using the sed command.

                    I read in other topics that some users wants to, for example, play NES games with their NES-like controllers, and play SNES games with their SNES-like controller. I think it's also feasible.

                    Just what I was looking for!

                    FBNeo rom filtering
                    Mame2003 Arcade Bezels
                    Fba Arcade Bezels
                    Fba NeoGeo Bezels

                    1 Reply Last reply Reply Quote 0
                    • meleuM
                      meleu @Rion
                      last edited by

                      @Rion said in how can I get the connected joypad names?:

                      I have the same problem sort of.

                      I have two 8bitdo controllers, SFC30 & NES30.

                      I want to have the NES30 as player 1 and SFC30 as player 2.

                      This works 5 out of 10 times if I do it in this order. Start SFC30 first then NES30.
                      But the other 5 times retroarch decide SFC30 is Player 1 and Player 2 is NES30.

                      So an emulator specific change for what controller is p1 & p2 would be the best solution using the run command.

                      Something like a joystick/gamepad hierarchy.

                      Example:
                      NES30 is always p1 if it's connected.
                      SFC30 is always p2 if it's connected & Nes30 is connected.
                      Nes30 is off = SFC30 is p1.

                      @herb_fargus was talking about something like this as part of the Retropie Setup in this thread usb-controller-player-order

                      As a workaround you can change this all on-the-fly inside RetroArch. Go to the RGUI (Select+X), Settings -> Input -> Input User X Binds -> User X Device Index.

                      Be aware that the change is done immediately! It's a really weird behavior. If you change this field on RGUI using a controller, this same controler stops to control the RGUI and the chosen controller at the "User X Device Index" takes its place!

                      1 Reply Last reply Reply Quote 1
                      • RionR
                        Rion
                        last edited by

                        @meleu

                        I think I will hold off on that until you made some progress on the run command script.

                        But thank you for pointing it out for me :)

                        FBNeo rom filtering
                        Mame2003 Arcade Bezels
                        Fba Arcade Bezels
                        Fba NeoGeo Bezels

                        1 Reply Last reply Reply Quote 1
                        • meleuM
                          meleu @Zigurana
                          last edited by meleu

                          @Zigurana You are amazing!!! :D

                          You pointed me out that SDL stuff and I did my research on that topic.

                          I can't play with C++ but I can remember my teenager hacking days with C language!

                          I wrote this small program to get the joystick names and indexes:

                          /* jslist.c
                           * This little program just list the joysticks connected to the system.
                           * The ouput format is "index:JoystickName".
                           */
                          
                          #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\n", i, SDL_JoystickNameForIndex(i));
                          
                          	SDL_Quit();
                          	return 0;
                          }
                          

                          The command to compile this code (as pointed in SDL Wiki):
                          gcc jslist.c -o jslist $(sdl2-config --cflags --libs)

                          This was my first step. The jslist needs some little improvements to avoid problems with controllers with the same name. It's easy to solve, but I will work on that later. Now I have to play with my children! :D

                          1 Reply Last reply Reply Quote 2
                          • Z
                            Zigurana
                            last edited by

                            Good work! interested to see where this ends!
                            Have fun with the little ones!

                            If tetris has thought me anything, it's that errors pile up and that accomplishments dissappear.

                            1 Reply Last reply Reply Quote 1
                            • meleuM
                              meleu
                              last edited by meleu

                              This post is deleted!
                              1 Reply Last reply Reply Quote 0
                              • meleuM
                                meleu
                                last edited by

                                Hey guys! I think I did it! Or, at least, started it!

                                Let's talk about it at a proper thread:
                                https://retropie.org.uk/forum/topic/1167/here-is-a-way-to-select-input-for-retroarch-players-1-4

                                1 Reply Last reply Reply Quote 0
                                • BuZzB
                                  BuZz administrators
                                  last edited by

                                  from shell

                                  for js in /dev/input/js*; do path=$(udevadm info --name=$js | grep DEVPATH | cut -d= -f2); name=$(</$(dirname sys$path)/name); echo $name; done
                                  

                                  To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                                  meleuM 1 Reply Last reply Reply Quote 0
                                  • meleuM
                                    meleu @BuZz
                                    last edited by meleu

                                    @BuZz said in [SOLVED] how can I get the connected joypad names?:

                                    from shell

                                    for js in /dev/input/js*; do path=$(udevadm info --name=$js | grep DEVPATH | cut -d= -f2); name=$(</$(dirname sys$path)/name); echo $name; done
                                    

                                    pretty awesome! :)

                                    It perfectly answer the topic question. But another problem arises for my application...

                                    The problem is how to find out the proper SDL2/RetroArch index. The SDL2 gives to my jslist.c the correct index, and it doesn't always happen to be the same number after the /dev/input/js.

                                    Example: I have 3 usb controllers (as js0, js1 and js2) and one bluetooth controller as js3. The js-RetroArch equivalence is:
                                    js0 = 0
                                    js1 = 1
                                    js2 = 2
                                    js3 = 3

                                    Then I unplug the second usb controller. Now the the relation is:
                                    js0 = 0
                                    js2 = 1
                                    js3 = 2

                                    I think it's hard to find the proper index with "pure" shell script.

                                    1 Reply Last reply Reply Quote 0
                                    • BuZzB
                                      BuZz administrators
                                      last edited by

                                      thats ok, you just go through them and increment the index in the loop.

                                      To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                                      1 Reply Last reply Reply Quote 0
                                      • BuZzB
                                        BuZz administrators
                                        last edited by BuZz

                                        i=0; for dev in $(find /dev/input -name "js*" | sort); do path=$(udevadm info --name=$dev | grep DEVPATH | cut -d= -f2); name=$(</$(dirname sys$path)/name); echo $dev $i $name; ((i++)); done

                                        /dev/input/js0 0 USB,2-axis 8-button gamepad
                                        /dev/input/js1 1 8Bitdo SFC30 GamePad Joystick
                                        

                                        then unplugging the USB

                                        /dev/input/js1 0 8Bitdo SFC30 GamePad Joystick
                                        

                                        (switched to find to avoid an error if no joysticks connected, but just for this quick one line example)

                                        To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                                        meleuM 1 Reply Last reply Reply Quote 0
                                        • meleuM
                                          meleu @BuZz
                                          last edited by meleu

                                          @BuZz
                                          Initially I was excited with this solution and went for the tests...

                                          Then I realized that the SDL algorithm index assignment isn't that simple...

                                          The scenario: 4 usb joysticks (js0, js1, js2 and js3) and one bluetooth controller (js4). And then I disconnected the 1st and 2nd usb joysticks (js0 and js1), and the bluetooth controller also. Several minutes later I reconnected the bluetooth controller and it took the js0 "slot". Look at the output differences:

                                          [prompt]$ jslist 
                                          0:Twin USB Joystick
                                          1:Twin USB Joystick
                                          2:8Bitdo Zero GamePad
                                          [prompt]$ bash buzz-jslist.sh
                                          /dev/input/js0 0 8Bitdo Zero GamePad
                                          /dev/input/js2 1 Twin USB Joystick
                                          /dev/input/js3 2 Twin USB Joystick
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • meleuM
                                            meleu
                                            last edited by

                                            I think my current dilema is: C or Python?

                                            The C solution is great because the SDL2 is installed by default in RetroPie. The only doubt I have is "where to put the binary?". Maybe /opt/retropie/supplementary?

                                            The Python solution requires the installation of python-pygame. It means 15.2 MB of additional disk space just to list the available joysticks.

                                            For the moment I think the C approach is the winner.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.