在Ubuntu中使用兼容HID的鼠标(例如设备)


8

目的:我有一个模仿鼠标的白板。因此,当您单击并拖动白板时,它应该移动光标。我想在Ubuntu中使白板工作在Windows上工作。设备信息:其输出cat /proc/bus/input包含设备信息

I: Bus=0003 Vendor=4623 Product=011a Version=0111
N: Name="Hite Board-XXXXXXXX"
P: Phys=usb-0000:00:14.0-1/input0
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/
U: Uniq=
H: Handlers=mouse2 event13
B: PROP=2
B: EV=b
B: KEY=400 0 0 0 0 0
B: ABS=260800000000003

abhishek@vaio:~$ lsusb -d 4623:011a -v
Bus 001 Device 012: ID 4623:011a  

Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x4623 
  idProduct          0x011a 
  bcdDevice            0.01
  iManufacturer           1 
  iProduct                2 
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           73                                                                                             
    bNumInterfaces          2                                                                                             
    bConfigurationValue     1                                                                                             
    iConfiguration          0                                                                                             
    bmAttributes         0x80                                                                                             
      (Bus Powered)                                                                                                       
    MaxPower              150mA                                                                                           
    Interface Descriptor:                                                                                                 
      bLength                 9                                                                                           
      bDescriptorType         4                                                                                           
      bInterfaceNumber        0                                                                                           
      bAlternateSetting       0                                                                                           
      bNumEndpoints           2                                                                                           
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength     429
         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               8
      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
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              6 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode           33 US
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      91
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 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     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1

由于bInterfaceProtocol为None,Linux不会将其识别为鼠标输入设备。

从Windows对其进行反向工程以使其在Linux中工作的理想方法是什么。

Windows设备管理器中的设备:

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

编辑1:

abhishek@vaio:~/dev_work/whiteboard/pyusbwhiteboard$ usb-devices | grep -A5 'Vendor=4623 ProdID=011a' | grep Driver
I:  If#= 0 Alt= 0 #EPs= 2 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbfs
I:  If#= 1 Alt= 0 #EPs= 2 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid

dmesg输出:http : //codepad.org/fFtwryw6


“从Windows进行逆向工程的理想方法是什么”:您不需要对其进行逆向工程,驱动程序已经就位,并且将其称为“ usbhid”。该命令的输出是什么usb-devices | grep -A5 'Vendor=4623 ProdID=011a' | grep Driver?另外,尝试断开连接,然后再次连接设备,然后运行dmesg。说什么
Sam Protsenko '16

@SamProtsenko添加了,请检查。
Abhishek Bhatia'5

好了,驱动程序就位了,您只需要告诉Linux(用户空间部分)您的设备就是鼠标即可。我没有发现自己在这样的情况下,但如果我是你,我会尝试指定xorg.conf中(通过搜索InputClassMatchVendorMatchProduct关键字),或试图替代bInterfaceProtocolbInterfaceSubclass使用udev规则。
Sam Protsenko '16

根据您提供的dmesg输出,它似乎被识别为触摸屏,而不是鼠标(hid-multitouch加载驱动程序)?
2016年

@Janc你是正确的
Abhishek Bhatia

Answers:


1

我写了能够做到这一点的脚本。但是我必须弄清楚设备的输入是什么意思。

import sys,pdb
import usb.core
import usb.util
from pymouse import PyMouse

# whiteboard coordinates axis computed by checking the output against strokes
white_board_x_min=(1<<8)+1
white_board_x_max=(127<<8)+255
white_board_y_min=(1<<8)+1
white_board_y_max=(127<<8)+255

white_board_x_diff=white_board_x_max-white_board_x_min
white_board_y_diff=white_board_y_max-white_board_y_min

# mouse handler
m = PyMouse()
x_screen, y_screen = m.screen_size()

# decimal vendor and product values
dev = usb.core.find(idVendor=17955, idProduct=282)

# first endpoint
interface = 0
endpoint = dev[0][(0,0)][0]
# if the OS kernel already claimed the device, which is most likely true
# thanks to http://stackoverflow.com/questions/8218683/pyusb-cannot-set-configuration
if dev.is_kernel_driver_active(interface) is True:
    # tell the kernel to detach
    dev.detach_kernel_driver(interface)
    # claim the device
    usb.util.claim_interface(dev, interface)
mouse_down_event=False
try:    
    while True :
        try:
            data = dev.read(endpoint.bEndpointAddress,endpoint.wMaxPacketSize)
            # click value
            click=data[1] # if it is 7 mouse down else if it is 4 it is mouse up 
            # get the coordinates
            xcor,ycor,dec_x_binary,dec_y_binary=data[4],data[6],data[3],data[5]
            # convert to decimal
            xcor_dec=(xcor<<8)+dec_x_binary
            ycor_dec=(ycor<<8)+dec_y_binary
            # convert to relative screen coordinates
            screen_xcor=int(round((float(xcor_dec-white_board_x_min)/float(white_board_x_diff)) * x_screen))
            screen_ycor=int(round((float(ycor_dec-white_board_y_min)/float(white_board_y_diff)) * y_screen))
            #print "%d, %d"%(xcor_dec,ycor_dec)
            #print "%d, %d"%(screen_xcor,screen_ycor)
            # check if it is valid event
            if xcor_dec!=0 and ycor_dec!=0:
                # move mouse    
                if click==7:
                    # mean mouse down event
                    if mouse_down_event:
                        # drag event
                        # draw a line from previous coordinates
                        m.drag(screen_xcor, screen_ycor)
                    else:
                        # first button press event
                        m.click(screen_xcor, screen_ycor, 1)
                    mouse_down_event=True
                else:
                    # mouse up event
                    # set event type in mouse_down_event
                    # first button press and drag
                    mouse_down_event=False
        except usb.core.USBError as e:
            data = None
            if e.args == ('Operation timed out',):
                continue  
finally:
    # release the device
    usb.util.release_interface(dev, interface)
    # reattach the device to the OS kernel
    dev.attach_kernel_driver(interface)

https://github.com/abhigenie92/pyusbwhiteboard

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.