Skip to content

Commit 58c323e

Browse files
committed
Correct value of BLE.connected()
Now it will check: - if in peripheral mode and if a central is connected - if in central mode and if a peripheral is connected
1 parent af07113 commit 58c323e

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

Diff for: libraries/CurieBLE/src/internal/BLEDeviceManager.cpp

+29-5
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,40 @@ bool BLEDeviceManager::connected(const BLEDevice *device) const
173173
{
174174
bt_conn_t* conn = bt_conn_lookup_addr_le(device->bt_le_address());
175175
bool retval = false;
176-
//pr_debug(LOG_MODULE_BLE, "%s-%d: add-%s", __FUNCTION__, __LINE__, device->address().c_str());
177-
if (NULL != conn)
176+
177+
if (BLEUtils::isLocalBLE(*device))
178178
{
179-
//pr_debug(LOG_MODULE_BLE, "%s-%d: state-%d", __FUNCTION__, __LINE__,conn->state);
180-
if (conn->state == BT_CONN_CONNECTED)
179+
// first check if in peripheral mode and a central is connected
180+
if (BLEUtils::macAddressValid(_peer_central))
181181
{
182182
retval = true;
183183
}
184-
bt_conn_unref(conn);
184+
else // next check if in central mode and connected to any peripherals
185+
{
186+
for (int i = 0; i < BLE_MAX_CONN_CFG; i++)
187+
{
188+
if (BLEUtils::macAddressValid(_peer_peripheral[i]))
189+
{
190+
retval = true;
191+
break;
192+
}
193+
}
194+
}
195+
}
196+
else
197+
{
198+
//pr_debug(LOG_MODULE_BLE, "%s-%d: add-%s", __FUNCTION__, __LINE__, device->address().c_str());
199+
if (NULL != conn)
200+
{
201+
//pr_debug(LOG_MODULE_BLE, "%s-%d: state-%d", __FUNCTION__, __LINE__,conn->state);
202+
if (conn->state == BT_CONN_CONNECTED)
203+
{
204+
retval = true;
205+
}
206+
bt_conn_unref(conn);
207+
}
185208
}
209+
186210
return retval;
187211
}
188212

0 commit comments

Comments
 (0)