2

ASUS PSR 2000 Web Surfing RemoteControlに付属のeDIOUSBマルチリモコン(赤外線リモコン)を持っています。

Remote COntrollerをpiに接続して、リモートから送信されたキーストロークを受信できるようにしようとしています。

コントローラはHIDデバイスとして検出されます。lsusb-vコマンドの詳細は次のとおりです

Bus 001 Device 007: ID 147a:e001 Formosa Industrial Computing, Inc.
Couldn't open device, some information will be missing
Device Descriptor:
bLength                18
bDescriptorType         1
bcdUSB               1.10
bDeviceClass            0 (Defined at Interface level)
bDeviceSubClass         0
bDeviceProtocol         0
bMaxPacketSize0         8
idVendor           0x147a Formosa Industrial Computing, Inc.
idProduct          0xe001
bcdDevice            1.22
iManufacturer           1
iProduct                2
iSerial                 0
bNumConfigurations      1
Configuration Descriptor:
bLength                 9
bDescriptorType         2
wTotalLength           34
bNumInterfaces          1
bConfigurationValue     1
iConfiguration          4
bmAttributes         0xa0
(Bus Powered)
Remote Wakeup
MaxPower              300mA
Interface Descriptor:
bLength                 9
bDescriptorType         4
bInterfaceNumber        0
bAlternateSetting       0
bNumEndpoints           1
bInterfaceClass         3 Human Interface Device
bInterfaceSubClass      1 Boot Interface Subclass
bInterfaceProtocol      2 Mouse
iInterface              0
HID Device Descriptor:
bLength                 9
bDescriptorType        33
bcdHID               1.10
bCountryCode            0 Not supported
bNumDescriptors         1
bDescriptorType        34 Report
wDescriptorLength      20
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     0x0004  1x 4 bytes
bInterval              10

イベントが作成されたdevフォルダー内のデバイスも使用できます

pi@raspberrypi /dev/input/by-id $ dir
usb-Cypress_Semiconductor_eDio_USB_Multi_Remote_Controlle-event-if00

次のコマンドからわかるように、それに関連付けられているイベントハンドラーは次のとおりです。

    pi@raspberrypi /proc/bus/input $ cat devices
    I: Bus=0003 Vendor=147a Product=e001 Version=0110
    N: Name="Cypress Semiconductor eDio USB Multi Remote Controlle"
    P: Phys=usb-bcm2708_usb-1.2/input0
    S: Sysfs=/devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2:1.0/input/input2
    U: Uniq=
    H: Handlers=event0
    B: PROP=0
    B: EV=1

問題は、デバイス用に作成されたイベントハンドラーからの出力を読み取ろうとしたときです。最初のキーストロークは登録されますが、後続のキーストロークはCATコマンドによって表示されません。

   pi@raspberrypi /dev/input $ cat event0 | xxd
   0000000: e007 9450 9476 0900 0000 0000 0000 0000  ...P.v..........

デバイスを機能させるために何ができるか教えてください。最初のキーストロークの後にキーを押しても、デバイスを再接続しない限り何も返されません。

問題を解決するために何をする必要があるかを提案してください。

4

2 に答える 2

2

最終的に何をしたいかによっては、HID リモートのボタンをキーストロークにマッピングするだけで十分な場合があり、QJoyPadなどのツールを使用するとかなり簡単に実現できます。

これを Raspberry Pi でビルドするのは難しいようです。そのため、代わりに、リポジトリで入手できるjoy2keyを試してみることをお勧めしますsudo apt-get install joy2key

于 2013-02-13T22:34:52.263 に答える
1

最後に、Libusb のラッパーである PyUSB ライブラリを使用して、独自の実装を作成する時間ができました。

ここにコードを投稿しています。誰かを助けるかもしれません。

ここで使用される構成ファイルを作成する別のコードがあります。すべてのリモート キーは必要ないため、すべてのリモート キーをマップしていません。

import usb.core
import usb.util
import ConfigParser
import shlex
import subprocess
import logging

# find our device
diction={
  6402315641282315:'1',
  6402415641282415:'2',
  6402515641282515:'3',
  6402615641282615:'4',
  6402715641282715:'5',
  6402815641282815:'6',
  6402915641282915:'7',
  6403015641283015:'8',
  6403115641283115:'9',
  }



