bool ble_connect_state = false;
bool ble_is_connected (void)
{
return ble_connect_state;
}
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
uint32_t err_code;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
NRF_LOG_INFO("Connected");
ble_connect_state = true;
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
APP_ERROR_CHECK(err_code);
break;
case BLE_GAP_EVT_DISCONNECTED:
NRF_LOG_INFO("Disconnected");
ble_connect_state = false;
// LED indication will be changed when advertising starts.
m_conn_handle = BLE_CONN_HANDLE_INVALID;
break;
/*
"case" omitted.
*/
default:
// No implementation needed.
break;
}
}
void my_ble_stop_advitising(void)
{
if (ble_is_connected() == true)
{
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
APP_ERROR_CHECK(err_code);
while (ble_is_connected() == true)
{
vTaskDelay(10);//sd_app_evt_wait();
}
}
(void)sd_ble_gap_adv_stop(m_advertising.adv_handle);
}
(待更新)
写博客不容易,需要大家多多支持。想了解更多,本人也可以提供有赏服务