Start stop button ?

Dear Members,

How can I make a start/stop button with 1 button ?

Here's my handler :

void bsp_event_handler(bsp_event_t event)
{
    switch (event)
    {
        case BSP_EVENT_SLEEP:
            nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
            break;
				
				 case BSP_EVENT_KEY_0:
					 NRF_LOG_INFO("BSP_EVENT_KEY 0 PUSH ON\n");
            if (actual_state != BSP_INDICATE_FIRST)
                actual_state--;
						    //NRF_LOG_INFO("BSP_EVENT_KEY 0 PUSH ON\n"); //2Mar22 Rixtronix LAB
            else
                actual_state = BSP_INDICATE_LAST;
						    NRF_LOG_INFO("BSP_EVENT_KEY 0 PUSH OFF\n"); //2Mar22 Rixtronix LAB
            break;
            ............

Any clues ?

Kind regards,

Rixtronix LAB

  • Hi Karl,

    I pushed BSP_BUTTON_2, but on timeout handler I got :


    the log :
    nfo> app: BSP_BUTTON_0
                                                           

    nfo> app: BSP_BUTTON_1
                                                           

    nfo> app: BSP_BUTTON_2
                                                           

    nfo> app: BSP_BUTTON_3
                                                           

    nfo> app: BSP_BUTTON_2
                                                           

    nfo> app: BSP_BUTTON_0

    Any ideas?

    Kind regards,

    Rixtronix LAB

    Rixtronix LAB

  • Hi Karl,

    Why isn't responding to

    bsp_button_event_handler on bsp.c, but only responding to bsp_event_handler in main.c ?

    Regards,

    Rixtronix

  • Hello again, Rixtronix

    Thank you for your patience with this.

    RixtronixLAB said:

    I pushed BSP_BUTTON_2, but on timeout handler I got :


    the log :
    nfo> app: BSP_BUTTON_0
                                                           

    nfo> app: BSP_BUTTON_1
                                                           

    nfo> app: BSP_BUTTON_2
                                                           

    nfo> app: BSP_BUTTON_3
                                                           

    nfo> app: BSP_BUTTON_2
                                                           

    nfo> app: BSP_BUTTON_0

    This looks for me like a possible fallthrough in a switch case handling, could this be the case?
    I do not see any break statements at the end of the BSP_EVENT_KEY_2 case you have shared, at least.

    I notice that you are not checking the returned error code from you calls to bsp_event_to_button_action_assign, please make sure to do so to see if they are succeeding.

    I also notice that you are using the ant bsp init, bsp_btn_ant_init, could you elaborate on why you are using this, and what your intentions are for calling it multiple times in a row?
    The bsp init function should only have to be called once.

    Best regards,
    Karl

  • Hi Karl,

    Thanks for the reply,

    Like this ?

    *********Button input 1Mar22 Rixtronix LAB********/
    void read_button()
    {
    	ret_code_t err_code;
    	  err_code = bsp_event_to_button_action_assign(BSP_BUTTON_0,
                                                                BSP_BUTTON_ACTION_PUSH,
                                                                BSP_EVENT_KEY_0);
    	   APP_ERROR_CHECK(err_code);
    	  
    	
     	  err_code = bsp_event_to_button_action_assign(BSP_BUTTON_1,
                                                                BSP_BUTTON_ACTION_PUSH, 
                                                                BSP_EVENT_KEY_1);//hardware not connected
    	   APP_ERROR_CHECK(err_code);
    	  
    	 
      /************originally***********/
    	 err_code = bsp_event_to_button_action_assign(BSP_BUTTON_2,
                                                                BSP_BUTTON_ACTION_PUSH,
                                                                BSP_EVENT_KEY_2);
    	 APP_ERROR_CHECK(err_code);
    	/**************
    	err_code = bsp_event_to_button_action_assign(BSP_BUTTON_2,
                                                                BSP_BUTTON_ACTION_LONG_PUSH, 
                                                                BSP_EVENT_KEY_2);
       ********/
    	/*************originally button 4*/
    	err_code = bsp_event_to_button_action_assign(BSP_BUTTON_3,
                                                                BSP_BUTTON_ACTION_PUSH,
                                                                BSP_EVENT_KEY_3);
       APP_ERROR_CHECK(err_code);																														
    																														
      /*************Rixtronix LAB 17 Mar 22
    	err_code = bsp_event_to_button_action_assign(BSP_BUTTON_3,
                                                                BSP_BUTTON_ACTION_LONG_PUSH, 
                                                                BSP_EVENT_KEY_3);
      */
    }	

    So I need to use only

     bsp_init

    and don't have to use bsp_btn_ant_init, I took it from ANT example ?

    Regards,

    Rixtronix

  • Hi Karl,

    from :

     err_code = bsp_event_to_button_action_assign(BSP_BUTTON_2,
                                                                BSP_BUTTON_ACTION_PUSH,
                                                                BSP_EVENT_KEY_2);
    	 //APP_ERROR_CHECK(err_code);
    	 NRF_LOG_INFO("Error code %u",err_code);

    I got "error code 7"

    what does it mean ?

    Regards,

    Rixtronix

Related