/**@brief Handle the key of the Unread Alert button. * * @details This function check the current state of unread alert and then, enable, disable or * clear the alert depending on the state. */ static void handle_key_press_unread_alert_button(void) { uint32_t err_code = NRF_SUCCESS; if (m_unread_alert_state == ALERT_NOTIFICATION_ON) { m_unread_alert_state = ALERT_NOTIFICATION_ENABLED; nrf_gpio_pin_clear(UNREAD_ALERT_NOTIF_LED_PIN_NO); } else if (m_unread_alert_state == ALERT_NOTIFICATION_ENABLED) { m_unread_alert_state = ALERT_NOTIFICATION_DISABLED; err_code = ble_ans_c_disable_notif_unread_alert(&m_ans_c); } else { m_unread_alert_state = ALERT_NOTIFICATION_ENABLED; err_code = ble_ans_c_enable_notif_unread_alert(&m_ans_c); } // If the user presses the button while we are not connected, // we will have NRF_ERROR_INVALID_STATE, thus we just ignore the error code. if (err_code != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE) { APP_ERROR_HANDLER(err_code); } }
/**@brief Function for handling the key of the Unread Alert button. * * @details This function check the current state of unread alert and then, enable, disable or * clear the alert depending on the state. */ static void unread_alert_state_toggle(void) { uint32_t err_code = NRF_SUCCESS; if (m_unread_alert_state == ALERT_NOTIFICATION_ON) { m_unread_alert_state = ALERT_NOTIFICATION_ENABLED; err_code = bsp_indication_set(BSP_INDICATE_ALERT_OFF); } else if (m_unread_alert_state == ALERT_NOTIFICATION_ENABLED) { m_unread_alert_state = ALERT_NOTIFICATION_DISABLED; err_code = ble_ans_c_disable_notif_unread_alert(&m_ans_c); } else { m_unread_alert_state = ALERT_NOTIFICATION_ENABLED; err_code = ble_ans_c_enable_notif_unread_alert(&m_ans_c); } // If the user presses the button while we are not connected, // we will have NRF_ERROR_INVALID_STATE, thus we just ignore the error code. if (err_code != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE) { APP_ERROR_HANDLER(err_code); } }
/**@brief Setup of alert notifications in master. * * @details This function will be called when a successful connection has been established. */ static void setup_alert_notification(void) { uint32_t err_code; err_code = ble_ans_c_enable_notif_new_alert(&m_ans_c); APP_ERROR_CHECK(err_code); m_new_alert_state = ALERT_NOTIFICATION_ENABLED; err_code = ble_ans_c_enable_notif_unread_alert(&m_ans_c); APP_ERROR_CHECK(err_code); m_unread_alert_state = ALERT_NOTIFICATION_ENABLED; }