receive keystrokes from a usb keyboard



  • hi can i use the usb port to attach a keyboard or someting that outputs like a keyboard like a barcode scanner ?


  • administrators

    @Antonio-Ramos I've built in the necessary kernel modules to support Human Interface Devices (HID) over USB.
    Run oupgrade -force to grab build 216 that has all of the required updates.
    If anyone is interested, the modules added were:

    • kmod-hid
    • kmod-usb-hid
    • kmod-input-evdev

    Some instructions on using a HID with the Omega:

    Once the device is plugged in, dmesg will show something along these lines:

    [  923.700000] usb 1-1.4: new low-speed USB device number 9 using ehci-platform
    [  923.830000] input: BTC USB Multimedia Keyboard as /devices/platform/ehci-platform/usb1/1-1/1-1.4/1-1.4:1.0/0003:046D:C313.0008/input/input4
    [  923.840000] hid-generic 0003:046D:C313.0008: input,hidraw1: USB HID v1.10 Keyboard [BTC USB Multimedia Keyboard] on usb-ehci-platform-1.4/input0
    [  923.920000] input: BTC USB Multimedia Keyboard as /devices/platform/ehci-platform/usb1/1-1/1-1.4/1-1.4:1.1/0003:046D:C313.0009/input/input5
    [  923.930000] hid-generic 0003:046D:C313.0009: input,hiddev0,hidraw2: USB HID v1.10 Device [BTC USB Multimedia Keyboard] on usb-ehci-platform-1.4/input1
    

    You can then run lsusb to see more info on your device:

    root@Omega-0100:/# lsusb
    Bus 001 Device 002: ID 0835:8500
    Bus 001 Device 001: ID 1d6b:0002
    Bus 001 Device 003: ID 0835:8501
    Bus 001 Device 009: ID 046d:c313
    Bus 001 Device 005: ID 0835:8500
    Bus 001 Device 006: ID 0835:8502
    

    My keyboard was mapped to device 9 (I'm using a powered USB hub), so the Device 009 ID matches the identifier for Logitech keyboards.

    Take a look at /proc/bus/input/devices for more info on the keyboard you've plugged in:

    root@Omega-0100:/# cat /proc/bus/input/devices 
    I: Bus=0003 Vendor=046d Product=c313 Version=0110
    N: Name="BTC USB Multimedia Keyboard"
    P: Phys=usb-ehci-platform-1.4/input0
    S: Sysfs=/devices/platform/ehci-platform/usb1/1-1/1-1.4/1-1.4:1.0/0003:046D:C313.0008/input/input4
    U: Uniq=
    H: Handlers=event0 
    B: PROP=0
    B: EV=120013
    B: KEY=10000 7 ff9f207a c14057ff febeffdf ffefffff ffffffff fffffffe
    B: MSC=10
    B: LED=7
    
    I: Bus=0003 Vendor=046d Product=c313 Version=0110
    N: Name="BTC USB Multimedia Keyboard"
    P: Phys=usb-ehci-platform-1.4/input1
    S: Sysfs=/devices/platform/ehci-platform/usb1/1-1/1-1.4/1-1.4:1.1/0003:046D:C313.0009/input/input5
    U: Uniq=
    H: Handlers=event1 
    B: PROP=0
    B: EV=13
    B: KEY=2000000 387a d801d6a1 1e0000 0 0 0
    B: MSC=10
    

    Since this is an input device, it will get mapped to /dev/input:

    root@Omega-0100:/# ls /dev/input/
    event0  event1
    

    To read data from the keyboard, run cat /dev/input/event0 | hexdump
    Each key press generates a lot of data:

    root@Omega-0100:/# cat /dev/input/event0 | hexdump
    0000000 5642 5f73 0000 b58c 0004 0004 0007 0012
    0000010 5642 5f73 0000 b58c 0001 0018 0000 0001
    0000020 5642 5f73 0000 b58c 0000 0000 0000 0000
    0000030 5642 5f73 0001 ee07 0004 0004 0007 0012
    0000040 5642 5f73 0001 ee07 0001 0018 0000 0000
    0000050 5642 5f73 0001 ee07 0000 0000 0000 0000
    0000060 5642 5f76 000b 3627 0004 0004 0007 0010
    0000070 5642 5f76 000b 3627 0001 0032 0000 0001
    0000080 5642 5f76 000b 3627 0000 0000 0000 0000
    0000090 5642 5f76 000c 4f6d 0004 0004 0007 0010
    00000a0 5642 5f76 000c 4f6d 0001 0032 0000 0000
    00000b0 5642 5f76 000c 4f6d 0000 0000 0000 0000
    

    You'll have to look up how to decode this data. Let us know when you figure it out!
    I don't have a barcode scanner to test, but I imagine that it will work the same way.

    Happy hacking!


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.