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

Button normal press and long press detect

Hi,

I need some clarification about how to differentiate the normal press and long press detect for a single button to assign awake and sleep mode.

I am using nRF52832 SDK15.3 in segger embedded studio .

Is there any predefined code for sleep and awake system?

Parents Reply
  • Hi, Vidar

    i have used the code when i press the button 1 . short press arrived

    but during long press no log came it shows only short press ..?!

    and one more thing

    as per ble_app_uart

    uses BSP_BLE_ module  link .  here

    as it is but i need is

    current status         button          action              event

    connected                 1              long push            BSP_EVENT_SLEEP

    not connected          1              long push            BSP_EVENT_SLEEP

    sleep                         1              long push            BSP_EVENT_WAKEUP

    shall we change it like this???

Children
  • The implementations include code for using both BSP and button handling library, see #ifdefs. I have tested it with SDK 15.2.0

  • Vidar, Now i didn't change anything

    freshly opened ble_app_uart  (from sdk15.3)

    In bsp_btn_ble.c  file

    static uint32_t connection_buttons_configure()
    {
        uint32_t err_code;
    
        err_code = bsp_event_to_button_action_assign(BTN_ID_SLEEP,
                                                     BTN_ACTION_SLEEP,
                                                     BSP_EVENT_DEFAULT);
        RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code);
    
        err_code = bsp_event_to_button_action_assign(BTN_ID_WHITELIST_OFF,
                                                     BTN_ACTION_WHITELIST_OFF,
                                                     BSP_EVENT_WHITELIST_OFF);
        RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code);
    
    
        err_code = bsp_event_to_button_action_assign(BTN_ID_DISCONNECT,
                                                     BTN_ACTION_DISCONNECT,
                                                     BSP_EVENT_DISCONNECT);
        RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code);
    
        return NRF_SUCCESS;
    }
    

    is changed to

    static uint32_t connection_buttons_configure()
    {
        uint32_t err_code;
    
        err_code = bsp_event_to_button_action_assign(BTN_ID_SLEEP,
                                                     BTN_ACTION_SLEEP,
                                                     BSP_EVENT_DEFAULT);
        RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code);
    
        err_code = bsp_event_to_button_action_assign(BTN_ID_WHITELIST_OFF,
                                                     BTN_ACTION_WHITELIST_OFF,
                                                     BSP_EVENT_WHITELIST_OFF);
        RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code);
    
    
        err_code = bsp_event_to_button_action_assign(BTN_ID_DISCONNECT,
                                                     BTN_ACTION_DISCONNECT,
                                                     BSP_EVENT_SLEEP);
        RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code);
    
        return NRF_SUCCESS;
    }

    getting restarted

  • Coming back to your code which you given from the link

    i changed the value as

    #define USE_BSP 1

    and

    void bsp_event_handler(bsp_event_t event)
    {
        uint32_t err_code;
        switch (event)
        {
            case BT0_SHORT_PUSH:
                NRF_LOG_INFO("Short button press");
                printf("\r\n Short button press.\r\n");
    		 
                break;
            
            case BT0_LONG_PUSH:
                NRF_LOG_INFO("Long button press");
    		printf("\r\n Long button press.\r\n");	 
    			sleep_mode_enter(); 
                break;
    
            default:
                break;
        }
    }
    
    

    just called sleep_mode_enter(); in the LONG_PUSH event

    system getting  restarted  not when to off state

  • It either means that the chip does not enter sleep because it is in debug interface mode, or that you have a pin that wakes it up again as soon as it goes to sleep. In other words, you need to test this without having the debugger attached, and go over your pin configurations.  

Related