RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    xboxdrv - 2 zero delay encoders. Best way to determine p1 vs p2

    Scheduled Pinned Locked Moved Help and Support
    xboxdrv2 controllers
    13 Posts 4 Posters 1.8k 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.
    • D
      dsstrainer
      last edited by dsstrainer

      I am using 2 zero delay encoders in an arcade setup.

      The problem:
      Retroarch only supports player 1 for hotkeys. The ZD encoder does have 12 inputs which is enough for my needs, but the wires that come with it are too short to reach the other end of the board.

      My proposed solution:
      To use xboxdrv as the driver for both ZD players but for player 2, 2 of the buttons will map to keyboard commands, thus allowing me to use keyboard hotkeys from the player 2 encoder.

      The struggle:
      Both encoders are named exactly the same in cat proc, so doing it by name is no good.

      If I use
      sudo xboxdrv --evdev /dev/input/by-id/usb-DragonRise_Inc._Generic_USB_Joystick-event-joystick
      it only has one listing even though there are 2 encoders connected, so it always assumes the second one

      if I use
      sudo xboxdrv --evdev /dev/input/event[*]
      the event could change between restarts or when new devices are plugged/unplugged (like keyboard)

      I could use
      sudo xboxdrv --evdev /dev/input/by-path/platform-3f980000.usb-usb-0:1.2:2.0-event-joystick
      But I'm surprised this isn't a larger issue for others. Or perhaps nobody else bothers to use xboxdrv for normal encoders because they aren't trying to do what I'm doing. With this method, I'd only have to make sure that I always use the same port assignment for player 1 and player 2, but that should be fine.

      Alternatively I could write some bash code to go through each device in
      cat /proc/bus/input/devices
      and find which one gets assigned "js1" and which is assigned "js2" on the fly during startup and assign that way.

      So I just wanted to get some thoughts on the best practice for this or if there were any other ideas.

      RetroPie v4.2 • RPi3 Model B • 5.1V 2.5A PSU • 8GB SanDisk class 10 microSD • 16GB External USB Thumb Drive
      Roms, images and configs stored in USB and symlinked from normal microsd location
      Xarcade Keyboard encoder + Zero Delay Joystick encoder

      mediamogulM S 2 Replies Last reply Reply Quote 0
      • P
        psyke83 Global Moderator
        last edited by psyke83

        You could write a udev rule to do what you want, but you can't use udev to launch long-running daemons, as udev may become blocked or will kill blocking processes.

        You can configure a udev rule to launch a systemd service.

        Create a service file: /etc/systemd/system/xboxdrv@.service

        [Unit]
        Description=xboxdrv helper (%I)
        
        [Service]
        Type=simple
        ExecStart=xboxdrv --evdev %I
        
        [Install]
        WantedBy=multi-user.target
        

        You may need to prepend the exact path to xboxdrv in case systemd doesn't search the full range of paths compared to a regular bash session.

        Now create your udev rule that will match against the needed device, and have it launch an instance of the service. For example, /etc/udev/rules.d/99-xboxdrv.rules:

        ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="Controller Name", TAG+="systemd", ENV{SYSTEMD_WANTS}="xboxdrv@%p.service"
        

        Replace Controller Namewith the actual name of the device that's reported to udev.

        I recommend that you avoid matching a rule that includes the full device path, as udev mangles any hyphens in the path, which will pass an invalid device to the systemd service. In that case you may need to rewrite this rule to match the simpler /dev/input/event event.

        To get a better idea of how to create a rule, plug in your device, and check the output of udevadm info /dev/input/eventX (where X is the currently enumerated device). You may be able to match a rule via the ID_MODEL, for example.

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

          @dsstrainer said in xboxdrv - 2 zero delay encoders. Best way to determine p1 vs p2:

          To use xboxdrv as the driver for both ZD players but for player 2, 2 of the buttons will map to keyboard commands, thus allowing me to use keyboard hotkeys from the player 2 encoder.

          I have a few use cases where I do this.

          I could use
          sudo xboxdrv --evdev /dev/input/by-path/platform-3f980000.usb-usb-0:1.2:2.0-event-joystick
          But I'm surprised this isn't a larger issue for others.

          It affects me directly, as I use two Logitech Rumblepad 2s and the same issue arises. I've been using by-path for nearly a year now and it's worked out well for my needs.

          Alternatively I could write some bash code to go through each device in
          cat /proc/bus/input/devices
          and find which one gets assigned "js1" and which is assigned "js2" on the fly during startup and assign that way.

          Like I said above, I'm pretty happy with my setup, but I really like this idea. If you follow through with it, definitely post the details of how it worked out.

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

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

            @psyke83 said in xboxdrv - 2 zero delay encoders. Best way to determine p1 vs p2:

            You could write a udev rule to do what you want

            I really like that too. I experimented with using a udev rule for this at one time and although I didn't see it through, it looked like it would work well.

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

            P 1 Reply Last reply Reply Quote 0
            • P
              psyke83 Global Moderator @mediamogul
              last edited by

              @mediamogul said in xboxdrv - 2 zero delay encoders. Best way to determine p1 vs p2:

              @psyke83 said in xboxdrv - 2 zero delay encoders. Best way to determine p1 vs p2:

              You could write a udev rule to do what you want

              I really like that too. I experimented with using a udev rule for this at one time and although I didn't see it through, it looked like it was going to work.

              It will work if the rule is correctly implemented. I'm using precisely the same method for my sixaxis service: https://github.com/RetroPie/RetroPie-Setup/pull/2263

              One annoyance, as I said, is that hyphens get mangled during udev <-> systemd communication. I workaround that problem via a simple function in the script, however.

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

                @psyke83

                Very nice.

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

                1 Reply Last reply Reply Quote 0
                • S
                  spud11 @dsstrainer
                  last edited by

                  @dsstrainer I have 4 DragonRise usb zero delay joysticks and use the by-path method to mimic keys on a keyboard, accompanied by an appropriate udev rule. Like mediamogul, I've been using this set up for more than a year and haven't had any issues. I also use meleu's retropie-joystick-selection tool which is very handy too.

                  RetroPie v4.4.1 • RPi3 Model B • 5.1V 2.5A PSU • 32GB SanDisk Extreme microSD • 2TB Toshiba Canvio Basics Portable USB 3.0 hard drive • 4 x DragonRise USB Arcade joysticks • 2 x TurboTwist spinners • 1 x USB trackball • 1 x PS4 wireless • 1 x 8BitDo Zero

                  1 Reply Last reply Reply Quote 0
                  • D
                    dsstrainer
                    last edited by dsstrainer

                    Thanks for all the advice. Oddly though, my initial first test did not work.
                    I decided to start small. Since I was only trying to get the player 2 encoder to have 2 buttons send out the 2 keys I have mapped to Save "]" and Load "6", I only used xboxdrv for those 2 buttons on that input.

                    I mapped the 2 buttons on the encoder and started it with --detach. Then I was able to visually see that when I hit those buttons on the command line, it indeed typed out ] and 6
                    I also have a keyboard plugged in and it also types out ] and 6
                    But when I goto the game and hit those buttons, nothing happens. But if I use the keyboard, it works fine.

                    I don't have the exact command line at the moment as I am not home but I'll paste that later. Still was surprised it didn't work.

                    RetroPie v4.2 • RPi3 Model B • 5.1V 2.5A PSU • 8GB SanDisk class 10 microSD • 16GB External USB Thumb Drive
                    Roms, images and configs stored in USB and symlinked from normal microsd location
                    Xarcade Keyboard encoder + Zero Delay Joystick encoder

                    1 Reply Last reply Reply Quote 0
                    • D
                      dsstrainer
                      last edited by

                      ok here is the command line I used to test quickly:

                      sudo /opt/retropie/supplementary/xboxdrv/bin/xboxdrv --detach --daemon --evdev /dev/input/by-path/platform-3f980000.usb-usb-0:1.3:1.0-event-joystick --evdev-keymap BTN_BASE=l2,BTN_BASE2=r2 --ui-buttonmap l2=KEY_RIGHTBRACE --silent
                      

                      So this is Joy number 2 (in the 1.3 usb port)
                      I set the button which turns out to be BTN_BASE to L2
                      Then I map the buttonmap of L2 to the "]" key which is KEY_RIGHTBRACE in xboxdrv

                      On the command line, when I hit that button, I see it outputting the "]" key
                      When I hit that key on my keyboard I also see the "]" key
                      When I start a game and hit that mapped button, it doesn't nothing
                      But if I use the keyboard, it works fine.

                      So where is the disconnect with it in the game?

                      RetroPie v4.2 • RPi3 Model B • 5.1V 2.5A PSU • 8GB SanDisk class 10 microSD • 16GB External USB Thumb Drive
                      Roms, images and configs stored in USB and symlinked from normal microsd location
                      Xarcade Keyboard encoder + Zero Delay Joystick encoder

                      1 Reply Last reply Reply Quote 0
                      • P
                        psyke83 Global Moderator
                        last edited by psyke83

                        My guess is that xboxdrv is creating a unique virtual uinput device node to emit the emulated keystrokes, but the emulator is only observing the actual keyboard's input event node? I have never used this daemon so I can't be sure.

                        D 1 Reply Last reply Reply Quote 0
                        • D
                          dsstrainer
                          last edited by

                          Well you are right.. I do see virtual devices. I will try without the daemon and see if that works

                          RetroPie v4.2 • RPi3 Model B • 5.1V 2.5A PSU • 8GB SanDisk class 10 microSD • 16GB External USB Thumb Drive
                          Roms, images and configs stored in USB and symlinked from normal microsd location
                          Xarcade Keyboard encoder + Zero Delay Joystick encoder

                          1 Reply Last reply Reply Quote 0
                          • D
                            dsstrainer @psyke83
                            last edited by

                            @psyke83 So how do you handle multiple joypads without running as a daemon? Just run multiple instances of xboxdrv process?

                            RetroPie v4.2 • RPi3 Model B • 5.1V 2.5A PSU • 8GB SanDisk class 10 microSD • 16GB External USB Thumb Drive
                            Roms, images and configs stored in USB and symlinked from normal microsd location
                            Xarcade Keyboard encoder + Zero Delay Joystick encoder

                            S 1 Reply Last reply Reply Quote 0
                            • S
                              spud11 @dsstrainer
                              last edited by

                              @dsstrainer That is correct.

                              RetroPie v4.4.1 • RPi3 Model B • 5.1V 2.5A PSU • 32GB SanDisk Extreme microSD • 2TB Toshiba Canvio Basics Portable USB 3.0 hard drive • 4 x DragonRise USB Arcade joysticks • 2 x TurboTwist spinners • 1 x USB trackball • 1 x PS4 wireless • 1 x 8BitDo Zero

                              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.