From 9cee7f56440fac51fa1478cd96f747130b29870a Mon Sep 17 00:00:00 2001 From: lianggao Date: Mon, 20 Feb 2017 09:37:36 +0800 Subject: [PATCH 1/2] Fix #445 Deprecated BLEConnected and BLEDisconnected events not triggered 1. Root casue: The callback regiter before the begin and the begin reset the callback. 2. Solution: Remove it from the init method and init it when create. --- libraries/CurieBLE/src/BLEPeripheral.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/CurieBLE/src/BLEPeripheral.cpp b/libraries/CurieBLE/src/BLEPeripheral.cpp index 760d374f..990bd965 100644 --- a/libraries/CurieBLE/src/BLEPeripheral.cpp +++ b/libraries/CurieBLE/src/BLEPeripheral.cpp @@ -21,7 +21,7 @@ #include "BLEPeripheral.h" -static BLEPeripheralEventHandler m_eventHandlers[BLEDeviceLastEvent]; +static BLEPeripheralEventHandler m_eventHandlers[BLEDeviceLastEvent] = {NULL, NULL, NULL, NULL}; void bleBackCompatiblePeripheralConnectHandler(BLEDevice central) { @@ -154,7 +154,6 @@ void BLEPeripheral::init() if (!_initCalled) { BLE.begin(); - memset(m_eventHandlers, 0, sizeof(m_eventHandlers)); _initCalled = true; } } From a2aca67cc05b82bb5a538782aed7c740482702c1 Mon Sep 17 00:00:00 2001 From: lianggao Date: Mon, 20 Feb 2017 09:39:50 +0800 Subject: [PATCH 2/2] Fix #444 BLEPeripheral::connected() always returns false 1. Root casue: the stack need use connected device to get the state. The current code used local address to get the link and get an error. 2. Solution: Use central's address to get connection state. --- libraries/CurieBLE/src/BLEPeripheral.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/CurieBLE/src/BLEPeripheral.cpp b/libraries/CurieBLE/src/BLEPeripheral.cpp index 990bd965..ec817f9d 100644 --- a/libraries/CurieBLE/src/BLEPeripheral.cpp +++ b/libraries/CurieBLE/src/BLEPeripheral.cpp @@ -146,7 +146,8 @@ BLECentral BLEPeripheral::central(void) bool BLEPeripheral::connected(void) { - return BLE.connected(); + BLEDevice centralBle = BLE.central(); + return centralBle.connected(); } void BLEPeripheral::init()