diff --git a/src/logid/CMakeLists.txt b/src/logid/CMakeLists.txt index 2118e6e..27b804f 100644 --- a/src/logid/CMakeLists.txt +++ b/src/logid/CMakeLists.txt @@ -60,6 +60,7 @@ add_executable(logid backend/hidpp20/features/HiresScroll.cpp backend/hidpp20/features/ChangeHost.cpp backend/hidpp20/features/WirelessDeviceStatus.cpp + backend/hidpp20/features/ThumbWheel.cpp backend/dj/Report.cpp util/mutex_queue.h util/workqueue.cpp diff --git a/src/logid/backend/hidpp20/feature_defs.h b/src/logid/backend/hidpp20/feature_defs.h index eb0fc9d..687dcc4 100644 --- a/src/logid/backend/hidpp20/feature_defs.h +++ b/src/logid/backend/hidpp20/feature_defs.h @@ -81,6 +81,7 @@ namespace hidpp20 { HIRES_SCROLLING = 0x2120, HIRES_SCROLLING_V2 = 0x2121, // Referred to as Hi-res wheel in cvuchener/hidpp, seems to be V2? LORES_SCROLLING = 0x2130, + THUMB_WHEEL = 0x2150, MOUSE_POINTER = 0x2200, // Possibly predecessor to 0x2201? ADJUSTABLE_DPI = 0x2201, ANGLE_SNAPPING = 0x2230, diff --git a/src/logid/backend/hidpp20/features/ThumbWheel.cpp b/src/logid/backend/hidpp20/features/ThumbWheel.cpp new file mode 100644 index 0000000..ef9e8d4 --- /dev/null +++ b/src/logid/backend/hidpp20/features/ThumbWheel.cpp @@ -0,0 +1,83 @@ +/* + * 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 +#include "ThumbWheel.h" + +using namespace logid::backend::hidpp20; + +ThumbWheel::ThumbWheel(Device *dev) : Feature(dev, ID) +{ +} + +ThumbWheel::ThumbwheelInfo ThumbWheel::getInfo() +{ + std::vector params(0), response; + ThumbwheelInfo info{}; + response = callFunction(GetInfo, params); + + info.nativeRes = response[1]; + info.nativeRes |= (response[0] << 8); + info.divertedRes = response[3]; + info.divertedRes |= (response[2] << 8); + info.defaultDirection = response[4] ? 1 : -1; /* 1 increment to the right */ + info.capabilities = response[5]; + info.timeElapsed = response[7]; + info.timeElapsed |= response[6] << 8; + + return info; +} + +ThumbWheel::ThumbwheelStatus ThumbWheel::getStatus() +{ + std::vector params(0), response; + ThumbwheelStatus status{}; + response = callFunction(GetStatus, params); + + status.diverted = response[0]; + status.inverted = response[1] & 1; + + return status; +} + +ThumbWheel::ThumbwheelStatus ThumbWheel::setStatus(bool divert, bool invert) +{ + std::vector params(2), response; + ThumbwheelStatus status{}; + params[1] = divert; + params[2] = invert; + + response = callFunction(SetReporting, params); + status.diverted = response[0]; + status.inverted = response[1] & 1; + + return status; +} + +ThumbWheel::ThumbwheelEvent ThumbWheel::thumbwheelEvent(hidpp::Report& report) +{ + assert(report.function() == Event); + ThumbwheelEvent event{}; + event.rotation = report.paramBegin()[1]; + event.rotation |= report.paramBegin()[0] << 8; + event.timestamp = report.paramBegin()[3]; + event.timestamp |= report.paramBegin()[2] << 8; + event.rotationStatus = static_cast(report.paramBegin()[4]); + event.flags = report.paramBegin()[5]; + return event; +} \ No newline at end of file diff --git a/src/logid/backend/hidpp20/features/ThumbWheel.h b/src/logid/backend/hidpp20/features/ThumbWheel.h new file mode 100644 index 0000000..7079f76 --- /dev/null +++ b/src/logid/backend/hidpp20/features/ThumbWheel.h @@ -0,0 +1,93 @@ +/* + * 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_THUMBWHEEL_H +#define LOGID_BACKEND_HIDPP20_FEATURE_THUMBWHEEL_H + +#include "../feature_defs.h" +#include "../Feature.h" + +namespace logid { +namespace backend { +namespace hidpp20 +{ + class ThumbWheel : public Feature + { + public: + static const uint16_t ID = FeatureID::THUMB_WHEEL; + virtual uint16_t getID() { return ID; } + + enum Function { + GetInfo = 0, + GetStatus = 1, + SetReporting = 2 + }; + + enum Event { + Event = 0 /* Catch-all event */ + }; + + explicit ThumbWheel(Device* dev); + + enum Capabilities : uint8_t + { + Timestamp = 1, + Touch = 1<<1, + Proxy = 1<<2, + SingleTap = 1<<3 + }; + + struct ThumbwheelInfo { + uint16_t nativeRes; + uint16_t divertedRes; + int8_t defaultDirection; + uint8_t capabilities; + uint16_t timeElapsed; + }; + + struct ThumbwheelStatus { + bool diverted; + bool inverted; + bool touch; + bool proxy; + }; + + enum RotationStatus : uint8_t + { + Inactive = 0, + Start = 1, + Active = 2, + Stop = 3 + }; + + struct ThumbwheelEvent { + int16_t rotation; + uint16_t timestamp; + RotationStatus rotationStatus; + uint8_t flags; + }; + + ThumbwheelInfo getInfo(); + ThumbwheelStatus getStatus(); + + ThumbwheelStatus setStatus(bool divert, bool invert); + + ThumbwheelEvent thumbwheelEvent(hidpp::Report& report); + }; +}}} + +#endif //LOGID_BACKEND_HIDPP20_FEATURE_THUMBWHEEL_H