From 5f76ccc4ac9fa673b2851c8a5310c5cb7354deed Mon Sep 17 00:00:00 2001 From: pixl Date: Wed, 24 Jun 2020 20:17:32 -0400 Subject: [PATCH] Implement AdjustableDPI feature --- src/logid/CMakeLists.txt | 1 + .../hidpp20/features/AdjustableDPI.cpp | 88 +++++++++++++++++++ .../backend/hidpp20/features/AdjustableDPI.h | 60 +++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 src/logid/backend/hidpp20/features/AdjustableDPI.cpp create mode 100644 src/logid/backend/hidpp20/features/AdjustableDPI.h diff --git a/src/logid/CMakeLists.txt b/src/logid/CMakeLists.txt index 529c5f7..653d2b9 100644 --- a/src/logid/CMakeLists.txt +++ b/src/logid/CMakeLists.txt @@ -32,6 +32,7 @@ add_executable(logid backend/hidpp20/features/FeatureSet.cpp backend/hidpp20/features/DeviceName.cpp backend/hidpp20/features/Reset.cpp + backend/hidpp20/features/AdjustableDPI.cpp backend/dj/Report.cpp util/mutex_queue.h util/thread.cpp diff --git a/src/logid/backend/hidpp20/features/AdjustableDPI.cpp b/src/logid/backend/hidpp20/features/AdjustableDPI.cpp new file mode 100644 index 0000000..722d6cb --- /dev/null +++ b/src/logid/backend/hidpp20/features/AdjustableDPI.cpp @@ -0,0 +1,88 @@ +/* + * Copyright 2019-2020 PixlOne + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * 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 . + * + */ +#include "AdjustableDPI.h" + +using namespace logid::backend::hidpp20; + +AdjustableDPI::AdjustableDPI(Device* dev) : Feature(dev, ID) +{ +} + +uint8_t AdjustableDPI::getSensorCount() +{ + std::vector params(0); + auto response = callFunction(GetSensorCount, params); + return response[0]; +} + +AdjustableDPI::SensorDPIList AdjustableDPI::getSensorDPIList(uint8_t sensor) +{ + SensorDPIList dpi_list{}; + std::vector params(1); + params[0] = sensor; + auto response = callFunction(GetSensorDPIList, params); + + dpi_list.dpiStep = false; + for(std::size_t i = 1; i < response.size(); i+=2) { + uint16_t dpi = response[i + 1]; + dpi |= (response[i] << 8); + if(!dpi) + break; + if(dpi >= 0xe000) { + dpi_list.isRange = true; + dpi_list.dpiStep = dpi - 0xe000; + } else { + dpi_list.dpis.push_back(dpi); + } + } + + return dpi_list; +} + +uint16_t AdjustableDPI::getDefaultSensorDPI(uint8_t sensor) +{ + std::vector params(1); + params[0] = sensor; + auto response = callFunction(GetSensorDPI, params); + + uint16_t default_dpi = response[4]; + default_dpi |= (response[3] << 8); + + return default_dpi; +} + +uint16_t AdjustableDPI::getSensorDPI(uint8_t sensor) +{ + std::vector params(1); + params[0] = sensor; + auto response = callFunction(GetSensorDPI, params); + + uint16_t dpi = response[2]; + dpi |= (response[1] << 8); + + return dpi; +} + +void AdjustableDPI::setSensorDPI(uint8_t sensor, uint16_t dpi) +{ + std::vector params(3); + params[0] = sensor; + params[1] = (dpi >> 8); + params[2] = (dpi & 0xFF); + callFunction(SetSensorDPI, params); +} \ No newline at end of file diff --git a/src/logid/backend/hidpp20/features/AdjustableDPI.h b/src/logid/backend/hidpp20/features/AdjustableDPI.h new file mode 100644 index 0000000..9a76d0f --- /dev/null +++ b/src/logid/backend/hidpp20/features/AdjustableDPI.h @@ -0,0 +1,60 @@ +/* + * Copyright 2019-2020 PixlOne + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * 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 . + * + */ +#ifndef LOGID_BACKEND_HIDPP20_FEATURE_ADJUSTABLEDPI_H +#define LOGID_BACKEND_HIDPP20_FEATURE_ADJUSTABLEDPI_H + +#include "../feature_defs.h" +#include "../Feature.h" + +namespace logid { +namespace backend { +namespace hidpp20 +{ + class AdjustableDPI : public Feature + { + public: + static const uint16_t ID = FeatureID::ADJUSTABLE_DPI; + virtual uint16_t getID() { return ID; } + + enum Function { + GetSensorCount = 0, + GetSensorDPIList = 1, + GetSensorDPI = 2, + SetSensorDPI = 3 + }; + + AdjustableDPI(Device* dev); + + uint8_t getSensorCount(); + + struct SensorDPIList + { + std::vector dpis; + bool isRange; + uint16_t dpiStep; + }; + SensorDPIList getSensorDPIList(uint8_t sensor); + + uint16_t getDefaultSensorDPI(uint8_t sensor); + uint16_t getSensorDPI(uint8_t sensor); + + void setSensorDPI(uint8_t sensor, uint16_t dpi); + }; +}}} + +#endif //LOGID_BACKEND_HIDPP20_FEATURE_ADJUSTABLEDPI_H