#include <iostream>
#include <hidapi/hidapi.h>
class HIDException {
private:
std::wstring message;
public:
HIDException(std::wstring message) : message(message) {
}
virtual ~HIDException() {
}
const std::wstring getMessage() const {
return message;
}
};
class HIDDevice {
private:
hid_device* handle;
public:
HIDDevice(unsigned short vendorId, unsigned short productId, const wchar_t *serialNumber) {
handle = hid_open(vendorId, productId, serialNumber);
if (handle == nullptr) throw HIDException(L"Unable to open HID device. Are you root? Is mouse present?");
}
virtual ~HIDDevice() {
hid_close(handle);
}
};
int main(int argc, char** argv) {
try {
std::wcout << L"cadMousePro" << std::endl;
HIDDevice mouse(0x256f, 0xc652, nullptr);
std::wcout << L"mouse opened" << std::endl;
} catch (const HIDException& e) {
std::wcout << L"HIDException: " << e.getMessage() << std::endl;
}
}