Skip to content

Commit ab44659

Browse files
committed
changed template arg to _Setting
1 parent 1ae439d commit ab44659

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-32
lines changed

examples/CustomerBufferSize/CustomerBufferSize.ino

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#include <BLEMIDI_Transport.h>
22

3-
// struct CustomBufferSizeSettings : public BLEMIDI_NAMESPACE::DefaultSettings {
4-
// static const size_t MaxBufferSize = 16; // was 64
5-
//};
3+
struct CustomBufferSizeSettings : public BLEMIDI_NAMESPACE::DefaultSettings {
4+
static const size_t MaxBufferSize = 16;
5+
};
66

77
#include <hardware/BLEMIDI_ESP32_NimBLE.h>
88
//#include <hardware/BLEMIDI_ESP32.h>
99
//#include <hardware/BLEMIDI_nRF52.h>
1010
//#include <hardware/BLEMIDI_ArduinoBLE.h>
1111

12-
BLEMIDI_CREATE_CUSTOM_INSTANCE("Esp32-NimBLE-MIDI", MIDI, 16);
12+
BLEMIDI_CREATE_CUSTOM_INSTANCE("Esp32-NimBLE-MIDI", MIDI, BLEMIDI_NAMESPACE::DefaultSettings);
1313

1414
unsigned long t0 = millis();
1515
bool isConnected = false;
1616

17+
1718
// -----------------------------------------------------------------------------
1819
// When BLE connected, LED will turn on (indication that connection was successful)
1920
// When receiving a NoteOn, LED will go out, on NoteOff, light comes back on.

src/BLEMIDI_Settings.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
BEGIN_BLEMIDI_NAMESPACE
66

7-
//struct DefaultSettings
8-
//{
9-
// static const short MaxBufferSize = 64;
10-
//};
7+
struct DefaultSettings
8+
{
9+
static const short MaxBufferSize = 64;
10+
};
1111

1212
END_BLEMIDI_NAMESPACE

src/BLEMIDI_Transport.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ static const char *const CHARACTERISTIC_UUID = "7772e5db-3868-4112-a1a9-f2669d10
2323

2424
#define MIDI_TYPE 0x80
2525

26-
template <class T, int Size = 64>
26+
template <class T, class _Settings = DefaultSettings>
2727
class BLEMIDI_Transport
2828
{
2929
private:
30-
byte mRxBuffer[Size];
30+
byte mRxBuffer[_Settings::MaxBufferSize];
3131
unsigned mRxIndex = 0;
3232

33-
byte mTxBuffer[Size]; // minimum 5 bytes
33+
byte mTxBuffer[_Settings::MaxBufferSize]; // minimum 5 bytes
3434
unsigned mTxIndex = 0;
3535

3636
char mDeviceName[24];
@@ -57,7 +57,7 @@ class BLEMIDI_Transport
5757
mBleClass.begin(mDeviceName, this);
5858

5959
Serial.print("size : ");
60-
Serial.println(Size);
60+
Serial.println(_Settings::MaxBufferSize);
6161
}
6262

6363
void end()

src/hardware/BLEMIDI_ESP32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_Transport<class BLEMID
129129

130130
// To communicate between the 2 cores.
131131
// Core_0 runs here, core_1 runs the BLE stack
132-
mRxQueue = xQueueCreate(64, sizeof(uint8_t)); // TODO Settings::MaxBufferSize
132+
mRxQueue = xQueueCreate(_Settings::MaxBufferSize, sizeof(uint8_t));
133133

134134
_server = BLEDevice::createServer();
135135
_server->setCallbacks(new MyServerCallbacks(this));

src/hardware/BLEMIDI_ESP32_NimBLE.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55

66
BEGIN_BLEMIDI_NAMESPACE
77

8-
template <int Size>
8+
template <class _Settings>
99
class BLEMIDI_ESP32_NimBLE
1010
{
1111
private:
1212
BLEServer *_server = nullptr;
1313
BLEAdvertising *_advertising = nullptr;
1414
BLECharacteristic *_characteristic = nullptr;
1515

16-
BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *_bleMidiTransport = nullptr;
16+
BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<_Settings>, _Settings> *_bleMidiTransport = nullptr;
1717

18-
template <int> friend class MyServerCallbacks;
19-
template <int> friend class MyCharacteristicCallbacks;
18+
template <class> friend class MyServerCallbacks;
19+
template <class> friend class MyCharacteristicCallbacks;
2020

2121
protected:
2222
QueueHandle_t mRxQueue;
@@ -26,7 +26,7 @@ class BLEMIDI_ESP32_NimBLE
2626
{
2727
}
2828

29-
bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *);
29+
bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<_Settings>, _Settings> *);
3030

