log values while configuring mouse, checking mouse presence or reading mouse name
/**
* cadMousePro
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <iostream>
#include <QObject>
#include <QDBusContext>
#include <QDBusConnection>
#include "HID.h"
#include "CadMouseConfig.h"
#include "Common.h"
class Daemon : public QObject, public QDBusContext {
Q_OBJECT;
private:
HIDDevice getMouse() {
return HIDDevice(VENDOR_ID, PRODUCT_ID, nullptr);
}
void logException(const HIDException& e) {
std::wcout << L"HIDException: " << e.getMessage() << std::endl;
}
public:
static unsigned short const VENDOR_ID = 0x256f;
static unsigned short const PRODUCT_ID = 0xc652;
Daemon(QObject* parent = nullptr) : QObject(parent) {
}
Q_PROPERTY(bool devicePresent READ devicePresent)
bool devicePresent() {
std::wcout << L"checking mouse presence: ";
try {
getMouse();
std::wcout << L"present" << std::endl;
return true;
} catch (const HIDException& e) {
std::wcout << std::endl;
logException(e);
return false;
}
}
Q_PROPERTY(QString deviceName READ deviceName)
QString deviceName() {
std::wcout << L"reading mouse name: ";
try {
auto productName = getMouse().getProductName();
std::wcout << productName << std::endl;
return QString::fromStdWString(productName);
} catch (HIDException& e) {
std::wcout << std::endl;
logException(e);
return QString();
}
}
void configure(bool liftOffDetection, bool smartScrolling, bool remapWheelPress, bool remapGestureButton, int frequency) {
std::wcout << L"configuring mouse:"
<< L" liftOffDetection=" << liftOffDetection
<< L" smartScrolling=" << smartScrolling
<< L" remapWheelPress=" << remapWheelPress
<< L" remapGestureButton=" << remapGestureButton
<< L" frequency=" << frequency
<< std::endl;
try {
CadMouseConfig config;
config.setLiftOffDetection(liftOffDetection);
config.setSmartScrolling(smartScrolling);
config.setWheelPressRemapped(remapWheelPress);
config.setRemapGestureButton(remapGestureButton);
config.setFrequency(Common::parseFrequency(std::to_wstring(frequency)));
getMouse().sendFeatureReport(config.serialize());
} catch (HIDException& e) {
logException(e);
sendErrorReply(QDBusError::ErrorType::Failed, QString::fromStdWString(e.getMessage()));
} catch (CLIException& e) {
sendErrorReply(QDBusError::ErrorType::Failed, QString::fromStdWString(e.getMessage()));
}
}
};