This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Documentation for BSP_EVENT_MID_PRESS event or how is the best way to know button press length

I am working with some code from a previous provider and I found in its void bsp_event_handler(bsp_event_t event) function this code:

case BSP_EVENT_MID_PRESS:
            err_code = app_timer_stop(wake_button);
            APP_ERROR_CHECK(err_code);
            lock = 0;
        break;

I have looked for the BSP_EVENT_MID_PRESS everywhere but I could not find any documentation about it. My concern is about my internal flag called lock which might be causing a endless loop at main:

lock = 1;
// do the inits()....
start_counting_press_time();

if(is_counting) {
	while(lock == 1) {
	}
}

In case you were wondering about the is_counting flag, it is only assigned in this function

void start_counting_press_time(void)
{
    button_is_not_pushed = nrf_gpio_pin_read(BUTTON_1) ? true : false;
	if( button_is_not_pushed == 0 )
	{
		uint32_t err_code = app_timer_start(wake_button, APP_TIMER_TICKS(500, APP_TIMER_PRESCALER) , NULL);
		APP_ERROR_CHECK(err_code);
		// ...
		is_counting = 1;
	}
}

Is this the best way to achieve the length of a button press, so it can wake up and begin advertising after x seconds button press/release?

Parents
  • This looks like peripheral driver example which is not running with BLE stack. Once you want to use radio stack then you cannot have such blocking waiting loops like this. However determining length of the button press (or two GPIOTE events to be technically accurate) should be done through RTC or TIMER peripheral. Using app_timer library is good idea especially if you want to detect that button is pressed for certain time but you don't want to wait for release but want to start once certain time window is over (then you get beside GPIOTE interrupt handler calls also timing call).

  • From what I see there is app_button library in nRF5 SDK v13.0.0 which can cooperate with app_timer in order to detect duration of different button actions. Both seems to be used in bsp library and that has pretty nice example in pwr_mgmt example (in peripherals section). Just note that this is not including BLE stack so all clock initialization and main loops are done in "naive" way, these will probably change once you will be including these examples into real BLE application.

Reply
  • From what I see there is app_button library in nRF5 SDK v13.0.0 which can cooperate with app_timer in order to detect duration of different button actions. Both seems to be used in bsp library and that has pretty nice example in pwr_mgmt example (in peripherals section). Just note that this is not including BLE stack so all clock initialization and main loops are done in "naive" way, these will probably change once you will be including these examples into real BLE application.

Children
No Data
Related