-
Notifications
You must be signed in to change notification settings - Fork 5
/
BluetoothMouseService.h
102 lines (78 loc) · 2.17 KB
/
BluetoothMouseService.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef __BLEMOUSE_H__
#define __BLEMOUSE_H__
#include "ble/BLE.h"
#include "ble/GattAttribute.h"
#define BLE_UUID_DESCRIPTOR_REPORT_REFERENCE 0x2908
enum ButtonState
{
BUTTON_UP,
BUTTON_DOWN
};
enum MouseButton
{
MOUSE_BUTTON_LEFT = 0x1,
MOUSE_BUTTON_RIGHT = 0x2,
MOUSE_BUTTON_MIDDLE = 0x4,
};
#define INPUT_REPORT 0x1
#define OUTPUT_REPORT 0x2
#define FEATURE_REPORT 0x3
#define BOOT_PROTOCOL 0x0
#define REPORT_PROTOCOL 0x1
typedef struct
{
uint8_t ID;
uint8_t type;
} report_reference_t;
/**
* A class to communicate a BLE Mouse device
*/
class BluetoothMouseService
{
public:
/**
* Constructor
* @param dev BLE device
*/
BluetoothMouseService(BLEDevice *device);
/**
* Set X, Y, wheel speed of the mouse. Parameters are sticky and will be
* transmitted on every tick. Users should therefore reset them to 0 when
* the device is immobile.
*
* @param x Speed on horizontal axis [-127, 127]
* @param y Speed on vertical axis [-127, 127]
* @param wheel Scroll speed [-127, 127]
*/
void setSpeed(int8_t x, int8_t y, int8_t wheel);
/**
* Toggle the state of one button
*/
void setButton(MouseButton button, ButtonState state);
private:
BLEDevice &ble;
bool connected;
Ticker reportTicker;
bool reportTickerIsActive;
uint8_t protocolMode;
uint8_t controlPointCommand;
uint8_t inputReportData[4];
uint8_t buttonsState;
uint8_t speed[3];
void onConnection(const Gap::ConnectionCallbackParams_t *params);
void onDisconnection(const Gap::DisconnectionCallbackParams_t *params);
GattCharacteristic *protocolModeCharacteristic;
GattCharacteristic *inputReportCharacteristic;
GattCharacteristic *reportMapCharacteristic;
GattCharacteristic *hidInformationCharacteristic;
GattCharacteristic *hidControlPointCharacteristic;
GattAttribute *inputReportReferenceDescriptor;
GattAttribute *inputReportDescriptors[1];
void startReportTicker();
void stopReportTicker();
void onDataSent(unsigned count);
void sendCallback();
void startAdvertise();
void startService();
};
#endif /* __BLEMOUSE_H__ */