IR HID USB Remote

From ArmadeusWiki
Jump to: navigation, search

This page explain how to use Infrared USB HID Remote on APF board. Some (but not all) are supported by the Linux kernel.


Driver installation

We have to know the model of your USB device under Linux. Connect it on a PC with Linux running, open a console and type:

 $ dmesg

You should obtain something like that :

[ 8893.213869] generic-usb 0003:062A:0000.0005: input,hidraw0: USB HID v1.10 Mouse [HID 062a:0000] on usb-0000:00:1d.0-2/input0
[ 9739.616076] usb 3-2: new low speed USB device using uhci_hcd and address 5
[ 9739.942974] zydacron 0003:13EC:0006.0006: fixing up zydacron remote control report descriptor
[ 9739.978243] input: HID 13ec:0006 as /devices/pci0000:00/0000:00:1d.1/usb3/3-2/3-2:1.0/input/input16
[ 9739.979060] zydacron 0003:13EC:0006.0006: input,hiddev0,hidraw1: USB HID v1.10 Keyboard [HID 13ec:0006] on usb-0000:00:1d.1-2/input0

The last line give the model and the identifier of the product : "Zydacron" If you don't see anything about the model of your HID device, copy/paste the identifier in google. The identifier must be something like that : 13ec:0006 It always be composed of 4 characters, ":", and 4 characters again.

Then, configure your Linux configuration in your armadeus directory

 $ make linux-menuconfig
  Device Drivers  --->
    [*] HID Devices  --->
      Special HID drivers  --->

And then, search your driver (Zydacron in our case).

  <M> Zydacron remote control support 

Reflash kernel and rootfs.

Load the driver

You must know the module name of the driver. For Zydacron it is "hid_zydacron".

If you don't know the name of your Linux driver:

  # ls /lib/modules/$(uname -r)/kernel/drivers/hid/
Note Note: $(uname -r) will be replaced with your kernel version.


You should see some or one file(s) with the ".ko" extension, like your_hid_driver.ko (hid_zydacron.ko in our case).

then :

  #modprobe your_hid_driver

in our case:

  # modprobe hid_zydacron

Usage

Plug the usb receiver of your remote on APF board and type

  # modprobe dmsg

If you read the model name of your device and something like "eventX" where X is the event number, the Linux input is ready.

Check if the event is correctly set in the input directory:

  # ls /dev/input/

You should read the event of your device.

Check if the communication is set (replace X by your event number, usualy 0 if no hid device other than your remote has been plugged)

  # od -x /dev/input/eventX

Push a button on your remote. You should see some incomprehensible characters on the screen, don't worry it sounds good!

Application example

The USB HID remote device is configured in Linux like a keyboard.

Here a little example of application in langage C :

#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

/* Replace X by the number of your event */
char input[] = "/dev/input/eventX";

int main(void)
{
    int fd;
    struct input_event remote_event;
    fd = open(input, O_RDONLY); /* Open the event file */

    if(fd == -1) {
        printf("Can not open the input device!\n");
        return 1;
    }
    else {
        while (1) {
            read(fd, &remote_event, sizeof(struct input_event)); /* read the last event */
            if(remote_event.type == EV_KEY && remote_event.value == 1) { /* Check if a key was pressed */
                if(remote_event.code==103) { /* Compare with key up code */
                    printf("Key up was pressed\n");
                }
                else if(remote_event.code==108) { /* Compare with key down code */
                    printf("Key down was pressed\n");
                }
		/* ... */
                else {
                   printf("Unknown button with code %d was pressed\n", remote_event.code); /* Print code */
                }
            }
        }
    }

    return 0;
}

Links

Getting started with uinput [1]

A little example of code in C [2]