Fully implement Root and virutal Feature class

This commit is contained in:
pixl 2020-06-18 02:22:05 -04:00
parent c21a923ab2
commit cc025d3b96
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
4 changed files with 34 additions and 14 deletions

View File

@ -1,13 +1,15 @@
#include "Feature.h"
#include "feature_defs.h"
#include "features/Root.h"
using namespace logid::backend::hidpp20;
const char* Feature::UnsupportedFeature::what() const noexcept
const char* UnsupportedFeature::what() const noexcept
{
return "Unsupported feature";
}
uint16_t Feature::UnsupportedFeature::code() const noexcept
uint16_t UnsupportedFeature::code() const noexcept
{
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);
}
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);
}
}

View File

@ -7,8 +7,6 @@
namespace logid {
namespace backend {
namespace hidpp20 {
class Feature
{
class UnsupportedFeature : public std::exception
{
public:
@ -19,13 +17,14 @@ namespace hidpp20 {
uint16_t _f_id;
};
class Feature
{
public:
static const uint16_t ID;
virtual uint16_t getID() = 0;
protected:
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>& params);
private:

View File

@ -4,22 +4,33 @@ using namespace logid::backend::hidpp20;
Root::Root(Device* dev) : Feature(dev, ID)
{
}
feature_info Root::getFeature(uint16_t feature_id)
{
feature_info info;
feature_info info{};
std::vector<uint8_t> params(2);
params[0] = feature_id & 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];
if(!info.feature_id)
throw UnsupportedFeature(feature_id);
info.hidden = response[1] & FeatureFlag::Hidden;
info.obsolete = response[1] & FeatureFlag::Obsolete;
info.internal = response[1] & FeatureFlag::Internal;
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]);
}

View File

@ -23,7 +23,7 @@ namespace hidpp20
Root(Device* device);
feature_info getFeature (uint16_t feature_id);
void ping();
std::tuple<uint8_t, uint8_t> getVersion();
private:
enum FeatureFlag : uint8_t
{