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

 

Parents
  • 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.

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

Children
Related