Refer to receiver from receiver devices

This commit is contained in:
pixl
2020-07-20 00:25:04 -04:00
parent 1056dfa032
commit 34b8047360
10 changed files with 70 additions and 10 deletions

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,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);
}
}
}

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,