7 #include "/home/mj/linux/linux-2.6.27.4/include/linux/hiddev.h"
9 static void die(char *x)
11 fprintf(stderr, "hidtest: %s: %m\n", x);
18 int fd = open("/dev/.static/dev/usb/hiddev5", O_RDWR);
19 if (fd < 0) die("open");
22 if (ioctl(fd, HIDIOCGVERSION, &ver) < 0)
24 printf("hiddev version %x\n", ver);
26 struct hiddev_devinfo di;
27 if (ioctl(fd, HIDIOCGDEVINFO, &di) < 0)
29 printf("%d:%d:%d vendor %04x, product %04x, version %04x, num_appl %d\n",
30 di.busnum, di.devnum, di.ifnum, di.vendor, di.product, di.version, di.num_applications);
33 for (i=0; i<100; i++) {
34 struct hiddev_string_descriptor ss;
36 if (ioctl(fd, HIDIOCGSTRING, &ss) < 0)
37 printf("S%d: ???\n", i);
39 printf("S%d: %s\n", i, ss.value);
43 for (i=0; i<di.num_applications; i++) {
44 int appl = ioctl(fd, HIDIOCAPPLICATION, i);
45 if (appl < 0) die("application");
46 printf("Appl %d: %x\n", i, appl);
49 //ioctl(fd, HIDIOCINITREPORT, 0);
51 struct hiddev_report_info rinfo;
52 struct hiddev_field_info finfo;
53 struct hiddev_usage_ref uref;
54 rinfo.report_type = HID_REPORT_TYPE_INPUT;
55 rinfo.report_id = HID_REPORT_ID_FIRST;
56 int ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
58 printf("rinfo: type=%d, id=%d, fields=%d\n", rinfo.report_type, rinfo.report_id, rinfo.num_fields);
59 for (i = 0; i < rinfo.num_fields; i++) {
60 finfo.report_type = rinfo.report_type;
61 finfo.report_id = rinfo.report_id;
62 finfo.field_index = i;
63 ioctl(fd, HIDIOCGFIELDINFO, &finfo);
64 printf("\tField %d:\n", i);
65 printf("\t\tflags: %04x, phys: %d, log: %d, appl: %x, log=<%d,%d>, phys=<%d,%d>, unit=%d E%d\n",
66 finfo.flags, finfo.physical, finfo.logical, finfo.application,
67 finfo.logical_minimum, finfo.logical_maximum,
68 finfo.physical_minimum, finfo.physical_maximum,
69 finfo.unit, finfo.unit_exponent);
70 for (j = 0; j < finfo.maxusage; j++) {
71 uref.report_type = finfo.report_type;
72 uref.report_id = finfo.report_id;
75 ioctl(fd, HIDIOCGUCODE, &uref);
76 ioctl(fd, HIDIOCGUSAGE, &uref);
77 printf("\t\tUsage %d: code=%x, value=%d\n", j, uref.usage_code, uref.value);
80 rinfo.report_id |= HID_REPORT_ID_NEXT; /* FIXME: bug in hiddev.h, beware */
81 ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
84 int f = HIDDEV_FLAG_UREF;
85 if (ioctl(fd, HIDIOCSFLAG, &f) < 0) die("sflag");
86 struct hiddev_usage_ref ev;
87 while (read(fd, &ev, sizeof(ev))) {
88 printf("EV: %x = %d\n", ev.usage_code, ev.value);