def load_config():
    dict={}
    config = ConfigParser.RawConfigParser()
    config.read('/codes/remote/remote.cfg')

    dict['vendor']=config.getint('Settings','idVendor')

    dict['product']=config.getint('Settings','idProduct')

    dict['interface']=config.getint('Settings', 'interface')

    r=config.options('Key Mappings')

    for item in r:
        if config.get('Key Mappings',item)!='': 
            dict[item]=config.get('Key Mappings',item)
            #print config.get('Key Mappings',item)
    return dict

def pyus():

    try:
        load_log()
        dict=load_config()
        join_int = lambda nums: int(''.join(str(i) for i in nums))
        #print dict

        dev = usb.core.find(idVendor=dict['vendor'], idProduct=dict['product'])
        interface=dict['interface']

        if dev is None:
            raise ValueError('Device not found')

        if dev.is_kernel_driver_active(interface) is True:
                #print "but we need to detach kernel driver"
                dev.detach_kernel_driver(interface)
        #dev.detatch_kernel_driver(interface) 
        # set the active configuration. With no arguments, the first
        # configuration will be the active one
        dev.set_configuration()

        # get an endpoint instance
        cfg = dev.get_active_configuration()
        interface_number = cfg[(0,0)].bInterfaceNumber
        alternate_setting = usb.control.get_interface(dev,interface_number)
        intf = usb.util.find_descriptor(
            cfg, bInterfaceNumber = interface_number,
            bAlternateSetting = alternate_setting
        )

        ep = usb.util.find_descriptor(
            intf,
            # match the first IN endpoint
            custom_match = \
            lambda e: \
                usb.util.endpoint_direction(e.bEndpointAddress) == \
                usb.util.ENDPOINT_IN
        )

        assert ep is not None
        #print 'packet details',ep.bEndpointAddress , ep.wMaxPacketSize

        while 1:
            try:
                data = dev.read(ep.bEndpointAddress, ep.wMaxPacketSize*2,interface,1000)
                data=data.tolist()
                key=join_int(data)
                #print "Key is " , key
                if  key in diction:

                    try:
                        args=shlex.split(dict[diction[key]])
                        #print args
                        p=subprocess.Popen(args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
                        #print "Pressed key is ",diction[key]
                    except:
                        pass


            except usb.core.USBError as e:
                pass
    except:
        pass

pyus()






#____________________________REPORT DESCRIPTOR EXAMPLE___________________
# Bus 001 Device 007: ID 147a:e001 Formosa Industrial Computing, Inc.
    # Couldn't open device, some information will be missing
    # Device Descriptor:
    # bLength                18
    # bDescriptorType         1
    # bcdUSB               1.10
    # bDeviceClass            0 (Defined at Interface level)
   # bDeviceSubClass         0
   # bDeviceProtocol         0
   # bMaxPacketSize0         8
   # idVendor           0x147a Formosa Industrial Computing, Inc.
   # idProduct          0xe001
   # bcdDevice            1.22
   # iManufacturer           1
   # iProduct                2
   # iSerial                 0
   # bNumConfigurations      1
  # Configuration Descriptor:
  # bLength                 9
  # bDescriptorType         2
# wTotalLength           34
# bNumInterfaces          1
# bConfigurationValue     1
# iConfiguration          4
# bmAttributes         0xa0
  # (Bus Powered)
  # Remote Wakeup
# MaxPower              300mA
# Interface Descriptor:
  # bLength                 9
  # bDescriptorType         4
  # bInterfaceNumber        0
  # bAlternateSetting       0
  # bNumEndpoints           1
  # bInterfaceClass         3 Human Interface Device
  # bInterfaceSubClass      1 Boot Interface Subclass
  # bInterfaceProtocol      2 Mouse
  # iInterface              0
    # HID Device Descriptor:
      # bLength                 9
      # bDescriptorType        33
      # bcdHID               1.10
      # bCountryCode            0 Not supported
      # bNumDescriptors         1
      # bDescriptorType        34 Report
      # wDescriptorLength      20
     # 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     0x0004  1x 4 bytes
    # bInterval              10
于 2013-03-18T18:36:50.857 に答える