forked from bfoz/libhid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
61 lines (41 loc) · 1.91 KB
/
README
File metadata and controls
61 lines (41 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Introduction
============
libhid is a cross-platform C++ library for interacting with [USB Human Interface Devices](http://en.wikipedia.org/wiki/USB_human_interface_device_class).
Installation
============
git submodule
-------------
To use libhid as a submodule in your project's git repository:
git add submodule git://github.com/bfoz/libhid.git *path*
where *path* is the path to put the submodule (relative to your repository root). Then follow the instructions below for linking the library into your project.
Linking
=======
Qt / qmake
----------
Simply include libhid.pri in your project's .pro file. qmake will take care of the rest.
Example
=======
Here is a simple example that finds a device by it's Product ID and Vendor ID, opens the device, and then sends a simple output report.
#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();
HID::buffer_type buffer;
device.output(REPORT_ID, buffer);
}
Devices can also be found using an enumerator object. The enumerator generates notifications whenever a device is added or removed and matches an optional filter (the same filter objects used by find() ). Here's a quick example…
#include <hid.h>
// Called when a device is added that matches the enumerator's filter
void matched(HID::enumerator_type* enumerator, HID::device_type* device, void* context)
{}
// Called when a matching device is removed
void removed(HID::enumerator_type* enumerator, HID::device_type* device, void* context)
{}
// Create a USB HID enumerator to watch for device events and dispatch them accordingly
HID::enumerator_type* enumerator = HID::enumerator();
enumerator->setMatchCallback(matched, &my_context);
enumerator->setRemovalCallback(removed, &my_context);