Skip to content

Commit 1ae439d

Browse files
committed
tmp simplified template arg to int
1 parent 2f9c684 commit 1ae439d

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

examples/CustomerBufferSize/CustomerBufferSize.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
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; // was 64
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, BLEMIDI_NAMESPACE::DefaultSettings);
12+
BLEMIDI_CREATE_CUSTOM_INSTANCE("Esp32-NimBLE-MIDI", MIDI, 16);
1313

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

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 size_t 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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ static const char *const CHARACTERISTIC_UUID = "7772e5db-3868-4112-a1a9-f2669d10
2323

2424
#define MIDI_TYPE 0x80
2525

26-
template <class T, class _Settings = DefaultSettings>
26+
template <class T, int Size = 64>
2727
class BLEMIDI_Transport
2828
{
29-
typedef _Settings Settings;
30-
3129
private:
32-
byte mRxBuffer[Settings::MaxBufferSize];
30+
byte mRxBuffer[Size];
3331
unsigned mRxIndex = 0;
3432

35-
byte mTxBuffer[Settings::MaxBufferSize]; // minimum 5 bytes
33+
byte mTxBuffer[Size]; // minimum 5 bytes
3634
unsigned mTxIndex = 0;
3735

3836
char mDeviceName[24];
@@ -57,6 +55,9 @@ class BLEMIDI_Transport
5755
void begin()
5856
{
5957
mBleClass.begin(mDeviceName, this);
58+
59+
Serial.print("size : ");
60+
Serial.println(Size);
6061
}
6162

6263
void end()

src/hardware/BLEMIDI_ArduinoBLE.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class BLEMIDI_ArduinoBLE
6666
static BLEMIDI_Transport<class BLEMIDI_ArduinoBLE, DefaultSettings>* _bleMidiTransport;
6767
static BLEDevice* _central;
6868

69-
Fifo<byte, 64> mRxBuffer;
69+
Fifo<byte, rawSize> mRxBuffer;
7070

7171
public:
7272
BLEMIDI_ArduinoBLE()

src/hardware/BLEMIDI_ESP32_NimBLE.h

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

66
BEGIN_BLEMIDI_NAMESPACE
77

8+
template <int Size>
89
class BLEMIDI_ESP32_NimBLE
910
{
1011
private:
1112
BLEServer *_server = nullptr;
1213
BLEAdvertising *_advertising = nullptr;
1314
BLECharacteristic *_characteristic = nullptr;
1415

15-
BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE, DefaultSettings> *_bleMidiTransport = nullptr;
16+
BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *_bleMidiTransport = nullptr;
1617

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

2021
protected:
2122
QueueHandle_t mRxQueue;
@@ -25,7 +26,7 @@ class BLEMIDI_ESP32_NimBLE
2526
{
2627
}
2728

28-
bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE, DefaultSettings> *);
29+
bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *);
2930

3031
void end()
3132
{
@@ -69,16 +70,17 @@ class BLEMIDI_ESP32_NimBLE
6970
}
7071
};
7172

73+
template <int Size>
7274
class MyServerCallbacks : public BLEServerCallbacks
7375
{
7476
public:
75-
MyServerCallbacks(BLEMIDI_ESP32_NimBLE *bluetoothEsp32)
77+
MyServerCallbacks(BLEMIDI_ESP32_NimBLE<Size> *bluetoothEsp32)
7678
: _bluetoothEsp32(bluetoothEsp32)
7779
{
7880
}
7981

8082
protected:
81-
BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr;
83+
BLEMIDI_ESP32_NimBLE<Size> *_bluetoothEsp32 = nullptr;
8284

8385
void onConnect(BLEServer *)
8486
{
@@ -93,16 +95,17 @@ class MyServerCallbacks : public BLEServerCallbacks
9395
}
9496
};
9597

98+
template <int Size>
9699
class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
97100
{
98101
public:
99-
MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE *bluetoothEsp32)
102+
MyCharacteristicCallbacks(BLEMIDI_ESP32_NimBLE<Size> *bluetoothEsp32)
100103
: _bluetoothEsp32(bluetoothEsp32)
101104
{
102105
}
103106

104107
protected:
105-
BLEMIDI_ESP32_NimBLE *_bluetoothEsp32 = nullptr;
108+
BLEMIDI_ESP32_NimBLE<Size> *_bluetoothEsp32 = nullptr;
106109

107110
void onWrite(BLECharacteristic *characteristic)
108111
{
@@ -114,18 +117,19 @@ class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
114117
}
115118
};
116119

117-
bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE, DefaultSettings> *bleMidiTransport)
120+
template <int Size>
121+
bool BLEMIDI_ESP32_NimBLE<Size>::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE<Size>, Size> *bleMidiTransport)
118122
{
119123
_bleMidiTransport = bleMidiTransport;
120124

121125
BLEDevice::init(deviceName);
122126

123127
// To communicate between the 2 cores.
124128
// Core_0 runs here, core_1 runs the BLE stack
125-
mRxQueue = xQueueCreate(64, sizeof(uint8_t)); // TODO Settings::MaxBufferSize
129+
mRxQueue = xQueueCreate(Size, sizeof(uint8_t)); // TODO DefaultSettings::MaxBufferSize
126130

127131
_server = BLEDevice::createServer();
128-
_server->setCallbacks(new MyServerCallbacks(this));
132+
_server->setCallbacks(new MyServerCallbacks<Size>(this));
129133
_server->advertiseOnDisconnect(true);
130134

131135
// Create the BLE Service
@@ -139,7 +143,7 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class
139143
NIMBLE_PROPERTY::NOTIFY |
140144
NIMBLE_PROPERTY::WRITE_NR);
141145

142-
_characteristic->setCallbacks(new MyCharacteristicCallbacks(this));
146+
_characteristic->setCallbacks(new MyCharacteristicCallbacks<Size>(this));
143147

144148
auto _security = new NimBLESecurity();
145149
_security->setAuthenticationMode(ESP_LE_AUTH_BOND);
@@ -158,9 +162,9 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class
158162

159163
/*! \brief Create an instance for ESP32 named <DeviceName>
160164
*/
161-
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, CustomSettings) \
162-
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE, CustomSettings> BLE##Name(DeviceName); \
163-
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);
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);
164168

165169
/*! \brief Create an instance for ESP32 named <DeviceName>
166170
*/

0 commit comments

Comments
 (0)