diff --git a/examples/CustomerBufferSize/CustomerBufferSize.ino b/examples/CustomerBufferSize/CustomerBufferSize.ino index 5d86f67..6f25bb9 100644 --- a/examples/CustomerBufferSize/CustomerBufferSize.ino +++ b/examples/CustomerBufferSize/CustomerBufferSize.ino @@ -1,15 +1,15 @@ #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; // was 64 +//}; #include //#include //#include //#include -BLEMIDI_CREATE_CUSTOM_INSTANCE("Esp32-NimBLE-MIDI", MIDI, BLEMIDI_NAMESPACE::DefaultSettings); +BLEMIDI_CREATE_CUSTOM_INSTANCE("Esp32-NimBLE-MIDI", MIDI, 16); unsigned long t0 = millis(); bool isConnected = false; diff --git a/src/BLEMIDI_Settings.h b/src/BLEMIDI_Settings.h index f4c8b5a..871d683 100644 --- a/src/BLEMIDI_Settings.h +++ b/src/BLEMIDI_Settings.h @@ -4,9 +4,9 @@ BEGIN_BLEMIDI_NAMESPACE -struct DefaultSettings -{ - static const size_t 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 45b028a..db75080 100644 --- a/src/BLEMIDI_Transport.h +++ b/src/BLEMIDI_Transport.h @@ -23,16 +23,14 @@ static const char *const CHARACTERISTIC_UUID = "7772e5db-3868-4112-a1a9-f2669d10 #define MIDI_TYPE 0x80 -template +template class BLEMIDI_Transport { - typedef _Settings Settings; - private: - byte mRxBuffer[Settings::MaxBufferSize]; + byte mRxBuffer[Size]; unsigned mRxIndex = 0; - byte mTxBuffer[Settings::MaxBufferSize]; // minimum 5 bytes + byte mTxBuffer[Size]; // minimum 5 bytes unsigned mTxIndex = 0; char mDeviceName[24]; @@ -57,6 +55,9 @@ public: void begin() { mBleClass.begin(mDeviceName, this); + + Serial.print("size : "); + Serial.println(Size); } void end() diff --git a/src/hardware/BLEMIDI_ArduinoBLE.h b/src/hardware/BLEMIDI_ArduinoBLE.h index 4044c60..8a6cabc 100644 --- a/src/hardware/BLEMIDI_ArduinoBLE.h +++ b/src/hardware/BLEMIDI_ArduinoBLE.h @@ -66,7 +66,7 @@ private: static BLEMIDI_Transport* _bleMidiTransport; static BLEDevice* _central; - Fifo mRxBuffer; + Fifo mRxBuffer; public: BLEMIDI_ArduinoBLE() diff --git a/src/hardware/BLEMIDI_ESP32_NimBLE.h b/src/hardware/BLEMIDI_ESP32_NimBLE.h index 4684250..cedb88f 100644 --- a/src/hardware/BLEMIDI_ESP32_NimBLE.h +++ b/src/hardware/BLEMIDI_ESP32_NimBLE.h @@ -5,6 +5,7 @@ BEGIN_BLEMIDI_NAMESPACE +template class BLEMIDI_ESP32_NimBLE { private: @@ -12,10 +13,10 @@ private: BLEAdvertising *_advertising = nullptr; BLECharacteristic *_characteristic = nullptr; - BLEMIDI_Transport *_bleMidiTransport = nullptr; + BLEMIDI_Transport, Size> *_bleMidiTransport = nullptr; - friend class MyServerCallbacks; - friend class MyCharacteristicCallbacks; + template friend class MyServerCallbacks; + template friend class MyCharacteristicCallbacks; protected: QueueHandle_t mRxQueue; @@ -25,7 +26,7 @@ public: { } - bool begin(const char *, BLEMIDI_Transport *); + bool begin(const char *, BLEMIDI_Transport, Size> *); void end() { @@ -69,16 +70,17 @@ protected: } }; +template class MyServerCallbacks : public BLEServerCallbacks { public: - MyServerCallbacks(BLEMIDI_ESP32_NimBLE *bluetoothEsp32) + MyServerCallbacks(BLEMIDI_ESP32_NimBLE *bluetoothEsp32) : _bluetoothEsp32(bluetoothEsp32) { } protected: - BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr; + BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr; void onConnect(BLEServer *) { @@ -93,16 +95,17 @@ protected: } }; +template class MyCharacteristicCallbacks : public BLECharacteristicCallbacks { public: - MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE *bluetoothEsp32) + MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE *bluetoothEsp32) : _bluetoothEsp32(bluetoothEsp32) { } protected: - BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr; + BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr; void onWrite(BLECharacteristic *characteristic) { @@ -114,7 +117,8 @@ protected: } }; -bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport *bleMidiTransport) +template +bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport, Size> *bleMidiTransport) { _bleMidiTransport = bleMidiTransport; @@ -122,10 +126,10 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_TransportsetCallbacks(new MyServerCallbacks(this)); + _server->setCallbacks(new MyServerCallbacks(this)); _server->advertiseOnDisconnect(true); // Create the BLE Service @@ -139,7 +143,7 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_TransportsetCallbacks(new MyCharacteristicCallbacks(this)); + _characteristic->setCallbacks(new MyCharacteristicCallbacks(this)); auto _security = new NimBLESecurity(); _security->setAuthenticationMode(ESP_LE_AUTH_BOND); @@ -158,9 +162,9 @@ bool BLEMIDI_ESP32_NimBLE::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, Size) \ + BLEMIDI_NAMESPACE::BLEMIDI_Transport, Size> BLE##Name(DeviceName); \ + MIDI_NAMESPACE::MidiInterface, Size>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport, Size> &)BLE##Name); /*! \brief Create an instance for ESP32 named */