Refer to receiver from receiver devices

This commit is contained in:
pixl 2020-07-20 00:25:04 -04:00
parent 1056dfa032
commit 34b8047360
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
10 changed files with 70 additions and 10 deletions

View File

@ -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<backend::raw::RawDevice>& 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();
}

View File

@ -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<backend::raw::RawDevice>& 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<std::function<void()>> _reset_mechanism;
};

View File

@ -63,8 +63,8 @@ void Receiver::addDevice(hidpp::DeviceConnectionEvent event)
return;
}
std::shared_ptr<Device> device = std::make_shared<Device>(
receiver()->rawDevice(), event.index);
std::shared_ptr<Device> device = std::make_shared<Device>(this,
event.index);
_devices.emplace(event.index, device);
@ -88,3 +88,13 @@ void Receiver::removeDevice(hidpp::DeviceIndex index)
std::unique_lock<std::mutex> lock(_devices_change);
_devices.erase(index);
}
const std::string& Receiver::path() const
{
return _path;
}
std::shared_ptr<dj::Receiver> Receiver::rawReceiver()
{
return receiver();
}

View File

@ -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<backend::dj::Receiver> rawReceiver();
protected:
void addDevice(backend::hidpp::DeviceConnectionEvent event) override;
void removeDevice(backend::hidpp::DeviceIndex index) override;

View File

@ -65,7 +65,8 @@ Device::Device(std::shared_ptr<raw::RawDevice> raw_device, DeviceIndex index) :
Device::Device(std::shared_ptr<dj::Receiver> 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<dj::Receiver> receiver,
_init();
}
Device::Device(std::shared_ptr<dj::Receiver> 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,8 +135,17 @@ void Device::_init()
_name = _raw_device->name();
}
} else {
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);
}
}
}
Device::~Device()

View File

@ -62,10 +62,12 @@ namespace hidpp
};
explicit Device(const std::string& path, DeviceIndex index);
explicit Device(std::shared_ptr<raw::RawDevice> raw_device,
Device(std::shared_ptr<raw::RawDevice> raw_device,
DeviceIndex index);
explicit Device(std::shared_ptr<dj::Receiver> receiver,
Device(std::shared_ptr<dj::Receiver> receiver,
hidpp::DeviceConnectionEvent event);
Device(std::shared_ptr<dj::Receiver> receiver,
DeviceIndex index);
~Device();
std::string devicePath() const;

View File

@ -36,6 +36,12 @@ Device::Device(std::shared_ptr<raw::RawDevice> raw_dev,
assert(version() == std::make_tuple(1, 0));
}
Device::Device(std::shared_ptr<dj::Receiver> receiver, hidpp::DeviceIndex index)
: hidpp::Device(receiver, index)
{
assert(version() == std::make_tuple(1, 0));
}
std::vector<uint8_t> Device::getRegister(uint8_t address,
const std::vector<uint8_t>& params, hidpp::Report::Type type)
{

View File

@ -31,6 +31,8 @@ namespace hidpp10
Device(const std::string& path, hidpp::DeviceIndex index);
Device(std::shared_ptr<raw::RawDevice> raw_dev,
hidpp::DeviceIndex index);
Device(std::shared_ptr<dj::Receiver> receiver,
hidpp::DeviceIndex index);
std::vector<uint8_t> getRegister(uint8_t address,
const std::vector<uint8_t>& params, hidpp::Report::Type type);

View File

@ -35,6 +35,12 @@ Device::Device(std::shared_ptr<raw::RawDevice> raw_device, hidpp::DeviceIndex in
assert(std::get<0>(version()) >= 2);
}
Device::Device(std::shared_ptr<dj::Receiver> receiver, hidpp::DeviceIndex index)
: hidpp::Device(receiver, index)
{
assert(std::get<0>(version()) >= 2);
}
std::vector<uint8_t> Device::callFunction(uint8_t feature_index,
uint8_t function, std::vector<uint8_t>& params)
{

View File

@ -30,6 +30,8 @@ namespace hidpp20 {
public:
Device(std::string path, hidpp::DeviceIndex index);
Device(std::shared_ptr<raw::RawDevice> raw_device, hidpp::DeviceIndex index);
Device(std::shared_ptr<dj::Receiver> receiver, hidpp::DeviceIndex
index);
std::vector<uint8_t> callFunction(uint8_t feature_index,
uint8_t function,