added template params
This commit is contained in:
parent
9c0e0e0627
commit
948fc1165f
|
|
@ -60,10 +60,11 @@ private:
|
||||||
T raw[rawSize];
|
T raw[rawSize];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class _Settings>
|
||||||
class BLEMIDI_ArduinoBLE
|
class BLEMIDI_ArduinoBLE
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static BLEMIDI_Transport<class BLEMIDI_ArduinoBLE, DefaultSettings>* _bleMidiTransport;
|
static BLEMIDI_Transport<class BLEMIDI_ArduinoBLE<_Settings>, _Settings>* _bleMidiTransport;
|
||||||
static BLEDevice* _central;
|
static BLEDevice* _central;
|
||||||
|
|
||||||
Fifo<byte, rawSize> mRxBuffer;
|
Fifo<byte, rawSize> mRxBuffer;
|
||||||
|
|
@ -73,7 +74,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool begin(const char*, BLEMIDI_Transport<class BLEMIDI_ArduinoBLE, DefaultSettings>*);
|
bool begin(const char*, BLEMIDI_Transport<class BLEMIDI_ArduinoBLE<_Settings>, _Settings>*);
|
||||||
|
|
||||||
void end()
|
void end()
|
||||||
{
|
{
|
||||||
|
|
@ -183,10 +184,11 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BLEMIDI_Transport<class BLEMIDI_ArduinoBLE, DefaultSettings>* BLEMIDI_ArduinoBLE::_bleMidiTransport = nullptr;
|
BLEMIDI_Transport<class BLEMIDI_ArduinoBLE<_Settings>, _Settings>* BLEMIDI_ArduinoBLE::_bleMidiTransport = nullptr;
|
||||||
BLEDevice* BLEMIDI_ArduinoBLE::_central = nullptr;
|
BLEDevice* BLEMIDI_ArduinoBLE::_central = nullptr;
|
||||||
|
|
||||||
bool BLEMIDI_ArduinoBLE::begin(const char* deviceName, BLEMIDI_Transport<class BLEMIDI_ArduinoBLE, DefaultSettings>* bleMidiTransport)
|
template <class _Settings>
|
||||||
|
bool BLEMIDI_ArduinoBLE<_Settings>::begin(const char* deviceName, BLEMIDI_Transport<class BLEMIDI_ArduinoBLE<_Settings>, _Settings>* bleMidiTransport)
|
||||||
{
|
{
|
||||||
_bleMidiTransport = bleMidiTransport;
|
_bleMidiTransport = bleMidiTransport;
|
||||||
|
|
||||||
|
|
@ -219,9 +221,9 @@ bool BLEMIDI_ArduinoBLE::begin(const char* deviceName, BLEMIDI_Transport<class B
|
||||||
|
|
||||||
/*! \brief Create an instance for nRF52 named <DeviceName>
|
/*! \brief Create an instance for nRF52 named <DeviceName>
|
||||||
*/
|
*/
|
||||||
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, CustomSettings) \
|
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, _Settings) \
|
||||||
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE, CustomSettings> BLE##Name(DeviceName); \
|
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE<_Settings>, _Settings> BLE##Name(DeviceName); \
|
||||||
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE, CustomSettings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE, CustomSettings> &)BLE##Name);
|
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE<_Settings>, _Settings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE<_Settings>, _Settings> &)BLE##Name);
|
||||||
|
|
||||||
/*! \brief Create an instance for nRF52 named <DeviceName>
|
/*! \brief Create an instance for nRF52 named <DeviceName>
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
BEGIN_BLEMIDI_NAMESPACE
|
BEGIN_BLEMIDI_NAMESPACE
|
||||||
|
|
||||||
|
template <class _Settings>
|
||||||
class BLEMIDI_ESP32
|
class BLEMIDI_ESP32
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
@ -15,10 +16,10 @@ private:
|
||||||
BLEAdvertising *_advertising = nullptr;
|
BLEAdvertising *_advertising = nullptr;
|
||||||
BLECharacteristic *_characteristic = nullptr;
|
BLECharacteristic *_characteristic = nullptr;
|
||||||
|
|
||||||
BLEMIDI_Transport<class BLEMIDI_ESP32, DefaultSettings> *_bleMidiTransport = nullptr;
|
BLEMIDI_Transport<class BLEMIDI_ESP32<_Settings>, _Settings> *_bleMidiTransport = nullptr;
|
||||||
|
|
||||||
friend class MyServerCallbacks;
|
template <class> friend class MyServerCallbacks;
|
||||||
friend class MyCharacteristicCallbacks;
|
template <class> friend class MyCharacteristicCallbacks;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QueueHandle_t mRxQueue;
|
QueueHandle_t mRxQueue;
|
||||||
|
|
@ -28,7 +29,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32, DefaultSettings> *);
|
bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32<_Settings>, _Settings> *);
|
||||||
|
|
||||||
void end()
|
void end()
|
||||||
{
|
{
|
||||||
|
|
@ -74,16 +75,17 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class _Settings>
|
||||||
class MyServerCallbacks : public BLEServerCallbacks
|
class MyServerCallbacks : public BLEServerCallbacks
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyServerCallbacks(BLEMIDI_ESP32 *bluetoothEsp32)
|
MyServerCallbacks(BLEMIDI_ESP32<_Settings> *bluetoothEsp32)
|
||||||
: _bluetoothEsp32(bluetoothEsp32)
|
: _bluetoothEsp32(bluetoothEsp32)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BLEMIDI_ESP32 *_bluetoothEsp32 = nullptr;
|
BLEMIDI_ESP32<_Settings> *_bluetoothEsp32 = nullptr;
|
||||||
|
|
||||||
void onConnect(BLEServer *)
|
void onConnect(BLEServer *)
|
||||||
{
|
{
|
||||||
|
|
@ -100,16 +102,17 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class _Settings>
|
||||||
class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
|
class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyCharacteristicCallbacks(BLEMIDI_ESP32 *bluetoothEsp32)
|
MyCharacteristicCallbacks(BLEMIDI_ESP32<_Settings> *bluetoothEsp32)
|
||||||
: _bluetoothEsp32(bluetoothEsp32)
|
: _bluetoothEsp32(bluetoothEsp32)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BLEMIDI_ESP32 *_bluetoothEsp32 = nullptr;
|
BLEMIDI_ESP32<_Settings> *_bluetoothEsp32 = nullptr;
|
||||||
|
|
||||||
void onWrite(BLECharacteristic *characteristic)
|
void onWrite(BLECharacteristic *characteristic)
|
||||||
{
|
{
|
||||||
|
|
@ -121,7 +124,8 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32, DefaultSettings> *bleMidiTransport)
|
template <class _Settings>
|
||||||
|
bool BLEMIDI_ESP32<_Settings>::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32<_Settings>, _Settings> *bleMidiTransport)
|
||||||
{
|
{
|
||||||
_bleMidiTransport = bleMidiTransport;
|
_bleMidiTransport = bleMidiTransport;
|
||||||
|
|
||||||
|
|
@ -132,7 +136,7 @@ bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_Transport<class BLEMID
|
||||||
mRxQueue = xQueueCreate(_Settings::MaxBufferSize, sizeof(uint8_t));
|
mRxQueue = xQueueCreate(_Settings::MaxBufferSize, sizeof(uint8_t));
|
||||||
|
|
||||||
_server = BLEDevice::createServer();
|
_server = BLEDevice::createServer();
|
||||||
_server->setCallbacks(new MyServerCallbacks(this));
|
_server->setCallbacks(new MyServerCallbacks<_Settings>(this));
|
||||||
|
|
||||||
// Create the BLE Service
|
// Create the BLE Service
|
||||||
auto service = _server->createService(BLEUUID(SERVICE_UUID));
|
auto service = _server->createService(BLEUUID(SERVICE_UUID));
|
||||||
|
|
@ -147,7 +151,7 @@ bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_Transport<class BLEMID
|
||||||
// Add CCCD 0x2902 to allow notify
|
// Add CCCD 0x2902 to allow notify
|
||||||
_characteristic->addDescriptor(new BLE2902());
|
_characteristic->addDescriptor(new BLE2902());
|
||||||
|
|
||||||
_characteristic->setCallbacks(new MyCharacteristicCallbacks(this));
|
_characteristic->setCallbacks(new MyCharacteristicCallbacks<_Settings>(this));
|
||||||
|
|
||||||
auto _security = new BLESecurity();
|
auto _security = new BLESecurity();
|
||||||
_security->setAuthenticationMode(ESP_LE_AUTH_BOND);
|
_security->setAuthenticationMode(ESP_LE_AUTH_BOND);
|
||||||
|
|
@ -166,9 +170,9 @@ bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_Transport<class BLEMID
|
||||||
|
|
||||||
/*! \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, _Settings) \
|
||||||
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32, CustomSettings> BLE##Name(DeviceName); \
|
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32<_Settings>, _Settings> BLE##Name(DeviceName); \
|
||||||
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32, CustomSettings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32, CustomSettings> &)BLE##Name);
|
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32<_Settings>, _Settings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32<_Settings>, _Settings> &)BLE##Name);
|
||||||
|
|
||||||
/*! \brief Create an instance for ESP32 named <DeviceName>
|
/*! \brief Create an instance for ESP32 named <DeviceName>
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,24 @@
|
||||||
|
|
||||||
BEGIN_BLEMIDI_NAMESPACE
|
BEGIN_BLEMIDI_NAMESPACE
|
||||||
|
|
||||||
|
template <class _Settings>
|
||||||
class BLEMIDI_nRF52
|
class BLEMIDI_nRF52
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// BLEDis bledis;
|
// BLEDis bledis;
|
||||||
// BLEMidi blemidi;
|
// BLEMidi blemidi;
|
||||||
|
|
||||||
BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52, DefaultSettings>* _bleMidiTransport;
|
BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52<_Settings>, _Settings>* _bleMidiTransport;
|
||||||
|
|
||||||
friend class MyServerCallbacks;
|
template <class> friend class MyServerCallbacks;
|
||||||
friend class MyCharacteristicCallbacks;
|
template <class> friend class MyCharacteristicCallbacks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BLEMIDI_nRF52()
|
BLEMIDI_nRF52()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool begin(const char*, BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52, DefaultSettings>*);
|
bool begin(const char*, BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52<_Settings>, _Settings>*);
|
||||||
|
|
||||||
void end()
|
void end()
|
||||||
{
|
{
|
||||||
|
|
@ -61,7 +62,8 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool BLEMIDI_nRF52::begin(const char* deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52, DefaultSettings>* bleMidiTransport)
|
template <class _Settings>
|
||||||
|
bool BLEMIDI_nRF52<_Settings>::begin(const char* deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52<_Settings>, _Settings>* bleMidiTransport)
|
||||||
{
|
{
|
||||||
_bleMidiTransport = bleMidiTransport;
|
_bleMidiTransport = bleMidiTransport;
|
||||||
|
|
||||||
|
|
@ -116,9 +118,9 @@ bool BLEMIDI_nRF52::begin(const char* deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Tra
|
||||||
|
|
||||||
/*! \brief Create an instance for nRF52 named <DeviceName>
|
/*! \brief Create an instance for nRF52 named <DeviceName>
|
||||||
*/
|
*/
|
||||||
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, CustomSettings) \
|
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, _Settings) \
|
||||||
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52, CustomSettings> BLE##Name(DeviceName); \
|
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52<_Settings>, _Settings> BLE##Name(DeviceName); \
|
||||||
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52, CustomSettings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52, CustomSettings> &)BLE##Name);
|
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52<_Settings>, _Settings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52<_Settings>, _Settings> &)BLE##Name);
|
||||||
|
|
||||||
/*! \brief Create an instance for nRF52 named <DeviceName>
|
/*! \brief Create an instance for nRF52 named <DeviceName>
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue