Main index | Section 3 | Options |
#include <usbhid.h>
The routines can be divided into four parts: extraction of the descriptor, parsing of the descriptor, translating to/from symbolic names, and data manipulation.
hid_get_report() and hid_set_report() functions allow to synchronously get and set specific report if device supports it. For devices with multiple report IDs, wanted ID should be provided in the first byte of the buffer for both get and set.
To iterate through all the items in the report descriptor hid_get_item() should be called while it returns a value greater than 0. When the report descriptor ends it will returns 0; a syntax error within the report descriptor will cause a return value less than 0. The struct pointed to by h will be filled with the relevant data for the item. The definition of hid_item_t can be found in <usbhid.h> and the meaning of the components in the USB HID documentation.
Data should be read/written to the device in the size of the report. The size of a report (of a certain kind) can be computed by the hid_report_size() function. If the report is prefixed by an ID byte it is given by id.
To locate a single item the hid_locate() function can be used. It should be given the usage code of the item and its kind and it will fill the item and return non-zero if the item was found.
The functions hid_parse_usage_page() and hid_parse_usage_in_page() are the inverses of hid_usage_page() and hid_usage_in_page(). They take a usage string and return the number of the usage, or -1 if it cannot be found.
Before any of these functions can be called the usage table must be parsed, this is done by calling hid_init() with the name of the table. Passing NULL to this function will cause it to use the default table.
/usr/share/misc/usb_hid_usages | |
The default HID usage table. | |
USBHID (3) | January 27, 2009 |
Main index | Section 3 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | Some people open all the windows; wise wives welcome spring by moving the UNIX. | ” |