Linux 游戏手柄 - 没有输入事件

Linux 游戏手柄 - 没有输入事件

我正在尝试在 Linux 下使用游戏手柄(内核是 4.16.10),但似乎没有从中得到任何输入事件。

该设备是一个假冒的 Xbox 360 控制器,似乎已被检测到,dmesg报告如下:

#dmesg when pluging in controller

[29505.029981] usb 1-2: new full-speed USB device number 29 using xhci_hcd
[29505.158111] usb 1-2: New USB device found, idVendor=2563, idProduct=0575
[29505.158116] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[29505.158119] usb 1-2: Product: PS3/PC Gamepad
[29505.158121] usb 1-2: Manufacturer: SHANWAN
[29505.160469] input: SHANWAN PS3/PC Gamepad as /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/0003:2563:0575.000D/input/input52
[29505.160604] hid-generic 0003:2563:0575.000D: input,hidraw0: USB HID v1.10 Gamepad [SHANWAN PS3/PC Gamepad] on usb-0000:00:14.0-2/input0
[29505.238365] usb 1-2: USB disconnect, device number 29
[29505.845839] usb 1-2: new full-speed USB device number 30 using xhci_hcd
[29505.974584] usb 1-2: New USB device found, idVendor=045e, idProduct=028e
[29505.974590] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[29505.974594] usb 1-2: Product: Controller
[29505.974598] usb 1-2: Manufacturer: SHANWAN
[29505.976469] input: Microsoft X-Box 360 pad as /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/input/input53

我尝试了evdevjoystick驱动程序:

# /var/log/x-0.log with joystick driver

(II) config/udev: Adding input device Microsoft X-Box 360 pad (/dev/input/event7)
(**) Microsoft X-Box 360 pad: Applying InputClass "joystick catchall"
(II) Using input driver 'joystick' for 'Microsoft X-Box 360 pad'
(**) Microsoft X-Box 360 pad: always reports core events
(**) Microsoft X-Box 360 pad (keys): Applying InputClass "joystick catchall"
(II) Using input driver 'joystick' for 'Microsoft X-Box 360 pad (keys)'
(**) Microsoft X-Box 360 pad (keys): always reports core events
(**) Option "config_info" "udev:/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/input/input55/event7"
(II) XINPUT: Adding extended input device "Microsoft X-Box 360 pad (keys)" (type: JOYSTICK, id 18)
(**) Option "Device" "/dev/input/event7"
(**) Option "StartMouseEnabled" "False"
(**) Option "StartKeysEnabled" "False"
(**) Option "config_info" "udev:/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/input/input55/event7"
(II) XINPUT: Adding extended input device "Microsoft X-Box 360 pad" (type: JOYSTICK, id 19)
(II) Joystick: Microsoft X-Box 360 pad. bus 0x3 vendor 0x45e product 0x28e version 0x110
(II) Joystick: found 8 axes, 11 buttons
JOYSTICK: DebugLevel set to 0
(**) Microsoft X-Box 360 pad: (accel) keeping acceleration scheme 1
(**) Microsoft X-Box 360 pad: (accel) acceleration profile 0
(**) Microsoft X-Box 360 pad: (accel) acceleration factor: 2.000
(**) Microsoft X-Box 360 pad: (accel) acceleration threshold: 4

# /var/log/x-0.log with evdev driver

(II) config/udev: removing device Microsoft X-Box 360 pad
(II) evdev: Microsoft X-Box 360 pad: Close
(II) UnloadModule: "evdev"
(II) config/udev: Adding input device SHANWAN PS3/PC Gamepad (/dev/input/js0)
(II) No input driver specified, ignoring this device.
(II) This device may have been added with another device file.
(II) config/udev: Adding input device (unnamed) (/dev/input/event7)
(II) No input driver specified, ignoring this device.
(II) This device may have been added with another device file.
(II) config/udev: Adding input device Microsoft X-Box 360 pad (/dev/input/js0)
(**) Microsoft X-Box 360 pad: Applying InputClass "joystick catchall"
(II) Using input driver 'evdev' for 'Microsoft X-Box 360 pad'
(**) Microsoft X-Box 360 pad: always reports core events
(**) evdev: Microsoft X-Box 360 pad: Device: "/dev/input/js0"
(EE) evdev: Microsoft X-Box 360 pad: Unable to query fd: Invalid argument
(EE) PreInit returned 2 for "Microsoft X-Box 360 pad"
(II) UnloadModule: "evdev"
(II) config/udev: Adding input device Microsoft X-Box 360 pad (/dev/input/event7)
(**) Microsoft X-Box 360 pad: Applying InputClass "joystick catchall"
(II) Using input driver 'evdev' for 'Microsoft X-Box 360 pad'
(**) Microsoft X-Box 360 pad: always reports core events
(**) evdev: Microsoft X-Box 360 pad: Device: "/dev/input/event7"
(--) evdev: Microsoft X-Box 360 pad: Vendor 0x45e Product 0x28e
(--) evdev: Microsoft X-Box 360 pad: Found absolute axes
(--) evdev: Microsoft X-Box 360 pad: Found x and y absolute axes
(II) evdev: Microsoft X-Box 360 pad: Forcing relative x/y axes to exist.
(II) evdev: Microsoft X-Box 360 pad: Configuring as mouse
(**) Option "config_info" "udev:/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/input/input59/event7"
(II) XINPUT: Adding extended input device "Microsoft X-Box 360 pad" (type: MOUSE, id 16)
(II) evdev: Microsoft X-Box 360 pad: initialized for absolute axes.
(**) Microsoft X-Box 360 pad: (accel) keeping acceleration scheme 1
(**) Microsoft X-Box 360 pad: (accel) acceleration profile 0
(**) Microsoft X-Box 360 pad: (accel) acceleration factor: 2.000
(**) Microsoft X-Box 360 pad: (accel) acceleration threshold: 4

