This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to 2 events based on the same key

Hello?

I need to create 2 events on the same key with two operation like LONG_PRESSED and RELEASE after pressed it. (With precondition no RELEASE event after event of LONG_PRESSED)

I touched several spots like the below, (Custom_board.h, bsp.c, & bsp.h)

But the initialization of “buttons_leds_init()” was failed, so it run repeatedly.  

QUESTION,

Creating 2 events based on ONE KEY, Is it possible on KEY input system provided?

Is here anybody who succeed implementing this feature based on KEY input system provided?

 

@ to assign key event to each Key @ bsp_init in bsp.c

num=0;

err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_RELEASE, BSP_EVENT_KEY_MODE);  //Mode change

err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_LONG_PUSH, BSP_EVENT_KEY_EDIT); //Mode edit

err_code = bsp_event_to_button_action_assign(++num, BSP_BUTTON_ACTION_RELEASE, BSP_EVENT_KEY_UP);         //UP

err_code = bsp_event_to_button_action_assign(++num, BSP_BUTTON_ACTION_RELEASE, BSP_EVENT_KEY_DN);          //Down

err_code = bsp_event_to_button_action_assign(++num, BSP_BUTTON_ACTION_LONG_PUSH, BSP_EVENT_KEY_RST); //Reset

 

@ for definition of Key Event in bsp.h/c

typedef enum

{

    BSP_EVENT_NOTHING = 0,      /**< Assign this….*/

….

BSP_EVENT_KEY_RST,      

    BSP_EVENT_KEY_MODE,

    BSP_EVENT_KEY_UP,

    BSP_EVENT_KEY_DN,

    BSP_EVENT_KEY_EDIT,   

    BSP_EVENT_KEY_LAST = BSP_EVENT_KEY_7,

} bsp_event_t;

@ for definition of HW Key in Custom_board.h

#define BUTTONS_NUMBER 5

#define BUTTON_START   5

#define BUTTON_1       5  <- the same port /w BUTTON_1/4

#define BUTTON_2       6

#define BUTTON_3       8

#define BUTTON_4       5 < <- the same port /w BUTTON_1/4

#define BUTTON_5       28

#define BUTTON_STOP    28

#define BUTTONS_LIST { BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4, BUTTON_5 }

#define BSP_BUTTON_0   BUTTON_1

#define BSP_BUTTON_1   BUTTON_2

#define BSP_BUTTON_2   BUTTON_3

#define BSP_BUTTON_3   BUTTON_4

#define BSP_BUTTON_4   BUTTON_5

 

  • Hi,

    Creating 2 events based on ONE KEY, Is it possible on KEY input system provided?

    Yes. The BSP library supports generating several events like this. For instance, the Power Management Example in SDK 15.3 generates events one both BSP_BUTTON_ACTION_LONG_PUSH and BSP_BUTTON_ACTION_RELEASE for the same button.

    Is here anybody who succeed implementing this feature based on KEY input system provided?

    Yes. I recomend you refer to the Power Management example. In practice it is just to call bsp_event_to_button_action_assign twice, like this:

        err_code = bsp_event_to_button_action_assign(BTN_ID_SLEEP,
                                                     BSP_BUTTON_ACTION_LONG_PUSH,
                                                     BSP_EVENT_SYSOFF);
        APP_ERROR_CHECK(err_code);
    
        err_code = bsp_event_to_button_action_assign(BTN_ID_SLEEP,
                                                     BSP_BUTTON_ACTION_RELEASE,
                                                     BSP_EVENT_SLEEP);
        APP_ERROR_CHECK(err_code);

  • Did you see my codes upper provided ? 

    These are the same what you're suggested in your answer.

    --------------------------------------

    err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_RELEASE, BSP_EVENT_KEY_MODE);  //Mode change

    err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_LONG_PUSH, BSP_EVENT_KEY_EDIT); //Mode edit

     --------------------------------------

    Update Jun 13

    I agree, basically the code (mine and yours) has no problem to implement 2 kind event based on the same key.

    In case of my code, the key events are processing on BSP_EVENT_HANDLER with SYS_MODE created by myself.

    Unfortunately there's a problem in the special case. ( it is not  ALWAYS.) so I think it need to debug more but...

    It seems that debugger tool has a limitation to debug so I ordered new one (no limitation)

    When it arrive in next week, I'm going to go further with it.

     I mean I will update some information after debugging more with new one.

    So THIS REMAIN PENDING until that time.  

    Thanks Einar

  • Hi,

    BrianCS said:

    Did you see my codes upper provided ? 

    These are the same what you're suggested in your answer.

    Yes, though I dod not comment specifically. The question was "Is here anybody who succeed implementing this feature based on KEY input system provided?", which is why I pointed to an SDK example where this is used and working.

    BrianCS said:
    Unfortunately there's a problem in the special case. ( it is not  ALWAYS.)

    This is new information. You write that there is a problem sometimes (not always). Does that mean that one or both events are sometimes missing? Which of the events? How often? Can you say more about how you handle things in your application? There is not much to go on.

    I am having problems understanding how this could happen. How have you verfified that you don't get the two callbacks (one for each event)? Generally, both these events are based on the same interrupt, so you can at least rule out a problem with a missed interrupt. The BSP itself does not have an event queue, but calls the callback functions directly, so it could not be caused by a full event buffer either.

    BrianCS said:
    I will update some information after debugging more with new one.

    Sounds good. It will be interesting to know more about what is going on.

  • Hi

    Jun 18:

    Here's update

    I made 2 events, RELEASE & LONG_PRESS with A Key. (Like the below)

    err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_RELEASE, BSP_EVENT_KEY_MODE); //Mode change

    err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_LONG_PUSH, BSP_EVENT_KEY_EDIT); //Mode edit

    The scenario of reproducing

    1. Press the KEY.

    2. Keep pressing for 3 sec. (programmed) -> Happen LONG_PRESS event.

    3. Then, unpress the KEY. -> Happen RELEASE event.

    Problem : The RELEASE event come out when release the key, after checking LONG_PRESS event . (100% reproduce)

    My question was how to make it, not to happen RELEASE event, after happening the LONG_PRESS event with the same key.

  • Hi,

    BrianCS said:
    My question was how to make it, not to happen RELEASE event, after happening the LONG_PRESS event with the same key.

    The way I understand it you want the following behavior:

    1) If the button is released before 3 seconds, you sill get a RELEASE event.

    2) If the button is released after 3 seconds, you want only a LONG_PUSH event and not a RELEASE event when the button is pushed.

    This behavior is not supported by the BSP module. However, you can simply add a tiny piece of logic in your event handling where you ignore the first RELEASE event after a LONG_PUSH event.

Related