diff --git a/src/logid/Device.cpp b/src/logid/Device.cpp index 0338714..c84def2 100644 --- a/src/logid/Device.cpp +++ b/src/logid/Device.cpp @@ -19,6 +19,7 @@ #include "util/log.h" #include "features/DPI.h" #include "Device.h" +#include "Receiver.h" #include "features/SmartShift.h" #include "features/RemapButton.h" #include "backend/hidpp20/features/Reset.h" @@ -30,7 +31,7 @@ using namespace logid::backend; Device::Device(std::string path, backend::hidpp::DeviceIndex index) : _hidpp20 (path, index), _path (std::move(path)), _index (index), - _config (global_config, this) + _config (global_config, this), _receiver (nullptr) { _init(); } @@ -38,7 +39,14 @@ Device::Device(std::string path, backend::hidpp::DeviceIndex index) : Device::Device(const std::shared_ptr& raw_device, hidpp::DeviceIndex index) : _hidpp20(raw_device, index), _path (raw_device->hidrawPath()), _index (index), - _config (global_config, this) + _config (global_config, this), _receiver (nullptr) +{ + _init(); +} + +Device::Device(Receiver* receiver, hidpp::DeviceIndex index) : _hidpp20 + (receiver->rawReceiver(), index), _path (receiver->path()), _index (index), + _config (global_config, this), _receiver (receiver) { _init(); } diff --git a/src/logid/Device.h b/src/logid/Device.h index 8d3238f..f1ddd1f 100644 --- a/src/logid/Device.h +++ b/src/logid/Device.h @@ -28,6 +28,7 @@ namespace logid { class Device; + class Receiver; class DeviceConfig { @@ -51,6 +52,7 @@ namespace logid Device(std::string path, backend::hidpp::DeviceIndex index); Device(const std::shared_ptr& raw_device, backend::hidpp::DeviceIndex index); + Device(Receiver* receiver, backend::hidpp::DeviceIndex index); std::string name(); uint16_t pid(); @@ -97,6 +99,8 @@ namespace logid _features; DeviceConfig _config; + Receiver* _receiver; + void _makeResetMechanism(); std::unique_ptr> _reset_mechanism; }; diff --git a/src/logid/Receiver.cpp b/src/logid/Receiver.cpp index 15595e5..49c053d 100644 --- a/src/logid/Receiver.cpp +++ b/src/logid/Receiver.cpp @@ -63,8 +63,8 @@ void Receiver::addDevice(hidpp::DeviceConnectionEvent event) return; } - std::shared_ptr device = std::make_shared( - receiver()->rawDevice(), event.index); + std::shared_ptr device = std::make_shared(this, + event.index); _devices.emplace(event.index, device); @@ -87,4 +87,14 @@ void Receiver::removeDevice(hidpp::DeviceIndex index) { std::unique_lock lock(_devices_change); _devices.erase(index); +} + +const std::string& Receiver::path() const +{ + return _path; +} + +std::shared_ptr Receiver::rawReceiver() +{ + return receiver(); } \ No newline at end of file diff --git a/src/logid/Receiver.h b/src/logid/Receiver.h index 844a42d..e055008 100644 --- a/src/logid/Receiver.h +++ b/src/logid/Receiver.h @@ -28,8 +28,9 @@ namespace logid class Receiver : public backend::dj::ReceiverMonitor { public: - Receiver(const std::string& path); - + explicit Receiver(const std::string& path); + const std::string& path() const; + std::shared_ptr rawReceiver(); protected: void addDevice(backend::hidpp::DeviceConnectionEvent event) override; void removeDevice(backend::hidpp::DeviceIndex index) override; diff --git a/src/logid/backend/hidpp/Device.cpp b/src/logid/backend/hidpp/Device.cpp index 746487e..cc9db25 100644 --- a/src/logid/backend/hidpp/Device.cpp +++ b/src/logid/backend/hidpp/Device.cpp @@ -65,7 +65,8 @@ Device::Device(std::shared_ptr raw_device, DeviceIndex index) : Device::Device(std::shared_ptr receiver, hidpp::DeviceConnectionEvent event) : - _raw_device (receiver->rawDevice()), _index (event.index) + _raw_device (receiver->rawDevice()), _receiver (receiver), + _path (receiver->rawDevice()->hidrawPath()), _index (event.index) { // Device will throw an error soon, just do it now if(!event.linkEstablished) @@ -78,6 +79,15 @@ Device::Device(std::shared_ptr receiver, _init(); } +Device::Device(std::shared_ptr receiver, + DeviceIndex index) : _raw_device (receiver->rawDevice()), + _receiver (receiver), _path (receiver->rawDevice()->hidrawPath()), + _index (index) +{ + _pid = receiver->getPairingInfo(_index).pid; + _init(); +} + std::string Device::devicePath() const { return _path; @@ -125,7 +135,16 @@ void Device::_init() _name = _raw_device->name(); } } else { - _name = _receiver->getDeviceName(_index); + if(std::get<0>(_version) >= 2) { + try { + hidpp20::EssentialDeviceName deviceName(this); + _name = deviceName.getName(); + } catch(hidpp20::UnsupportedFeature &e) { + _name = _receiver->getDeviceName(_index); + } + } else { + _name = _receiver->getDeviceName(_index); + } } } diff --git a/src/logid/backend/hidpp/Device.h b/src/logid/backend/hidpp/Device.h index f6378a5..612318b 100644 --- a/src/logid/backend/hidpp/Device.h +++ b/src/logid/backend/hidpp/Device.h @@ -62,10 +62,12 @@ namespace hidpp }; explicit Device(const std::string& path, DeviceIndex index); - explicit Device(std::shared_ptr raw_device, + Device(std::shared_ptr raw_device, DeviceIndex index); - explicit Device(std::shared_ptr receiver, + Device(std::shared_ptr receiver, hidpp::DeviceConnectionEvent event); + Device(std::shared_ptr receiver, + DeviceIndex index); ~Device(); std::string devicePath() const; diff --git a/src/logid/backend/hidpp10/Device.cpp b/src/logid/backend/hidpp10/Device.cpp index d35d0d6..c56e407 100644 --- a/src/logid/backend/hidpp10/Device.cpp +++ b/src/logid/backend/hidpp10/Device.cpp @@ -36,6 +36,12 @@ Device::Device(std::shared_ptr raw_dev, assert(version() == std::make_tuple(1, 0)); } +Device::Device(std::shared_ptr receiver, hidpp::DeviceIndex index) + : hidpp::Device(receiver, index) +{ + assert(version() == std::make_tuple(1, 0)); +} + std::vector Device::getRegister(uint8_t address, const std::vector& params, hidpp::Report::Type type) { diff --git a/src/logid/backend/hidpp10/Device.h b/src/logid/backend/hidpp10/Device.h index b7ff479..a86d0e5 100644 --- a/src/logid/backend/hidpp10/Device.h +++ b/src/logid/backend/hidpp10/Device.h @@ -31,6 +31,8 @@ namespace hidpp10 Device(const std::string& path, hidpp::DeviceIndex index); Device(std::shared_ptr raw_dev, hidpp::DeviceIndex index); + Device(std::shared_ptr receiver, + hidpp::DeviceIndex index); std::vector getRegister(uint8_t address, const std::vector& params, hidpp::Report::Type type); diff --git a/src/logid/backend/hidpp20/Device.cpp b/src/logid/backend/hidpp20/Device.cpp index 9d82d25..d32bf41 100644 --- a/src/logid/backend/hidpp20/Device.cpp +++ b/src/logid/backend/hidpp20/Device.cpp @@ -35,6 +35,12 @@ Device::Device(std::shared_ptr raw_device, hidpp::DeviceIndex in assert(std::get<0>(version()) >= 2); } +Device::Device(std::shared_ptr receiver, hidpp::DeviceIndex index) + : hidpp::Device(receiver, index) +{ + assert(std::get<0>(version()) >= 2); +} + std::vector Device::callFunction(uint8_t feature_index, uint8_t function, std::vector& params) { diff --git a/src/logid/backend/hidpp20/Device.h b/src/logid/backend/hidpp20/Device.h index 770cb8f..2628016 100644 --- a/src/logid/backend/hidpp20/Device.h +++ b/src/logid/backend/hidpp20/Device.h @@ -30,6 +30,8 @@ namespace hidpp20 { public: Device(std::string path, hidpp::DeviceIndex index); Device(std::shared_ptr raw_device, hidpp::DeviceIndex index); + Device(std::shared_ptr receiver, hidpp::DeviceIndex + index); std::vector callFunction(uint8_t feature_index, uint8_t function,