/**@brief Function for handling of BLE stack events. */ void ble_ans_c_on_ble_evt(ble_ans_c_t * p_ans, const ble_evt_t * p_ble_evt) { uint16_t event = p_ble_evt->header.evt_id; switch (m_client_state) { case STATE_UNINITIALIZED: // Initialization is handle in special case, thus if we enter here, it means that an // event is received even though we are not initialized --> ignore. break; case STATE_IDLE: if (event == BLE_GAP_EVT_CONNECTED) { event_connect(p_ans, p_ble_evt); } break; case STATE_WAITING_ENC: if ((event == BLE_GAP_EVT_AUTH_STATUS) || (event == BLE_GAP_EVT_SEC_INFO_REQUEST)) { event_encrypted_link(p_ans, p_ble_evt); } else if (event == BLE_GAP_EVT_DISCONNECTED) { event_disconnect(p_ans); } break; case STATE_DISC_SERV: if (event == BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP) { event_discover_rsp(p_ans, p_ble_evt); } else if (event == BLE_GAP_EVT_DISCONNECTED) { event_disconnect(p_ans); } break; case STATE_DISC_CHAR: if (event == BLE_GATTC_EVT_CHAR_DISC_RSP) { event_characteristic_rsp(p_ans, p_ble_evt); } else if (event == BLE_GAP_EVT_DISCONNECTED) { event_disconnect(p_ans); } break; case STATE_DISC_DESC: if (event == BLE_GATTC_EVT_DESC_DISC_RSP) { event_descriptor_rsp(p_ans, p_ble_evt); } else if (event == BLE_GAP_EVT_DISCONNECTED) { event_disconnect(p_ans); } break; case STATE_RUNNING: if (event == BLE_GATTC_EVT_HVX) { event_notify(p_ans, p_ble_evt); } else if (event == BLE_GATTC_EVT_READ_RSP) { event_read_rsp(p_ans, p_ble_evt); } else if (event == BLE_GATTC_EVT_WRITE_RSP) { event_write_rsp(p_ans, p_ble_evt); } else if (event == BLE_GAP_EVT_DISCONNECTED) { event_disconnect(p_ans); } else { // Do nothing, event not handled in this state. } break; case STATE_RUNNING_NOT_DISCOVERED: if (event == BLE_GAP_EVT_DISCONNECTED) { event_disconnect(p_ans); } break; default: event_disconnect(p_ans); break; } }
/** * Initializes this module. */ void timer_init() { // Register events evt_sdl_user = event_connect("sdl-user", 0, _timer_evt_sdl_user, NULL, EVENT_HANDLER_ENABLED); }