From 3c789b0b5f3ed24c1562275ea0bfbb718692e39b Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sun, 5 Jun 2022 10:26:47 +0200 Subject: [PATCH] removed all event code cleanup - removed all polling code --- src/hardware/BLEMIDI_ArduinoBLE.h | 38 +++++-------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/src/hardware/BLEMIDI_ArduinoBLE.h b/src/hardware/BLEMIDI_ArduinoBLE.h index 5209dfa..59397c9 100644 --- a/src/hardware/BLEMIDI_ArduinoBLE.h +++ b/src/hardware/BLEMIDI_ArduinoBLE.h @@ -2,9 +2,6 @@ #include -#define BLE_POLLING -//#define BLE_EVENTS // TODO: requires static function (don't like) - BEGIN_BLEMIDI_NAMESPACE template @@ -90,7 +87,6 @@ public: bool available(byte *pvBuffer) { -#ifdef BLE_POLLING if (mRxBuffer.count() > 0) { *pvBuffer = mRxBuffer.dequeue(); @@ -109,11 +105,6 @@ public: } } return false; -#endif -#ifdef BLE_EVENTS - BLE.poll(); - return false; -#endif } void add(byte value) @@ -136,7 +127,7 @@ protected: { if (_central) { - BLEMIDI_ArduinoBLE::blePeripheralDisconnectHandler(*_central); + onDisconnected(*_central); _central = nullptr; } return false; @@ -147,15 +138,15 @@ protected: if (nullptr == _central) { - BLEMIDI_ArduinoBLE::blePeripheralConnectHandler(central); + onConnected(central); _central = ¢ral; } else { if (*_central != central) { - BLEMIDI_ArduinoBLE::blePeripheralDisconnectHandler(*_central); - BLEMIDI_ArduinoBLE::blePeripheralConnectHandler(central); + onDisconnected(*_central); + onConnected(central); _central = ¢ral; } } @@ -163,7 +154,7 @@ protected: return true; } - void blePeripheralConnectHandler(BLEDevice central) + void onConnected(BLEDevice central) { _central = ¢ral; @@ -171,22 +162,13 @@ protected: _bleMidiTransport->_connectedCallback(); } - void blePeripheralDisconnectHandler(BLEDevice central) + void onDisconnected(BLEDevice central) { if (_bleMidiTransport->_disconnectedCallback) _bleMidiTransport->_disconnectedCallback(); _central = nullptr; } - - void characteristicWritten(BLEDevice central, BLECharacteristic characteristic) - { - auto buffer = characteristic.value(); - auto length = characteristic.valueLength(); - - if (length > 0) - receive(buffer, length); - } }; template @@ -208,14 +190,6 @@ bool BLEMIDI_ArduinoBLE<_Settings>::begin(const char *deviceName, BLEMIDI_Transp // (when not set, the device will disconnect after 0.5 seconds) _midiChar.writeValue((uint8_t)0); -#ifdef BLE_EVENTS - // assign event handlers for connected, disconnected to peripheral - BLE.setEventHandler(BLEConnected, BLEMIDI_ArduinoBLE::blePeripheralConnectHandler); - BLE.setEventHandler(BLEDisconnected, BLEMIDI_ArduinoBLE::blePeripheralDisconnectHandler); - - _midiChar.setEventHandler(BLEWritten, characteristicWritten); -#endif - /* Start advertising BLE. It will start continuously transmitting BLE advertising packets and will be visible to remote BLE central devices until it receives a new connection */