You are not logged in.

#1 2014-11-20 18:49:52

klenamenis
Member
Registered: 2014-07-03
Posts: 101

run command when (un)plugging (in) Xbox Controller

Hey,

I recently got a USB Xbox 360 Controller and set it up using antimicro and the kernel's xpad driver. Now, I want to start antimicro in the background, when I plug the controller in and stop antimicro when I unplug it.

Is there a more elegant way than running a bash script at startup which periodically checks lsusb's output and acts accordingly?

## command to run when plugged in
/usr/bin/antimicro --no-tray --hidden
## command to run when unplugged
/usr/bin/pkill antimicro

[klemens@arch-pc ~]$ lsusb | grep Xbox
Bus 003 Device 012: ID 045e:028e Microsoft Corp. Xbox360 Controller

Offline

#2 2014-11-20 19:36:50

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: run command when (un)plugging (in) Xbox Controller


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2014-11-21 00:31:36

klenamenis
Member
Registered: 2014-07-03
Posts: 101

Re: run command when (un)plugging (in) Xbox Controller

[klemens@arch-pc]$ cat /etc/udev/rules.d/60-xbox-controller.rules 
SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="add", SYMLINK+="xbox", RUN+="/usr/bin/antimicro --no-tray --hidden"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="remove", SYMLINK-="xbox", RUN+="/usr/bin/pkill antimicro"

I created this one, but it has no effect. I read through the pages but can't figure out why, can you help me?

Last edited by klenamenis (2014-11-21 00:32:02)

Offline

#4 2014-11-21 00:38:37

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: run command when (un)plugging (in) Xbox Controller

Don't use RUN, use SYSTEMD_WANTS and a service file. See `man systemd.device`.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2014-11-22 17:08:53

klenamenis
Member
Registered: 2014-07-03
Posts: 101

Re: run command when (un)plugging (in) Xbox Controller

OK, I got the reason why not to use the RUN key, but also got confused using a systemd unit. So far, this is it:

[klemens@arch-pc ~]$ cat /etc/udev/rules.d/60-xbox-controller.rules /etc/systemd/system/dev-xbox-{in,out}.device
SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="add", SYMLINK+="xbox", ENV{SYSTEMD_WANTS}=="dev-xbox-in.device"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="remove", SYMLINK-="xbox", ENV{SYSTEMD_WANTS}=="dev-xbox-out.device"

[Unit]
Description=Xbox Controller
[Service]
ExecStart=/usr/bin/antimicro --no-tray --hidden

[Unit]
Description=Xbox Controller
[Service]
ExecStart=/usr/bin/pkill antimicro

Do I have to use service units? (How) can I put this into a single unit with ExecStart and ExecStop? Obviously, this way it's not working...

Offline

Board footer

Powered by FluxBB