I'm using the example ble_app_hrs
along with the HRM
part of the nRF Toolbox
iOS app. It makes sense to handle this in on_ble_evt
in main.c
but am unclear how I can recover from enter system mode off.
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
uint32_t err_code;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
led_stop();
// Initialize the current heart rate to the average of max and min values. So that
// everytime a new connection is made, the heart rate starts from the same value.
m_cur_heart_rate = (MAX_HEART_RATE + MIN_HEART_RATE) / 2;
// Start timers used to generate battery and HR measurements.
application_timers_start();
// Start handling button presses
err_code = app_button_enable();
APP_ERROR_CHECK(err_code);
break;
case BLE_GAP_EVT_DISCONNECTED:
// @note Flash access may not be complete on return of this API. System attributes are now
// stored to flash when they are updated to ensure flash access on disconnect does not
// result in system powering off before data was successfully written.
// Go to system-off mode, should not return from this function, wakeup will trigger
// a reset.
system_off_mode_enter();
break;
case BLE_GAP_EVT_TIMEOUT:
if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT)
{
led_stop();
nrf_gpio_cfg_sense_input(HR_INC_BUTTON_PIN_NO,
BUTTON_PULL,
NRF_GPIO_PIN_SENSE_LOW);
nrf_gpio_cfg_sense_input(HR_DEC_BUTTON_PIN_NO,
BUTTON_PULL,
NRF_GPIO_PIN_SENSE_LOW);
system_off_mode_enter();
}
break;
default:
// No implementation needed.
break;
}
}