-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
HIDReporter.cpp
45 lines (39 loc) · 1.37 KB
/
HIDReporter.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
#include "MicroBitConfig.h"
#if CONFIG_ENABLED(DEVICE_BLE)
#include "HIDReporter.h"
#include "HIDService.h"
HIDReporter::HIDReporter(const char *_name, const int _reportSize, const uint8_t *_reportMap, const int _reportMapSize, int _reportIDOffset, int _eventID) :
name(_name),
enabled(false),
reportIndex(-1),
reportID(-1),
report(NULL),
reportSize(_reportSize),
reportIDOffset(_reportIDOffset),
reportMap(_reportMap),
reportMapSize(_reportMapSize),
eventID(_eventID)
{
DEBUG("Name %s ReportSize %d\n", name, reportMapSize);
// Get the instance of the HID service
HIDService *hidService = HIDService::getInstance();
// Add this object
hidService->addReporter(this);
report = hidService->getReportBuffer(reportIndex);
}
void HIDReporter::sendReport() {
//DEBUG("Send Notify %d (size %d)\n", reportIndex, reportSize);
// Get the instance of the HID service
HIDService *hidService = HIDService::getInstance();
// Notify with new data
hidService->notifyChrValue(reportIndex, report, reportSize);
}
void HIDReporter::setStatusChangeHandler(Action action) {
registerWithDal(eventID, HIDService::EVT_STATUS, action);
}
void HIDReporter::setEnabled(bool status) {
DEBUG("%s Setting Enabled %d; id %d\n", name, status, eventID);
enabled = status;
MicroBitEvent(eventID, HIDService::EVT_STATUS);
}
#endif