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

never call "app_button_is_pushed()" function in ble-lbs-master project

Hello Nordic,

I am trying debugging on following project [--ble_app_lbs_master--]. During debugging, I never reach at app_button_is_pushed function. I tried pressing the button while debugging and in connected state.

Actually I want to read the button_pin_status (value) in between when button pressed and button detected. How can I do that?

Please suggest valuable suggestions.

Thanks n Regards

Update1: @Aryan: Please find the attached app_button.x file.app_button.c

Update2: @Aryan:

image description

uint32_t app_button_init(app_button_cfg_t * p_buttons, uint8_t button_count, uint32_t detection_delay) image description

  • app_button library also has a debounce timer, so you do not have to worry about it. It filters debounces already. you can configure the debounce delay time in app_button_init

    Also if you are not able to detect the button press directly from the example of GITHUB that is probably because the example enables the button after it gets connected,

    Add this below line in your main() function if you want to test button before your device connects.

         uint32_t err_code;
         err_code = app_button_enable();
        APP_ERROR_CHECK(err_code);
    
  • Thanks @Aryan, thats working without getting connected state. but still its not reaching at [app_button_is_pushed].

    Please suggest me how can I read the button_pin_state start from, when I press the button and when I release the button. (including bouncing and debouncing state). Do I need do add the extra timer and timer polling for this. If yes then how can I add that and where?

    Thanks n Regards

  • app_button_is_pushed is not used by the example that is why it never gets called.

    bool m_is_pushed;
    static void gpiote_event_handler(uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low)
    {
        uint32_t err_code;
     
        // Start detection timer. If timer is already running, the detection period is restarted.
        // NOTE: Using the p_context parameter of app_timer_start() to transfer the pin states to the
        //       timeout handler (by casting event_pins_mask into the equally sized void * p_context
        //       parameter).
        STATIC_ASSERT(sizeof(void *) == sizeof(uint32_t));
    
        err_code = app_timer_stop(m_detection_delay_timer_id);
    
        if (err_code != NRF_SUCCESS)
        {
            // The impact in app_button of the app_timer queue running full is losing a button press.
            // The current implementation ensures that the system will continue working as normal. 
            return;
        }
        
        err_code = app_button_is_pushed(1,  &m_is_pushed);
            if (err_code != NRF_SUCCESS)
        {
            while(1); // you handle your error here
        }
        m_pin_transition.low_to_high = event_pins_low_to_high;
        m_pin_transition.high_to_low = event_pins_high_to_low;
        
        err_code = app_timer_start(m_detection_delay_timer_id,
                                   m_detection_delay,
                                   (void *)(event_pins_low_to_high | event_pins_high_to_low));
        if (err_code != NRF_SUCCESS)
        {
            // The impact in app_button of the app_timer queue running full is losing a button press.
            // The current implementation ensures that the system will continue working as normal. 
        }
    }
    

    in main.c you can access m_is_pushed by declaring it as extern.

    the first argument in the function app_button_is_pushed is the index of the button config you have used in app_button_init. For me it was 1.

  • Hello @Aryan sir,

    Thanks for your reply~

    Could you please elaborate this (where and how can I use this...) (how can I read the pin_status while bouncing and debouncing) in detail to make me understand its flow ?

    Thanks for your help~

    Regards

  • I just added

    err_code = app_button_is_pushed(1,  &m_is_pushed);
    if (err_code != NRF_SUCCESS)
    {
        while(1); // you handle your error here
    }
    

    in the gpiote event handler (callback after the button state is changed) in app_button.c (SDK8.0.0). The above code will read if the button is pushed and store the result in global variable m_is_pushed before starting the debouncing timer. You can access this in main.c file by declaring it as extern.

    if you want to read the button status after the debounce timer expired then you need to do the same in the timer callback function.

Related