equal
deleted
inserted
replaced
|
1 #include <iostream> |
|
2 |
|
3 #include <hidapi/hidapi.h> |
|
4 |
|
5 class HIDException { |
|
6 private: |
|
7 std::wstring message; |
|
8 public: |
|
9 |
|
10 HIDException(std::wstring message) : message(message) { |
|
11 } |
|
12 |
|
13 virtual ~HIDException() { |
|
14 } |
|
15 |
|
16 const std::wstring getMessage() const { |
|
17 return message; |
|
18 } |
|
19 |
|
20 }; |
|
21 |
|
22 class HIDDevice { |
|
23 private: |
|
24 hid_device* handle; |
|
25 public: |
|
26 |
|
27 HIDDevice(unsigned short vendorId, unsigned short productId, const wchar_t *serialNumber) { |
|
28 handle = hid_open(vendorId, productId, serialNumber); |
|
29 if (handle == nullptr) throw HIDException(L"Unable to open HID device. Are you root? Is mouse present?"); |
|
30 } |
|
31 |
|
32 virtual ~HIDDevice() { |
|
33 hid_close(handle); |
|
34 } |
|
35 |
|
36 |
|
37 }; |
|
38 |
|
39 int main(int argc, char** argv) { |
|
40 try { |
|
41 |
|
42 std::wcout << L"cadMousePro" << std::endl; |
|
43 HIDDevice mouse(0x256f, 0xc652, nullptr); |
|
44 std::wcout << L"mouse opened" << std::endl; |
|
45 } catch (const HIDException& e) { |
|
46 std::wcout << L"HIDException: " << e.getMessage() << std::endl; |
|
47 |
|
48 } |
|
49 } |