diff --git a/src/hardware/BLEMIDI_ArduinoBLE.h b/src/hardware/BLEMIDI_ArduinoBLE.h index 8a6cabc..fd5007b 100644 --- a/src/hardware/BLEMIDI_ArduinoBLE.h +++ b/src/hardware/BLEMIDI_ArduinoBLE.h @@ -60,10 +60,11 @@ private: T raw[rawSize]; }; +template class BLEMIDI_ArduinoBLE { private: - static BLEMIDI_Transport* _bleMidiTransport; + static BLEMIDI_Transport, _Settings>* _bleMidiTransport; static BLEDevice* _central; Fifo mRxBuffer; @@ -73,7 +74,7 @@ public: { } - bool begin(const char*, BLEMIDI_Transport*); + bool begin(const char*, BLEMIDI_Transport, _Settings>*); void end() { @@ -183,10 +184,11 @@ protected: } }; -BLEMIDI_Transport* BLEMIDI_ArduinoBLE::_bleMidiTransport = nullptr; +BLEMIDI_Transport, _Settings>* BLEMIDI_ArduinoBLE::_bleMidiTransport = nullptr; BLEDevice* BLEMIDI_ArduinoBLE::_central = nullptr; -bool BLEMIDI_ArduinoBLE::begin(const char* deviceName, BLEMIDI_Transport* bleMidiTransport) +template +bool BLEMIDI_ArduinoBLE<_Settings>::begin(const char* deviceName, BLEMIDI_Transport, _Settings>* bleMidiTransport) { _bleMidiTransport = bleMidiTransport; @@ -219,9 +221,9 @@ bool BLEMIDI_ArduinoBLE::begin(const char* deviceName, BLEMIDI_Transport */ -#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, CustomSettings) \ -BLEMIDI_NAMESPACE::BLEMIDI_Transport BLE##Name(DeviceName); \ -MIDI_NAMESPACE::MidiInterface, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport &)BLE##Name); +#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, _Settings) \ +BLEMIDI_NAMESPACE::BLEMIDI_Transport, _Settings> BLE##Name(DeviceName); \ +MIDI_NAMESPACE::MidiInterface, _Settings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport, _Settings> &)BLE##Name); /*! \brief Create an instance for nRF52 named */ diff --git a/src/hardware/BLEMIDI_ESP32.h b/src/hardware/BLEMIDI_ESP32.h index 038f4f4..e1898c7 100644 --- a/src/hardware/BLEMIDI_ESP32.h +++ b/src/hardware/BLEMIDI_ESP32.h @@ -8,6 +8,7 @@ BEGIN_BLEMIDI_NAMESPACE +template class BLEMIDI_ESP32 { private: @@ -15,10 +16,10 @@ private: BLEAdvertising *_advertising = nullptr; BLECharacteristic *_characteristic = nullptr; - BLEMIDI_Transport *_bleMidiTransport = nullptr; + BLEMIDI_Transport, _Settings> *_bleMidiTransport = nullptr; - friend class MyServerCallbacks; - friend class MyCharacteristicCallbacks; + template friend class MyServerCallbacks; + template friend class MyCharacteristicCallbacks; protected: QueueHandle_t mRxQueue; @@ -28,7 +29,7 @@ public: { } - bool begin(const char *, BLEMIDI_Transport *); + bool begin(const char *, BLEMIDI_Transport, _Settings> *); void end() { @@ -74,16 +75,17 @@ protected: } }; +template class MyServerCallbacks : public BLEServerCallbacks { public: - MyServerCallbacks(BLEMIDI_ESP32 *bluetoothEsp32) + MyServerCallbacks(BLEMIDI_ESP32<_Settings> *bluetoothEsp32) : _bluetoothEsp32(bluetoothEsp32) { } protected: - BLEMIDI_ESP32 *_bluetoothEsp32 = nullptr; + BLEMIDI_ESP32<_Settings> *_bluetoothEsp32 = nullptr; void onConnect(BLEServer *) { @@ -100,16 +102,17 @@ protected: } }; +template class MyCharacteristicCallbacks : public BLECharacteristicCallbacks { public: - MyCharacteristicCallbacks(BLEMIDI_ESP32 *bluetoothEsp32) + MyCharacteristicCallbacks(BLEMIDI_ESP32<_Settings> *bluetoothEsp32) : _bluetoothEsp32(bluetoothEsp32) { } protected: - BLEMIDI_ESP32 *_bluetoothEsp32 = nullptr; + BLEMIDI_ESP32<_Settings> *_bluetoothEsp32 = nullptr; void onWrite(BLECharacteristic *characteristic) { @@ -121,7 +124,8 @@ protected: } }; -bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_Transport *bleMidiTransport) +template +bool BLEMIDI_ESP32<_Settings>::begin(const char *deviceName, BLEMIDI_Transport, _Settings> *bleMidiTransport) { _bleMidiTransport = bleMidiTransport; @@ -132,7 +136,7 @@ bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_TransportsetCallbacks(new MyServerCallbacks(this)); + _server->setCallbacks(new MyServerCallbacks<_Settings>(this)); // Create the BLE Service auto service = _server->createService(BLEUUID(SERVICE_UUID)); @@ -147,7 +151,7 @@ bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_TransportaddDescriptor(new BLE2902()); - _characteristic->setCallbacks(new MyCharacteristicCallbacks(this)); + _characteristic->setCallbacks(new MyCharacteristicCallbacks<_Settings>(this)); auto _security = new BLESecurity(); _security->setAuthenticationMode(ESP_LE_AUTH_BOND); @@ -166,9 +170,9 @@ bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_Transport */ -#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, CustomSettings) \ - BLEMIDI_NAMESPACE::BLEMIDI_Transport BLE##Name(DeviceName); \ - MIDI_NAMESPACE::MidiInterface, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport &)BLE##Name); +#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, _Settings) \ + BLEMIDI_NAMESPACE::BLEMIDI_Transport, _Settings> BLE##Name(DeviceName); \ + MIDI_NAMESPACE::MidiInterface, _Settings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport, _Settings> &)BLE##Name); /*! \brief Create an instance for ESP32 named */ diff --git a/src/hardware/BLEMIDI_nRF52.h b/src/hardware/BLEMIDI_nRF52.h index 4be4a31..429c7c4 100644 --- a/src/hardware/BLEMIDI_nRF52.h +++ b/src/hardware/BLEMIDI_nRF52.h @@ -6,23 +6,24 @@ BEGIN_BLEMIDI_NAMESPACE +template class BLEMIDI_nRF52 { private: // BLEDis bledis; // BLEMidi blemidi; - BLEMIDI_NAMESPACE::BLEMIDI_Transport* _bleMidiTransport; + BLEMIDI_NAMESPACE::BLEMIDI_Transport, _Settings>* _bleMidiTransport; - friend class MyServerCallbacks; - friend class MyCharacteristicCallbacks; + template friend class MyServerCallbacks; + template friend class MyCharacteristicCallbacks; public: BLEMIDI_nRF52() { } - bool begin(const char*, BLEMIDI_NAMESPACE::BLEMIDI_Transport*); + bool begin(const char*, BLEMIDI_NAMESPACE::BLEMIDI_Transport, _Settings>*); void end() { @@ -61,7 +62,8 @@ protected: } }; -bool BLEMIDI_nRF52::begin(const char* deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Transport* bleMidiTransport) +template +bool BLEMIDI_nRF52<_Settings>::begin(const char* deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Transport, _Settings>* bleMidiTransport) { _bleMidiTransport = bleMidiTransport; @@ -116,9 +118,9 @@ bool BLEMIDI_nRF52::begin(const char* deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Tra /*! \brief Create an instance for nRF52 named */ -#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, CustomSettings) \ -BLEMIDI_NAMESPACE::BLEMIDI_Transport BLE##Name(DeviceName); \ -MIDI_NAMESPACE::MidiInterface, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport &)BLE##Name); +#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, _Settings) \ +BLEMIDI_NAMESPACE::BLEMIDI_Transport, _Settings> BLE##Name(DeviceName); \ +MIDI_NAMESPACE::MidiInterface, _Settings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport, _Settings> &)BLE##Name); /*! \brief Create an instance for nRF52 named */