diff --git a/src/logid/CMakeLists.txt b/src/logid/CMakeLists.txt index a51ed2b..043f859 100644 --- a/src/logid/CMakeLists.txt +++ b/src/logid/CMakeLists.txt @@ -29,6 +29,7 @@ add_executable(logid backend/hidpp20/Feature.cpp backend/hidpp20/EssentialFeature.cpp backend/hidpp20/features/Root.cpp + backend/hidpp20/features/FeatureSet.cpp backend/hidpp20/features/DeviceName.cpp backend/dj/Report.cpp util/mutex_queue.h) diff --git a/src/logid/backend/hidpp20/Feature.cpp b/src/logid/backend/hidpp20/Feature.cpp index bfcfeb7..5f32bbb 100644 --- a/src/logid/backend/hidpp20/Feature.cpp +++ b/src/logid/backend/hidpp20/Feature.cpp @@ -44,8 +44,8 @@ Feature::Feature(Device* dev, uint16_t _id) : _device (dev) if(_id) { std::vector getFunc_req(2); - getFunc_req[0] = _id & 0xff; - getFunc_req[1] = (_id >> 8) & 0xff; + getFunc_req[0] = (_id >> 8) & 0xff; + getFunc_req[1] = _id & 0xff; auto getFunc_resp = this->callFunction(Root::GetFeature, getFunc_req); _index = getFunc_resp[0]; diff --git a/src/logid/backend/hidpp20/features/FeatureSet.cpp b/src/logid/backend/hidpp20/features/FeatureSet.cpp new file mode 100644 index 0000000..092b809 --- /dev/null +++ b/src/logid/backend/hidpp20/features/FeatureSet.cpp @@ -0,0 +1,51 @@ +/* + * Copyright 2019-2020 PixlOne + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#include "FeatureSet.h" + +using namespace logid::backend::hidpp20; + +FeatureSet::FeatureSet(Device *device) : Feature(device, ID) +{ +} + +uint8_t FeatureSet::getFeatureCount() +{ + std::vector params(0); + auto response = callFunction(GetFeatureCount, params); + return response[0]; +} + +uint16_t FeatureSet::getFeature(uint8_t feature_index) +{ + std::vector params(1); + params[0] = feature_index; + auto response = callFunction(GetFeature, params); + + uint16_t feature_id = (response[0] << 8); + feature_id |= response[1]; + return feature_id; +} + +std::map FeatureSet::getFeatures() +{ + uint8_t feature_count = getFeatureCount(); + std::map features; + for(uint8_t i = 0; i < feature_count; i++) + features[i] = getFeature(i); + return features; +} \ No newline at end of file diff --git a/src/logid/backend/hidpp20/features/FeatureSet.h b/src/logid/backend/hidpp20/features/FeatureSet.h new file mode 100644 index 0000000..27a814e --- /dev/null +++ b/src/logid/backend/hidpp20/features/FeatureSet.h @@ -0,0 +1,48 @@ +/* + * Copyright 2019-2020 PixlOne + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#ifndef LOGID_BACKEND_HIDPP20_FEATURE_FEATURESET_H +#define LOGID_BACKEND_HIDPP20_FEATURE_FEATURESET_H + +#include "../Feature.h" +#include "../feature_defs.h" + +namespace logid { +namespace backend { +namespace hidpp20 +{ + class FeatureSet : public Feature + { + public: + static const uint16_t ID = FeatureID::FEATURE_SET; + virtual uint16_t getID() { return ID; } + + enum Function : uint8_t + { + GetFeatureCount = 0, + GetFeature = 1 + }; + + explicit FeatureSet(Device* device); + + uint8_t getFeatureCount(); + uint16_t getFeature(uint8_t feature_index); + std::map getFeatures(); + }; +}}} + +#endif //LOGID_BACKEND_HIDPP20_FEATURE_FEATURESET_H