Skip to content

Commit

Permalink
Feature compatibility check
Browse files Browse the repository at this point in the history
  • Loading branch information
dslul committed Nov 29, 2018
2 parents 8d9a556 + 550e3d1 commit 5014b44
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Linux alternative for the Logitech Gaming Software.

Currently, it works only for the G402 Gaming Mouse.
Currently, it is tested with the G402 Gaming Mouse, but should also work with others. Please open an issue if you encounter any problem.

INSTRUCTIONS:
move 99-hidraw-logitech-g402.rules to /lib/udev/rules.d/99-hidraw-permissions.rules, unplug and plug the mouse
65 changes: 44 additions & 21 deletions logiconf-gui/devicecommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include "devicemanager.h"

DeviceCommunicator::DeviceCommunicator(QObject *parent)
: QObject(parent), dev(nullptr), profiles(nullptr), hidprofile(nullptr),
dpi(nullptr), profileformat(nullptr), profile(nullptr),
: QObject(parent), dev(nullptr), profiles(nullptr), featureset(nullptr),
hidprofile(nullptr), dpi(nullptr), profileformat(nullptr),
breathingIntensity(200), breathingRate(10000), oldBreathingRate(10000)
{

Expand All @@ -27,6 +27,7 @@ DeviceCommunicator::DeviceCommunicator(QObject *parent)

HIDPP::Dispatcher *dispatcher = new HIDPP::SimpleDispatcher(devmanager.getDevicePath().c_str());
dev = new HIDPP20::Device(dispatcher, HIDPP::DefaultDevice);
featureset = new HIDPP20::IFeatureSet(dev);
profiles = new HIDPP20::IOnboardProfiles(dev);
hidprofile = new HIDPP::Profile();
dpi = new HIDPP20::IAdjustableDPI(dev);
Expand All @@ -49,21 +50,21 @@ DeviceCommunicator::DeviceCommunicator(QObject *parent)
for(auto elem : profileformat->generalSettings())
std::cout << elem.first << std::endl;

unsigned int feature_count = featureset->getCount ();
for(int i = 1; i <= feature_count; ++i) {
uint8_t feature_index = i;
uint16_t feature_id;

//dpi->setSensorDPI(0, 1722);
//profile.setCurrentProfile(HIDPP20::IOnboardProfiles::MemoryType::Writeable, 1);
//std::cout << profile->modes.at(0) << std::endl;
feature_id = featureset->getFeatureID(feature_index);
HIDPP20Features.insert(std::pair<uint16_t, uint8_t>(feature_id, i));
}

tmpprofile = *hidprofile;

//tmpprofile.settings.at("report_rate") = std::move(HIDPP::Setting(1));
std::cout << hidprofile->settings.at("report_rate").toString() << std::endl;
std::cout << tmpprofile.settings.at("report_rate").toString() << std::endl;

//tmpprofile.modes[0].at("dpi") = std::move(HIDPP::Setting(400));
std::cout << hidprofile->modes[0].at("dpi").toString() << std::endl;
//dpi->setSensorDPI(0, 1722);
//profile.setCurrentProfile(HIDPP20::IOnboardProfiles::MemoryType::Writeable, 1);
//std::cout << profile->modes.at(0) << std::endl;

//applySettings();

QFile savefile(savefilePath);
std::cout << savefilePath.toStdString() << std::endl;
Expand Down Expand Up @@ -211,17 +212,21 @@ int DeviceCommunicator::getMaxButtonsNumber()

bool DeviceCommunicator::isFusionEngineEnabled()
{
return dev->callFunction(0x0d, 0, {0,0,0}).at(0);
if(hasFeature(0x2400))
return dev->callFunction(getFeatureIndex(0x2400), 0, {0,0,0}).at(0);
return false;
}

void DeviceCommunicator::enableFusionEngine()
{
dev->callFunction(0x0d, 1, {1,0,0});
if(hasFeature(0x2400))
dev->callFunction(getFeatureIndex(0x2400), 1, {1,0,0});
}

void DeviceCommunicator::disableFusionEngine()
{
dev->callFunction(0x0d, 1, {0,0,0});
if(hasFeature(0x2400))
dev->callFunction(getFeatureIndex(0x2400), 1, {0,0,0});
}

bool DeviceCommunicator::isPendingModification()
Expand All @@ -244,15 +249,17 @@ void DeviceCommunicator::applySettings()

void DeviceCommunicator::toggleDPILed()
{
uint8_t function = getFeatureIndex(0x1300);
if(isDPILedOn())
dev->callFunction(5, 7, {0,4,0});
dev->callFunction(function, 7, {0,4,0});
else
dev->callFunction(5, 7, {0,2,0});
dev->callFunction(function, 7, {0,2,0});
}

bool DeviceCommunicator::isDPILedOn()
{
std::vector<uint8_t> result = dev->callFunction(5, 6, {0,0,0});
uint8_t function = getFeatureIndex(0x1300);
std::vector<uint8_t> result = dev->callFunction(function, 6, {0,0,0});
if(result.at(1) == 0x04) {
return false;
} else if(result.at(1) == 0x02) {
Expand Down Expand Up @@ -288,10 +295,11 @@ void DeviceCommunicator::setLogoGlow(quint16 value)

void DeviceCommunicator::setBackLlight(quint16 intensity, quint16 rate)
{
dev->callFunction(5, 3, {1,0,0});
dev->callFunction(5, 5, {1,0,0x80,0,(uint8_t)intensity,
uint8_t function = getFeatureIndex(0x1300);
dev->callFunction(function, 3, {1,0,0});
dev->callFunction(function, 5, {1,0,0x80,0,(uint8_t)intensity,
(uint8_t)(rate>>8),(uint8_t)(rate&0x00ff),0,0,0,0,0,0,0,0,0});
dev->callFunction(5, 3, {0,0,0});
dev->callFunction(function, 3, {0,0,0});
saveSettings();
}

Expand Down Expand Up @@ -356,3 +364,18 @@ bool DeviceCommunicator::isBreathingEnabled()
else
return true;
}

uint8_t DeviceCommunicator::getFeatureIndex(uint16_t featureid)
{
return HIDPP20Features[featureid];
}

bool DeviceCommunicator::hasFeature(uint16_t featureid)
{
if(HIDPP20Features.find(featureid) == HIDPP20Features.end()) {
std::cout << "Feature " << featureid << " not compatible with this device." << std::endl;
return false;
} else {
return true;
}
}
8 changes: 6 additions & 2 deletions logiconf-gui/devicecommunicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <hidpp20/IOnboardProfiles.h>
#include <hidpp20/IAdjustableDPI.h>
#include <hidpp20/ProfileFormat.h>
#include <hidpp20/IFeatureSet.h>
#include <hidpp/AbstractMemoryMapping.h>

#include "profile.h"

class DeviceCommunicator : public QObject
{
Expand Down Expand Up @@ -54,9 +54,13 @@ class DeviceCommunicator : public QObject
Q_INVOKABLE quint16 getBreathingIntensity();
Q_INVOKABLE quint16 getBreathingRate();
Q_INVOKABLE bool isBreathingEnabled();

Q_INVOKABLE bool hasFeature(uint16_t featureid);
Q_INVOKABLE uint8_t getFeatureIndex(uint16_t featureid);
private:
HIDPP20::Device *dev;
HIDPP20::IOnboardProfiles *profiles;
HIDPP20::IFeatureSet *featureset;
HIDPP::Profile *hidprofile;
HIDPP::Profile tmpprofile;
HIDPP20::IAdjustableDPI *dpi;
Expand All @@ -65,7 +69,7 @@ class DeviceCommunicator : public QObject

std::unique_ptr<HIDPP::AbstractMemoryMapping> memory;

Profile *profile;
std::map<uint16_t, uint8_t> HIDPP20Features;

quint16 breathingIntensity;
quint16 breathingRate;
Expand Down
3 changes: 1 addition & 2 deletions logiconf-gui/logiconf-gui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin

HEADERS += \
devicecommunicator.h \
devicemanager.h \
profile.h
devicemanager.h

unix:!macx: LIBS += -L$$OUT_PWD/../hidpp/ -lhidpp

Expand Down
17 changes: 0 additions & 17 deletions logiconf-gui/profile.h

This file was deleted.

0 comments on commit 5014b44

Please sign in to comment.