From cc025d3b967d0e1b32fe71e0af1cc68df448f80e Mon Sep 17 00:00:00 2001 From: pixl Date: Thu, 18 Jun 2020 02:22:05 -0400 Subject: [PATCH] Fully implement Root and virutal Feature class --- src/logid/backend/hidpp20/Feature.cpp | 24 +++++++++++++++------ src/logid/backend/hidpp20/Feature.h | 5 ++--- src/logid/backend/hidpp20/features/Root.cpp | 17 ++++++++++++--- src/logid/backend/hidpp20/features/Root.h | 2 +- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/logid/backend/hidpp20/Feature.cpp b/src/logid/backend/hidpp20/Feature.cpp index 58abb57..90ec9ae 100644 --- a/src/logid/backend/hidpp20/Feature.cpp +++ b/src/logid/backend/hidpp20/Feature.cpp @@ -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 Feature::callFunction(uint8_t function_id, std::vectorcallFunction(_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 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); + } } diff --git a/src/logid/backend/hidpp20/Feature.h b/src/logid/backend/hidpp20/Feature.h index dcea923..8a96602 100644 --- a/src/logid/backend/hidpp20/Feature.h +++ b/src/logid/backend/hidpp20/Feature.h @@ -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 callFunction(uint8_t function_id, std::vector& params); private: diff --git a/src/logid/backend/hidpp20/features/Root.cpp b/src/logid/backend/hidpp20/features/Root.cpp index 8e06874..7f44da8 100644 --- a/src/logid/backend/hidpp20/features/Root.cpp +++ b/src/logid/backend/hidpp20/features/Root.cpp @@ -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 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 Root::getVersion() +{ + std::vector params(0); + auto response = this->callFunction(Function::Ping, params); + + return std::make_tuple(response[0], response[1]); } \ No newline at end of file diff --git a/src/logid/backend/hidpp20/features/Root.h b/src/logid/backend/hidpp20/features/Root.h index 59a41ea..b6f0fb2 100644 --- a/src/logid/backend/hidpp20/features/Root.h +++ b/src/logid/backend/hidpp20/features/Root.h @@ -23,7 +23,7 @@ namespace hidpp20 Root(Device* device); feature_info getFeature (uint16_t feature_id); - void ping(); + std::tuple getVersion(); private: enum FeatureFlag : uint8_t {