forked from lemmingDev/ESP32-BLE-Gamepad
-
Notifications
You must be signed in to change notification settings - Fork 3
/
BleCompositeHID.h
57 lines (44 loc) · 1.5 KB
/
BleCompositeHID.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
#ifndef ESP32_BLE_MULTI_HID_H
#define ESP32_BLE_MULTI_HID_H
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include "nimconfig.h"
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
#include "BleConnectionStatus.h"
#include "NimBLEHIDDevice.h"
#include "NimBLECharacteristic.h"
#include "BLEHostConfiguration.h"
#include "BaseCompositeDevice.h"
#include <vector>
#include "SafeQueue.hpp"
class BleCompositeHID
{
public:
BleCompositeHID(std::string deviceName = "ESP32 BLE Composite HID", std::string deviceManufacturer = "Espressif", uint8_t batteryLevel = 100);
~BleCompositeHID();
void begin();
void begin(const BLEHostConfiguration& config);
void end();
void setBatteryLevel(uint8_t level);
void addDevice(BaseCompositeDevice* device);
bool isConnected();
void queueDeviceDeferredReport(std::function<void()> && reportFunc);
void sendDeferredReports();
uint8_t batteryLevel;
std::string deviceManufacturer;
std::string deviceName;
protected:
virtual void onStarted(NimBLEServer *pServer){};
private:
static void taskServer(void *pvParameter);
static void timedSendDeferredReports(void *pvParameter);
BLEHostConfiguration _configuration;
BleConnectionStatus* _connectionStatus;
NimBLEHIDDevice* _hid;
std::vector<BaseCompositeDevice*> _devices;
SafeQueue<std::function<void()>> _deferredReports;
TaskHandle_t _autoSendTaskHandle;
};
#endif // CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
#endif // CONFIG_BT_ENABLED
#endif // ESP32_BLE_MULTI_HID_H