Skip to content

Commit

Permalink
Add event parsers in IReprogControlsV4
Browse files Browse the repository at this point in the history
cvuchener committed Jul 20, 2017
1 parent cc40c2d commit e8c0360
Showing 2 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/libhidpp/hidpp20/IReprogControlsV4.cpp
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
#include "IReprogControlsV4.h"

#include <misc/Endian.h>
#include <cassert>

using namespace HIDPP20;

@@ -70,3 +71,23 @@ void IReprogControlsV4::setControlReporting (uint16_t control_id, uint8_t flags,
call (SetControlReporting, params);
}

std::vector<uint16_t> IReprogControlsV4::divertedButtonEvent (const HIDPP::Report &event)
{
assert (event.function () == DivertedButtonEvent);
std::vector<uint16_t> buttons;
auto params = event.parameterBegin ();
for (unsigned int i = 0; i < 4; ++i) {
uint16_t control_id = readBE<uint16_t> (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<int16_t> (params+0), readBE<int16_t> (params+2) };
}
8 changes: 8 additions & 0 deletions src/libhidpp/hidpp20/IReprogControlsV4.h
Original file line number Diff line number Diff line change
@@ -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<uint16_t> divertedButtonEvent (const HIDPP::Report &event);

struct Move
{
int16_t x, y;
};
static Move divertedRawXYEvent (const HIDPP::Report &event);
};

}

0 comments on commit e8c0360

Please sign in to comment.