Skip to content

Commit

Permalink
adding addition operator to merge mouse, keyboard and gamepad HID rep…
Browse files Browse the repository at this point in the history
…orts
  • Loading branch information
jpconstantineau committed Apr 20, 2022
1 parent f21579b commit 5e541d4
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/hid_data_structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ struct HIDKeyboard {
uint8_t modifier;
uint8_t keycode[6];

HIDKeyboard operator+(const HIDKeyboard& b) {
HIDKeyboard c;
c.modifier = this->modifier | b.modifier;
int j = 0;
for (int i = 0; i < 5; i++) {
if(this->keycode[i]>0)
{
c.keycode[i] = this->keycode[i];
}
else
{
c.keycode[i] = b.keycode[j];
j++;
}
}
return c;
}

bool operator!= (const HIDKeyboard &c2)
{
return !(*this == c2);
Expand All @@ -41,6 +59,16 @@ struct HIDMouse {
int8_t wheel;
int8_t pan;

HIDMouse operator+(const HIDMouse& b) {
HIDMouse c;
c.buttons = this->buttons | b.buttons;
c.x = this->x+b.x;
c.y = this->y+b.y;
c.wheel = this->wheel + b.wheel;
c.pan = this->pan + b.pan;
return c;
}

bool operator!= (const HIDMouse &c2)
{
return !(*this == c2);
Expand All @@ -60,6 +88,12 @@ struct HIDMouse {
struct HIDConsumer {
uint16_t usage_code;

HIDConsumer operator+(const HIDConsumer& b) {
HIDConsumer c;
c.usage_code = (this->usage_code > b.usage_code)?this->usage_code:b.usage_code;
return c;
}

bool operator!= (const HIDConsumer &c2)
{
return !(*this == c2);
Expand All @@ -80,6 +114,17 @@ struct HIDGamepad {
int8_t rx;
int8_t r;

HIDGamepad operator+(const HIDGamepad& b) {
HIDGamepad c;
c.x = this->x +b.x;
c.y = this->y +b.y;
c.z = this->z +b.z;
c.rx = this->rx+b.rx;
c.r = this->r +b.r;
c.rz = this->rz+b.rz;
return c;
}

bool operator!= (const HIDGamepad &c2)
{
return !(*this == c2);
Expand Down

0 comments on commit 5e541d4

Please sign in to comment.