Implement AdjustableDPI feature

This commit is contained in:
pixl 2020-06-24 20:17:32 -04:00
parent 1106133f3c
commit 5f76ccc4ac
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
3 changed files with 149 additions and 0 deletions

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#include "AdjustableDPI.h"
using namespace logid::backend::hidpp20;
AdjustableDPI::AdjustableDPI(Device* dev) : Feature(dev, ID)
{
}
uint8_t AdjustableDPI::getSensorCount()
{
std::vector<uint8_t> params(0);
auto response = callFunction(GetSensorCount, params);
return response[0];
}
AdjustableDPI::SensorDPIList AdjustableDPI::getSensorDPIList(uint8_t sensor)
{
SensorDPIList dpi_list{};
std::vector<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> params(3);
params[0] = sensor;
params[1] = (dpi >> 8);
params[2] = (dpi & 0xFF);
callFunction(SetSensorDPI, params);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#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<uint16_t> 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