tmp simplified template arg to int

This commit is contained in:
lathoub 2022-06-01 08:14:45 +02:00
parent 2f9c684140
commit 1ae439d76c
5 changed files with 34 additions and 29 deletions

View File

@ -1,15 +1,15 @@
#include <BLEMIDI_Transport.h> #include <BLEMIDI_Transport.h>
struct CustomBufferSizeSettings : public BLEMIDI_NAMESPACE::DefaultSettings { // struct CustomBufferSizeSettings : public BLEMIDI_NAMESPACE::DefaultSettings {
static const size_t MaxBufferSize = 16; // was 64 // static const size_t MaxBufferSize = 16; // was 64
}; //};
#include <hardware/BLEMIDI_ESP32_NimBLE.h> #include <hardware/BLEMIDI_ESP32_NimBLE.h>
//#include <hardware/BLEMIDI_ESP32.h> //#include <hardware/BLEMIDI_ESP32.h>
//#include <hardware/BLEMIDI_nRF52.h> //#include <hardware/BLEMIDI_nRF52.h>
//#include <hardware/BLEMIDI_ArduinoBLE.h> //#include <hardware/BLEMIDI_ArduinoBLE.h>
BLEMIDI_CREATE_CUSTOM_INSTANCE("Esp32-NimBLE-MIDI", MIDI, BLEMIDI_NAMESPACE::DefaultSettings); BLEMIDI_CREATE_CUSTOM_INSTANCE("Esp32-NimBLE-MIDI", MIDI, 16);
unsigned long t0 = millis(); unsigned long t0 = millis();
bool isConnected = false; bool isConnected = false;

View File

@ -4,9 +4,9 @@
BEGIN_BLEMIDI_NAMESPACE BEGIN_BLEMIDI_NAMESPACE
struct DefaultSettings //struct DefaultSettings
{ //{
static const size_t MaxBufferSize = 64; // static const short MaxBufferSize = 64;
}; //};
END_BLEMIDI_NAMESPACE END_BLEMIDI_NAMESPACE

View File

