How to disable Bluetooth Radio and SPI Communication when Power button pressed

Hello!

I am using nRF Connect SDK  v2.6.0

I am new to NCS can you give some examples and suggestions on this.

I'm doing the firmware that will be applied to the custom device.


This device contains one button to switch on/off the device on 3 sec long press, I am bit confusing on long press button(give some examples or suggestions on power button)

I am reading 2 sensors data every 2msec continuosly and i am sending sensor values to the  android(client)  via BLE.

This is the first time to control the power, CPU using push button.

I want to apply the long press(3 sec) button functionality to turn off the BLE and communications(in my case SPI) 

I went through nRF9160 Feather blog its different 

I am facing difficulty to apply the long press button 

Now I am trying to implement press the same button for 3 sec  to turn/off the led.

Thank you in advance.

Parents Reply Children
  • Hello!

    I implemented Long press button , below is my code.

    volatile bool button_pressed_var = false;
    
    struct k_timer mytimer;
    /* timer call back function */
    static void my_timer(struct k_timer *dummy)
    {
    	if(gpio_pin_get_dt(&button))
    	{
    			button_pressed_var = !button_pressed_var;
                if(button_pressed_var)
    			{
    				printk("device Off: \n");
    				
    				"If I add bt_disable here ASSERTION FETAL Error coming"
    			}
    			else
    			{
    			    printk("device On: \n");
    			}
    			k_timer_stop(&mytimer);
    	}
    
    }
    
    /*Button call back function */
    void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
    {
    	int err;
    	
    	if(BIT(button.pin) & pins)
    	{
    		if(gpio_pin_get_dt(&button))
    		{
    			k_timer_start(&mytimer, K_SECONDS(2), K_NO_WAIT);
    
    		}
    	}
    	
    }
    /*Define a variable of type static struct gpio_callback */
    static struct gpio_callback button_cb_data;
    
    int main()
    {
        k_timer_init(&mytimer, my_timer, NULL);
        ret = gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_TO_ACTIVE );
    
    	/* Initialize the static struct gpio_callback variable   */
        gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin)); 	
    	
    	/* Add the callback function by calling gpio_add_callback()   */
    	gpio_add_callback(button.port, &button_cb_data);
    	
    }


    The above code is accuratly will work for longer time?

    For custom board to switch off/on the device it will work good for long time?

    and How to disable advertisemnet and disable the bluetooth for power optimizations when button is pressed?

    Thank you in advance.

Related