xboxdrv - 2 zero delay encoders. Best way to determine p1 vs p2
-
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 Name
with 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 theID_MODEL
, for example. -
@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.
-
@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.
-
@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.
-
Very nice.
-
@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. -
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.
-
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 xboxdrvOn 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?
-
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.
-
Well you are right.. I do see virtual devices. I will try without the daemon and see if that works
-
@psyke83 So how do you handle multiple joypads without running as a daemon? Just run multiple instances of xboxdrv process?
-
@dsstrainer That is correct.
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.