@ -23,16 +23,14 @@ static const char *const CHARACTERISTIC_UUID = "7772e5db-3868-4112-a1a9-f2669d10
#define MIDI_TYPE 0x80 #define MIDI_TYPE 0x80
template <class T, class _Settings = DefaultSettings> template <class T, int Size = 64>
class BLEMIDI_Transport class BLEMIDI_Transport
{ {
typedef _Settings Settings;
private: private:
byte mRxBuffer[Settings::MaxBufferSize]; byte mRxBuffer[Size];
unsigned mRxIndex = 0; unsigned mRxIndex = 0;
byte mTxBuffer[Settings::MaxBufferSize]; // minimum 5 bytes byte mTxBuffer[Size]; // minimum 5 bytes
unsigned mTxIndex = 0; unsigned mTxIndex = 0;
char mDeviceName[24]; char mDeviceName[24];
@ -57,6 +55,9 @@ public:
void begin() void begin()
{ {
mBleClass.begin(mDeviceName, this); mBleClass.begin(mDeviceName, this);
Serial.print("size : ");
Serial.println(Size);
} }
void end() void end()

View File

@ -66,7 +66,7 @@ private:
static BLEMIDI_Transport<class BLEMIDI_ArduinoBLE, DefaultSettings>* _bleMidiTransport; static BLEMIDI_Transport<class BLEMIDI_ArduinoBLE, DefaultSettings>* _bleMidiTransport;
static BLEDevice* _central; static BLEDevice* _central;
Fifo<byte, 64> mRxBuffer; Fifo<byte, rawSize> mRxBuffer;
public: public:
BLEMIDI_ArduinoBLE() BLEMIDI_ArduinoBLE()

View File

@ -5,6 +5,7 @@
BEGIN_BLEMIDI_NAMESPACE BEGIN_BLEMIDI_NAMESPACE
template <int Size>
class BLEMIDI_ESP32_NimBLE class BLEMIDI_ESP32_NimBLE
{ {
private: private:
@ -12,10 +13,10 @@ private:
BLEAdvertising *_advertising = nullptr; BLEAdvertising *_advertising = nullptr;
BLECharacteristic *_characteristic = nullptr; BLECharacteristic *_characteristic = nullptr;
BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE, DefaultSettings> *_bleMidiTransport = nullptr; BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *_bleMidiTransport = nullptr;
friend class MyServerCallbacks; template <int> friend class MyServerCallbacks;
friend class MyCharacteristicCallbacks; template <int> friend class MyCharacteristicCallbacks;
protected: protected:
QueueHandle_t mRxQueue; QueueHandle_t mRxQueue;
@ -25,7 +26,7 @@ public:
{ {
} }
bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE, DefaultSettings> *); bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *);
void end() void end()
{ {
@ -69,16 +70,17 @@ protected:
} }
}; };
template <int Size>
class MyServerCallbacks : public BLEServerCallbacks class MyServerCallbacks : public BLEServerCallbacks
{ {
public: public:
MyServerCallbacks(BLEMIDI_ESP32_NimBLE *bluetoothEsp32) MyServerCallbacks(BLEMIDI_ESP32_NimBLE<Size> *bluetoothEsp32)
: _bluetoothEsp32(bluetoothEsp32) : _bluetoothEsp32(bluetoothEsp32)
{ {
} }
protected: protected:
BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr; BLEMIDI_ESP32_NimBLE<Size> *_bluetoothEsp32 = nullptr;
void onConnect(BLEServer *) void onConnect(BLEServer *)
{ {
@ -93,16 +95,17 @@ protected:
} }
}; };
template <int Size>
class MyCharacteristicCallbacks : public BLECharacteristicCallbacks class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
{ {
public: public:
MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE *bluetoothEsp32) MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE<Size> *bluetoothEsp32)
: _bluetoothEsp32(bluetoothEsp32) : _bluetoothEsp32(bluetoothEsp32)
{ {
} }
protected: protected:
BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr; BLEMIDI_ESP32_NimBLE<Size> *_bluetoothEsp32 = nullptr;
void onWrite(BLECharacteristic *characteristic) void onWrite(BLECharacteristic *characteristic)
{ {
@ -114,7 +117,8 @@ protected:
} }
}; };
bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE, DefaultSettings> *bleMidiTransport) template <int Size>
bool BLEMIDI_ESP32_NimBLE<Size>::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *bleMidiTransport)
{ {
_bleMidiTransport = bleMidiTransport; _bleMidiTransport = bleMidiTransport;
@ -122,10 +126,10 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class
// To communicate between the 2 cores. // To communicate between the 2 cores.
// Core_0 runs here, core_1 runs the BLE stack // Core_0 runs here, core_1 runs the BLE stack
mRxQueue = xQueueCreate(64, sizeof(uint8_t)); // TODO Settings::MaxBufferSize mRxQueue = xQueueCreate(Size, sizeof(uint8_t)); // TODO DefaultSettings::MaxBufferSize
_server = BLEDevice::createServer(); _server = BLEDevice::createServer();
_server->setCallbacks(new MyServerCallbacks(this)); _server->setCallbacks(new MyServerCallbacks<Size>(this));
_server->advertiseOnDisconnect(true); _server->advertiseOnDisconnect(true);
// Create the BLE Service // Create the BLE Service
@ -139,7 +143,7 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class
NIMBLE_PROPERTY::NOTIFY | NIMBLE_PROPERTY::NOTIFY |
NIMBLE_PROPERTY::WRITE_NR); NIMBLE_PROPERTY::WRITE_NR);
_characteristic->setCallbacks(new MyCharacteristicCallbacks(this)); _characteristic->setCallbacks(new MyCharacteristicCallbacks<Size>(this));
auto _security = new NimBLESecurity(); auto _security = new NimBLESecurity();
_security->setAuthenticationMode(ESP_LE_AUTH_BOND); _security->setAuthenticationMode(ESP_LE_AUTH_BOND);
@ -158,9 +162,9 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class
/*! \brief Create an instance for ESP32 named <DeviceName> /*! \brief Create an instance for ESP32 named <DeviceName>
*/ */
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, CustomSettings) \ #define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, Size) \
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE, CustomSettings> BLE##Name(DeviceName); \ BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE<Size>, Size> BLE##Name(DeviceName); \
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); 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);
/*! \brief Create an instance for ESP32 named <DeviceName> /*! \brief Create an instance for ESP32 named <DeviceName>
*/ */