2
2
3
3
#include < ArduinoBLE.h>
4
4
5
- #define BLE_POLLING
6
- // #define BLE_EVENTS // TODO: requires static function (don't like)
7
-
8
5
BEGIN_BLEMIDI_NAMESPACE
9
6
10
7
template <typename T, short rawSize>
@@ -90,7 +87,6 @@ class BLEMIDI_ArduinoBLE
90
87
91
88
bool available (byte *pvBuffer)
92
89
{
93
- #ifdef BLE_POLLING
94
90
if (mRxBuffer .count () > 0 )
95
91
{
96
92
*pvBuffer = mRxBuffer .dequeue ();
@@ -109,11 +105,6 @@ class BLEMIDI_ArduinoBLE
109
105
}
110
106
}
111
107
return false ;
112
- #endif
113
- #ifdef BLE_EVENTS
114
- BLE.poll ();
115
- return false ;
116
- #endif
117
108
}
118
109
119
110
void add (byte value)
@@ -136,7 +127,7 @@ class BLEMIDI_ArduinoBLE
136
127
{
137
128
if (_central)
138
129
{
139
- BLEMIDI_ArduinoBLE::blePeripheralDisconnectHandler (*_central);
130
+ onDisconnected (*_central);
140
131
_central = nullptr ;
141
132
}
142
133
return false ;
@@ -147,46 +138,37 @@ class BLEMIDI_ArduinoBLE
147
138
148
139
if (nullptr == _central)
149
140
{
150
- BLEMIDI_ArduinoBLE::blePeripheralConnectHandler (central);
141
+ onConnected (central);
151
142
_central = ¢ral;
152
143
}
153
144
else
154
145
{
155
146
if (*_central != central)
156
147
{
157
- BLEMIDI_ArduinoBLE::blePeripheralDisconnectHandler (*_central);
158
- BLEMIDI_ArduinoBLE::blePeripheralConnectHandler (central);
148
+ onDisconnected (*_central);
149
+ onConnected (central);
159
150
_central = ¢ral;
160
151
}
161
152
}
162
153
163
154
return true ;
164
155
}
165
156
166
- void blePeripheralConnectHandler (BLEDevice central)
157
+ void onConnected (BLEDevice central)
167
158
{
168
159
_central = ¢ral;
169
160
170
161
if (_bleMidiTransport->_connectedCallback )
171
162
_bleMidiTransport->_connectedCallback ();
172
163
}
173
164
174
- void blePeripheralDisconnectHandler (BLEDevice central)
165
+ void onDisconnected (BLEDevice central)
175
166
{
176
167
if (_bleMidiTransport->_disconnectedCallback )
177
168
_bleMidiTransport->_disconnectedCallback ();
178
169
179
170
_central = nullptr ;
180
171
}
181
-
182
- void characteristicWritten (BLEDevice central, BLECharacteristic characteristic)
183
- {
184
- auto buffer = characteristic.value ();
185
- auto length = characteristic.valueLength ();
186
-
187
- if (length > 0 )
188
- receive (buffer, length);
189
- }
190
172
};
191
173
192
174
template <class _Settings >
@@ -208,14 +190,6 @@ bool BLEMIDI_ArduinoBLE<_Settings>::begin(const char *deviceName, BLEMIDI_Transp
208
190
// (when not set, the device will disconnect after 0.5 seconds)
209
191
_midiChar.writeValue ((uint8_t )0 );
210
192
211
- #ifdef BLE_EVENTS
212
- // assign event handlers for connected, disconnected to peripheral
213
- BLE.setEventHandler (BLEConnected, BLEMIDI_ArduinoBLE::blePeripheralConnectHandler);
214
- BLE.setEventHandler (BLEDisconnected, BLEMIDI_ArduinoBLE::blePeripheralDisconnectHandler);
215
-
216
- _midiChar.setEventHandler (BLEWritten, characteristicWritten);
217
- #endif
218
-
219
193
/* Start advertising BLE. It will start continuously transmitting BLE
220
194
advertising packets and will be visible to remote BLE central devices
221
195
until it receives a new connection */
0 commit comments