From ab44659ce3dba2d6342494915855224619ea8dd8 Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Wed, 1 Jun 2022 08:30:12 +0200 Subject: [PATCH] changed template arg to _Setting --- .../CustomerBufferSize/CustomerBufferSize.ino | 9 +++-- src/BLEMIDI_Settings.h | 8 ++-- src/BLEMIDI_Transport.h | 8 ++-- src/hardware/BLEMIDI_ESP32.h | 2 +- src/hardware/BLEMIDI_ESP32_NimBLE.h | 38 +++++++++---------- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/examples/CustomerBufferSize/CustomerBufferSize.ino b/examples/CustomerBufferSize/CustomerBufferSize.ino index 6f25bb9..dc55071 100644 --- a/examples/CustomerBufferSize/CustomerBufferSize.ino +++ b/examples/CustomerBufferSize/CustomerBufferSize.ino @@ -1,19 +1,20 @@ #include -// struct CustomBufferSizeSettings : public BLEMIDI_NAMESPACE::DefaultSettings { -// static const size_t MaxBufferSize = 16; // was 64 -//}; + struct CustomBufferSizeSettings : public BLEMIDI_NAMESPACE::DefaultSettings { + static const size_t MaxBufferSize = 16; +}; #include //#include //#include //#include -BLEMIDI_CREATE_CUSTOM_INSTANCE("Esp32-NimBLE-MIDI", MIDI, 16); +BLEMIDI_CREATE_CUSTOM_INSTANCE("Esp32-NimBLE-MIDI", MIDI, BLEMIDI_NAMESPACE::DefaultSettings); unsigned long t0 = millis(); bool isConnected = false; + // ----------------------------------------------------------------------------- // When BLE connected, LED will turn on (indication that connection was successful) // When receiving a NoteOn, LED will go out, on NoteOff, light comes back on. diff --git a/src/BLEMIDI_Settings.h b/src/BLEMIDI_Settings.h index 871d683..5463737 100644 --- a/src/BLEMIDI_Settings.h +++ b/src/BLEMIDI_Settings.h @@ -4,9 +4,9 @@ BEGIN_BLEMIDI_NAMESPACE -//struct DefaultSettings -//{ -// static const short MaxBufferSize = 64; -//}; +struct DefaultSettings +{ + static const short MaxBufferSize = 64; +}; END_BLEMIDI_NAMESPACE diff --git a/src/BLEMIDI_Transport.h b/src/BLEMIDI_Transport.h index db75080..bf5b830 100644 --- a/src/BLEMIDI_Transport.h +++ b/src/BLEMIDI_Transport.h @@ -23,14 +23,14 @@ static const char *const CHARACTERISTIC_UUID = "7772e5db-3868-4112-a1a9-f2669d10 #define MIDI_TYPE 0x80 -template +template class BLEMIDI_Transport { private: - byte mRxBuffer[Size]; + byte mRxBuffer[_Settings::MaxBufferSize]; unsigned mRxIndex = 0; - byte mTxBuffer[Size]; // minimum 5 bytes + byte mTxBuffer[_Settings::MaxBufferSize]; // minimum 5 bytes unsigned mTxIndex = 0; char mDeviceName[24]; @@ -57,7 +57,7 @@ public: mBleClass.begin(mDeviceName, this); Serial.print("size : "); - Serial.println(Size); + Serial.println(_Settings::MaxBufferSize); } void end() diff --git a/src/hardware/BLEMIDI_ESP32.h b/src/hardware/BLEMIDI_ESP32.h index 6aba70d..038f4f4 100644 --- a/src/hardware/BLEMIDI_ESP32.h +++ b/src/hardware/BLEMIDI_ESP32.h @@ -129,7 +129,7 @@ bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_TransportsetCallbacks(new MyServerCallbacks(this)); diff --git a/src/hardware/BLEMIDI_ESP32_NimBLE.h b/src/hardware/BLEMIDI_ESP32_NimBLE.h index cedb88f..702114a 100644 --- a/src/hardware/BLEMIDI_ESP32_NimBLE.h +++ b/src/hardware/BLEMIDI_ESP32_NimBLE.h @@ -5,7 +5,7 @@ BEGIN_BLEMIDI_NAMESPACE -template +template class BLEMIDI_ESP32_NimBLE { private: @@ -13,10 +13,10 @@ private: BLEAdvertising *_advertising = nullptr; BLECharacteristic *_characteristic = nullptr; - BLEMIDI_Transport, Size> *_bleMidiTransport = nullptr; + BLEMIDI_Transport, _Settings> *_bleMidiTransport = nullptr; - template friend class MyServerCallbacks; - template friend class MyCharacteristicCallbacks; + template friend class MyServerCallbacks; + template friend class MyCharacteristicCallbacks; protected: QueueHandle_t mRxQueue; @@ -26,7 +26,7 @@ public: { } - bool begin(const char *, BLEMIDI_Transport, Size> *); + bool begin(const char *, BLEMIDI_Transport, _Settings> *); void end() { @@ -70,17 +70,17 @@ protected: } }; -template +template class MyServerCallbacks : public BLEServerCallbacks { public: - MyServerCallbacks(BLEMIDI_ESP32_NimBLE *bluetoothEsp32) + MyServerCallbacks(BLEMIDI_ESP32_NimBLE<_Settings> *bluetoothEsp32) : _bluetoothEsp32(bluetoothEsp32) { } protected: - BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr; + BLEMIDI_ESP32_NimBLE<_Settings> *_bluetoothEsp32 = nullptr; void onConnect(BLEServer *) { @@ -95,17 +95,17 @@ protected: } }; -template +template class MyCharacteristicCallbacks : public BLECharacteristicCallbacks { public: - MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE *bluetoothEsp32) + MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE<_Settings> *bluetoothEsp32) : _bluetoothEsp32(bluetoothEsp32) { } protected: - BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr; + BLEMIDI_ESP32_NimBLE<_Settings> *_bluetoothEsp32 = nullptr; void onWrite(BLECharacteristic *characteristic) { @@ -117,8 +117,8 @@ protected: } }; -template -bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport, Size> *bleMidiTransport) +template +bool BLEMIDI_ESP32_NimBLE<_Settings>::begin(const char *deviceName, BLEMIDI_Transport, _Settings> *bleMidiTransport) { _bleMidiTransport = bleMidiTransport; @@ -126,10 +126,10 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport // To communicate between the 2 cores. // Core_0 runs here, core_1 runs the BLE stack - mRxQueue = xQueueCreate(Size, sizeof(uint8_t)); // TODO DefaultSettings::MaxBufferSize + mRxQueue = xQueueCreate(_Settings::MaxBufferSize, sizeof(uint8_t)); _server = BLEDevice::createServer(); - _server->setCallbacks(new MyServerCallbacks(this)); + _server->setCallbacks(new MyServerCallbacks<_Settings>(this)); _server->advertiseOnDisconnect(true); // Create the BLE Service @@ -143,7 +143,7 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport NIMBLE_PROPERTY::NOTIFY | NIMBLE_PROPERTY::WRITE_NR); - _characteristic->setCallbacks(new MyCharacteristicCallbacks(this)); + _characteristic->setCallbacks(new MyCharacteristicCallbacks<_Settings>(this)); auto _security = new NimBLESecurity(); _security->setAuthenticationMode(ESP_LE_AUTH_BOND); @@ -162,9 +162,9 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport /*! \brief Create an instance for ESP32 named */ -#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, Size) \ - BLEMIDI_NAMESPACE::BLEMIDI_Transport, Size> BLE##Name(DeviceName); \ - MIDI_NAMESPACE::MidiInterface, Size>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport, Size> &)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 */