src/cadMousePro.cpp
author František Kučera <franta-hg@frantovo.cz>
Sun, 18 Aug 2019 23:00:21 +0200
branchv_0
changeset 4 405aa9de65d2
parent 3 1197b42e8b2e
child 5 6799cec5c2f8
permissions -rw-r--r--
CadMouseConfig class, frequency, lift-off detection, smart scrolling
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
#include <iostream>
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
     2
#include <array>
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
     3
#include <vector>
4
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     4
#include <memory>
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     5
#include <unistd.h>
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     6
#include <cassert>
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     7
#include <type_traits>
0
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
#include <hidapi/hidapi.h>
4
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    10
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    11
using Packet = std::vector<uint8_t>;
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    12
static_assert(sizeof (uint8_t) == sizeof (unsigned char)); // unsigned char is used in the HID API library
0
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
class HIDException {
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
private:
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
	std::wstring message;
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
public:
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	HIDException(std::wstring message) : message(message) {
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
	}
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
	virtual ~HIDException() {
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
	}
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    24
0
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
	const std::wstring getMessage() const {
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
		return message;
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
	}
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
};
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
class HIDDevice {
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
private:
3
1197b42e8b2e use a smart pointer with custom deleter inside HIDDevice, so instances can be copied
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    33
	std::shared_ptr<hid_device> handle;
2
abeba77ec581 private copy constructor (to avoid unwanted close() in copie's destructor)
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    34
0
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
public:
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	HIDDevice(unsigned short vendorId, unsigned short productId, const wchar_t *serialNumber) {
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    38
		int initError = hid_init(); // TODO: move to HIDContext class?
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    39
		if (initError) throw HIDException(L"Unable to init HID API.");
3
1197b42e8b2e use a smart pointer with custom deleter inside HIDDevice, so instances can be copied
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    40
		handle.reset(hid_open(vendorId, productId, serialNumber), hid_close);
0
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		if (handle == nullptr) throw HIDException(L"Unable to open HID device. Are you root? Is mouse present?");
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	}
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	virtual ~HIDDevice() {
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    45
		hid_exit(); // TODO: move to HIDContext class?
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    46
	}
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    47
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    48
	const std::wstring getManufacturerName() const {
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    49
		std::array<wchar_t, 200 > buffer;
3
1197b42e8b2e use a smart pointer with custom deleter inside HIDDevice, so instances can be copied
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    50
		int error = hid_get_manufacturer_string(handle.get(), buffer.data(), buffer.size());
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    51
		if (error) throw HIDException(L"Unable to get manufacturer name.");
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    52
		return buffer.data();
0
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	}
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    55
	const std::wstring getProductName() const {
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    56
		std::array<wchar_t, 200 > buffer;
3
1197b42e8b2e use a smart pointer with custom deleter inside HIDDevice, so instances can be copied
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    57
		int error = hid_get_product_string(handle.get(), buffer.data(), buffer.size());
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    58
		if (error) throw HIDException(L"Unable to get product name.");
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    59
		return buffer.data();
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    60
	}
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    61
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    62
	const std::wstring getSerialNumber() const {
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    63
		std::array<wchar_t, 200 > buffer;
3
1197b42e8b2e use a smart pointer with custom deleter inside HIDDevice, so instances can be copied
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    64
		int error = hid_get_serial_number_string(handle.get(), buffer.data(), buffer.size());
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    65
		if (error) throw HIDException(L"Unable to get serial number.");
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    66
		return buffer.data();
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    67
	}
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    68
4
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    69
	void sendFeatureReport(Packet data) {
3
1197b42e8b2e use a smart pointer with custom deleter inside HIDDevice, so instances can be copied
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    70
		int written = hid_send_feature_report(handle.get(), data.data(), data.size());
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    71
		if (written < 0) throw HIDException(L"Unable to send feature report.");
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    72
	}
0
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
};
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
4
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    76
enum class Frequency : uint8_t {
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    77
	Hz_0125 = 8,
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    78
	Hz_0250 = 4,
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    79
	Hz_0500 = 2,
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    80
	Hz_1000 = 1
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    81
};
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    82
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    83
using FrequencyType = std::underlying_type<Frequency>::type;
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    84
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    85
class CadMouseConfig {
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    86
private:
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    87
	bool liftOffDetection = true;
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    88
	bool smartScrolling = false;
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    89
	Frequency frequency = Frequency::Hz_1000;
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    90
public:
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    91
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    92
	void setFrequency(Frequency frequency) {
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    93
		this->frequency = frequency;
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    94
	}
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    95
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    96
	void setLiftOffDetection(bool liftOffDetection) {
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    97
		this->liftOffDetection = liftOffDetection;
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    98
	}
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    99
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   100
	void setSmartScrolling(bool smartScrolling) {
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   101
		this->smartScrolling = smartScrolling;
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   102
	}
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   103
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   104
	Packet serialize() {
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   105
		Packet data;
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   106
		data.reserve(32);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   107
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   108
		data.push_back(0x10); // report ID
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   109
		data.push_back(0x00); // option
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   110
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   111
		data.push_back(0x1c); // speed
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   112
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   113
		data.push_back(liftOffDetection ? 0x00 : 0x1f);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   114
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   115
		if (smartScrolling) {
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   116
			data.push_back(0x00);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   117
			data.push_back(0x00);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   118
			data.push_back(0x00);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   119
			data.push_back(0x01);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   120
		} else {
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   121
			data.push_back(0x01);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   122
			data.push_back(0xff);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   123
			data.push_back(0x00);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   124
			data.push_back(0x00);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   125
		}
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   126
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   127
		for (int i = 0; i < 8; i++) data.push_back(0x00); // constant padding or magic
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   128
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   129
		// magic constants or unknown fields
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   130
		data.push_back(0x00);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   131
		data.push_back(0x03);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   132
		data.push_back(0x00);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   133
		data.push_back(0x0a);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   134
		data.push_back(0x0b);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   135
		data.push_back(0x0c);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   136
		data.push_back(0x0c);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   137
		data.push_back(0x0e);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   138
		data.push_back(0x0d);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   139
		data.push_back(0x2f);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   140
		data.push_back(0x00);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   141
		data.push_back(0x1e);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   142
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   143
		data.push_back(0x00);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   144
		data.push_back(0x00);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   145
		data.push_back(0x00);
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   146
		data.push_back(static_cast<FrequencyType> (frequency));
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   147
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   148
		return data;
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   149
	}
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   150
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   151
};
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   152
0
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   153
int main(int argc, char** argv) {
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   154
	try {
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   155
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   156
		std::wcout << L"cadMousePro" << std::endl;
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   157
		HIDDevice mouse(0x256f, 0xc652, nullptr);
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   158
		std::wcout << L"mouse opened" << std::endl;
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   159
		std::wcout << L"manufacturer:  " << mouse.getManufacturerName() << std::endl;
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   160
		std::wcout << L"product:       " << mouse.getProductName() << std::endl;
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   161
		// std::wcout << L"serial number: " << mouse.getSerialNumber() << std::endl; // throws exception
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   162
4
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   163
		CadMouseConfig config;
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   164
4
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   165
		mouse.sendFeatureReport(config.serialize());
1
29cbe171cd43 first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   166
4
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   167
		return 0;
0
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   168
	} catch (const HIDException& e) {
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   169
		std::wcout << L"HIDException: " << e.getMessage() << std::endl;
4
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   170
		return 1;
0
6ff501639c23 project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   171
	}
4
405aa9de65d2 CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   172
}