Skip to content

Commit 9e68c95

Browse files
authored
Merge pull request #74 from MicroMidi/master
Callback method added that returns the name of the connected BLE-MIDI device
2 parents 929c2fc + db8a00a commit 9e68c95

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/BLEMIDI_Transport.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class BLEMIDI_Transport
185185
public:
186186
// callbacks
187187
void (*_connectedCallback)() = nullptr;
188+
void (*_connectedCallbackDeviceName)(char *) = nullptr;
188189
void (*_disconnectedCallback)() = nullptr;
189190

190191
BLEMIDI_Transport &setName(const char *deviceName)
@@ -199,6 +200,12 @@ class BLEMIDI_Transport
199200
_connectedCallback = fptr;
200201
return *this;
201202
}
203+
204+
BLEMIDI_Transport &setHandleConnected(void (*fptr)(char*))
205+
{
206+
_connectedCallbackDeviceName= fptr;
207+
return *this;
208+
}
202209

203210
BLEMIDI_Transport &setHandleDisconnected(void (*fptr)())
204211
{

src/hardware/BLEMIDI_Client_ESP32.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ class BLEMIDI_Client_ESP32
228228
BLERemoteCharacteristic *_characteristic = nullptr;
229229
BLERemoteService *pSvc = nullptr;
230230
bool firstTimeSend = true; //First writeValue get sends like Write with reponse for clean security flags. After first time, all messages are send like WriteNoResponse for increase transmision speed.
231-
231+
char connectedDeviceName[24];
232+
232233
BLEMIDI_Transport<class BLEMIDI_Client_ESP32> *_bleMidiTransport = nullptr;
233234

234235
bool specificTarget = false;
@@ -303,6 +304,12 @@ class BLEMIDI_Client_ESP32
303304
_bleMidiTransport->_connectedCallback();
304305
}
305306
firstTimeSend = true;
307+
308+
if (_bleMidiTransport->_connectedCallbackDeviceName)
309+
{
310+
sprintf(connectedDeviceName, "%s", myAdvCB.advDevice.getName().c_str());
311+
_bleMidiTransport->_connectedCallbackDeviceName(connectedDeviceName);
312+
}
306313
}
307314

308315
void disconnected()

0 commit comments

Comments
 (0)