author | František Kučera <franta-hg@frantovo.cz> |
Sat, 03 Apr 2021 17:39:35 +0200 | |
branch | v_0 |
changeset 33 | 0dc4e2942840 |
parent 31 | 3cbac1956f05 |
permissions | -rw-r--r-- |
12 | 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 |
|
26
fff8e9a86e85
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
12 | 8 |
* |
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
#pragma once |
|
18 |
||
19 |
#include <iostream> |
|
20 |
#include <QObject> |
|
21 |
#include <QDBusContext> |
|
13
52d92c1b340e
generate C++ classes from D-Bus XML using cmake instead of a custom script
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
22 |
#include <QDBusConnection> |
12 | 23 |
|
24 |
#include "HID.h" |
|
25 |
#include "CadMouseConfig.h" |
|
26 |
#include "Common.h" |
|
27 |
||
28 |
class Daemon : public QObject, public QDBusContext { |
|
29 |
Q_OBJECT; |
|
30 |
||
31 |
private: |
|
32 |
||
33
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
33 |
static unsigned short const VENDOR_ID = 0x256f; |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
34 |
static unsigned short const PRODUCT_ID_WIRELESS = 0xc652; |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
35 |
static unsigned short const PRODUCT_ID_WIRED = 0xc656; |
12 | 36 |
|
37 |
void logException(const HIDException& e) { |
|
38 |
std::wcout << L"HIDException: " << e.getMessage() << std::endl; |
|
39 |
} |
|
40 |
public: |
|
41 |
||
33
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
42 |
Daemon(QObject* parent = nullptr) : QObject(parent) { |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
43 |
} |
12 | 44 |
|
33
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
45 |
static HIDDevice getMouse() { |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
46 |
// TODO: multiple mouse support, better mouse selection, specific settings for particular type… |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
47 |
// (probably after future redesign/rewrite – this is just a simple tool written for 3DConnexion CadMouse Pro) |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
48 |
std::vector<HIDDeviceInfo> devices = HIDDeviceInfo::enumerate(); |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
49 |
for (auto pid :{PRODUCT_ID_WIRELESS, PRODUCT_ID_WIRED}) { |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
50 |
for (HIDDeviceInfo device : devices) { |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
51 |
if (device.matches(VENDOR_ID, pid)) return device.open(); |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
52 |
} |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
53 |
} |
0dc4e2942840
support also the wired version of CadMouse Pro
František Kučera <franta-hg@frantovo.cz>
parents:
31
diff
changeset
|
54 |
throw HIDException(L"No suitable mouse found."); |
12 | 55 |
} |
56 |
||
57 |
Q_PROPERTY(bool devicePresent READ devicePresent) |
|
58 |
bool devicePresent() { |
|
31
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
59 |
std::wcout << L"checking mouse presence: "; |
12 | 60 |
try { |
61 |
getMouse(); |
|
31
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
62 |
std::wcout << L"present" << std::endl; |
12 | 63 |
return true; |
64 |
} catch (const HIDException& e) { |
|
31
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
65 |
std::wcout << std::endl; |
12 | 66 |
logException(e); |
67 |
return false; |
|
68 |
} |
|
69 |
} |
|
70 |
||
71 |
Q_PROPERTY(QString deviceName READ deviceName) |
|
72 |
QString deviceName() { |
|
31
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
73 |
std::wcout << L"reading mouse name: "; |
12 | 74 |
try { |
31
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
75 |
auto productName = getMouse().getProductName(); |
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
76 |
std::wcout << productName << std::endl; |
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
77 |
return QString::fromStdWString(productName); |
12 | 78 |
} catch (HIDException& e) { |
31
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
79 |
std::wcout << std::endl; |
12 | 80 |
logException(e); |
81 |
return QString(); |
|
82 |
} |
|
83 |
} |
|
84 |
||
29
361687fe303a
add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
85 |
void configure(bool liftOffDetection, bool smartScrolling, bool remapWheelPress, bool remapGestureButton, int frequency) { |
31
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
86 |
std::wcout << L"configuring mouse:" |
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
87 |
<< L" liftOffDetection=" << liftOffDetection |
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
88 |
<< L" smartScrolling=" << smartScrolling |
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
89 |
<< L" remapWheelPress=" << remapWheelPress |
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
90 |
<< L" remapGestureButton=" << remapGestureButton |
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
91 |
<< L" frequency=" << frequency |
3cbac1956f05
log values while configuring mouse, checking mouse presence or reading mouse name
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
92 |
<< std::endl; |
12 | 93 |
try { |
94 |
CadMouseConfig config; |
|
95 |
config.setLiftOffDetection(liftOffDetection); |
|
96 |
config.setSmartScrolling(smartScrolling); |
|
29
361687fe303a
add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
97 |
config.setWheelPressRemapped(remapWheelPress); |
361687fe303a
add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
98 |
config.setRemapGestureButton(remapGestureButton); |
12 | 99 |
config.setFrequency(Common::parseFrequency(std::to_wstring(frequency))); |
100 |
getMouse().sendFeatureReport(config.serialize()); |
|
101 |
} catch (HIDException& e) { |
|
102 |
logException(e); |
|
103 |
sendErrorReply(QDBusError::ErrorType::Failed, QString::fromStdWString(e.getMessage())); |
|
104 |
} catch (CLIException& e) { |
|
105 |
sendErrorReply(QDBusError::ErrorType::Failed, QString::fromStdWString(e.getMessage())); |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
}; |