-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathBleComboMouse.cpp
69 lines (60 loc) · 1.14 KB
/
BleComboMouse.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "BleComboMouse.h"
#define LSB(v) ((v >> 8) & 0xff)
#define MSB(v) (v & 0xff)
void BleComboMouse::click(uint8_t b)
{
_buttons = b;
move(0,0,0,0);
_buttons = 0;
move(0,0,0,0);
}
void BleComboMouse::move(signed char x, signed char y, signed char wheel, signed char hWheel)
{
if (_keyboard->isConnected())
{
uint8_t m[5];
m[0] = _buttons;
m[1] = x;
m[2] = y;
m[3] = wheel;
m[4] = hWheel;
_keyboard->inputRELMouse->setValue(m, 5);
_keyboard->inputRELMouse->notify();
}
}
void BleComboMouse::send(int state, int16_t x, int16_t y)
{
if (_keyboard->isConnected())
{
uint8_t m[5];
m[0] = state;
m[1] = MSB(x);
m[2] = LSB(x);
m[3] = MSB(y);
m[4] = LSB(y);
_keyboard->inputMouse->setValue(m, 5);
_keyboard->inputMouse->notify();
}
}
void BleComboMouse::buttons(uint8_t b)
{
if (b != _buttons)
{
_buttons = b;
move(0,0,0,0);
}
}
void BleComboMouse::press(uint8_t b)
{
buttons(_buttons | b);
}
void BleComboMouse::release(uint8_t b)
{
buttons(_buttons & ~b);
}
bool BleComboMouse::isPressed(uint8_t b)
{
if ((b & _buttons) > 0)
return true;
return false;
}