Hi
Using an nRF52832 and SDK11, I have the following issue:
I want to use button 0 with a regular push for functionality and a long press to go to sleep. The detection of long and short pushes work, and the button is configured to cause a wakeup. Problem is that when going to sleep during a long press, the system automatically powers back up due to the button still being pressed.
Is there any way to avoid the wakeup when the button is still pressed and wait till a new flank (so first release, then push again)
Here's my relevant code:
static void buttons_leds_init(bool * p_erase_bonds)
{
bsp_event_t startup_event;
uint32_t err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
bsp_event_handler);
APP_ERROR_CHECK(err_code);
err_code = bsp_btn_ble_init(NULL, &startup_event);
APP_ERROR_CHECK(err_code);
err_code = bsp_event_to_button_action_assign(0, BSP_BUTTON_ACTION_LONG_PUSH, BSP_EVENT_LONG_KEY_0);
APP_ERROR_CHECK(err_code);
*p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA);
}
void bsp_event_handler(bsp_event_t event)
{
uint32_t err_code;
switch (event)
{ case BSP_EVENT_KEY_0:
{
someFunction();
break;
}
case BSP_EVENT_LONG_KEY_0:
{
sleep_mode_enter();
break;
}
default:
break;
}
}
static void sleep_mode_enter(void)
{
uint32_t err_code = bsp_indication_set(BSP_INDICATE_IDLE);
APP_ERROR_CHECK(err_code);
// Prepare wakeup buttons.
err_code = bsp_btn_ble_sleep_mode_prepare();
APP_ERROR_CHECK(err_code);
// Go to system-off mode (this function will not return; wakeup will cause a reset).
err_code = sd_power_system_off();
APP_ERROR_CHECK(err_code);
}