mirror of
https://github.com/PixlOne/logiops.git
synced 2025-07-14 05:12:34 +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 logid::config;
|
||||
|
||||
Configuration::Configuration(const std::string& config_file) :
|
||||
_config_file (config_file)
|
||||
Configuration::Configuration(std::string config_file) :
|
||||
_config_file (std::move(config_file))
|
||||
{
|
||||
try {
|
||||
_config.readFile(_config_file);
|
||||
|
@ -39,7 +39,7 @@ namespace logid
|
||||
class Configuration : public config::Config
|
||||
{
|
||||
public:
|
||||
explicit Configuration(const std::string& config_file);
|
||||
explicit Configuration(std::string config_file);
|
||||
Configuration() = default;
|
||||
|
||||
// Reloading is not safe, references will be invalidated
|
||||
|
@ -29,7 +29,12 @@ const char* ChangeDPI::interface_name = "ChangeDPI";
|
||||
ChangeDPI::ChangeDPI(
|
||||
Device *device, config::ChangeDPI& config,
|
||||
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");
|
||||
if(!_dpi)
|
||||
@ -39,6 +44,25 @@ ChangeDPI::ChangeDPI(
|
||||
_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()
|
||||
{
|
||||
_pressed = true;
|
||||
|
@ -35,6 +35,10 @@ namespace logid {
|
||||
virtual void press();
|
||||
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;
|
||||
|
||||
protected:
|
||||
|
@ -28,8 +28,13 @@ using namespace libconfig;
|
||||
const char* CycleDPI::interface_name = "CycleDPI";
|
||||
|
||||
CycleDPI::CycleDPI(Device* device, config::CycleDPI& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action (device, interface_name),
|
||||
[[maybe_unused]] const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action (device, interface_name, {
|
||||
{
|
||||
{"GetDPIs", {this, &CycleDPI::getDPIs, {"dpis"}}},
|
||||
{"SetDPIs", {this, &CycleDPI::setDPIs, {"dpis"}}}
|
||||
}, {}, {}
|
||||
}),
|
||||
_config (config)
|
||||
{
|
||||
_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()
|
||||
{
|
||||
_pressed = true;
|
||||
|
@ -35,6 +35,9 @@ namespace actions {
|
||||
virtual void press();
|
||||
virtual void release();
|
||||
|
||||
std::vector<int> getDPIs();
|
||||
void setDPIs(const std::vector<int>& dpis);
|
||||
|
||||
virtual uint8_t reprogFlags() const;
|
||||
|
||||
protected:
|
||||
|
@ -16,7 +16,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include "Gesture.h"
|
||||
#include "ReleaseGesture.h"
|
||||
@ -71,20 +70,17 @@ std::shared_ptr<Gesture> Gesture::makeGesture(
|
||||
{
|
||||
if(type == AxisGesture::interface_name) {
|
||||
config = config::AxisGesture();
|
||||
return makeGesture(device, config, parent);
|
||||
} else if(type == IntervalGesture::interface_name) {
|
||||
config = config::IntervalGesture();
|
||||
return makeGesture(device, config, parent);
|
||||
} else if(type == ReleaseGesture::interface_name) {
|
||||
config = config::IntervalGesture();
|
||||
return makeGesture(device, config, parent);
|
||||
config = config::ReleaseGesture();
|
||||
} else if(type == ThresholdGesture::interface_name) {
|
||||
config = config::ThresholdGesture();
|
||||
return makeGesture(device, config, parent);
|
||||
} else if(type == NullGesture::interface_name) {
|
||||
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