Setting up script for ds4 when connected
So I'm trying to edit the udev rule from ds4drv so it runs when its plugged in. I'm looking to see if udev can also stop the script once the controller is no longer paired.
My udev and script that is run:
cat /etc/udev/rules.d/50-ds4drv.rules
KERNEL=="uinput", MODE="0666"
#KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="05c4", MODE="0666"
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="05c4", MODE="0666" RUN+="/home/andrew/.config/ds4.sh"
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", KERNELS=="0005:054C:05C4.*", MODE="0666"
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="09cc", MODE="0666"
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", KERNELS=="0005:054C:09CC.*", MODE="0666"
cat /home/andrew/.config/ds4.sh
#!/usr/bin/env bash
# Terminate already running ds4drv instances
killall -q ds4drv
# Wait until the processes have been shut down
while pgrep -u $UID -x ds4drv >/dev/null; do sleep 1; done
ds4drv --hidraw --udp
I take it I just need a udev rule to check if the ds4 has been removed but I'm not seeing/googling successfully if udev has a disconnected rule.
Edited 24 Jan 2020. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 6 · 100% up
- Kind
- Text
- ID
- etdkbs
4 comments
Have you tried delegating to systemd? This is how I do in on my LibreELEC box:
udev.rules.d/10-sony_ds4.rules
system.d/sony_ds4.service
I only run a script on connect - so you'd have to adapt it to your use case (ExecStop etc), but systemd units are less of a pain in the ass than udev rules imo.
No I haven't sounds great but I am still confused after read the wiki bit on systemd units.
I made /etc/systemd/system/sony_ds4.service
Edited /etc/udev/rules.d/50-ds4drv.rules
Testing:
The User= would be me wanting to eventually have this run as a non root user, but I'm far from fully grasping this yet. Is systemd looking for the wrong mount just because my bindsto= and after= are wrong?
It's been a while since I set this up (it took me hours of reading udev/systemd man pages, apparently I immediately suppressed the memories of what I did exactly). Once enabled, it should start/stop automatically on connect/disconnect (tracking the device state via sysfs).
I find stuff like this hard to debug remotely, but first I'd check that the udev rule works correctly and systemd correctly tracks the device.
When you pair the ds4, udev should create the symlink
/dev/sony_ds4(that's the SYMLINK+= part of the udev rule) andsystemctl status dev-sony_ds4.deviceshould get you something like this:
If that's working, then set up the systemd service unit file.
I'm afraid these are all the pointers I can come up with at the moment, but please do document if/how you get it working. Maybe someone else can help.
Edit: Oh, and don't use the full path to service unit files with systemctl. Just
systemctl enable sony_ds4.service. that's what the "not found" error is about when you're running systemctl.Also note that my setup only has one controller hardcoded because that's all I needed.