1 /** |
|
2 * cadMousePro |
|
3 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 #pragma once |
|
19 |
|
20 #include <type_traits> |
|
21 |
|
22 #include "HID.h" |
|
23 |
|
24 enum class Frequency : uint8_t { |
|
25 Hz_0125 = 8, |
|
26 Hz_0250 = 4, |
|
27 Hz_0500 = 2, |
|
28 Hz_1000 = 1 |
|
29 }; |
|
30 |
|
31 using FrequencyType = std::underlying_type<Frequency>::type; |
|
32 |
|
33 class CadMouseConfig { |
|
34 private: |
|
35 bool liftOffDetection = true; |
|
36 bool smartScrolling = false; |
|
37 Frequency frequency = Frequency::Hz_1000; |
|
38 public: |
|
39 |
|
40 void setFrequency(Frequency frequency) { |
|
41 this->frequency = frequency; |
|
42 } |
|
43 |
|
44 void setLiftOffDetection(bool liftOffDetection) { |
|
45 this->liftOffDetection = liftOffDetection; |
|
46 } |
|
47 |
|
48 void setSmartScrolling(bool smartScrolling) { |
|
49 this->smartScrolling = smartScrolling; |
|
50 } |
|
51 |
|
52 Packet serialize() { |
|
53 Packet data; |
|
54 data.reserve(32); |
|
55 |
|
56 data.push_back(0x10); // report ID |
|
57 data.push_back(0x00); // option |
|
58 |
|
59 data.push_back(0x1c); // speed |
|
60 |
|
61 data.push_back(liftOffDetection ? 0x00 : 0x1f); |
|
62 |
|
63 if (smartScrolling) { |
|
64 data.push_back(0x00); |
|
65 data.push_back(0x00); |
|
66 data.push_back(0x00); |
|
67 data.push_back(0x01); |
|
68 } else { |
|
69 data.push_back(0x01); |
|
70 data.push_back(0xff); |
|
71 data.push_back(0x00); |
|
72 data.push_back(0x00); |
|
73 } |
|
74 |
|
75 for (int i = 0; i < 8; i++) data.push_back(0x00); // constant padding or magic |
|
76 |
|
77 // magic constants or unknown fields |
|
78 data.push_back(0x00); |
|
79 data.push_back(0x03); |
|
80 data.push_back(0x00); |
|
81 data.push_back(0x0a); |
|
82 data.push_back(0x0b); |
|
83 data.push_back(0x0c); |
|
84 data.push_back(0x0c); |
|
85 data.push_back(0x0e); |
|
86 data.push_back(0x0d); |
|
87 data.push_back(0x2f); |
|
88 data.push_back(0x00); |
|
89 data.push_back(0x1e); |
|
90 |
|
91 data.push_back(0x00); |
|
92 data.push_back(0x00); |
|
93 data.push_back(0x00); |
|
94 data.push_back(static_cast<FrequencyType> (frequency)); |
|
95 |
|
96 return data; |
|
97 } |
|
98 |
|
99 }; |
|