5
5
6
6
BEGIN_BLEMIDI_NAMESPACE
7
7
8
+ template <int Size>
8
9
class BLEMIDI_ESP32_NimBLE
9
10
{
10
11
private:
11
12
BLEServer *_server = nullptr ;
12
13
BLEAdvertising *_advertising = nullptr ;
13
14
BLECharacteristic *_characteristic = nullptr ;
14
15
15
- BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE , DefaultSettings > *_bleMidiTransport = nullptr ;
16
+ BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE <Size>, Size > *_bleMidiTransport = nullptr ;
16
17
17
- friend class MyServerCallbacks ;
18
- friend class MyCharacteristicCallbacks ;
18
+ template < int > friend class MyServerCallbacks ;
19
+ template < int > friend class MyCharacteristicCallbacks ;
19
20
20
21
protected:
21
22
QueueHandle_t mRxQueue ;
@@ -25,7 +26,7 @@ class BLEMIDI_ESP32_NimBLE
25
26
{
26
27
}
27
28
28
- bool begin (const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE , DefaultSettings > *);
29
+ bool begin (const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE <Size>, Size > *);
29
30
30
31
void end ()
31
32
{
@@ -69,16 +70,17 @@ class BLEMIDI_ESP32_NimBLE
69
70
}
70
71
};
71
72
73
+ template <int Size>
72
74
class MyServerCallbacks : public BLEServerCallbacks
73
75
{
74
76
public:
75
- MyServerCallbacks (BLEMIDI_ESP32_NimBLE *bluetoothEsp32)
77
+ MyServerCallbacks (BLEMIDI_ESP32_NimBLE<Size> *bluetoothEsp32)
76
78
: _bluetoothEsp32(bluetoothEsp32)
77
79
{
78
80
}
79
81
80
82
protected:
81
- BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr ;
83
+ BLEMIDI_ESP32_NimBLE<Size> *_bluetoothEsp32 = nullptr ;
82
84
83
85
void onConnect (BLEServer *)
84
86
{
@@ -93,16 +95,17 @@ class MyServerCallbacks : public BLEServerCallbacks
93
95
}
94
96
};
95
97
98
+ template <int Size>
96
99
class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
97
100
{
98
101
public:
99
- MyCharacteristicCallbacks (BLEMIDI_ESP32_NimBLE *bluetoothEsp32)
102
+ MyCharacteristicCallbacks (BLEMIDI_ESP32_NimBLE<Size> *bluetoothEsp32)
100
103
: _bluetoothEsp32(bluetoothEsp32)
101
104
{
102
105
}
103
106
104
107
protected:
105
- BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr ;
108
+ BLEMIDI_ESP32_NimBLE<Size> *_bluetoothEsp32 = nullptr ;
106
109
107
110
void onWrite (BLECharacteristic *characteristic)
108
111
{
@@ -114,18 +117,19 @@ class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
114
117
}
115
118
};
116
119
117
- bool BLEMIDI_ESP32_NimBLE::begin (const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE , DefaultSettings> *bleMidiTransport)
120
+ template <int Size>
121
+ bool BLEMIDI_ESP32_NimBLE<Size>::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE <Size>, Size> *bleMidiTransport)
118
122
{
119
123
_bleMidiTransport = bleMidiTransport;
120
124
121
125
BLEDevice::init (deviceName);
122
126
123
127
// To communicate between the 2 cores.
124
128
// Core_0 runs here, core_1 runs the BLE stack
125
- mRxQueue = xQueueCreate (64 , sizeof (uint8_t )); // TODO Settings ::MaxBufferSize
129
+ mRxQueue = xQueueCreate (Size , sizeof (uint8_t )); // TODO DefaultSettings ::MaxBufferSize
126
130
127
131
_server = BLEDevice::createServer ();
128
- _server->setCallbacks (new MyServerCallbacks (this ));
132
+ _server->setCallbacks (new MyServerCallbacks<Size> (this ));
129
133
_server->advertiseOnDisconnect (true );
130
134
131
135
// Create the BLE Service
@@ -139,7 +143,7 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class
139
143
NIMBLE_PROPERTY::NOTIFY |
140
144
NIMBLE_PROPERTY::WRITE_NR);
141
145
142
- _characteristic->setCallbacks (new MyCharacteristicCallbacks (this ));
146
+ _characteristic->setCallbacks (new MyCharacteristicCallbacks<Size> (this ));
143
147
144
148
auto _security = new NimBLESecurity ();
145
149
_security->setAuthenticationMode (ESP_LE_AUTH_BOND);
@@ -158,9 +162,9 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class
158
162
159
163
/* ! \brief Create an instance for ESP32 named <DeviceName>
160
164
*/
161
- #define BLEMIDI_CREATE_CUSTOM_INSTANCE (DeviceName, Name, CustomSettings ) \
162
- BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE, CustomSettings > BLE##Name(DeviceName); \
163
- MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE, CustomSettings >, BLEMIDI_NAMESPACE::MySettings> Name ((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE, CustomSettings > &)BLE##Name);
165
+ #define BLEMIDI_CREATE_CUSTOM_INSTANCE (DeviceName, Name, Size ) \
166
+ BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE<Size>, Size > BLE##Name(DeviceName); \
167
+ MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE<Size>, Size >, BLEMIDI_NAMESPACE::MySettings> Name ((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE<Size>, Size > &)BLE##Name);
164
168
165
169
/* ! \brief Create an instance for ESP32 named <DeviceName>
166
170
*/
0 commit comments