Refer to receiver from receiver devices
This commit is contained in:
parent
1056dfa032
commit
34b8047360
|
@ -19,6 +19,7 @@
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "features/DPI.h"
|
#include "features/DPI.h"
|
||||||
#include "Device.h"
|
#include "Device.h"
|
||||||
|
#include "Receiver.h"
|
||||||
#include "features/SmartShift.h"
|
#include "features/SmartShift.h"
|
||||||
#include "features/RemapButton.h"
|
#include "features/RemapButton.h"
|
||||||
#include "backend/hidpp20/features/Reset.h"
|
#include "backend/hidpp20/features/Reset.h"
|
||||||
|
@ -30,7 +31,7 @@ using namespace logid::backend;
|
||||||
|
|
||||||
Device::Device(std::string path, backend::hidpp::DeviceIndex index) :
|
Device::Device(std::string path, backend::hidpp::DeviceIndex index) :
|
||||||
_hidpp20 (path, index), _path (std::move(path)), _index (index),
|
_hidpp20 (path, index), _path (std::move(path)), _index (index),
|
||||||
_config (global_config, this)
|
_config (global_config, this), _receiver (nullptr)
|
||||||
{
|
{
|
||||||
_init();
|
_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,
|
Device::Device(const std::shared_ptr<backend::raw::RawDevice>& raw_device,
|
||||||
hidpp::DeviceIndex index) : _hidpp20(raw_device, index), _path
|
hidpp::DeviceIndex index) : _hidpp20(raw_device, index), _path
|
||||||
(raw_device->hidrawPath()), _index (index),
|
(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();
|
_init();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
namespace logid
|
namespace logid
|
||||||
{
|
{
|
||||||
class Device;
|
class Device;
|
||||||
|
class Receiver;
|
||||||
|
|
||||||
class DeviceConfig
|
class DeviceConfig
|
||||||
{
|
{
|
||||||
|
@ -51,6 +52,7 @@ namespace logid
|
||||||
Device(std::string path, backend::hidpp::DeviceIndex index);
|
Device(std::string path, backend::hidpp::DeviceIndex index);
|
||||||
Device(const std::shared_ptr<backend::raw::RawDevice>& raw_device,
|
Device(const std::shared_ptr<backend::raw::RawDevice>& raw_device,
|
||||||
backend::hidpp::DeviceIndex index);
|
backend::hidpp::DeviceIndex index);
|
||||||
|
Device(Receiver* receiver, backend::hidpp::DeviceIndex index);
|
||||||
|
|
||||||
std::string name();
|
std::string name();
|
||||||
uint16_t pid();
|
uint16_t pid();
|
||||||
|
@ -97,6 +99,8 @@ namespace logid
|
||||||
_features;
|
_features;
|
||||||
DeviceConfig _config;
|
DeviceConfig _config;
|
||||||
|
|
||||||
|
Receiver* _receiver;
|
||||||
|
|
||||||
void _makeResetMechanism();
|
void _makeResetMechanism();
|
||||||
std::unique_ptr<std::function<void()>> _reset_mechanism;
|
std::unique_ptr<std::function<void()>> _reset_mechanism;
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,8 +63,8 @@ void Receiver::addDevice(hidpp::DeviceConnectionEvent event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Device> device = std::make_shared<Device>(
|
std::shared_ptr<Device> device = std::make_shared<Device>(this,
|
||||||
receiver()->rawDevice(), event.index);
|
event.index);
|
||||||
|
|
||||||
_devices.emplace(event.index, device);
|
_devices.emplace(event.index, device);
|
||||||
|
|
||||||
|
@ -87,4 +87,14 @@ void Receiver::removeDevice(hidpp::DeviceIndex index)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(_devices_change);
|
std::unique_lock<std::mutex> lock(_devices_change);
|
||||||
_devices.erase(index);
|
_devices.erase(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& Receiver::path() const
|
||||||
|
{
|
||||||
|
return _path;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<dj::Receiver> Receiver::rawReceiver()
|
||||||
|
{
|
||||||
|
return receiver();
|
||||||
}
|
}
|
|
@ -28,8 +28,9 @@ namespace logid
|
||||||
class Receiver : public backend::dj::ReceiverMonitor
|
class Receiver : public backend::dj::ReceiverMonitor
|
||||||
{
|
{
|
||||||
public:
|
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:
|
protected:
|
||||||
void addDevice(backend::hidpp::DeviceConnectionEvent event) override;
|
void addDevice(backend::hidpp::DeviceConnectionEvent event) override;
|
||||||
void removeDevice(backend::hidpp::DeviceIndex index) override;
|
void removeDevice(backend::hidpp::DeviceIndex index) override;
|
||||||
|
|
|
@ -65,7 +65,8 @@ Device::Device(std::shared_ptr<raw::RawDevice> raw_device, DeviceIndex index) :
|
||||||
|
|
||||||
Device::Device(std::shared_ptr<dj::Receiver> receiver,
|
Device::Device(std::shared_ptr<dj::Receiver> receiver,
|
||||||
hidpp::DeviceConnectionEvent event) :
|
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
|
// Device will throw an error soon, just do it now
|
||||||
if(!event.linkEstablished)
|
if(!event.linkEstablished)
|
||||||
|
@ -78,6 +79,15 @@ Device::Device(std::shared_ptr<dj::Receiver> receiver,
|
||||||
_init();
|
_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
|
std::string Device::devicePath() const
|
||||||
{
|
{
|
||||||
return _path;
|
return _path;
|
||||||
|
@ -125,7 +135,16 @@ void Device::_init()
|
||||||
_name = _raw_device->name();
|
_name = _raw_device->name();
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,10 +62,12 @@ namespace hidpp
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit Device(const std::string& path, DeviceIndex index);
|
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);
|
DeviceIndex index);
|
||||||
explicit Device(std::shared_ptr<dj::Receiver> receiver,
|
Device(std::shared_ptr<dj::Receiver> receiver,
|
||||||
hidpp::DeviceConnectionEvent event);
|
hidpp::DeviceConnectionEvent event);
|
||||||
|
Device(std::shared_ptr<dj::Receiver> receiver,
|
||||||
|
DeviceIndex index);
|
||||||
~Device();
|
~Device();
|
||||||
|
|
||||||
std::string devicePath() const;
|
std::string devicePath() const;
|
||||||
|
|
|
@ -36,6 +36,12 @@ Device::Device(std::shared_ptr<raw::RawDevice> raw_dev,
|
||||||
assert(version() == std::make_tuple(1, 0));
|
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,
|
std::vector<uint8_t> Device::getRegister(uint8_t address,
|
||||||
const std::vector<uint8_t>& params, hidpp::Report::Type type)
|
const std::vector<uint8_t>& params, hidpp::Report::Type type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,8 @@ namespace hidpp10
|
||||||
Device(const std::string& path, hidpp::DeviceIndex index);
|
Device(const std::string& path, hidpp::DeviceIndex index);
|
||||||
Device(std::shared_ptr<raw::RawDevice> raw_dev,
|
Device(std::shared_ptr<raw::RawDevice> raw_dev,
|
||||||
hidpp::DeviceIndex index);
|
hidpp::DeviceIndex index);
|
||||||
|
Device(std::shared_ptr<dj::Receiver> receiver,
|
||||||
|
hidpp::DeviceIndex index);
|
||||||
|
|
||||||
std::vector<uint8_t> getRegister(uint8_t address,
|
std::vector<uint8_t> getRegister(uint8_t address,
|
||||||
const std::vector<uint8_t>& params, hidpp::Report::Type type);
|
const std::vector<uint8_t>& params, hidpp::Report::Type type);
|
||||||
|
|
|
@ -35,6 +35,12 @@ Device::Device(std::shared_ptr<raw::RawDevice> raw_device, hidpp::DeviceIndex in
|
||||||
assert(std::get<0>(version()) >= 2);
|
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,
|
std::vector<uint8_t> Device::callFunction(uint8_t feature_index,
|
||||||
uint8_t function, std::vector<uint8_t>& params)
|
uint8_t function, std::vector<uint8_t>& params)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,6 +30,8 @@ namespace hidpp20 {
|
||||||
public:
|
public:
|
||||||
Device(std::string path, hidpp::DeviceIndex index);
|
Device(std::string path, hidpp::DeviceIndex index);
|
||||||
Device(std::shared_ptr<raw::RawDevice> raw_device, 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,
|
std::vector<uint8_t> callFunction(uint8_t feature_index,
|
||||||
uint8_t function,
|
uint8_t function,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user