3131
void end()
3232
{
@@ -70,17 +70,17 @@ class BLEMIDI_ESP32_NimBLE
7070
}
7171
};
7272

73-
template <int Size>
73+
template <class _Settings>
7474
class MyServerCallbacks : public BLEServerCallbacks
7575
{
7676
public:
77-
MyServerCallbacks(BLEMIDI_ESP32_NimBLE<Size> *bluetoothEsp32)
77+
MyServerCallbacks(BLEMIDI_ESP32_NimBLE<_Settings> *bluetoothEsp32)
7878
: _bluetoothEsp32(bluetoothEsp32)
7979
{
8080
}
8181

8282
protected:
83-
BLEMIDI_ESP32_NimBLE<Size> *_bluetoothEsp32 = nullptr;
83+
BLEMIDI_ESP32_NimBLE<_Settings> *_bluetoothEsp32 = nullptr;
8484

8585
void onConnect(BLEServer *)
8686
{
@@ -95,17 +95,17 @@ class MyServerCallbacks : public BLEServerCallbacks
9595
}
9696
};
9797

98-
template <int Size>
98+
template <class _Settings>
9999
class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
100100
{
101101
public:
102-
MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE<Size> *bluetoothEsp32)
102+
MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE<_Settings> *bluetoothEsp32)
103103
: _bluetoothEsp32(bluetoothEsp32)
104104
{
105105
}
106106

107107
protected:
108-
BLEMIDI_ESP32_NimBLE<Size> *_bluetoothEsp32 = nullptr;
108+
BLEMIDI_ESP32_NimBLE<_Settings> *_bluetoothEsp32 = nullptr;
109109

110110
void onWrite(BLECharacteristic *characteristic)
111111
{
@@ -117,19 +117,19 @@ class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
117117
}
118118
};
119119

120-
template <int Size>
121-
bool BLEMIDI_ESP32_NimBLE<Size>::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *bleMidiTransport)
120+
template <class _Settings>
121+
bool BLEMIDI_ESP32_NimBLE<_Settings>::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<_Settings>, _Settings> *bleMidiTransport)
122122
{
123123
_bleMidiTransport = bleMidiTransport;
124124

125125
BLEDevice::init(deviceName);
126126

127127
// To communicate between the 2 cores.
128128
// Core_0 runs here, core_1 runs the BLE stack
129-
mRxQueue = xQueueCreate(Size, sizeof(uint8_t)); // TODO DefaultSettings::MaxBufferSize
129+
mRxQueue = xQueueCreate(_Settings::MaxBufferSize, sizeof(uint8_t));
130130

131131
_server = BLEDevice::createServer();
132-
_server->setCallbacks(new MyServerCallbacks<Size>(this));
132+
_server->setCallbacks(new MyServerCallbacks<_Settings>(this));
133133
_server->advertiseOnDisconnect(true);
134134

135135
// Create the BLE Service
@@ -143,7 +143,7 @@ bool BLEMIDI_ESP32_NimBLE<Size>::begin(const char *deviceName, BLEMIDI_Transport
143143
NIMBLE_PROPERTY::NOTIFY |
144144
NIMBLE_PROPERTY::WRITE_NR);
145145

146-
_characteristic->setCallbacks(new MyCharacteristicCallbacks<Size>(this));
146+
_characteristic->setCallbacks(new MyCharacteristicCallbacks<_Settings>(this));
147147

148148
auto _security = new NimBLESecurity();
149149
_security->setAuthenticationMode(ESP_LE_AUTH_BOND);
@@ -162,9 +162,9 @@ bool BLEMIDI_ESP32_NimBLE<Size>::begin(const char *deviceName, BLEMIDI_Transport
162162

163163
/*! \brief Create an instance for ESP32 named <DeviceName>
164164
*/
165-
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, Size) \
166-
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE<Size>, Size> BLE##Name(DeviceName); \
167-
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);
165+
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, _Settings) \
166+
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE<_Settings>, _Settings> BLE##Name(DeviceName); \
167+
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);
168168

169169
/*! \brief Create an instance for ESP32 named <DeviceName>
170170
*/

0 commit comments

Comments
 (0)