Skip to content

Commit 7da9b62

Browse files
don't reinit the ble and disconnect after bond
1 parent d041131 commit 7da9b62

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

BLE_Privacy/source/main.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,17 @@ class PrivacyDevice : private mbed::NonCopyable<PrivacyDevice>,
6262
_bonded(false),
6363
_led1(LED1, 0) { };
6464

65-
virtual ~PrivacyDevice()
66-
{
67-
if (_ble.hasInitialized()) {
68-
_ble.shutdown();
69-
}
70-
};
65+
virtual ~PrivacyDevice() { };
7166

7267
/** Start BLE interface initialisation */
7368
void run()
7469
{
75-
ble_error_t error;
76-
7770
/* to show we're running we'll blink every 500ms */
7871
_event_queue.call_every(500, this, &PrivacyDevice::blink);
7972

8073
if (_ble.hasInitialized()) {
81-
printf("Ble instance already initialised.\r\n");
74+
/* ble instance already initialised, skip init and start activity */
75+
start();
8276
return;
8377
}
8478

@@ -192,6 +186,14 @@ class PrivacyDevice : private mbed::NonCopyable<PrivacyDevice>,
192186
print_address(connection_event->peerResolvableAddr);
193187

194188
_handle = connection_event->handle;
189+
190+
if (_bonded) {
191+
/* disconnect in 2s */
192+
_event_queue.call_in(
193+
2000, &_ble.gap(),
194+
&Gap::disconnect, _handle, Gap::REMOTE_USER_TERMINATED_CONNECTION
195+
);
196+
}
195197
};
196198

197199
/** This is called by Gap to notify the application we disconnected */

0 commit comments

Comments
 (0)