################################################################################
# An example udev rules file for eventlircd.
#
# This rules file does not start eventlircd. Many applications only check for
# the lircd socket at application lauch. Therefore, it is better to start
# eventlircd in an init script so that eventlircd creates the lircd socket
# before any applications that use LIRC launch.
################################################################################

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

# eventlircd only does something "input" subsystem devices.
SUBSYSTEM!="input", GOTO="end"

# eventlircd can only handle event devices.
KERNEL!="event[0-9]*", GOTO="end"

# eventlircd ignores devices created by eventlircd.
ATTRS{name}=="eventlircd", GOTO="end"

#-------------------------------------------------------------------------------
# Ask eventlircd to handle input event devices created by lircd. For this to
# work, lircd must be configured to output Linux input events and must be
# configured to output key names that conform to the LIRC namespace derived from
# the Linux key/button event names. This rule assumes that lircd performs all
# key mappings, so the rule does not provide a value for "eventlircd_evmap".
# For more information on lircd, see <http://www.lirc.org/>.
#-------------------------------------------------------------------------------
ATTRS{name}=="lircd", \
  ENV{eventlircd_enable}="true"

#-------------------------------------------------------------------------------
# Ask eventlircd to handle input event devices created by bdremoteng. For this
# to work, bdremoteng must be configured to output Linux input events and must
# be configured to output key names that conform to LIRC namespace derived
# from the Linux key/button event names. For more information on bdremoteng,
# see <http://code.google.com/p/bdremote-ng/>.
#-------------------------------------------------------------------------------
ATTRS{name}=="bdremoteng", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="bdremoteng.evmap"

#-------------------------------------------------------------------------------
# Ask eventlircd to handle input event devices created by wminput. This rule
# assumes that wminput performs all key mappings, so the rule does not provide a
# value for "eventlircd_evmap" For more information on wminput, see
# <http://abstrakraft.org/cwiid/>.
#-------------------------------------------------------------------------------
ATTRS{name}=="bdremoteng", \
  ENV{eventlircd_enable}="true"

#-------------------------------------------------------------------------------
# Ask eventlircd to handle input event devices created by ir-core (kernel).
#-------------------------------------------------------------------------------
SUBSYSTEMS=="rc", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="ircore.evmap"

#-------------------------------------------------------------------------------
# Ask eventlircd to handle power button.
#-------------------------------------------------------------------------------
SUBSYSTEMS=="acpi", ATTRS{hid}=="LNXPWRBN", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="power.evmap"

#-------------------------------------------------------------------------------
# Ask eventlircd to handle USB HID devices that show up as event devices and are
# known to be remote controls. For simplicity, the event map file names have the
# format <BUSTYPE>_<VENDOR>_<PRODUCT>.evmap.
#-------------------------------------------------------------------------------
SUBSYSTEMS=="usb", GOTO="begin-usb"
GOTO="end-usb"
LABEL="begin-usb"

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

ENV{ID_VENDOR_ID}=="0bc7", ENV{ID_MODEL_ID}=="0006", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

ENV{ID_VENDOR_ID}=="0419", ENV{ID_MODEL_ID}=="0001", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

ENV{ID_VENDOR_ID}=="046d", ENV{ID_MODEL_ID}=="c101", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

ENV{ID_VENDOR_ID}=="046e", ENV{ID_MODEL_ID}=="5577", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="topseed.evmap"

ENV{ID_VENDOR_ID}=="046e", ENV{ID_MODEL_ID}=="5578", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="topseed.evmap"

ENV{ID_VENDOR_ID}=="04b4", ENV{ID_MODEL_ID}=="0100", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="cypress.evmap"

ENV{ID_VENDOR_ID}=="04b4", ENV{ID_MODEL_ID}=="0101", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="cypress.evmap"

ENV{ID_VENDOR_ID}=="04f2", ENV{ID_MODEL_ID}=="0618", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="topseed.evmap"

ENV{ID_VENDOR_ID}=="0766", ENV{ID_MODEL_ID}=="0204", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="topseed.evmap"

ENV{ID_VENDOR_ID}=="1784", ENV{ID_MODEL_ID}=="0004", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="topseed.evmap"

ENV{ID_VENDOR_ID}=="03eb", ENV{ID_MODEL_ID}=="0002", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

ENV{ID_VENDOR_ID}=="05a4", ENV{ID_MODEL_ID}=="9881", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

# ENV{ID_VENDOR_ID}=="05ac", ENV{ID_MODEL_ID}=="8241", \
#   ENV{eventlircd_enable}="true", \
#   ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

ENV{ID_VENDOR_ID}=="0709", ENV{ID_MODEL_ID}=="9137", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

ENV{ID_VENDOR_ID}=="0755", ENV{ID_MODEL_ID}=="2626", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

ENV{ID_VENDOR_ID}=="1241", ENV{ID_MODEL_ID}=="e000", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

ENV{ID_VENDOR_ID}=="13ec", ENV{ID_MODEL_ID}=="0006", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

ENV{ID_VENDOR_ID}=="147a", ENV{ID_MODEL_ID}=="e02d", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

ENV{ID_VENDOR_ID}=="18b1", ENV{ID_MODEL_ID}=="0037", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

ENV{ID_VENDOR_ID}=="1d57", ENV{ID_MODEL_ID}=="ac01", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="03_$env{ID_VENDOR_ID}_$env{ID_MODEL_ID}.evmap"

#ENV{ID_VENDOR_ID}=="9022", ENV{ID_MODEL_ID}=="d660", \
ATTRS{idVendor}=="9022", ATTRS{idProduct}=="d660", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="tevii_s660.evmap"

ENV{ID_VENDOR_ID}=="0471", ENV{ID_MODEL_ID}=="0613", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="spinelplus.evmap"

ENV{ID_VENDOR_ID}=="0471", ENV{ID_MODEL_ID}=="206c", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="spinelplus.evmap"

ENV{ID_VENDOR_ID}=="0471", ENV{ID_MODEL_ID}=="20cc", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="spinelplus.evmap"

# Enable wake-on-usb for the USB remotes.
  RUN+="wakeup_enable"

LABEL="end-usb"

# Automatically set Delayrate to 200ms to avoid double keypresses with
# gpio-rc-recv
  DRIVERS=="gpio-rc-recv", \
    RUN+="/usr/bin/ir-keytable --delay=200 --device=$devnode", \
    GOTO="end-keytable"

# Set default delays (1000ms for first repeat, to avoid multiple keypresses).
  RUN+="/usr/bin/ir-keytable --delay=1000 --device=$devnode"

LABEL="end-keytable"
#-------------------------------------------------------------------------------
# Ask eventlircd to handle Bluetooth HID devices that show up as event devices
# and are known to be remote controls. For simplicity, the event map file names
# have the format <BUSTYPE>_<VENDOR>_<PRODUCT>.evmap.
#-------------------------------------------------------------------------------
SUBSYSTEMS=="bluetooth", GOTO="begin-bluetooth"
GOTO="end-bluetooth"
LABEL="begin-bluetooth"

ATTRS{name}=="Nintendo Wii Remote", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="wiimote.evmap"

ATTRS{name}=="BD Remote Control", \
  ENV{eventlircd_enable}="true", \
  ENV{eventlircd_evmap}="ps3remote.evmap"

LABEL="end-bluetooth"

LABEL="end"
