author | František Kučera <franta-hg@frantovo.cz> |
Tue, 09 Jun 2020 22:13:44 +0200 | |
branch | v_0 |
changeset 32 | 09d20a946a01 |
parent 31 | 3cbac1956f05 |
child 33 | 0dc4e2942840 |
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 |
HIDDevice getMouse() { |
|
34 |
return HIDDevice(VENDOR_ID, PRODUCT_ID, nullptr); |
|
35 |
} |
|
36 |
||
37 |
void logException(const HIDException& e) { |
|
38 |
std::wcout << L"HIDException: " << e.getMessage() << std::endl; |
|
39 |
} |
|
40 |
public: |
|
41 |
||
42 |
static unsigned short const VENDOR_ID = 0x256f; |
|
43 |
static unsigned short const PRODUCT_ID = 0xc652; |
|
44 |
||
45 |
Daemon(QObject* parent = nullptr) : QObject(parent) { |
|
46 |
} |
|
47 |
||
48 |
Q_PROPERTY(bool devicePresent READ devicePresent) |
|
49 |
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
|
50 |
std::wcout << L"checking mouse presence: "; |
12 | 51 |
try { |
52 |
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
|
53 |
std::wcout << L"present" << std::endl; |
12 | 54 |
return true; |
55 |
} 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
|
56 |
std::wcout << std::endl; |
12 | 57 |
logException(e); |
58 |
return false; |
|
59 |
} |
|
60 |
} |
|
61 |
||
62 |
Q_PROPERTY(QString deviceName READ deviceName) |
|
63 |
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
|
64 |
std::wcout << L"reading mouse name: "; |
12 | 65 |
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
|
66 |
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
|
67 |
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
|
68 |
return QString::fromStdWString(productName); |
12 | 69 |
} 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
|
70 |
std::wcout << std::endl; |
12 | 71 |
logException(e); |
72 |
return QString(); |
|
73 |
} |
|
74 |
} |
|
75 |
||
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
|
76 |
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
|
77 |
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
|
78 |
<< 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
|
79 |
<< 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
|
80 |
<< 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
|
81 |
<< 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
|
82 |
<< 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
|
83 |
<< std::endl; |
12 | 84 |
try { |
85 |
CadMouseConfig config; |
|
86 |
config.setLiftOffDetection(liftOffDetection); |
|
87 |
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
|
88 |
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
|
89 |
config.setRemapGestureButton(remapGestureButton); |
12 | 90 |
config.setFrequency(Common::parseFrequency(std::to_wstring(frequency))); |
91 |
getMouse().sendFeatureReport(config.serialize()); |
|
92 |
} catch (HIDException& e) { |
|
93 |
logException(e); |
|
94 |
sendErrorReply(QDBusError::ErrorType::Failed, QString::fromStdWString(e.getMessage())); |
|
95 |
} catch (CLIException& e) { |
|
96 |
sendErrorReply(QDBusError::ErrorType::Failed, QString::fromStdWString(e.getMessage())); |
|
97 |
} |
|
98 |
} |
|
99 |
||
100 |
}; |