################################################################################
# An example udev rules file for lircd.
################################################################################

# lircd_helper only does something for "add" and "remove" actions.
ACTION!="add|remove", GOTO="end"

KERNEL=="hiddev[0-9]*", SUBSYSTEM=="usb",  SUBSYSTEMS=="usb", GOTO="begin"
KERNEL=="ttyACM[0-9]*", SUBSYSTEM=="tty",  SUBSYSTEMS=="usb", GOTO="begin"
KERNEL=="lirc[0-9]*",   SUBSYSTEM=="lirc", SUBSYSTEMS=="i2c", GOTO="begin"
KERNEL=="lirc[0-9]*",   SUBSYSTEM=="lirc", SUBSYSTEMS=="usb", GOTO="begin"
KERNEL=="lirc[0-9]*",   SUBSYSTEM=="lirc", SUBSYSTEMS=="platform", GOTO="begin"
KERNEL=="lirc[0-9]*",   SUBSYSTEM=="lirc", SUBSYSTEMS=="pnp", GOTO="begin"
GOTO="end"
LABEL="begin"

#-------------------------------------------------------------------------------
# Ask lircd_helper to lirc devices.
#-------------------------------------------------------------------------------

#SUBSYSTEM=="lirc", \
#  ENV{lircd_driver}="default", \
#  ENV{lircd_conf}="lircd.conf"

### Microsoft Xbox DVD dongle
SUBSYSTEM=="lirc", DRIVERS=="lirc_xbox", \
  ENV{lircd_driver}="default", \
  ENV{lircd_conf}="lircd.conf.xbox"

### RPi GPIO IR Receiver
SUBSYSTEM=="lirc", DRIVERS=="lirc_rpi", \
  ENV{lircd_driver}="default", \
  ENV{lircd_conf}="lircd.conf.rpi"

#-------------------------------------------------------------------------------
# Ask lircd_helper to handle USB devices that do not show up as lirc devices
# and are supported by lircd. Remote controls that are USB HID devices that show
# up as event devices are not included as as they are handled by eventlircd.
#-------------------------------------------------------------------------------
SUBSYSTEMS=="usb", GOTO="begin-usb"
GOTO="end-usb"

LABEL="begin-usb"

ENV{ID_USB_INTERFACES}=="", IMPORT{builtin}="usb_id"

ENV{ID_VENDOR_ID}=="04d8", ENV{ID_MODEL_ID}=="fd08", \
  ENV{lircd_driver}="usb_irtoy", \
  ENV{lircd_conf}="lircd.conf"

ENV{ID_VENDOR_ID}=="0fe9", ENV{ID_MODEL_ID}=="9010", \
  ENV{lircd_driver}="dvico", \
  ENV{lircd_conf}="lircd.conf"

LABEL="end-usb"

ENV{lircd_driver}=="?*", ENV{lircd_conf}=="?*", ACTION=="add", \
  TAG+="systemd", ENV{SYSTEMD_WANTS}+="lircd@$name:$env{lircd_driver}:$env{lircd_conf}.service", \
  RUN+="lircd_wakeup_enable"

ENV{lircd_driver}=="?*", ENV{lircd_conf}=="?*", ACTION=="remove", \
  RUN+="/usr/bin/systemctl stop lircd@$name:$env{lircd_driver}:$env{lircd_conf}.service"

LABEL="end"
