diff --git a/README.md b/README.md index 0944179..b23021c 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/src/logid/Actions.h b/src/logid/Actions.h index 06f3b1c..b572ba3 100644 --- a/src/logid/Actions.h +++ b/src/logid/Actions.h @@ -2,7 +2,7 @@ #define LOGIOPS_ACTIONS_H #include -#include +#include #include "Device.h" enum class Action diff --git a/src/logid/Device.cpp b/src/logid/Device.cpp index a460672..4e62fe8 100644 --- a/src/logid/Device.cpp +++ b/src/logid/Device.cpp @@ -5,11 +5,12 @@ #include #include #include -#include +#include #include #include #include #include +#include #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(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 Device::get_features() { std::map 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; } \ No newline at end of file diff --git a/src/logid/Device.h b/src/logid/Device.h index 9014620..aed7866 100644 --- a/src/logid/Device.h +++ b/src/logid/Device.h @@ -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 states; std::vector new_states; diff --git a/src/logid/DeviceFinder.cpp b/src/logid/DeviceFinder.cpp index bea9cf6..9bcc720 100644 --- a/src/logid/DeviceFinder.cpp +++ b/src/logid/DeviceFinder.cpp @@ -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); diff --git a/src/logid/logid.cpp b/src/logid/logid.cpp index a7ad129..93dde33 100644 --- a/src/logid/logid.cpp +++ b/src/logid/logid.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include