mirror of
https://github.com/PixlOne/logiops.git
synced 2025-07-14 21:32:33 +08:00
Add DPI action IPC bindings
This commit is contained in:
parent
f76d9dfaf5
commit
56dee076ea
@ -27,8 +27,8 @@ using namespace logid;
|
|||||||
using namespace libconfig;
|
using namespace libconfig;
|
||||||
using namespace logid::config;
|
using namespace logid::config;
|
||||||
|
|
||||||
Configuration::Configuration(const std::string& config_file) :
|
Configuration::Configuration(std::string config_file) :
|
||||||
_config_file (config_file)
|
_config_file (std::move(config_file))
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
_config.readFile(_config_file);
|
_config.readFile(_config_file);
|
||||||
|
@ -39,7 +39,7 @@ namespace logid
|
|||||||
class Configuration : public config::Config
|
class Configuration : public config::Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Configuration(const std::string& config_file);
|
explicit Configuration(std::string config_file);
|
||||||
Configuration() = default;
|
Configuration() = default;
|
||||||
|
|
||||||
// Reloading is not safe, references will be invalidated
|
// Reloading is not safe, references will be invalidated
|
||||||
|
@ -29,7 +29,12 @@ const char* ChangeDPI::interface_name = "ChangeDPI";
|
|||||||
ChangeDPI::ChangeDPI(
|
ChangeDPI::ChangeDPI(
|
||||||
Device *device, config::ChangeDPI& config,
|
Device *device, config::ChangeDPI& config,
|
||||||
const std::shared_ptr<ipcgull::node>& parent) :
|
const std::shared_ptr<ipcgull::node>& parent) :
|
||||||
Action(device, interface_name), _config (config)
|
Action(device, interface_name, {
|
||||||
|
{
|
||||||
|
{"GetConfig", {this, &ChangeDPI::getConfig, {"change", "sensor"}}},
|
||||||
|
{"SetChange", {this, &ChangeDPI::setChange, {"change"}}},
|
||||||
|
{"SetSensor", {this, &ChangeDPI::setSensor, {"sensor", "reset"}}},
|
||||||
|
}, {}, {} }), _config (config)
|
||||||
{
|
{
|
||||||
_dpi = _device->getFeature<features::DPI>("dpi");
|
_dpi = _device->getFeature<features::DPI>("dpi");
|
||||||
if(!_dpi)
|
if(!_dpi)
|
||||||
@ -39,6 +44,25 @@ ChangeDPI::ChangeDPI(
|
|||||||
_device->hidpp20().deviceIndex());
|
_device->hidpp20().deviceIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::tuple<int16_t, uint16_t> ChangeDPI::getConfig()
|
||||||
|
{
|
||||||
|
return {_config.inc.value_or(0), _config.sensor.value_or(0)};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeDPI::setChange(int16_t change)
|
||||||
|
{
|
||||||
|
_config.inc = change;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeDPI::setSensor(uint8_t sensor, bool reset)
|
||||||
|
{
|
||||||
|
if (reset) {
|
||||||
|
_config.sensor.reset();
|
||||||
|
} else {
|
||||||
|
_config.sensor = sensor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ChangeDPI::press()
|
void ChangeDPI::press()
|
||||||
{
|
{
|
||||||
_pressed = true;
|
_pressed = true;
|
||||||
|
@ -35,6 +35,10 @@ namespace logid {
|
|||||||
virtual void press();
|
virtual void press();
|
||||||
virtual void release();
|
virtual void release();
|
||||||
|
|
||||||
|
std::tuple<int16_t, uint16_t> getConfig();
|
||||||
|
void setChange(int16_t change);
|
||||||
|
void setSensor(uint8_t sensor, bool reset);
|
||||||
|
|
||||||
virtual uint8_t reprogFlags() const;
|
virtual uint8_t reprogFlags() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -28,8 +28,13 @@ using namespace libconfig;
|
|||||||
const char* CycleDPI::interface_name = "CycleDPI";
|
const char* CycleDPI::interface_name = "CycleDPI";
|
||||||
|
|
||||||
CycleDPI::CycleDPI(Device* device, config::CycleDPI& config,
|
CycleDPI::CycleDPI(Device* device, config::CycleDPI& config,
|
||||||
const std::shared_ptr<ipcgull::node>& parent) :
|
[[maybe_unused]] const std::shared_ptr<ipcgull::node>& parent) :
|
||||||
Action (device, interface_name),
|
Action (device, interface_name, {
|
||||||
|
{
|
||||||
|
{"GetDPIs", {this, &CycleDPI::getDPIs, {"dpis"}}},
|
||||||
|
{"SetDPIs", {this, &CycleDPI::setDPIs, {"dpis"}}}
|
||||||
|
}, {}, {}
|
||||||
|
}),
|
||||||
_config (config)
|
_config (config)
|
||||||
{
|
{
|
||||||
_dpi = _device->getFeature<features::DPI>("dpi");
|
_dpi = _device->getFeature<features::DPI>("dpi");
|
||||||
@ -44,6 +49,20 @@ CycleDPI::CycleDPI(Device* device, config::CycleDPI& config,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<int> CycleDPI::getDPIs()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_dpi_lock);
|
||||||
|
auto dpis = _config.dpis.value_or(std::list<int>());
|
||||||
|
return {dpis.begin(), dpis.end()};
|
||||||
|
}
|
||||||
|
|
||||||
|
void CycleDPI::setDPIs(const std::vector<int>& dpis)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_dpi_lock);
|
||||||
|
_config.dpis.emplace(dpis.begin(), dpis.end());
|
||||||
|
_current_dpi = _config.dpis->cbegin();
|
||||||
|
}
|
||||||
|
|
||||||
void CycleDPI::press()
|
void CycleDPI::press()
|
||||||
{
|
{
|
||||||
_pressed = true;
|
_pressed = true;
|
||||||
|
@ -35,6 +35,9 @@ namespace actions {
|
|||||||
virtual void press();
|
virtual void press();
|
||||||
virtual void release();
|
virtual void release();
|
||||||
|
|
||||||
|
std::vector<int> getDPIs();
|
||||||
|
void setDPIs(const std::vector<int>& dpis);
|
||||||
|
|
||||||
virtual uint8_t reprogFlags() const;
|
virtual uint8_t reprogFlags() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "Gesture.h"
|
#include "Gesture.h"
|
||||||
#include "ReleaseGesture.h"
|
#include "ReleaseGesture.h"
|
||||||
@ -71,20 +70,17 @@ std::shared_ptr<Gesture> Gesture::makeGesture(
|
|||||||
{
|
{
|
||||||
if(type == AxisGesture::interface_name) {
|
if(type == AxisGesture::interface_name) {
|
||||||
config = config::AxisGesture();
|
config = config::AxisGesture();
|
||||||
return makeGesture(device, config, parent);
|
|
||||||
} else if(type == IntervalGesture::interface_name) {
|
} else if(type == IntervalGesture::interface_name) {
|
||||||
config = config::IntervalGesture();
|
config = config::IntervalGesture();
|
||||||
return makeGesture(device, config, parent);
|
|
||||||
} else if(type == ReleaseGesture::interface_name) {
|
} else if(type == ReleaseGesture::interface_name) {
|
||||||
config = config::IntervalGesture();
|
config = config::ReleaseGesture();
|
||||||
return makeGesture(device, config, parent);
|
|
||||||
} else if(type == ThresholdGesture::interface_name) {
|
} else if(type == ThresholdGesture::interface_name) {
|
||||||
config = config::ThresholdGesture();
|
config = config::ThresholdGesture();
|
||||||
return makeGesture(device, config, parent);
|
|
||||||
} else if(type == NullGesture::interface_name) {
|
} else if(type == NullGesture::interface_name) {
|
||||||
config = config::NoGesture();
|
config = config::NoGesture();
|
||||||
return makeGesture(device, config, parent);
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
throw InvalidGesture();
|
throw InvalidGesture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return makeGesture(device, config, parent);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user