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

button_event_handler not triggering when not connected

Hi

I started form the lbs example to build my application. I have now the following problem: apparently the button_event_handler is only triggered when the device is connected over bluetooth. However, I would like it to trigger also when bluetooth is not connected, to count events on the button input. How do I do that?

Parents
  • Hi

    In the ble_app_lbs, you enable the app_button user when you connect. When the device connects you get a callback from the softdevice which is received in the on_ble_evt callback function in main.c. There you have the code :

        case BLE_GAP_EVT_CONNECTED:
            nrf_gpio_pin_set(CONNECTED_LED_PIN_NO);
            nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO);
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
    
            err_code = app_button_enable();
            APP_ERROR_CHECK(err_code);
            break;
    

    So if you call app_button_enable in the main function instead before you enter the main loop, then the button should be enabled all the time.

Reply
  • Hi

    In the ble_app_lbs, you enable the app_button user when you connect. When the device connects you get a callback from the softdevice which is received in the on_ble_evt callback function in main.c. There you have the code :

        case BLE_GAP_EVT_CONNECTED:
            nrf_gpio_pin_set(CONNECTED_LED_PIN_NO);
            nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO);
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
    
            err_code = app_button_enable();
            APP_ERROR_CHECK(err_code);
            break;
    

    So if you call app_button_enable in the main function instead before you enter the main loop, then the button should be enabled all the time.

Children
Related