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

Parents
  • Hi Karl,

    How can I make power on and off in 1 button ?

    Regards,

    Rixtronix

  • Hello,

    You can follow the same procedure that I outlined earlier, without the conditional variable, to have it enter into SYSTEM_OFF sleep, and as part of this function you should setup the same button to enable it for wakeup.

    Best regards,
    Karl

  • 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

Reply
  • 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

Children
  • 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

Related