diff --git a/src/logid/Device.cpp b/src/logid/Device.cpp index 7aa3e11..7867f0b 100644 --- a/src/logid/Device.cpp +++ b/src/logid/Device.cpp @@ -21,6 +21,7 @@ #include "Device.h" #include "features/SmartShift.h" #include "features/RemapButton.h" +#include "backend/hidpp20/features/Reset.h" using namespace logid; using namespace logid::backend; @@ -49,6 +50,9 @@ void Device::_init() _addFeature("smartshift"); _addFeature("remapbutton"); + _makeResetMechanism(); + reset(); + for(auto& feature: _features) { feature.second->configure(); feature.second->listen(); @@ -76,10 +80,22 @@ void Device::wakeup() { logPrintf(INFO, "%s:%d woke up.", _path.c_str(), _index); std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + reset(); + for(auto& feature: _features) feature.second->configure(); } +void Device::reset() +{ + if(_reset_mechanism) + (*_reset_mechanism)(); + else + logPrintf(DEBUG, "%s:%d tried to reset, but no reset mechanism was " + "available.", _path.c_str(), _index); +} + DeviceConfig& Device::config() { return _config; @@ -90,6 +106,17 @@ hidpp20::Device& Device::hidpp20() return _hidpp20; } +void Device::_makeResetMechanism() +{ + try { + hidpp20::Reset reset(&_hidpp20); + _reset_mechanism = std::make_unique>( + [dev=&this->_hidpp20]{ hidpp20::Reset(dev).reset(); }); + } catch(hidpp20::UnsupportedFeature& e) { + // Reset unsupported, ignore. + } +} + DeviceConfig::DeviceConfig(const std::shared_ptr& config, Device* device) : _device (device), _config (config) { diff --git a/src/logid/Device.h b/src/logid/Device.h index ad047f8..c1e7dbc 100644 --- a/src/logid/Device.h +++ b/src/logid/Device.h @@ -62,6 +62,8 @@ namespace logid void wakeup(); void sleep(); + void reset(); + template std::shared_ptr getFeature(std::string name) { auto it = _features.find(name); @@ -96,6 +98,9 @@ namespace logid std::map> _features; DeviceConfig _config; + + void _makeResetMechanism(); + std::unique_ptr> _reset_mechanism; }; }