但是,我无法获取任何输入事件,无论是使用jstestnor evtest(无论是作为 root 还是非 root)。xboxdrv顺便说一句也是如此。

usbmon仅在插入和拔出控制器时获取数据。按下按钮时不会报告任何内容。

evdev检测到几个可能发生的事件:

# evtest

Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 304 (BTN_SOUTH)
    Event code 305 (BTN_EAST)
    Event code 307 (BTN_NORTH)
    Event code 308 (BTN_WEST)
    Event code 310 (BTN_TL)
    Event code 311 (BTN_TR)
    Event code 314 (BTN_SELECT)
    Event code 315 (BTN_START)
    Event code 316 (BTN_MODE)
    Event code 317 (BTN_THUMBL)
    Event code 318 (BTN_THUMBR)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value      0
      Min   -32768
      Max    32767
      Fuzz      16
      Flat     128
    Event code 1 (ABS_Y)
      Value      0
      Min   -32768
      Max    32767
      Fuzz      16
      Flat     128
    Event code 2 (ABS_Z)
      Value      0
      Min        0
      Max      255
    Event code 3 (ABS_RX)
      Value      0
      Min   -32768
      Max    32767
      Fuzz      16
      Flat     128
    Event code 4 (ABS_RY)
      Value      0
      Min   -32768
      Max    32767
      Fuzz      16
      Flat     128
    Event code 5 (ABS_RZ)
      Value      0
      Min        0
      Max      255
    Event code 16 (ABS_HAT0X)
      Value      0
      Min       -1
      Max        1
    Event code 17 (ABS_HAT0Y)
      Value      0
      Min       -1
      Max        1
  Event type 21 (EV_FF)
    Event code 80 (FF_RUMBLE)
    Event code 81 (FF_PERIODIC)
    Event code 88 (FF_SQUARE)
    Event code 89 (FF_TRIANGLE)
    Event code 90 (FF_SINE)
    Event code 96 (FF_GAIN)

附赠 Wireshark 的 usbmon 报告和带有 Windows 对应部分的 csv: https://filebin.net/n416mszk1155zbjb (抱歉,txt 版本尚未消化)

有谁有任何想法或线索来找到解决这个问题的方法吗?

谢谢,

答案1

如果按下按钮时没有收到任何 USB 流量,则表示硬件上的某些部件工作不正常。

要么是硬件损坏了,要么是它需要在宣布自己为的阶段进行正确的初始化SHANWAN PS3/PC,或者可能是在化身中,因为Microsoft X-Box 360 pad它需要 Windows 驱动程序的初始化命令,而 Linux 驱动程序不提供该命令。

下一步是将它连接到具有正确 Windows 驱动程序的计算机,看看它是否在那里工作。如果不行,请返回它;如果是,请嗅探 USB 流量(有适用于此的 Windows 工具,谷歌搜索)以找出应如何初始化它。

编辑

我仍然不明白这两个设备之间为什么会出现这种混乱(而且也没有时间详细研究)。但是,我们可以看到,在 Windows 下,在发送关键事件之前,会发生以下交换:

In:  01 03 02
Out: 01 03 02
In:  02 03 00
Out:
In:  03 03 03
Out: 
In:  08 03 00
Out: 

在 Linux 下,只显示第一行;永远没有答案。这可能是缺少初始化(或其他原因)。

在查看时,我发现这xpad是将 HID 事件转换为输入事件的内核驱动程序,我无法从您的dmesg摘录中看到它是否已加载。在双重检查中,使用 进行检查lsmod。(不过,我在快速检查源代码时找不到这些序列)。

似乎还有一个用户空间库,参见例如这里,它似乎比内核驱动程序工作得更好,所以这也值得一试。

答案2

我有同样的问题,但我设法识别了 Windows 驱动程序的初始化序列,并在此基础上编写了一个将必要的代码发送到设备的 Python 脚本。

这是脚本,您必须使用 sudo 运行它:pyusb-测试.py

相关内容