我有一个运行 Bookworm 且内核为 6.1.21 的 Pi4,我正在尝试模拟键盘和鼠标。 我正在运行一个如下所示的启动脚本:Raspberry Pi 4 上的鼠标模拟不起作用
我遵循了此链接中的基础知识:在此处输入链接描述以初始化一些内核位。
我尝试从 python 文件运行这些示例:
NULL_CHAR = chr(0)
#keyboard
def write_report(report):
with open('/dev/hidg0', 'rb+') as fd:
fd.write(report.encode())
write_report(NULL_CHAR*2+chr(6)+chr(7)+chr(8)+chr(9)+chr(10)+chr(11))
write_report(NULL_CHAR*8)
#mouse
def ms_write(report):
with open("/dev/hidg1", "wb+") as fd:
fd.write(report.encode())
ms_write(NULL_CHAR+chr(100)+NULL_CHAR)
ms_write(NULL_CHAR*3)
我得到的错误是:BrokenPipeError:[Errno 108]传输端点关闭后无法发送
通过搜索,我可以看到工作示例使用带有其他内核的旧安装,因此这可能是问题所在。
或者设置在某种程度上是错误的,因为大多数示例都是将 Pi Zero 连接到另一个设备,这不是我正在做的。
有人与 Bookworm 合作过,或者有任何问题可能出在哪里吗?
我的初始化 bash 脚本:
#!/bin/bash
# Initializes the device by adding necessary kernel modules.
set -e
reboot_required=0
# Make sure we use the dwc2 USB driver.
# This driver is capable of handling OTG, consequently
# allowing this device to act as USB slave.
if ! grep "dtoverlay=dwc2" /boot/config.txt; then
echo "dtoverlay=dwc2" >> /boot/config.txt
reboot_required=1
fi
# Enable the corresponding kernel module.
if ! grep "dwc2" /etc/modules; then
echo "dwc2" >> /etc/modules
reboot_required=1
fi
if [ $reboot_required -eq 1 ]; then
echo "Please reboot the device for the initialization to take effect"
else
echo "Everything set up"
fi
我的设置脚本:
#!/bin/bash
set -e
modprobe libcomposite
cd /sys/kernel/config/usb_gadget/
mkdir -p pihid
cd pihid
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
mkdir -p strings/0x409
echo "fedcba9876543210" > strings/0x409/serialnumber
echo "test" > strings/0x409/manufacturer
echo "PiHID" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "Config 1: ECM network" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower
# Add functions here
mkdir -p functions/hid.usb0
echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
echo 8 > functions/hid.usb0/report_length
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.usb0/report_desc
ln -s functions/hid.usb0 configs/c.1/
mkdir -p functions/hid.usb1
echo 2 > functions/hid.usb1/protocol
echo 2 > functions/hid.usb1/subclass
echo 8 > functions/hid.usb1/report_length
echo -ne \\x05\\x01\\x09\\x02\\xA1\\x01\\x09\\x01\\xA1\\x00\\x05\\x09\\x19\\x01\\x29\\x03\\x15\\x00\\x25\\x01\\x95\\x03\\x75\\x01\\x81\\x02\\x95\\x01\\x75\\x05\\x81\\x03\\x05\\x01\\x09\\x30\\x09\\x31\\x15\\x81\\x25\\x7F\\x75\\x08\\x95\\x02\\x81\\x06\\xC0\\xC0 > functions/hid.usb1/report_desc
ln -s functions/hid.usb1 configs/c.1/
# End functions
ls /sys/class/udc > UDC
#chmod 777 /dev/hidg0
#chmod 777 /dev/hidg1
#
和/etc/rc.local:
#mouse emulator config
sudo /home/martinval/projects/hid/mouse_keyb.sh
sudo chmod -R 777 /dev/hidg0
sudo chmod -R 777 /dev/hidg1
我正在努力将 bmy raspberry pi 4 配置为 HID 键盘,先生,您能帮我建立一下吗?这是我最后一年的项目。请通过 [电子邮件受保护] 与我联系,请帮助我,先生。