From e8c03601995ecd8e72ac407e9b304b7380d7cca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vuchener?= Date: Thu, 20 Jul 2017 11:40:00 +0200 Subject: [PATCH] Add event parsers in IReprogControlsV4 --- src/libhidpp/hidpp20/IReprogControlsV4.cpp | 21 +++++++++++++++++++++ src/libhidpp/hidpp20/IReprogControlsV4.h | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/src/libhidpp/hidpp20/IReprogControlsV4.cpp b/src/libhidpp/hidpp20/IReprogControlsV4.cpp index d4367bb..816b28b 100644 --- a/src/libhidpp/hidpp20/IReprogControlsV4.cpp +++ b/src/libhidpp/hidpp20/IReprogControlsV4.cpp @@ -19,6 +19,7 @@ #include "IReprogControlsV4.h" #include +#include using namespace HIDPP20; @@ -70,3 +71,23 @@ void IReprogControlsV4::setControlReporting (uint16_t control_id, uint8_t flags, call (SetControlReporting, params); } +std::vector IReprogControlsV4::divertedButtonEvent (const HIDPP::Report &event) +{ + assert (event.function () == DivertedButtonEvent); + std::vector buttons; + auto params = event.parameterBegin (); + for (unsigned int i = 0; i < 4; ++i) { + uint16_t control_id = readBE (params + 2*i); + if (control_id == 0) + break; + buttons.push_back (control_id); + } + return buttons; +} + +IReprogControlsV4::Move IReprogControlsV4::divertedRawXYEvent (const HIDPP::Report &event) +{ + assert (event.function () == DivertedRawXYEvent); + auto params = event.parameterBegin (); + return Move { readBE (params+0), readBE (params+2) }; +} diff --git a/src/libhidpp/hidpp20/IReprogControlsV4.h b/src/libhidpp/hidpp20/IReprogControlsV4.h index 2ccae47..a5054f5 100644 --- a/src/libhidpp/hidpp20/IReprogControlsV4.h +++ b/src/libhidpp/hidpp20/IReprogControlsV4.h @@ -116,6 +116,14 @@ class IReprogControlsV4: public FeatureInterface * \see ControlReportingFlags. */ void setControlReporting (uint16_t control_id, uint8_t flags, uint16_t remap); + + static std::vector divertedButtonEvent (const HIDPP::Report &event); + + struct Move + { + int16_t x, y; + }; + static Move divertedRawXYEvent (const HIDPP::Report &event); }; }