libhid is a cross-platform C++ library for interacting with USB Human Interface Devices. It provides both synchronous and asynchronous interfaces.
Here is a simple example that finds a device by its Product ID and Vendor ID, opens the device, and then sends a simple output report. More examples can be found here.
#include <hid.h>
HID::filter::And filters;
filters.push_back(new VendorID(VENDOR_ID));
filters.push_back(new ProductID(PRODUCT_ID));
HID::device_list devices = HID::find(&filters);
if( devices.size() )
{
HID::device_type* device = devices.front();
device.open(HID::WriteMode);
HID::buffer_type buffer;
device.output(REPORT_ID, buffer);
}
For git users, the easiest option is to include libhid as a submodule in your project. If you're using qmake you can use the included libhid.pri. Otherwise you'll need to add the appropriate files to whatever build mechanism you're using.
To use libhid as a submodule in your project's git repository:
Then follow the instructions below for linking the library into your project.git add submodule git://github.com/bfoz/libhid /your_project/lib/hid
Download the source and extract it into a subdirectory of your project, then follow the linking instructions below.
libhid is small and light enough to be statically linked into your applications. Support for building a shared library isn't currently planned, but there's no reason it can't be done.
At the moment, qmake is the only build mechanism directly supported in the source. Other mechanisms will be supported eventually.
Simply include libhid.pri in your project's .pro file. qmake will take care of the rest.
You can download this project in either zip or tar formats.
You can also clone the project with Git by running:
$ git clone git://github.com/bfoz/libhid