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.
    • 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

      • Useful topics
      • joystick-selection tool
      • rpie-art tool
      • achievements I made
      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.

          • Useful topics
          • joystick-selection tool
          • rpie-art tool
          • achievements I made
          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
                
                • Useful topics
                • joystick-selection tool
                • rpie-art tool
                • achievements I made
                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.

                  • Useful topics
                  • joystick-selection tool
                  • rpie-art tool
                  • achievements I made
                  1 Reply Last reply Reply Quote 0
                  • meleuM
                    meleu
                    last edited by meleu

                    Hey @BuZz , I've just realized that your method can be used to let the user choose which controller to use in runcommand.
                    I saw this line in runcommand.sh and it seems to always get the first /dev/input/js*.
                    (no need for that sermon about your priorities. :-) It's just an enhancement idea, ok...)

                    • Useful topics
                    • joystick-selection tool
                    • rpie-art tool
                    • achievements I made
                    1 Reply Last reply Reply Quote -2
                    • BuZzB
                      BuZz administrators
                      last edited by

                      The smiley doesn't make that line funny.

                      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

                        @BuZz it represents the effect, not the cause

                        • Useful topics
                        • joystick-selection tool
                        • rpie-art tool
                        • achievements I made
                        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.