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

Button release event?

Am I right in thinking that the button handler only causes an event for a button press(although I realize it is possible to configure the button such that a release is interpreted as a press), rather than a change of state? I expect I can work around this, but would it be possible to re-configure the button in the event handler, such that events would be generated on both press and release?

Parents
  • Hi John,

    From SDK v6.0 and newer, app_button will give you an event on both button press and release. Here's an example snippet:

    static void button_event_handler(uint8_t pin_no, uint8_t button_action)
    {
        if (button_action == APP_BUTTON_PUSH)
        {
            switch (pin_no)
            {
    			case MY_BUTTON:
    				do_something_on_press();
    				break;		
                default:
                    APP_ERROR_HANDLER(pin_no);
                    break;
            }
        }
        else if (button_action == APP_BUTTON_RELEASE)
        {
            switch (pin_no)
            {
    			case MY_BUTTON:
    				do_something_on_release();
    				break;
                default:
                    APP_ERROR_HANDLER(pin_no);
                    break;
            }
        }
    }
    

    Cheers, Håkon

Reply
  • Hi John,

    From SDK v6.0 and newer, app_button will give you an event on both button press and release. Here's an example snippet:

    static void button_event_handler(uint8_t pin_no, uint8_t button_action)
    {
        if (button_action == APP_BUTTON_PUSH)
        {
            switch (pin_no)
            {
    			case MY_BUTTON:
    				do_something_on_press();
    				break;		
                default:
                    APP_ERROR_HANDLER(pin_no);
                    break;
            }
        }
        else if (button_action == APP_BUTTON_RELEASE)
        {
            switch (pin_no)
            {
    			case MY_BUTTON:
    				do_something_on_release();
    				break;
                default:
                    APP_ERROR_HANDLER(pin_no);
                    break;
            }
        }
    }
    

    Cheers, Håkon

Children
Related