Detecting a button double click?

We are new to Nordic and have been making great progress with our nrf52840DK board and successfully running many of the Nordic SDK examples. We can't seem to find a single example of an API that will notify on a variety of button events (more than just a single click). Our code needs to respond differently for single-click, double-click, press-and-hold. Sure seems that the Nordic SDK would have something for that. Yes? Any help would be appreciated.

Thanks,

Steve K, PuzL Labs, LLC

Parents
  • Hi Priyanka,

    Thanks, good to know that v2.4.1 supports sensing button click events. I went looking within my v2.4.1 Nordic SDK installation to find a code example that might show the use of the "CAF: Buttons module". I couldn’t find anything. Being new to Nordic I guess it's possible I am looking in the wrong place. If you happen to have a tip I'd be grateful. Thanks in advance.

    Regards,

    Steve K, PuzL Labs, LLC

  • Please take a look at the nRF Desktop application where the CAF:Buttons module has been used.

    -Priyanka

  • Hi Priyanka,

    Uggggg, I took a look at the recent link. Again, I'm coming up empty handed. Frankly, it doesn't seem that the question I'm asking should be this difficult to get to the bottom of. I wish that I could be directed to a very specific block of logic that demonstrates how a double-click of a button can be detected. (buttons like any of the four buttons on the nrf52840-DK board). I've given an honest look at the collection of CAF content in my SDK as well as the documentation and I find it lacking. It is by no means obvious how to answer my question from the general pointers I've been given in the direction of CAF. I am imagining that there really wouldn't be that much code involved, but if I don't know the various interfaces available and the syntax it's hard to get anything working. I typically am very good at hunting things down and reverse engineering. It was not so difficult for me to locate/generate the logic required for a single button click (non-CAF), I'll show it below. It would be fantastic if someone could just present an example with this level of detail that I could then leverage to get Button Double-Click Detection.

    Button Single-Click Detection.

    #include <zephyr/kernel.h>

    #define Button_NODE DT_ALIAS(sw0)
    static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET(Button_NODE, gpios);
    static struct gpio_callback button_cb;

    static void button_callback(const struct device *gpiob, struct gpio_callback *cb, gpio_port_pins_t pins)
    {
       // TBSL — do logic here to process single button press event.
    }

    static void Init_button()
    {
        if (gpio_is_ready_dt(&button)) {
           gpio_pin_configure_dt(&button, GPIO_INPUT);
           gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_TO_ACTIVE);
           gpio_init_callback(&button_cb, button_callback, BIT(button.pin));
           gpio_add_callback(button.port, &button_cb);
        }
    }

    int main(void)
    {
       Init_button();
       while (true) {
          k_msleep(5000);
       }
       return 0;
    }

  • Hi,

    There does not seem an in-detail sample, but there is the CAF: Click detector module which can help. You can refer to the implementation details there, that does various click types, say, double click for instance. You can take a look at the click_detector code and copy the same method used here into your own application.

    Regards.

    Priyanka

Reply Children
No Data
Related