@@ -174,6 +174,7 @@ BEGIN_BLEMIDI_NAMESPACE
174
174
#define BLEMIDI_CLIENT_SECURITY_AUTH (BLEMIDI_CLIENT_BOND_DUMMY | BLEMIDI_CLIENT_MITM_DUMMY | BLEMIDI_CLIENT_PAIR_DUMMY)
175
175
176
176
/* * Define a class to handle the callbacks when advertisments are received */
177
+ template <class _Settings >
177
178
class AdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks
178
179
{
179
180
public:
@@ -220,6 +221,7 @@ class AdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks
220
221
void scanEndedCB (NimBLEScanResults results);
221
222
222
223
/* * Define the class that performs Client Midi (nimBLE) */
224
+ template <class _Settings >
223
225
class BLEMIDI_Client_ESP32
224
226
{
225
227
private:
@@ -229,15 +231,14 @@ class BLEMIDI_Client_ESP32
229
231
BLERemoteService *pSvc = nullptr ;
230
232
bool firstTimeSend = true ; // First writeValue get sends like Write with reponse for clean security flags. After first time, all messages are send like WriteNoResponse for increase transmision speed.
231
233
232
- BLEMIDI_Transport<class BLEMIDI_Client_ESP32 > *_bleMidiTransport = nullptr ;
234
+ BLEMIDI_Transport<class BLEMIDI_Client_ESP32 <_Settings>, _Settings > *_bleMidiTransport = nullptr ;
233
235
234
236
bool specificTarget = false ;
235
237
236
- friend class AdvertisedDeviceCallbacks ;
237
- friend class MyClientCallbacks ;
238
- friend class MIDI_NAMESPACE ::MidiInterface<BLEMIDI_Transport<BLEMIDI_Client_ESP32>, MySettings>; //
238
+ // TODO: somehow the forward declaration of the template class is not accepted by the compiler
239
+ // template <class> friend MyClientCallbacks;
239
240
240
- AdvertisedDeviceCallbacks myAdvCB;
241
+ AdvertisedDeviceCallbacks<_Settings> myAdvCB;
241
242
242
243
protected:
243
244
QueueHandle_t mRxQueue ;
@@ -247,7 +248,7 @@ class BLEMIDI_Client_ESP32
247
248
{
248
249
}
249
250
250
- bool begin (const char *, BLEMIDI_Transport<class BLEMIDI_Client_ESP32 > *);
251
+ bool begin (const char *, BLEMIDI_Transport<class BLEMIDI_Client_ESP32 <_Settings>, _Settings > *);
251
252
252
253
bool end ()
253
254
{
@@ -294,61 +295,55 @@ class BLEMIDI_Client_ESP32
294
295
_bleMidiTransport->receive (buffer, length);
295
296
}
296
297
297
- void connectCallbacks (MIDI_NAMESPACE::MidiInterface<BLEMIDI_Transport<BLEMIDI_Client_ESP32>, MySettings> *MIDIcallback );
298
+ void notifyCB (NimBLERemoteCharacteristic *pRemoteCharacteristic, uint8_t *pData, size_t length, bool isNotify );
298
299
300
+ void scan ();
301
+ bool connect ();
302
+
303
+ public: // TODO: somehow the forward declaration of the template class is not accepted by the compiler
299
304
void connected ()
300
305
{
301
306
if (_bleMidiTransport->_connectedCallback )
302
- {
303
307
_bleMidiTransport->_connectedCallback ();
304
- }
305
308
firstTimeSend = true ;
306
309
}
307
310
308
311
void disconnected ()
309
312
{
310
313
if (_bleMidiTransport->_disconnectedCallback )
311
- {
312
314
_bleMidiTransport->_disconnectedCallback ();
313
- }
314
315
firstTimeSend = true ;
315
316
}
316
-
317
- void notifyCB (NimBLERemoteCharacteristic *pRemoteCharacteristic, uint8_t *pData, size_t length, bool isNotify);
318
-
319
- void scan ();
320
- bool connect ();
321
317
};
322
318
323
319
/* * Define the class that performs interruption callbacks */
320
+ template <class _Settings >
324
321
class MyClientCallbacks : public BLEClientCallbacks
325
322
{
326
323
public:
327
- MyClientCallbacks (BLEMIDI_Client_ESP32 *bluetoothEsp32)
324
+ MyClientCallbacks (BLEMIDI_Client_ESP32<_Settings> *bluetoothEsp32)
328
325
: _bluetoothEsp32(bluetoothEsp32)
329
326
{
330
327
}
331
328
332
329
protected:
333
- BLEMIDI_Client_ESP32 *_bluetoothEsp32 = nullptr ;
330
+ BLEMIDI_Client_ESP32<_Settings> *_bluetoothEsp32 = nullptr ;
334
331
335
332
uint32_t onPassKeyRequest ()
336
333
{
337
334
return userOnPassKeyRequest ();
338
335
};
339
336
340
- void onConnect (BLEClient *pClient )
337
+ void onConnect (BLEClient* )
341
338
{
342
339
// Serial.println("##Connected##");
343
340
// pClient->updateConnParams(BLEMIDI_CLIENT_COMM_MIN_INTERVAL, BLEMIDI_CLIENT_COMM_MAX_INTERVAL, BLEMIDI_CLIENT_COMM_LATENCY, BLEMIDI_CLIENT_COMM_TIMEOUT);
344
341
vTaskDelay (1 );
345
342
if (_bluetoothEsp32)
346
- {
347
343
_bluetoothEsp32->connected ();
348
- }
349
344
};
350
345
351
- void onDisconnect (BLEClient *pClient )
346
+ void onDisconnect (BLEClient* )
352
347
{
353
348
// Serial.print(pClient->getPeerAddress().toString().c_str());
354
349
// Serial.println(" Disconnected - Starting scan");
@@ -403,7 +398,8 @@ class MyClientCallbacks : public BLEClientCallbacks
403
398
##########################################
404
399
*/
405
400
406
- bool BLEMIDI_Client_ESP32::begin (const char *deviceName, BLEMIDI_Transport<class BLEMIDI_Client_ESP32 > *bleMidiTransport)
401
+ template <class _Settings >
402
+ bool BLEMIDI_Client_ESP32<_Settings>::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_Client_ESP32 <_Settings>, _Settings> *bleMidiTransport)
407
403
{
408
404
_bleMidiTransport = bleMidiTransport;
409
405
@@ -450,7 +446,8 @@ bool BLEMIDI_Client_ESP32::begin(const char *deviceName, BLEMIDI_Transport<class
450
446
return true ;
451
447
}
452
448
453
- bool BLEMIDI_Client_ESP32::available (byte *pvBuffer)
449
+ template <class _Settings >
450
+ bool BLEMIDI_Client_ESP32<_Settings>::available(byte *pvBuffer)
454
451
{
455
452
if (myAdvCB.enableConnection )
456
453
{
@@ -479,15 +476,17 @@ bool BLEMIDI_Client_ESP32::available(byte *pvBuffer)
479
476
}
480
477
481
478
/* * Notification receiving handler callback */
482
- void BLEMIDI_Client_ESP32::notifyCB (NimBLERemoteCharacteristic *pRemoteCharacteristic, uint8_t *pData, size_t length, bool isNotify)
479
+ template <class _Settings >
480
+ void BLEMIDI_Client_ESP32<_Settings>::notifyCB(NimBLERemoteCharacteristic *pRemoteCharacteristic, uint8_t *pData, size_t length, bool isNotify)
483
481
{
484
482
if (this ->_characteristic == pRemoteCharacteristic) // Redundant protection
485
483
{
486
484
receive (pData, length);
487
485
}
488
486
}
489
487
490
- void BLEMIDI_Client_ESP32::scan ()
488
+ template <class _Settings >
489
+ void BLEMIDI_Client_ESP32<_Settings>::scan()
491
490
{
492
491
// Retrieve a Scanner and set the callback you want to use to be informed when a new device is detected.
493
492
// Specify that you want active scanning and start the
@@ -506,7 +505,8 @@ void BLEMIDI_Client_ESP32::scan()
506
505
}
507
506
};
508
507
509
- bool BLEMIDI_Client_ESP32::connect ()
508
+ template <class _Settings >
509
+ bool BLEMIDI_Client_ESP32<_Settings>::connect()
510
510
{
511
511
using namespace std ::placeholders; // <- for bind funtion in callback notification
512
512
@@ -553,7 +553,7 @@ bool BLEMIDI_Client_ESP32::connect()
553
553
// Create and setup a new client
554
554
_client = BLEDevice::createClient ();
555
555
556
- _client->setClientCallbacks (new MyClientCallbacks (this ), false );
556
+ _client->setClientCallbacks (new MyClientCallbacks<_Settings> (this ), false );
557
557
558
558
_client->setConnectionParams (BLEMIDI_CLIENT_COMM_MIN_INTERVAL, BLEMIDI_CLIENT_COMM_MAX_INTERVAL, BLEMIDI_CLIENT_COMM_LATENCY, BLEMIDI_CLIENT_COMM_TIMEOUT);
559
559
@@ -622,7 +622,14 @@ void scanEndedCB(NimBLEScanResults results)
622
622
623
623
END_BLEMIDI_NAMESPACE
624
624
625
- /* ! \brief Create an instance for ESP32 named <DeviceName>, and adviertise it like "Prefix + <DeviceName> + Subfix"
625
+ /* ! \brief Create a custom instance for ESP32 named <DeviceName>, and advertise it like "Prefix + <DeviceName> + Subfix"
626
+ It will try to connect to a specific server with equal name or addr than <DeviceName>. If <DeviceName> is "", it will connect to first midi server
627
+ */
628
+ #define BLEMIDI_CREATE_CUSTOM_INSTANCE (DeviceName, Name, _Settings ) \
629
+ BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_Client_ESP32<_Settings>, _Settings> BLE##Name(DeviceName); \
630
+ MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_Client_ESP32<_Settings>, _Settings>, BLEMIDI_NAMESPACE::MySettings> Name ((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_Client_ESP32<_Settings>, _Settings> &)BLE##Name);
631
+
632
+ /* ! \brief Create an instance for ESP32 named <DeviceName>, and advertise it like "Prefix + <DeviceName> + Subfix"
626
633
It will try to connect to a specific server with equal name or addr than <DeviceName>. If <DeviceName> is "", it will connect to first midi server
627
634
*/
628
635
#define BLEMIDI_CREATE_INSTANCE (DeviceName, Name ) \
0 commit comments