Add reset mechanism to logid::Device
This commit is contained in:
parent
5bf5dc75b5
commit
71b0ddd279
|
@ -21,6 +21,7 @@
|
||||||
#include "Device.h"
|
#include "Device.h"
|
||||||
#include "features/SmartShift.h"
|
#include "features/SmartShift.h"
|
||||||
#include "features/RemapButton.h"
|
#include "features/RemapButton.h"
|
||||||
|
#include "backend/hidpp20/features/Reset.h"
|
||||||
|
|
||||||
using namespace logid;
|
using namespace logid;
|
||||||
using namespace logid::backend;
|
using namespace logid::backend;
|
||||||
|
@ -49,6 +50,9 @@ void Device::_init()
|
||||||
_addFeature<features::SmartShift>("smartshift");
|
_addFeature<features::SmartShift>("smartshift");
|
||||||
_addFeature<features::RemapButton>("remapbutton");
|
_addFeature<features::RemapButton>("remapbutton");
|
||||||
|
|
||||||
|
_makeResetMechanism();
|
||||||
|
reset();
|
||||||
|
|
||||||
for(auto& feature: _features) {
|
for(auto& feature: _features) {
|
||||||
feature.second->configure();
|
feature.second->configure();
|
||||||
feature.second->listen();
|
feature.second->listen();
|
||||||
|
@ -76,10 +80,22 @@ void Device::wakeup()
|
||||||
{
|
{
|
||||||
logPrintf(INFO, "%s:%d woke up.", _path.c_str(), _index);
|
logPrintf(INFO, "%s:%d woke up.", _path.c_str(), _index);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
|
||||||
|
reset();
|
||||||
|
|
||||||
for(auto& feature: _features)
|
for(auto& feature: _features)
|
||||||
feature.second->configure();
|
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()
|
DeviceConfig& Device::config()
|
||||||
{
|
{
|
||||||
return _config;
|
return _config;
|
||||||
|
@ -90,6 +106,17 @@ hidpp20::Device& Device::hidpp20()
|
||||||
return _hidpp20;
|
return _hidpp20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::_makeResetMechanism()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
hidpp20::Reset reset(&_hidpp20);
|
||||||
|
_reset_mechanism = std::make_unique<std::function<void()>>(
|
||||||
|
[dev=&this->_hidpp20]{ hidpp20::Reset(dev).reset(); });
|
||||||
|
} catch(hidpp20::UnsupportedFeature& e) {
|
||||||
|
// Reset unsupported, ignore.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DeviceConfig::DeviceConfig(const std::shared_ptr<Configuration>& config, Device*
|
DeviceConfig::DeviceConfig(const std::shared_ptr<Configuration>& config, Device*
|
||||||
device) : _device (device), _config (config)
|
device) : _device (device), _config (config)
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,6 +62,8 @@ namespace logid
|
||||||
void wakeup();
|
void wakeup();
|
||||||
void sleep();
|
void sleep();
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::shared_ptr<T> getFeature(std::string name) {
|
std::shared_ptr<T> getFeature(std::string name) {
|
||||||
auto it = _features.find(name);
|
auto it = _features.find(name);
|
||||||
|
@ -96,6 +98,9 @@ namespace logid
|
||||||
std::map<std::string, std::shared_ptr<features::DeviceFeature>>
|
std::map<std::string, std::shared_ptr<features::DeviceFeature>>
|
||||||
_features;
|
_features;
|
||||||
DeviceConfig _config;
|
DeviceConfig _config;
|
||||||
|
|
||||||
|
void _makeResetMechanism();
|
||||||
|
std::unique_ptr<std::function<void()>> _reset_mechanism;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user