Add Reprog Controls V3 support

master
PixlOne 5 years ago
parent 9c092edcf3
commit fef5ade956
  1. 4
      README.md
  2. 2
      src/logid/Actions.h
  3. 60
      src/logid/Device.cpp
  4. 11
      src/logid/Device.h
  5. 8
      src/logid/DeviceFinder.cpp
  6. 2
      src/logid/logid.cpp

@ -6,7 +6,7 @@ This is currently only compatible with HID++ \>2.0 devices.
## 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:
@ -24,7 +24,7 @@ Installation is currently not implemented.
| Device | Compatible? |
|:---------:|:-----------:|
| MX Master | Yes |
| T400 | Untested |
| T400 | Yes |
| K400r | Untested |
| K350 | Untested |
| M325c | Untested |

@ -2,7 +2,7 @@
#define LOGIOPS_ACTIONS_H
#include <map>
#include <hidpp20/IReprogControlsV4.h>
#include <hidpp20/IReprogControls.h>
#include "Device.h"
enum class Action

@ -5,11 +5,12 @@
#include <hidpp20/IAdjustableDPI.h>
#include <hidpp20/IFeatureSet.h>
#include <hidpp20/Error.h>
#include <hidpp20/IReprogControlsV4.h>
#include <hidpp20/IReprogControls.h>
#include <hidpp20/Device.h>
#include <hidpp10/Error.h>
#include <algorithm>
#include <cstring>
#include <hidpp20/UnsupportedFeature.h>
#include "Device.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)
{
// Initialise variables
DeviceRemoved = false;
dispatcher = new HIDPP::SimpleDispatcher(path.c_str());
hidpp_dev = new HIDPP20::Device(dispatcher, index);
name = hidpp_dev->name();
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();
}
else config = global_config->devices.find(hidpp_dev->name())->second;
else config = global_config->devices.find(name)->second;
}
void Device::configure(bool scanning)
{
// Set DPI if it is set
if(config->dpi != nullptr)
set_dpi(*config->dpi, scanning);
// Set Smartshift if it is set
if(config->smartshift != nullptr)
set_smartshift(*config->smartshift, scanning);
// Set Hires Scroll if it is set
if(config->hiresscroll != nullptr)
set_hiresscroll(*config->hiresscroll, scanning);
// Divert buttons
divert_buttons();
}
void Device::divert_buttons(bool scanning)
{
HIDPP20::IReprogControlsV4 irc4(hidpp_dev);
for(auto it = config->actions.begin(); it != config->actions.end(); ++it)
try
{
uint8_t flags = 0;
flags |= HIDPP20::IReprogControlsV4::ChangeTemporaryDivert;
flags |= HIDPP20::IReprogControlsV4::TemporaryDiverted;
if(it->second->type == Action::Gestures)
HIDPP20::IReprogControls irc = HIDPP20::IReprogControls::auto_version(hidpp_dev);
for(auto it = config->actions.begin(); it != config->actions.end(); ++it)
{
flags |= HIDPP20::IReprogControlsV4::ChangeRawXYDivert;
flags |= HIDPP20::IReprogControlsV4::RawXYDiverted;
uint8_t flags = 0;
flags |= HIDPP20::IReprogControls::ChangeTemporaryDivert;
flags |= HIDPP20::IReprogControls::TemporaryDiverted;
if(it->second->type == Action::Gestures)
{
flags |= HIDPP20::IReprogControls::ChangeRawXYDivert;
flags |= HIDPP20::IReprogControls::RawXYDiverted;
}
irc.setControlReporting(it->first, flags, it->first);
log_printf(DEBUG, "Diverted 0x%x.", it->first);
}
it->first;
irc4.setControlReporting(it->first, flags, 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()
{
configure();
auto *d = new HIDPP::SimpleDispatcher(path.c_str());
listener = new SimpleListener(d, index);
listener->addEventHandler( std::make_unique<ButtonHandler>(hidpp_dev, this) );
@ -160,9 +174,9 @@ void Device::ButtonHandler::handleEvent (const HIDPP::Report &event)
{
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())
{
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())
{
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;
}
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())
{
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;
}
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> features;
HIDPP20::IFeatureSet ifs (hidpp_dev);
unsigned int feature_count = ifs.getCount();
for(unsigned int i = 1; i <= feature_count; i++)
for(uint8_t i = 1; i <= feature_count; i++)
{
features.insert({ifs.getFeatureID(i), i});
log_printf(DEBUG, "%s: 0x%02x : 0x%04x", name.c_str(), i, ifs.getFeatureID(i));
}
return features;
}

@ -14,6 +14,8 @@ class Device
public:
Device(std::string p, const HIDPP::DeviceIndex i);
std::string name;
void configure(bool scanning=false);
void press_button(uint16_t cid);
@ -41,17 +43,14 @@ public:
class ButtonHandler : public EventHandler
{
public:
ButtonHandler (HIDPP20::Device *hidppdev, Device *d):
_irc4 (hidppdev),
dev (d),
states (0) {}
ButtonHandler (HIDPP20::Device *hidppdev, Device *d) : _irc (HIDPP20::IReprogControls::auto_version(hidppdev)), dev (d) { }
const HIDPP20::FeatureInterface *feature () const
{
return &_irc4;
return &_irc;
}
void handleEvent (const HIDPP::Report &event);
protected:
HIDPP20::IReprogControlsV4 _irc4;
HIDPP20::IReprogControls _irc;
Device* dev;
std::vector<uint16_t> states;
std::vector<uint16_t> new_states;

@ -28,7 +28,7 @@ void DeviceFinder::addDevice(const char *path)
std::thread{[=]()
{
// 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.
std::string hidraw_name;
std::size_t spos = string_path.rfind('/');
@ -77,7 +77,7 @@ void DeviceFinder::addDevice(const char *path)
std::tie(major, minor) = d.protocolVersion();
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({
dev, std::async(std::launch::async, &Device::start, *dev)
});
@ -107,7 +107,7 @@ void DeviceFinder::addDevice(const char *path)
{
if(i == max_tries - 1)
log_printf(WARN, "Device %s (index %d) timed out.", string_path.c_str(), index);
else usleep(try_delay);
else usleep(try_delay);
}
catch(std::runtime_error &e)
{
@ -131,7 +131,7 @@ void DeviceFinder::removeDevice(const char* 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->second.wait();
//handlers.erase(it);

@ -2,7 +2,7 @@
#include <hidpp/DispatcherThread.h>
#include <hidpp20/Device.h>
#include <hidpp20/Error.h>
#include <hidpp20/IReprogControlsV4.h>
#include <hidpp20/IReprogControls.h>
#include <hidpp20/UnsupportedFeature.h>
#include <hid/DeviceMonitor.h>
#include <algorithm>

Loading…
Cancel
Save