Debugging

調試字元設備(滑鼠、鍵盤、觸摸屏等)並讀取輸入數據

  • June 17, 2021

我正在做一個項目,我有一個通過 USB 電纜連接到 PC 的紅外多點觸控框架,每當一個物體(例如手/手指)穿過它時,它就充當滑鼠。

我想要做的是能夠列印出物體經過的座標。我在想,如果我能理解設備如何與 PC 通信,那麼我可以編寫一些程序(如果可能的話),以 x 和 y 值的形式列印出座標。我讀過這些類型的設備也被稱為字元設備,我想知道是否有辦法調試它們並讀取它發送到電腦的輸入(我假設它們發送關於我的手經過的 x 和 y 座標的輸入這樣滑鼠游標就會移動到那裡)。

這不是我的研究領域,因為我是一名電腦工程師,所以我不知道如何開始。任何提示將不勝感激。提前致謝..

這是lsusb輸出:

mohammedaabdu@Mohammed-HP-Pavilion-Gaming-Notebook:~$ lsusb -D /dev/bus/usb/001/008
Device: ID 1870:010d Nexio Co., Ltd 
Couldn't open device, some information will be missing
Device Descriptor:
 bLength                18
 bDescriptorType         1
 bcdUSB               2.00
 bDeviceClass            0 
 bDeviceSubClass         0 
 bDeviceProtocol         0 
 bMaxPacketSize0        64
 idVendor           0x1870 Nexio Co., Ltd
 idProduct          0x010d 
 bcdDevice            5.a1
 iManufacturer           1 
 iProduct                2 
 iSerial                 0 
 bNumConfigurations      1
 Configuration Descriptor:
   bLength                 9
   bDescriptorType         2
   wTotalLength       0x0029
   bNumInterfaces          1
   bConfigurationValue     1
   iConfiguration          0 
   bmAttributes         0xc0
     Self Powered
   MaxPower              500mA
   Interface Descriptor:
     bLength                 9
     bDescriptorType         4
     bInterfaceNumber        0
     bAlternateSetting       0
     bNumEndpoints           2
     bInterfaceClass         3 Human Interface Device
     bInterfaceSubClass      0 
     bInterfaceProtocol      0 
     iInterface              0 
       HID Device Descriptor:
         bLength                 9
         bDescriptorType        33
         bcdHID               1.11
         bCountryCode            0 Not supported
         bNumDescriptors         1
         bDescriptorType        34 Report
         wDescriptorLength     736
        Report Descriptors: 
          ** UNAVAILABLE **
     Endpoint Descriptor:
       bLength                 7
       bDescriptorType         5
       bEndpointAddress     0x81  EP 1 IN
       bmAttributes            3
         Transfer Type            Interrupt
         Synch Type               None
         Usage Type               Data
       wMaxPacketSize     0x0040  1x 64 bytes
       bInterval               1
     Endpoint Descriptor:
       bLength                 7
       bDescriptorType         5
       bEndpointAddress     0x01  EP 1 OUT
       bmAttributes            3
         Transfer Type            Interrupt
         Synch Type               None
         Usage Type               Data
       wMaxPacketSize     0x0040  1x 64 bytes
       bInterval               1

這是 dmesg 輸出:

[ 7907.643318] usb 1-1: new full-speed USB device number 5 using xhci_hcd
[ 7907.792675] usb 1-1: New USB device found, idVendor=1870, idProduct=010d, bcdDevice= 5.a1
[ 7907.792681] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 7907.792684] usb 1-1: Product: Nexio HID Multi-Touch ATI0320-10
[ 7907.792687] usb 1-1: Manufacturer: Nexio Touch Device (HS)
[ 7907.798615] input: Nexio Touch Device (HS) Nexio HID Multi-Touch ATI0320-10 Touchscreen as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/0003:1870:010D.0002/input/input22
[ 7907.855645] input: Nexio Touch Device (HS) Nexio HID Multi-Touch ATI0320-10 Mouse as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/0003:1870:010D.0002/input/input23
[ 7907.856502] input: Nexio Touch Device (HS) Nexio HID Multi-Touch ATI0320-10 as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/0003:1870:010D.0002/input/input24
[ 7907.857637] hid-generic 0003:1870:010D.0002: input,hiddev1,hidraw1: USB HID v1.11 Mouse [Nexio Touch Device (HS) Nexio HID Multi-Touch ATI0320-10] on usb-0000:00:14.0-1/input0
[ 7908.181472] input: Nexio Touch Device (HS) Nexio HID Multi-Touch ATI0320-10 as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/0003:1870:010D.0002/input/input26
[ 7908.182031] input: Nexio Touch Device (HS) Nexio HID Multi-Touch ATI0320-10 as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/0003:1870:010D.0002/input/input28
[ 7908.182632] hid-multitouch 0003:1870:010D.0002: input,hiddev1,hidraw1: USB HID v1.11 Mouse [Nexio Touch Device (HS) Nexio HID Multi-Touch ATI0320-10] on usb-0000:00:14.0-1/input0

如果它已經表現得像滑鼠,您可以直接從滑鼠事件中獲取座標。

有很多方法可以做到這一點。例如一個 python 程序,帶有庫python-libinput

xev還將向您展示事件。

或者,以 root 身份evtest,將列印您將從中讀取的內容的人類可讀版本/dev/ìnput/eventX

某些硬體在系統中顯示為多個設備(例如,滑鼠和鍵盤)。

xinput --list

將告訴您您擁有的輸入設備(如果您不確定哪一個是正確的,您可以拔下並重新插入以查看差異)。

在這些情況下,您將不會訪問原始數據,而是訪問原始事件。

那應該讓你開始。有很多關於libinput.

引用自:https://unix.stackexchange.com/questions/654498