Hardware Reference
In-Depth Information
An example populating these structures is provided next. If you plan to inject
EV_ABS
events, you must also populate the
abs
members, mentioned in the “Configure
EV_ABS
” section.
struct uinput_user_dev uinp;
int rc;
memset(&uinp,0,sizeof uinp);
strncpy(uinp.name,"nunchuk",UINPUT_MAX_NAME_SIZE);
uinp.id.bustype = BUS_USB;
uinp.id.vendor = 0x1;
uinp.id.product = 0x1;
uinp.id.version = 1;
// uinp.absmax[ABS_X] = 1023; /
EV_ABS only
/
∗
∗
// ...
rc = write(fd,&uinp,sizeof(uinp));
assert(rc == sizeof(uinp));
The call to
write(2)
passes all of this important information to the
uinput
driver.
Now all that remains is to request a device node to be created for application use:
int rc;
rc = ioctl(fd,UI_DEV_CREATE);
assert(!rc);
This step causes the
uinput
driver to make a device node appear in the pseudo
directory
/dev/input
. An example is shown here:
$ ls -l /dev/input
total 0
drwxr−xr−x 2 root root 120 Dec 31 1969 by−id
drwxr−xr−x 2 root root 120 Dec 31 1969 by−path
crw−rw−−−T 1 root input 13, 64 Dec 31 1969 event0
crw−rw−−−T 1 root input 13, 65 Dec 31 1969 event1
crw−rw−−−T 1 root input 13, 66 Dec 31 1969 event2
crw−rw−−−T 1 root input 13, 67 Feb 23 13:40 event3
crw−rw−−−T 1 root input 13, 63 Dec 31 1969 mice
crw−rw−−−T 1 root input 13, 32 Dec 31 1969 mouse0
crw−rw−−−T 1 root input 13, 33 Feb 23 13:40 mouse1
The device
/dev/input/event3
was the Nunchuck's created
uinput
node, when the
program was run.