# HG changeset patch # User František Kučera # Date 1565800355 -7200 # Node ID 29cbe171cd439781a9ecc520d6d433cb9a127b50 # Parent 6ff501639c23ae23366bafd53dcc0e102accb851 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature diff -r 6ff501639c23 -r 29cbe171cd43 src/cadMousePro.cpp --- a/src/cadMousePro.cpp Wed Aug 14 16:16:58 2019 +0200 +++ b/src/cadMousePro.cpp Wed Aug 14 18:32:35 2019 +0200 @@ -1,4 +1,6 @@ #include +#include +#include #include @@ -12,7 +14,7 @@ virtual ~HIDException() { } - + const std::wstring getMessage() const { return message; } @@ -25,14 +27,42 @@ public: HIDDevice(unsigned short vendorId, unsigned short productId, const wchar_t *serialNumber) { + int initError = hid_init(); // TODO: move to HIDContext class? + if (initError) throw HIDException(L"Unable to init HID API."); 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); + hid_exit(); // TODO: move to HIDContext class? + } + + const std::wstring getManufacturerName() const { + std::array buffer; + int error = hid_get_manufacturer_string(handle, buffer.data(), buffer.size()); + if (error) throw HIDException(L"Unable to get manufacturer name."); + return buffer.data(); } + const std::wstring getProductName() const { + std::array buffer; + int error = hid_get_product_string(handle, buffer.data(), buffer.size()); + if (error) throw HIDException(L"Unable to get product name."); + return buffer.data(); + } + + const std::wstring getSerialNumber() const { + std::array buffer; + int error = hid_get_serial_number_string(handle, buffer.data(), buffer.size()); + if (error) throw HIDException(L"Unable to get serial number."); + return buffer.data(); + } + + void sendFeatureReport(std::vector data) { + int written = hid_send_feature_report(handle, data.data(), data.size()); + if (written < 0) throw HIDException(L"Unable to send feature report."); + } }; @@ -42,8 +72,22 @@ std::wcout << L"cadMousePro" << std::endl; HIDDevice mouse(0x256f, 0xc652, nullptr); std::wcout << L"mouse opened" << std::endl; + std::wcout << L"manufacturer: " << mouse.getManufacturerName() << std::endl; + std::wcout << L"product: " << mouse.getProductName() << std::endl; + // std::wcout << L"serial number: " << mouse.getSerialNumber() << std::endl; // throws exception + + std::vector enableFreeWheel{0x10, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0a, 0x0b, 0x0c, 0x0c, 0x0e, 0x0d, 0x2f, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01}; + std::vector disableFreeWheel{0x10, 0x00, 0x1c, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0a, 0x0b, 0x0c, 0x0c, 0x0e, 0x0d, 0x2f, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01}; + // mouse.sendFeatureReport(enableFreeWheel); + mouse.sendFeatureReport(disableFreeWheel); + + // TODO: enable acceleration + // TODO: enable lift-off detection + // TODO: sensof polling rate – frequency + // TODO: wheel scrolling size – lines, page + } catch (const HIDException& e) { std::wcout << L"HIDException: " << e.getMessage() << std::endl; - + } } \ No newline at end of file