This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Differentiate keyfob button is pressed or released

Other Parts Discussed in Thread: CC2541

Hi there, 

I need to implement long press feature on CC2541 keyfob.

To do that, I need to differentiate if the keyfob button is "pressed" or "released" in keyfobapp_HandleKeys() function.

Does anyone know the best way to differentiate it?

Thanks a lots!

Arthur

  • After the button is pressed, you can trigger a event to check every 500 mili-second if the button is release. After the button is detected release, top the event.

  • Hi YiKai,

    Thanks for the response, but the problem is that I don't know how to differentiate if the button is pressed or released.

    If I can differentiate it, I will do the following:

    When button is pressed, keyfobapp_HandleKeys() will get called, and it starts a 5s timer.

    When button is released, keyfobapp_HandleKeys() will get called, and it stops the 5s timer.

    If the 5s timer expired, "long press" is triggered, which will happen only when the user presses and holds button for 5s.

    Thanks,
    Arthur 

  • If you use CC2540DK MINI, there are two buttons on it, the left one uses P0.0 and the right one uses P0.1. All of them are active low. It will trigger a falling edge and make keyfobapp_HandleKeys called. So, you can create a event in keyfobapp_HandleKeys and check if P0.0/P0.1 changes back to high level in the event. If it keeps low in 5 seconds, it means a long hold.

  • Hi Yikai,

    Does that mean I can use the following condition check in keyfobapp_HandleKeys()?

    if (keys & HAL_KEY_SW_2) {

        // button is pressed

    } else {

        // button is released

    }

    Thanks a lots for the response!

    Arthur

  • No, you need to create a event in

    if (keys & HAL_KEY_SW_2) {

        // button is pressed

    }

    else doesn't mean the button is released. As I mentioned in previous post, you need to check if the button GPI changes back to high level in the event to decide if it is released.