Add Reprog Controls V3 support
This commit is contained in:
parent
9c092edcf3
commit
fef5ade956
|
@ -6,7 +6,7 @@ This is currently only compatible with HID++ \>2.0 devices.
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
This project requires a C++14 compiler, cmake, libevdev, libconfig, and [libhidpp](https://github.com/cvuchener/hidpp)
|
This project requires a C++14 compiler, cmake, libevdev, libconfig, and [my fork of libhidpp](https://github.com/PixlOne/hidpp)
|
||||||
|
|
||||||
To build this project, run:
|
To build this project, run:
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ Installation is currently not implemented.
|
||||||
| Device | Compatible? |
|
| Device | Compatible? |
|
||||||
|:---------:|:-----------:|
|
|:---------:|:-----------:|
|
||||||
| MX Master | Yes |
|
| MX Master | Yes |
|
||||||
| T400 | Untested |
|
| T400 | Yes |
|
||||||
| K400r | Untested |
|
| K400r | Untested |
|
||||||
| K350 | Untested |
|
| K350 | Untested |
|
||||||
| M325c | Untested |
|
| M325c | Untested |
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define LOGIOPS_ACTIONS_H
|
#define LOGIOPS_ACTIONS_H
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <hidpp20/IReprogControlsV4.h>
|
#include <hidpp20/IReprogControls.h>
|
||||||
#include "Device.h"
|
#include "Device.h"
|
||||||
|
|
||||||
enum class Action
|
enum class Action
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
#include <hidpp20/IAdjustableDPI.h>
|
#include <hidpp20/IAdjustableDPI.h>
|
||||||
#include <hidpp20/IFeatureSet.h>
|
#include <hidpp20/IFeatureSet.h>
|
||||||
#include <hidpp20/Error.h>
|
#include <hidpp20/Error.h>
|
||||||
#include <hidpp20/IReprogControlsV4.h>
|
#include <hidpp20/IReprogControls.h>
|
||||||
#include <hidpp20/Device.h>
|
#include <hidpp20/Device.h>
|
||||||
#include <hidpp10/Error.h>
|
#include <hidpp10/Error.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <hidpp20/UnsupportedFeature.h>
|
||||||
|
|
||||||
#include "Device.h"
|
#include "Device.h"
|
||||||
#include "Actions.h"
|
#include "Actions.h"
|
||||||
|
@ -21,45 +22,59 @@ using namespace std::chrono_literals;
|
||||||
|
|
||||||
Device::Device(std::string p, const HIDPP::DeviceIndex i) : path(p), index (i)
|
Device::Device(std::string p, const HIDPP::DeviceIndex i) : path(p), index (i)
|
||||||
{
|
{
|
||||||
|
// Initialise variables
|
||||||
DeviceRemoved = false;
|
DeviceRemoved = false;
|
||||||
dispatcher = new HIDPP::SimpleDispatcher(path.c_str());
|
dispatcher = new HIDPP::SimpleDispatcher(path.c_str());
|
||||||
hidpp_dev = new HIDPP20::Device(dispatcher, index);
|
hidpp_dev = new HIDPP20::Device(dispatcher, index);
|
||||||
|
name = hidpp_dev->name();
|
||||||
features = get_features();
|
features = get_features();
|
||||||
|
|
||||||
if(global_config->devices.find(hidpp_dev->name()) == global_config->devices.end())
|
// Set config, if none is found for this device then use default
|
||||||
|
if(global_config->devices.find(name) == global_config->devices.end())
|
||||||
{
|
{
|
||||||
log_printf(INFO, "Device %s not configured, using default.", hidpp_dev->name().c_str());
|
log_printf(INFO, "Device %s not configured, using default config.", hidpp_dev->name().c_str());
|
||||||
config = new DeviceConfig();
|
config = new DeviceConfig();
|
||||||
}
|
}
|
||||||
else config = global_config->devices.find(hidpp_dev->name())->second;
|
else config = global_config->devices.find(name)->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::configure(bool scanning)
|
void Device::configure(bool scanning)
|
||||||
{
|
{
|
||||||
|
// Set DPI if it is set
|
||||||
if(config->dpi != nullptr)
|
if(config->dpi != nullptr)
|
||||||
set_dpi(*config->dpi, scanning);
|
set_dpi(*config->dpi, scanning);
|
||||||
|
// Set Smartshift if it is set
|
||||||
if(config->smartshift != nullptr)
|
if(config->smartshift != nullptr)
|
||||||
set_smartshift(*config->smartshift, scanning);
|
set_smartshift(*config->smartshift, scanning);
|
||||||
|
// Set Hires Scroll if it is set
|
||||||
if(config->hiresscroll != nullptr)
|
if(config->hiresscroll != nullptr)
|
||||||
set_hiresscroll(*config->hiresscroll, scanning);
|
set_hiresscroll(*config->hiresscroll, scanning);
|
||||||
|
// Divert buttons
|
||||||
divert_buttons();
|
divert_buttons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::divert_buttons(bool scanning)
|
void Device::divert_buttons(bool scanning)
|
||||||
{
|
{
|
||||||
HIDPP20::IReprogControlsV4 irc4(hidpp_dev);
|
try
|
||||||
|
{
|
||||||
|
HIDPP20::IReprogControls irc = HIDPP20::IReprogControls::auto_version(hidpp_dev);
|
||||||
for(auto it = config->actions.begin(); it != config->actions.end(); ++it)
|
for(auto it = config->actions.begin(); it != config->actions.end(); ++it)
|
||||||
{
|
{
|
||||||
uint8_t flags = 0;
|
uint8_t flags = 0;
|
||||||
flags |= HIDPP20::IReprogControlsV4::ChangeTemporaryDivert;
|
flags |= HIDPP20::IReprogControls::ChangeTemporaryDivert;
|
||||||
flags |= HIDPP20::IReprogControlsV4::TemporaryDiverted;
|
flags |= HIDPP20::IReprogControls::TemporaryDiverted;
|
||||||
if(it->second->type == Action::Gestures)
|
if(it->second->type == Action::Gestures)
|
||||||
{
|
{
|
||||||
flags |= HIDPP20::IReprogControlsV4::ChangeRawXYDivert;
|
flags |= HIDPP20::IReprogControls::ChangeRawXYDivert;
|
||||||
flags |= HIDPP20::IReprogControlsV4::RawXYDiverted;
|
flags |= HIDPP20::IReprogControls::RawXYDiverted;
|
||||||
}
|
}
|
||||||
it->first;
|
irc.setControlReporting(it->first, flags, it->first);
|
||||||
irc4.setControlReporting(it->first, flags, it->first);
|
log_printf(DEBUG, "Diverted 0x%x.", it->first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(HIDPP20::UnsupportedFeature &e)
|
||||||
|
{
|
||||||
|
log_printf(DEBUG, "%s does not support Reprog controls, not diverting!", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +125,6 @@ void Device::set_dpi(int dpi, bool scanning)
|
||||||
void Device::start()
|
void Device::start()
|
||||||
{
|
{
|
||||||
configure();
|
configure();
|
||||||
|
|
||||||
auto *d = new HIDPP::SimpleDispatcher(path.c_str());
|
auto *d = new HIDPP::SimpleDispatcher(path.c_str());
|
||||||
listener = new SimpleListener(d, index);
|
listener = new SimpleListener(d, index);
|
||||||
listener->addEventHandler( std::make_unique<ButtonHandler>(hidpp_dev, this) );
|
listener->addEventHandler( std::make_unique<ButtonHandler>(hidpp_dev, this) );
|
||||||
|
@ -160,9 +174,9 @@ void Device::ButtonHandler::handleEvent (const HIDPP::Report &event)
|
||||||
{
|
{
|
||||||
switch (event.function())
|
switch (event.function())
|
||||||
{
|
{
|
||||||
case HIDPP20::IReprogControlsV4::Event::DivertedButtonEvent:
|
case HIDPP20::IReprogControls::Event::DivertedButtonEvent:
|
||||||
{
|
{
|
||||||
new_states = HIDPP20::IReprogControlsV4::divertedButtonEvent(event);
|
new_states = HIDPP20::IReprogControls::divertedButtonEvent(event);
|
||||||
if (states.empty())
|
if (states.empty())
|
||||||
{
|
{
|
||||||
for (uint16_t i : new_states)
|
for (uint16_t i : new_states)
|
||||||
|
@ -248,7 +262,7 @@ void Device::press_button(uint16_t cid)
|
||||||
{
|
{
|
||||||
if(config->actions.find(cid) == config->actions.end())
|
if(config->actions.find(cid) == config->actions.end())
|
||||||
{
|
{
|
||||||
log_printf(WARN, "0x%x was pressed but no action was found.", cid);
|
log_printf(DEBUG, "0x%x was pressed but no action was found.", cid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
config->actions.find(cid)->second->press();
|
config->actions.find(cid)->second->press();
|
||||||
|
@ -258,7 +272,7 @@ void Device::release_button(uint16_t cid)
|
||||||
{
|
{
|
||||||
if(config->actions.find(cid) == config->actions.end())
|
if(config->actions.find(cid) == config->actions.end())
|
||||||
{
|
{
|
||||||
log_printf(WARN, "0x%x was released but no action was found.", cid);
|
log_printf(DEBUG, "0x%x was released but no action was found.", cid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
config->actions.find(cid)->second->release();
|
config->actions.find(cid)->second->release();
|
||||||
|
@ -280,13 +294,13 @@ void Device::move_diverted(uint16_t cid, HIDPP20::IReprogControlsV4::Move m)
|
||||||
std::map<uint16_t, uint8_t> Device::get_features()
|
std::map<uint16_t, uint8_t> Device::get_features()
|
||||||
{
|
{
|
||||||
std::map<uint16_t, uint8_t> features;
|
std::map<uint16_t, uint8_t> features;
|
||||||
|
|
||||||
HIDPP20::IFeatureSet ifs (hidpp_dev);
|
HIDPP20::IFeatureSet ifs (hidpp_dev);
|
||||||
|
|
||||||
unsigned int feature_count = ifs.getCount();
|
unsigned int feature_count = ifs.getCount();
|
||||||
|
for(uint8_t i = 1; i <= feature_count; i++)
|
||||||
for(unsigned int i = 1; i <= feature_count; i++)
|
{
|
||||||
features.insert({ifs.getFeatureID(i), i});
|
features.insert({ifs.getFeatureID(i), i});
|
||||||
|
log_printf(DEBUG, "%s: 0x%02x : 0x%04x", name.c_str(), i, ifs.getFeatureID(i));
|
||||||
|
}
|
||||||
|
|
||||||
return features;
|
return features;
|
||||||
}
|
}
|
|
@ -14,6 +14,8 @@ class Device
|
||||||
public:
|
public:
|
||||||
Device(std::string p, const HIDPP::DeviceIndex i);
|
Device(std::string p, const HIDPP::DeviceIndex i);
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
|
||||||
void configure(bool scanning=false);
|
void configure(bool scanning=false);
|
||||||
|
|
||||||
void press_button(uint16_t cid);
|
void press_button(uint16_t cid);
|
||||||
|
@ -41,17 +43,14 @@ public:
|
||||||
class ButtonHandler : public EventHandler
|
class ButtonHandler : public EventHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ButtonHandler (HIDPP20::Device *hidppdev, Device *d):
|
ButtonHandler (HIDPP20::Device *hidppdev, Device *d) : _irc (HIDPP20::IReprogControls::auto_version(hidppdev)), dev (d) { }
|
||||||
_irc4 (hidppdev),
|
|
||||||
dev (d),
|
|
||||||
states (0) {}
|
|
||||||
const HIDPP20::FeatureInterface *feature () const
|
const HIDPP20::FeatureInterface *feature () const
|
||||||
{
|
{
|
||||||
return &_irc4;
|
return &_irc;
|
||||||
}
|
}
|
||||||
void handleEvent (const HIDPP::Report &event);
|
void handleEvent (const HIDPP::Report &event);
|
||||||
protected:
|
protected:
|
||||||
HIDPP20::IReprogControlsV4 _irc4;
|
HIDPP20::IReprogControls _irc;
|
||||||
Device* dev;
|
Device* dev;
|
||||||
std::vector<uint16_t> states;
|
std::vector<uint16_t> states;
|
||||||
std::vector<uint16_t> new_states;
|
std::vector<uint16_t> new_states;
|
||||||
|
|
|
@ -28,7 +28,7 @@ void DeviceFinder::addDevice(const char *path)
|
||||||
std::thread{[=]()
|
std::thread{[=]()
|
||||||
{
|
{
|
||||||
// Check /sys/class/hidraw/hidrawX/device/uevent for device details.
|
// Check /sys/class/hidraw/hidrawX/device/uevent for device details.
|
||||||
// Continue if HIDRAW_NAME contains 'Logitech' or is non-existent/
|
// Continue if HID_NAME contains 'Logitech' or is non-existent
|
||||||
// Otherwise, skip.
|
// Otherwise, skip.
|
||||||
std::string hidraw_name;
|
std::string hidraw_name;
|
||||||
std::size_t spos = string_path.rfind('/');
|
std::size_t spos = string_path.rfind('/');
|
||||||
|
@ -77,7 +77,7 @@ void DeviceFinder::addDevice(const char *path)
|
||||||
std::tie(major, minor) = d.protocolVersion();
|
std::tie(major, minor) = d.protocolVersion();
|
||||||
if(major > 1) // HID++ 2.0 devices only
|
if(major > 1) // HID++ 2.0 devices only
|
||||||
{
|
{
|
||||||
auto dev = new Device(string_path.c_str(), index);
|
auto dev = new Device(string_path, index);
|
||||||
handlers.insert({
|
handlers.insert({
|
||||||
dev, std::async(std::launch::async, &Device::start, *dev)
|
dev, std::async(std::launch::async, &Device::start, *dev)
|
||||||
});
|
});
|
||||||
|
@ -131,7 +131,7 @@ void DeviceFinder::removeDevice(const char* path)
|
||||||
{
|
{
|
||||||
if(it->first->path == path)
|
if(it->first->path == path)
|
||||||
{
|
{
|
||||||
log_printf(INFO, "%s on %s disconnected.", it->first->hidpp_dev->name(), path);
|
log_printf(INFO, "%s on %s disconnected.", it->first->name.c_str(), path);
|
||||||
it->first->stop();
|
it->first->stop();
|
||||||
it->second.wait();
|
it->second.wait();
|
||||||
//handlers.erase(it);
|
//handlers.erase(it);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <hidpp/DispatcherThread.h>
|
#include <hidpp/DispatcherThread.h>
|
||||||
#include <hidpp20/Device.h>
|
#include <hidpp20/Device.h>
|
||||||
#include <hidpp20/Error.h>
|
#include <hidpp20/Error.h>
|
||||||
#include <hidpp20/IReprogControlsV4.h>
|
#include <hidpp20/IReprogControls.h>
|
||||||
#include <hidpp20/UnsupportedFeature.h>
|
#include <hidpp20/UnsupportedFeature.h>
|
||||||
#include <hid/DeviceMonitor.h>
|
#include <hid/DeviceMonitor.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user