forked from sandeepmistry/arduino-BLEPeripheral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBLEHID.cpp
43 lines (34 loc) · 1.04 KB
/
BLEHID.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
#include "BLEHIDPeripheral.h"
#include "BLEHID.h"
unsigned char BLEHID::_numHids = 0;
BLEHID::BLEHID(const unsigned char* descriptor, unsigned char descriptorLength, unsigned char reportIdOffset) :
_reportId(0),
_descriptor(descriptor),
_descriptorLength(descriptorLength),
_reportIdOffset(reportIdOffset)
{
_numHids++;
}
void BLEHID::setReportId(unsigned char reportId) {
this->_reportId = reportId;
}
unsigned char BLEHID::getDescriptorLength() {
return this->_descriptorLength;
}
unsigned char BLEHID::getDescriptorValueAtOffset(unsigned char offset) {
if (offset == this->_reportIdOffset && this->_reportIdOffset) {
return this->_reportId;
} else {
return pgm_read_byte_near(&this->_descriptor[offset]);
}
}
unsigned char BLEHID::numHids() {
return _numHids;
}
void BLEHID::sendData(BLECharacteristic& characteristic, unsigned char data[], unsigned char length) {
// wait until we can notify
while(!characteristic.canNotify()) {
BLEHIDPeripheral::instance()->poll();
}
characteristic.setValue(data, length);
}