Hi everyone,
I am using nRF52840 to prototype and I want on certain occations to disconnect the peripheral from the central. On of these occations is when I charge my device. I tried the following snippet on the main for(;;) loop but it doesn't work
for (;;) {
int charging = nrf_gpio_pin_read(WC_CHG);
// na - enter if statement when charging
if (!charging) {
if (charge_flag == true) {
UN_state = BLE_STATE_CHARGING;
ret_code_t err_code;
bool check;
check = nrf_sdh_is_enabled();
if ((check == true) && (m_conn_handle != BLE_CONN_HANDLE_INVALID)) {
err_code = sd_ble_gap_disconnect(m_conn_handle,
BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION);
if (err_code == NRF_SUCCESS) {
NRF_LOG_INFO("Disconnected from Central");
}
}
charging_state(UN_state);
}
charge_flag = false;
}
// Enter system On sleep mode
idle_state_handle();
}
}
Any advice?
Thanks in advance
Nick