Fully implement Root and virutal Feature class
This commit is contained in:
parent
c21a923ab2
commit
cc025d3b96
|
@ -1,13 +1,15 @@
|
||||||
#include "Feature.h"
|
#include "Feature.h"
|
||||||
|
#include "feature_defs.h"
|
||||||
|
#include "features/Root.h"
|
||||||
|
|
||||||
using namespace logid::backend::hidpp20;
|
using namespace logid::backend::hidpp20;
|
||||||
|
|
||||||
const char* Feature::UnsupportedFeature::what() const noexcept
|
const char* UnsupportedFeature::what() const noexcept
|
||||||
{
|
{
|
||||||
return "Unsupported feature";
|
return "Unsupported feature";
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t Feature::UnsupportedFeature::code() const noexcept
|
uint16_t UnsupportedFeature::code() const noexcept
|
||||||
{
|
{
|
||||||
return _f_id;
|
return _f_id;
|
||||||
}
|
}
|
||||||
|
@ -17,12 +19,20 @@ std::vector<uint8_t> Feature::callFunction(uint8_t function_id, std::vector<uint
|
||||||
return _device->callFunction(_index, function_id, params);
|
return _device->callFunction(_index, function_id, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
Feature::Feature(Device* dev, uint16_t _id) : _device (dev), _index (0xff)
|
Feature::Feature(Device* dev, uint16_t _id) : _device (dev)
|
||||||
{
|
{
|
||||||
///TODO: Set index
|
_index = hidpp20::FeatureID::ROOT;
|
||||||
}
|
|
||||||
|
|
||||||
Feature::Feature(Device* dev, uint8_t _index) : _device (dev), _index (_index)
|
if(_id)
|
||||||
{
|
{
|
||||||
|
std::vector<uint8_t> getFunc_req(2);
|
||||||
|
getFunc_req[0] = _id & 0xff;
|
||||||
|
getFunc_req[1] = (_id >> 8) & 0xff;
|
||||||
|
auto getFunc_resp = this->callFunction(Root::GetFeature, getFunc_req);
|
||||||
|
_index = getFunc_resp[0];
|
||||||
|
|
||||||
|
// 0 if not found
|
||||||
|
if(!_index)
|
||||||
|
throw UnsupportedFeature(_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
namespace logid {
|
namespace logid {
|
||||||
namespace backend {
|
namespace backend {
|
||||||
namespace hidpp20 {
|
namespace hidpp20 {
|
||||||
class Feature
|
|
||||||
{
|
|
||||||
class UnsupportedFeature : public std::exception
|
class UnsupportedFeature : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -19,13 +17,14 @@ namespace hidpp20 {
|
||||||
uint16_t _f_id;
|
uint16_t _f_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Feature
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
static const uint16_t ID;
|
static const uint16_t ID;
|
||||||
virtual uint16_t getID() = 0;
|
virtual uint16_t getID() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Feature(Device* dev, uint16_t _id);
|
explicit Feature(Device* dev, uint16_t _id);
|
||||||
explicit Feature(Device* dev, uint8_t _index);
|
|
||||||
std::vector<uint8_t> callFunction(uint8_t function_id,
|
std::vector<uint8_t> callFunction(uint8_t function_id,
|
||||||
std::vector<uint8_t>& params);
|
std::vector<uint8_t>& params);
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -4,22 +4,33 @@ using namespace logid::backend::hidpp20;
|
||||||
|
|
||||||
Root::Root(Device* dev) : Feature(dev, ID)
|
Root::Root(Device* dev) : Feature(dev, ID)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
feature_info Root::getFeature(uint16_t feature_id)
|
feature_info Root::getFeature(uint16_t feature_id)
|
||||||
{
|
{
|
||||||
feature_info info;
|
feature_info info{};
|
||||||
std::vector<uint8_t> params(2);
|
std::vector<uint8_t> params(2);
|
||||||
params[0] = feature_id & 0xff;
|
params[0] = feature_id & 0xff;
|
||||||
params[1] = (feature_id >> 8) & 0xff;
|
params[1] = (feature_id >> 8) & 0xff;
|
||||||
|
|
||||||
auto response = this->callFunction(Function::Ping, params);
|
auto response = this->callFunction(Function::GetFeature, params);
|
||||||
|
|
||||||
info.feature_id = response[0];
|
info.feature_id = response[0];
|
||||||
|
|
||||||
|
if(!info.feature_id)
|
||||||
|
throw UnsupportedFeature(feature_id);
|
||||||
|
|
||||||
info.hidden = response[1] & FeatureFlag::Hidden;
|
info.hidden = response[1] & FeatureFlag::Hidden;
|
||||||
info.obsolete = response[1] & FeatureFlag::Obsolete;
|
info.obsolete = response[1] & FeatureFlag::Obsolete;
|
||||||
info.internal = response[1] & FeatureFlag::Internal;
|
info.internal = response[1] & FeatureFlag::Internal;
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::tuple<uint8_t, uint8_t> Root::getVersion()
|
||||||
|
{
|
||||||
|
std::vector<uint8_t> params(0);
|
||||||
|
auto response = this->callFunction(Function::Ping, params);
|
||||||
|
|
||||||
|
return std::make_tuple(response[0], response[1]);
|
||||||
|
}
|
|
@ -23,7 +23,7 @@ namespace hidpp20
|
||||||
Root(Device* device);
|
Root(Device* device);
|
||||||
|
|
||||||
feature_info getFeature (uint16_t feature_id);
|
feature_info getFeature (uint16_t feature_id);
|
||||||
void ping();
|
std::tuple<uint8_t, uint8_t> getVersion();
|
||||||
private:
|
private:
|
||||||
enum FeatureFlag : uint8_t
|
enum FeatureFlag : uint8_t
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user