forked from sandeepmistry/arduino-BLEPeripheral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BLESystemControl.cpp
63 lines (51 loc) · 2.04 KB
/
BLESystemControl.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
#include "BLESystemControl.h"
static const PROGMEM unsigned char descriptorValue[] = {
// From: https://github.com/adafruit/Adafruit-Trinket-USB/blob/master/TrinketHidCombo/TrinketHidComboC.c
// permission to use under MIT license by @ladyada (https://github.com/adafruit/Adafruit-Trinket-USB/issues/10)
// system controls, like power, needs a 3rd different report and report descriptor
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x80, // USAGE (System Control)
0xA1, 0x01, // COLLECTION (Application)
0x85, 0x00, // REPORT_ID
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x02, // REPORT_SIZE (2)
0x15, 0x01, // LOGICAL_MINIMUM (1)
0x25, 0x03, // LOGICAL_MAXIMUM (3)
0x09, 0x82, // USAGE (System Sleep)
0x09, 0x81, // USAGE (System Power)
0x09, 0x83, // USAGE (System Wakeup)
0x81, 0x60, // INPUT
0x75, 0x06, // REPORT_SIZE (6)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0xC0 // END_COLLECTION
};
BLESystemControl::BLESystemControl() :
BLEHID(descriptorValue, sizeof(descriptorValue), 7),
_reportCharacteristic("2a4d", BLERead | BLENotify, 4),
_reportReferenceDescriptor(BLEHIDDescriptorTypeInput)
{
}
size_t BLESystemControl::write(uint8_t k) {
uint8_t sysCtrlKeyPress[1]= { 0x00 };
// send key code
sysCtrlKeyPress[0] = k;
for (int i = 0; i < 2; i++) {
this->sendData(this->_reportCharacteristic, sysCtrlKeyPress, sizeof(sysCtrlKeyPress));
// send cleared code
sysCtrlKeyPress[0] = 0x00;
}
}
void BLESystemControl::setReportId(unsigned char reportId) {
BLEHID::setReportId(reportId);
this->_reportReferenceDescriptor.setReportId(reportId);
}
unsigned char BLESystemControl::numAttributes() {
return 2;
}
BLELocalAttribute** BLESystemControl::attributes() {
static BLELocalAttribute* attributes[] = {
&this->_reportCharacteristic,
&this->_reportReferenceDescriptor
};
return attributes;
}