/**@brief Function for checking if the erase bond button press sequence is detected. * * @param[out] p_erase_bonds Will be true if the clear bonding button was pressed to wake the application up. */ static void detect_erase_bond_pressed(bool * p_erase_bonds) { uint32_t err_code; bool button; *p_erase_bonds = false; err_code = app_button_is_pushed(0, &button); APP_ERROR_CHECK(err_code); uint8_t count = 0; while (button) { nrf_delay_ms(100); count++; if (count > 20) { *p_erase_bonds = true; NRF_LOG_DEBUG("Erasing bonds button press detected!\r\n"); break; } err_code = app_button_is_pushed(0, &button); APP_ERROR_CHECK(err_code); } while (button) { nrf_gpio_pin_clear(LED_1); nrf_delay_ms(200); nrf_gpio_pin_set(LED_1); nrf_delay_ms(200); err_code = app_button_is_pushed(0, &button); APP_ERROR_CHECK(err_code); } }
/**@brief Check if this is the first start, or if it was a restart due to a pushed button. */ static bool is_first_start(void) { uint32_t err_code; bool inc_button_pushed; bool dec_button_pushed; err_code = app_button_is_pushed(HR_INC_BUTTON_PIN_NO, &inc_button_pushed); APP_ERROR_CHECK(err_code); err_code = app_button_is_pushed(HR_DEC_BUTTON_PIN_NO, &dec_button_pushed); APP_ERROR_CHECK(err_code); return (!inc_button_pushed && !dec_button_pushed); }
/**@brief Function for the Device Manager initialization. */ static void device_manager_init(void) { uint32_t err_code; dm_init_param_t init_data; dm_application_param_t register_param; // Initialize persistent storage module. err_code = pstorage_init(); APP_ERROR_CHECK(err_code); // Clear all bonded centrals if the "delete all bonds" button is pushed. err_code = app_button_is_pushed(BOND_DELETE_ALL_BUTTON_ID, &init_data.clear_persistent_data); APP_ERROR_CHECK(err_code); err_code = dm_init(&init_data); APP_ERROR_CHECK(err_code); memset(®ister_param.sec_param, 0, sizeof(ble_gap_sec_params_t)); register_param.sec_param.timeout = SEC_PARAM_TIMEOUT; register_param.sec_param.bond = SEC_PARAM_BOND; register_param.sec_param.mitm = SEC_PARAM_MITM; register_param.sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; register_param.sec_param.oob = SEC_PARAM_OOB; register_param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; register_param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; register_param.evt_handler = device_manager_evt_handler; register_param.service_type = DM_PROTOCOL_CNTXT_GATT_SRVR_ID; err_code = dm_register(&m_app_handle, ®ister_param); APP_ERROR_CHECK(err_code); }
void config_init(void) { uint8_t buf[5]; ext_ram_read_data(EXT_RAM_CONFIG + OFFSET_MAGIC, buf, 5); bool force_reset; app_button_is_pushed(3, &force_reset); // force reset if back button is pressed if (force_reset || buf[0] != buf[2] || buf[0] != 0x05 || buf[1] != buf[3] || buf[1] != 0x5E) { // set up clear config buf[0] = 0x05; buf[1] = 0x5E; buf[2] = 0x05; buf[3] = 0x5E; buf[4] = 0x0; ext_ram_write_data(EXT_RAM_CONFIG + OFFSET_MAGIC, buf, 5); ext_ram_fill(EXT_RAM_CONFIG + OFFSET_DEFAULT_WATCH_FACE, 0, 1); for (int i=0; i<CUSTOM_WATCHSET_NUMBER; i++) { ext_ram_fill(EXT_RAM_CONFIG + OFFSET_CUSTOM_WATCHSET+(SPIFFS_OBJ_NAME_LEN*i), 0, 1); } config_reset_global_actions(); config_reset_watchface_actions(); } else { config_load_global_actions(); config_load_watchface_actions(); } }
/**@brief Initialization of the Alert Notification Service Client. */ static void alert_notification_init(void) { uint32_t err_code; ble_ans_c_init_t ans_init_obj; bool services_delete; memset(&ans_init_obj, 0, sizeof(ans_init_obj)); memset(m_alert_message_buffer, 0, MESSAGE_BUFFER_SIZE); ans_init_obj.evt_handler = on_ans_c_evt; ans_init_obj.message_buffer_size = MESSAGE_BUFFER_SIZE; ans_init_obj.p_message_buffer = m_alert_message_buffer; ans_init_obj.flash_page_num = ANS_FLASH_PAGE; ans_init_obj.error_handler = alert_notification_error_handler; err_code = ble_ans_c_init(&m_ans_c, &ans_init_obj); APP_ERROR_CHECK(err_code); // Clear all discovered and stored services if the "non-connectable advertisement start" // button is pushed err_code = app_button_is_pushed(BONDMNGR_DELETE_BUTTON_PIN_NO, &services_delete); APP_ERROR_CHECK(err_code); if (services_delete) { err_code = ble_ans_c_service_delete(); APP_ERROR_CHECK(err_code); } err_code = ble_ans_c_service_load(&m_ans_c); APP_ERROR_CHECK(err_code); }
static void button_long_press_timeout_handler(void * p_context) { uint32_t err_code; uint8_t pin_no = (uint8_t)((uint32_t)p_context&0xFF); bool pushed = false; for (uint32_t i = 0; i < BUTTONS_NO; i++) { app_button_cfg_t * p_btn = &buttons[i]; if (pin_no == p_btn->pin_no) { err_code = app_button_is_pushed(i, &pushed); if (err_code != NRF_SUCCESS) { // do nothing } if (pushed) { scr_mngr_handle_event(SCR_EVENT_BUTTON_LONG_PRESSED, 1<<i); } else { scr_mngr_handle_event(SCR_EVENT_BUTTON_PRESSED, 1<<i); } } } }
bool boardButtonCheck(uint8_t button_num) { bool is_pushed; ASSERT_INT( ERROR_NONE, app_button_is_pushed(button_gpio[button_num], &is_pushed), false ); return is_pushed; }
static void service_add(void) { ble_ancs_c_init_t ancs_init_obj; ble_uuid_t service_uuid; uint32_t err_code; bool services_delete; err_code = sd_ble_uuid_vs_add(&ble_ancs_base_uuid128, &m_ancs_uuid_type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_cp_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_ns_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_ds_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); memset(&ancs_init_obj, 0, sizeof(ancs_init_obj)); memset(m_apple_message_buffer, 0, MESSAGE_BUFFER_SIZE); ancs_init_obj.evt_handler = on_ancs_c_evt; ancs_init_obj.message_buffer_size = MESSAGE_BUFFER_SIZE; ancs_init_obj.p_message_buffer = m_apple_message_buffer; ancs_init_obj.error_handler = apple_notification_error_handler; err_code = ble_ancs_c_init(&m_ancs_c, &ancs_init_obj); APP_ERROR_CHECK(err_code); // Clear all discovered and stored services if the "delete all bonds" button is pushed. err_code = app_button_is_pushed(BONDMNGR_DELETE_BUTTON_PIN_NO, &services_delete); APP_ERROR_CHECK(err_code); if (services_delete) { err_code = ble_ans_c_service_delete(); APP_ERROR_CHECK(err_code); } err_code = ble_ans_c_service_load(&m_ancs_c); APP_ERROR_CHECK(err_code); }
/**@brief Bond Manager initialization. */ static void bond_manager_init(void) { uint32_t err_code; ble_bondmngr_init_t bond_init_data; bool bonds_delete; // Clear all bonded masters if the Bonds Delete button is pushed err_code = app_button_is_pushed(BONDMNGR_DELETE_BUTTON_PIN_NO, &bonds_delete); APP_ERROR_CHECK(err_code); // Initialize the Bond Manager bond_init_data.flash_page_num_bond = FLASH_PAGE_BOND; bond_init_data.flash_page_num_sys_attr = FLASH_PAGE_SYS_ATTR; bond_init_data.evt_handler = NULL; bond_init_data.error_handler = bond_manager_error_handler; bond_init_data.bonds_delete = bonds_delete; err_code = ble_bondmngr_init(&bond_init_data); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the Bond Manager. */ static void bond_manager_init(void) { uint32_t err_code; ble_bondmngr_init_t bond_init_data; bool bonds_delete; err_code = pstorage_init(); APP_ERROR_CHECK(err_code); // Clear all bonded masters if the Bonds Delete button is pushed. err_code = app_button_is_pushed(BONDMNGR_DELETE_BUTTON_PIN_NO, &bonds_delete); APP_ERROR_CHECK(err_code); // Initialize the Bond Manager. bond_init_data.evt_handler = on_bond_mgmr_evt; bond_init_data.error_handler = bond_manager_error_handler; bond_init_data.bonds_delete = bonds_delete; err_code = ble_bondmngr_init(&bond_init_data); APP_ERROR_CHECK(err_code); }