changed template arg to _Setting
This commit is contained in:
parent
1ae439d76c
commit
ab44659ce3
|
|
@ -1,19 +1,20 @@
|
|||
#include <BLEMIDI_Transport.h>
|
||||
|
||||
// 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 <hardware/BLEMIDI_ESP32_NimBLE.h>
|
||||
//#include <hardware/BLEMIDI_ESP32.h>
|
||||
//#include <hardware/BLEMIDI_nRF52.h>
|
||||
//#include <hardware/BLEMIDI_ArduinoBLE.h>
|
||||
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
BEGIN_BLEMIDI_NAMESPACE
|
||||
|
||||
//struct DefaultSettings
|
||||
//{
|
||||
// static const short MaxBufferSize = 64;
|
||||
//};
|
||||
struct DefaultSettings
|
||||
{
|
||||
static const short MaxBufferSize = 64;
|
||||
};
|
||||
|
||||
END_BLEMIDI_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ static const char *const CHARACTERISTIC_UUID = "7772e5db-3868-4112-a1a9-f2669d10
|
|||
|
||||
#define MIDI_TYPE 0x80
|
||||
|
||||
template <class T, int Size = 64>
|
||||
template <class T, class _Settings = DefaultSettings>
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_Transport<class BLEMID
|
|||
|
||||
// To communicate between the 2 cores.
|
||||
// Core_0 runs here, core_1 runs the BLE stack
|
||||
mRxQueue = xQueueCreate(64, sizeof(uint8_t)); // TODO Settings::MaxBufferSize
|
||||
mRxQueue = xQueueCreate(_Settings::MaxBufferSize, sizeof(uint8_t));
|
||||
|
||||
_server = BLEDevice::createServer();
|
||||
_server->setCallbacks(new MyServerCallbacks(this));
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
BEGIN_BLEMIDI_NAMESPACE
|
||||
|
||||
template <int Size>
|
||||
template <class _Settings>
|
||||
class BLEMIDI_ESP32_NimBLE
|
||||
{
|
||||
private:
|
||||
|
|
@ -13,10 +13,10 @@ private:
|
|||
BLEAdvertising *_advertising = nullptr;
|
||||
BLECharacteristic *_characteristic = nullptr;
|
||||
|
||||
BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *_bleMidiTransport = nullptr;
|
||||
BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<_Settings>, _Settings> *_bleMidiTransport = nullptr;
|
||||
|
||||
template <int> friend class MyServerCallbacks;
|
||||
template <int> friend class MyCharacteristicCallbacks;
|
||||
template <class> friend class MyServerCallbacks;
|
||||
template <class> friend class MyCharacteristicCallbacks;
|
||||
|
||||
protected:
|
||||
QueueHandle_t mRxQueue;
|
||||
|
|
@ -26,7 +26,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *);
|
||||
bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<_Settings>, _Settings> *);
|
||||
|
||||
void end()
|
||||
{
|
||||
|
|
@ -70,17 +70,17 @@ protected:
|
|||
}
|
||||
};
|
||||
|
||||
template <int Size>
|
||||
template <class _Settings>
|
||||
class MyServerCallbacks : public BLEServerCallbacks
|
||||
{
|
||||
public:
|
||||
MyServerCallbacks(BLEMIDI_ESP32_NimBLE<Size> *bluetoothEsp32)
|
||||
MyServerCallbacks(BLEMIDI_ESP32_NimBLE<_Settings> *bluetoothEsp32)
|
||||
: _bluetoothEsp32(bluetoothEsp32)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
BLEMIDI_ESP32_NimBLE<Size> *_bluetoothEsp32 = nullptr;
|
||||
BLEMIDI_ESP32_NimBLE<_Settings> *_bluetoothEsp32 = nullptr;
|
||||
|
||||
void onConnect(BLEServer *)
|
||||
{
|
||||
|
|
@ -95,17 +95,17 @@ protected:
|
|||
}
|
||||
};
|
||||
|
||||
template <int Size>
|
||||
template <class _Settings>
|
||||
class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
|
||||
{
|
||||
public:
|
||||
MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE<Size> *bluetoothEsp32)
|
||||
MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE<_Settings> *bluetoothEsp32)
|
||||
: _bluetoothEsp32(bluetoothEsp32)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
BLEMIDI_ESP32_NimBLE<Size> *_bluetoothEsp32 = nullptr;
|
||||
BLEMIDI_ESP32_NimBLE<_Settings> *_bluetoothEsp32 = nullptr;
|
||||
|
||||
void onWrite(BLECharacteristic *characteristic)
|
||||
{
|
||||
|
|
@ -117,8 +117,8 @@ protected:
|
|||
}
|
||||
};
|
||||
|
||||
template <int Size>
|
||||
bool BLEMIDI_ESP32_NimBLE<Size>::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *bleMidiTransport)
|
||||
template <class _Settings>
|
||||
bool BLEMIDI_ESP32_NimBLE<_Settings>::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<_Settings>, _Settings> *bleMidiTransport)
|
||||
{
|
||||
_bleMidiTransport = bleMidiTransport;
|
||||
|
||||
|
|
@ -126,10 +126,10 @@ bool BLEMIDI_ESP32_NimBLE<Size>::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<Size>(this));
|
||||
_server->setCallbacks(new MyServerCallbacks<_Settings>(this));
|
||||
_server->advertiseOnDisconnect(true);
|
||||
|
||||
// Create the BLE Service
|
||||
|
|
@ -143,7 +143,7 @@ bool BLEMIDI_ESP32_NimBLE<Size>::begin(const char *deviceName, BLEMIDI_Transport
|
|||
NIMBLE_PROPERTY::NOTIFY |
|
||||
NIMBLE_PROPERTY::WRITE_NR);
|
||||
|
||||
_characteristic->setCallbacks(new MyCharacteristicCallbacks<Size>(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<Size>::begin(const char *deviceName, BLEMIDI_Transport
|
|||
|
||||
/*! \brief Create an instance for ESP32 named <DeviceName>
|
||||
*/
|
||||
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, Size) \
|
||||
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<Size>, Size>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE<Size>, Size> &)BLE##Name);
|
||||
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, _Settings) \
|
||||
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE<_Settings>, _Settings> BLE##Name(DeviceName); \
|
||||
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE<_Settings>, _Settings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE<_Settings>, _Settings> &)BLE##Name);
|
||||
|
||||
/*! \brief Create an instance for ESP32 named <DeviceName>
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue