2
2
3
3
#include < ArduinoBLE.h>
4
4
5
- BLEService midiService (SERVICE_UUID);
6
- BLEStringCharacteristic midiChar (CHARACTERISTIC_UUID, // standard 16-bit characteristic UUID
7
- BLERead | BLEWrite | BLENotify | BLEWriteWithoutResponse, 16 ); // remote clients will be able to get notifications if this characteristic changes
8
-
9
5
#define BLE_POLLING
6
+ // #define BLE_EVENTS // TODO: requires static function (don't like)
10
7
11
8
BEGIN_BLEMIDI_NAMESPACE
12
9
13
- template <typename T, int rawSize>
10
+ BLEService midiService (SERVICE_UUID);
11
+
12
+ BLEStringCharacteristic midiChar (CHARACTERISTIC_UUID, // standard 16-bit characteristic UUID
13
+ BLERead | BLEWrite | BLENotify | BLEWriteWithoutResponse, 16 ); // remote clients will be able to get notifications if this characteristic changes
14
+
15
+ template <typename T, short rawSize>
14
16
class Fifo {
15
17
public:
16
18
const size_t size; // speculative feature, in case it's needed
@@ -64,10 +66,10 @@ template <class _Settings>
64
66
class BLEMIDI_ArduinoBLE
65
67
{
66
68
private:
67
- static BLEMIDI_Transport<class BLEMIDI_ArduinoBLE <_Settings>, _Settings>* _bleMidiTransport;
68
- static BLEDevice* _central;
69
+ BLEMIDI_Transport<class BLEMIDI_ArduinoBLE <_Settings>, _Settings>* _bleMidiTransport;
70
+ BLEDevice* _central;
69
71
70
- Fifo<byte, rawSize > mRxBuffer ;
72
+ Fifo<byte, _Settings::MaxBufferSize > mRxBuffer ;
71
73
72
74
public:
73
75
BLEMIDI_ArduinoBLE ()
@@ -78,7 +80,6 @@ class BLEMIDI_ArduinoBLE
78
80
79
81
void end ()
80
82
{
81
-
82
83
}
83
84
84
85
void write (uint8_t * buffer, size_t length)
@@ -112,8 +113,8 @@ class BLEMIDI_ArduinoBLE
112
113
return false ;
113
114
#endif
114
115
#ifdef BLE_EVENTS
115
- / BLE.poll ();
116
- return ; // ??
116
+ BLE.poll ();
117
+ return false ;
117
118
#endif
118
119
}
119
120
@@ -124,7 +125,7 @@ class BLEMIDI_ArduinoBLE
124
125
}
125
126
126
127
protected:
127
- static void receive (const unsigned char * buffer, size_t length)
128
+ void receive (const unsigned char * buffer, size_t length)
128
129
{
129
130
// forward the buffer so it can be parsed
130
131
_bleMidiTransport->receive ((uint8_t *)buffer, length);
@@ -160,22 +161,23 @@ class BLEMIDI_ArduinoBLE
160
161
return true ;
161
162
}
162
163
163
- static void blePeripheralConnectHandler (BLEDevice central)
164
+ void blePeripheralConnectHandler (BLEDevice central)
164
165
{
165
166
_central = ¢ral;
167
+
166
168
if (_bleMidiTransport->_connectedCallback )
167
169
_bleMidiTransport->_connectedCallback ();
168
170
}
169
171
170
- static void blePeripheralDisconnectHandler (BLEDevice central)
172
+ void blePeripheralDisconnectHandler (BLEDevice central)
171
173
{
172
174
if (_bleMidiTransport->_disconnectedCallback )
173
175
_bleMidiTransport->_disconnectedCallback ();
174
176
175
177
_central = nullptr ;
176
178
}
177
179
178
- static void characteristicWritten (BLEDevice central, BLECharacteristic characteristic) {
180
+ void characteristicWritten (BLEDevice central, BLECharacteristic characteristic) {
179
181
auto buffer = characteristic.value ();
180
182
auto length = characteristic.valueLength ();
181
183
@@ -184,14 +186,12 @@ class BLEMIDI_ArduinoBLE
184
186
}
185
187
};
186
188
187
- BLEMIDI_Transport<class BLEMIDI_ArduinoBLE <_Settings>, _Settings>* BLEMIDI_ArduinoBLE::_bleMidiTransport = nullptr ;
188
- BLEDevice* BLEMIDI_ArduinoBLE::_central = nullptr ;
189
-
190
189
template <class _Settings >
191
190
bool BLEMIDI_ArduinoBLE<_Settings>::begin(const char * deviceName, BLEMIDI_Transport<class BLEMIDI_ArduinoBLE <_Settings>, _Settings>* bleMidiTransport)
192
191
{
193
192
_bleMidiTransport = bleMidiTransport;
194
193
194
+ // initialize the Bluetooth® Low Energy hardware
195
195
if (!BLE.begin ())
196
196
return false ;
197
197
@@ -219,21 +219,20 @@ bool BLEMIDI_ArduinoBLE<_Settings>::begin(const char* deviceName, BLEMIDI_Transp
219
219
return true ;
220
220
}
221
221
222
- /* ! \brief Create an instance for nRF52 named <DeviceName>
222
+ /* ! \brief Create an instance for ArduinoBLE <DeviceName>
223
223
*/
224
224
#define BLEMIDI_CREATE_CUSTOM_INSTANCE (DeviceName, Name, _Settings ) \
225
- BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE<_Settings>, _Settings> BLE##Name(DeviceName); \
226
- 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);
225
+ BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE<_Settings>, _Settings> BLE##Name(DeviceName); \
226
+ 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);
227
227
228
- /* ! \brief Create an instance for nRF52 named <DeviceName>
228
+ /* ! \brief Create an instance for ArduinoBLE <DeviceName>
229
229
*/
230
230
#define BLEMIDI_CREATE_INSTANCE (DeviceName, Name ) \
231
- BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE> BLE##Name(DeviceName); \
232
- MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE>, BLEMIDI_NAMESPACE::MySettings> Name ((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE> &)BLE##Name);
231
+ BLEMIDI_CREATE_CUSTOM_INSTANCE (DeviceName, Name, BLEMIDI_NAMESPACE::DefaultSettings)
233
232
234
- /* ! \brief Create a default instance for nRF52 (Nano 33 BLE) named BLE-MIDI
233
+ /* ! \brief Create a default instance for ArduinoBLE named BLE-MIDI
235
234
*/
236
235
#define BLEMIDI_CREATE_DEFAULT_INSTANCE () \
237
- BLEMIDI_CREATE_INSTANCE (" BLE-MIDI" , MIDI)
236
+ BLEMIDI_CREATE_INSTANCE (" BLE-MIDI" , MIDI)
238
237
239
238
END_BLEMIDI_NAMESPACE
0 commit comments