我的电视连接了 Raspberry Pi 4。当我插入 USB 控制器时,我想运行一个使用 CEC 打开电视的脚本,将电视输入切换到 Pi,然后启动 Steam Link。如果我自己运行该脚本,该脚本就可以工作,但是当插入控制器时,我似乎无法触发规则。是的,我做到了sudo udevadm control --reload
这是我的工作脚本,另存为/usr/local/bin/autogame.sh
echo 'on 0.0.0.0' | cec-client -s -d 1
echo 'as' | cec-client -s -d 1
/usr/bin/steamlink
udevadm monitor --kernel --property --subsystem-match=usb
这是运行并插入控制器的结果
monitor will print the received events for:
KERNEL - the kernel uevent
KERNEL[189783.367795] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb)
ACTION=add
DEVPATH=/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2
SUBSYSTEM=usb
DEVNAME=/dev/bus/usb/001/012
DEVTYPE=usb_device
PRODUCT=e6f/213/100
TYPE=255/255/255
BUSNUM=001
DEVNUM=012
SEQNUM=1838
MAJOR=189
MINOR=11
KERNEL[189783.373779] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
ACTION=add
DEVPATH=/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=e6f/213/100
TYPE=255/255/255
INTERFACE=255/93/1
MODALIAS=usb:v0E6Fp0213d0100dcFFdscFFdpFFicFFisc5Dip01in00
SEQNUM=1839
KERNEL[189783.374744] bind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
ACTION=bind
DEVPATH=/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
DRIVER=xpad
PRODUCT=e6f/213/100
TYPE=255/255/255
INTERFACE=255/93/1
MODALIAS=usb:v0E6Fp0213d0100dcFFdscFFdpFFicFFisc5Dip01in00
SEQNUM=1844
KERNEL[189783.375136] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.1 (usb)
ACTION=add
DEVPATH=/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.1
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=e6f/213/100
TYPE=255/255/255
INTERFACE=255/93/3
MODALIAS=usb:v0E6Fp0213d0100dcFFdscFFdpFFicFFisc5Dip03in01
SEQNUM=1845
KERNEL[189783.375580] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.2 (usb)
ACTION=add
DEVPATH=/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.2
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=e6f/213/100
TYPE=255/255/255
INTERFACE=255/93/2
MODALIAS=usb:v0E6Fp0213d0100dcFFdscFFdpFFicFFisc5Dip02in02
SEQNUM=1846
KERNEL[189783.384551] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.3 (usb)
ACTION=add
DEVPATH=/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.3
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=e6f/213/100
TYPE=255/255/255
INTERFACE=255/253/19
MODALIAS=usb:v0E6Fp0213d0100dcFFdscFFdpFFicFFiscFDip13in03
SEQNUM=1847
KERNEL[189783.385026] bind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb)
ACTION=bind
DEVPATH=/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2
SUBSYSTEM=usb
DEVNAME=/dev/bus/usb/001/012
DEVTYPE=usb_device
DRIVER=usb
PRODUCT=e6f/213/100
TYPE=255/255/255
BUSNUM=001
DEVNUM=012
SEQNUM=1848
MAJOR=189
MINOR=11
这就是我从中得到的udevadm info -ap /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2
looking at device '//devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2':
KERNEL=="1-1.2"
SUBSYSTEM=="usb"
DRIVER=="usb"
ATTR{bDeviceSubClass}=="ff"
ATTR{quirks}=="0x0"
ATTR{bNumInterfaces}==" 4"
ATTR{bcdDevice}=="0100"
ATTR{bMaxPacketSize0}=="8"
ATTR{removable}=="unknown"
ATTR{bConfigurationValue}=="1"
ATTR{bDeviceClass}=="ff"
ATTR{urbnum}=="34"
ATTR{idVendor}=="0e6f"
ATTR{speed}=="12"
ATTR{version}==" 2.00"
ATTR{devspec}==" (null)"
ATTR{devnum}=="17"
ATTR{ltm_capable}=="no"
ATTR{bMaxPower}=="500mA"
ATTR{rx_lanes}=="1"
ATTR{serial}=="05F89012"
ATTR{devpath}=="1.2"
ATTR{authorized}=="1"
ATTR{busnum}=="1"
ATTR{manufacturer}=="Performance Designed Products"
ATTR{bmAttributes}=="a0"
ATTR{product}=="Afterglow Gamepad for Xbox 360"
ATTR{idProduct}=="0213"
ATTR{tx_lanes}=="1"
ATTR{avoid_reset_quirk}=="0"
ATTR{bNumConfigurations}=="1"
ATTR{maxchild}=="0"
ATTR{configuration}==""
ATTR{bDeviceProtocol}=="ff"
这些是我尝试过但没有成功的规则,另存为/etc/udev/rules.d/00-usb-autogame.rules
.
ACTION=="add", SUBSYSTEM=="usb", ENV{PRODUCT}=="e6f/213/100", RUN+="/usr/local/bin/autogame.sh"
ACTION=="add", SUBSYSTEM=="usb", PRODUCT=="e6f/213/100", RUN+="/usr/local/bin/autogame.sh"
ACTION=="add", SUBSYSTEM=="usb", ATTR{serial}=="05F89012", RUN+="/usr/local/bin/autogame.sh"
ACTION=="add", SUBSYSTEM=="usb", ATTR{product}=="Afterglow Gamepad for Xbox 360", RUN+="/usr/local/bin/autogame.sh"