Implement HID++ 2.0 ThumbWheel (0x2150)

master
pixl 4 years ago
parent 63ecbc411e
commit cce1275385
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
  1. 1
      src/logid/CMakeLists.txt
  2. 1
      src/logid/backend/hidpp20/feature_defs.h
  3. 83
      src/logid/backend/hidpp20/features/ThumbWheel.cpp
  4. 93
      src/logid/backend/hidpp20/features/ThumbWheel.h

@ -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

@ -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,

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#include <cassert>
#include "ThumbWheel.h"
using namespace logid::backend::hidpp20;
ThumbWheel::ThumbWheel(Device *dev) : Feature(dev, ID)
{
}
ThumbWheel::ThumbwheelInfo ThumbWheel::getInfo()
{
std::vector<uint8_t> 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<uint8_t> 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<uint8_t> 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<RotationStatus>(report.paramBegin()[4]);
event.flags = report.paramBegin()[5];
return event;
}

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#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
Loading…
Cancel
Save