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,

    Thanks for the reply,

    So :

      case BSP_EVENT_KEY_1:
          
                         if(button1_state)
                                            {
                                                    //OFF_function();
                                                SYSTEM_OFF
                                                
                                                    button1_state = STATE_OFF;
                                            }
                                            else
                                            {
                                                    //ON_function();
                                                   SYSTEM_WAKEUP
                                                    button1_state = STATE_ON;

                                           }

    What's the function for SYSTEM_OFF AND SYSTEM_WAKEUP for softdevice ?

    Kind regards,

    Rixtronix LAB

  • Hello again,

    I would recommend that you implement the entering of SYSTEM_OFF sleep in the same way that it is implemented in the BLE peripheral examples - such as the BLE NUS example - usually in the sleep_mode_enter function. This function first prepares the device for wakeup, and then places the device into SYSTEM_OFF sleep. You will not need to have the alternating function in the button handler then, because the only thing the device will be doing during SYSTEM_OFF sleep is to be ready for wakeup by the buttons configured for wakeup during the sleep_mode_enter function.

    Best regards,
    Karl

  • Hi Karl,

    from ble_peripheral directory examples above,

    which example is using button with SYSTEM_OFF,

    and which example is using "button long push" for event ?

    Best regards,

    Rixtronix

  • Hello,

    I am not sure that anyone of them uses a button to initiate SYSTEM_OFF, not long button push (because they all are using the btn_ble_bsp variant), but you can easily assign a new event to button action using the bsp function I mentioned earlier, and then initiate SYSTEM_OFF in the same manner as demonstrated in the sleep_mode_enter function.

    Best regards,
    Karl

  • Hi Karl,

    Thanks for the reply,

    I have :

    /*************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);

    and :

     case BSP_EVENT_KEY_3:
                //NRF_LOG_INFO("BSP_EVENT_KEY 3 PUSH OFF\n");
                            
                                                                   
                         if(button3_state)
                                            {  
                                                            
                                                                        
                                                    //ON_function();
                                                  NRF_LOG_INFO("BSP_EVENT_KEY 3 PUSH ON==> LONG PUSH >200ms\n");
                                                 //beep_v11();
                                                
                                                    button3_state = STATE_OFF;
                                            }
                                            else
                                            {
                                                    //OFF_function();
                                                  NRF_LOG_INFO("BSP_EVENT_KEY 3 PUSH OFF\n");
                                                  //beep_v12();
                                                
                                                    button3_state = STATE_ON;
                                            }
                                                         
                if (actual_state != BSP_INDICATE_LAST)
                    actual_state++;
                else
                    actual_state = BSP_INDICATE_FIRST;
                break;       

    on bsp.h

    #define BSP_BUTTON_ACTION_LONG_PUSH (2)                  /**< Represents pushing and holding a button for @ref BSP_LONG_PUSH_TIMEOUT_MS milliseconds. See also @ref bsp_button_action_t. */

    but it's not responding to 2 seconds long push,

    What am I missing here ?

    Regards,

    Rixtronix

Related