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);

Reply Children