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

Generate Events Continuously With BSP While Holding a Button Down?

Hi, 

I'm trying to use the BSP functions to do the following. 

1. Detect three different button pressing types. First - singular quick press, Second - Long Press with Timeout (say 1 second), and Third - Continual Press with no Timeout

2. Quick press and long press to disconnect and sleep (I have been successful in this)

3. Continual Press to send data as long as a button is held down. (This is what I'm having trouble with)

I'm having some issues figuring out the third one to always send data while I'm pressing a button. All of the examples (from what I can tell) only generate a singular button press EVENT. In essence what I want to do I believe is as long as the button is held down, generate an event so it can be handled in the bsp_event_handler. 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**@brief Function for handling events from the BSP module.
*
* @param[in] event Event generated when button is pressed.
*/
static void bsp_event_handler(bsp_event_t event)
{
ret_code_t err_code;
switch (event)
{
case BSP_EVENT_SLEEP:
sleep_mode_enter();
break; // BSP_EVENT_SLEEP
case BSP_EVENT_DISCONNECT:
err_code = sd_ble_gap_disconnect(m_conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
if (err_code != NRF_ERROR_INVALID_STATE)
{
APP_ERROR_CHECK(err_code);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

In examining bsp.c I've identified a potential spot to try and modify but I'm not sure if it would work or how to do it without conflicting with the long button press (1 sec) indication. I think if I could somehow use a rolling counter and with a "constant_pushed_pin_no = pin_no" it may work. 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**@brief Function for handling button events.
*
* @param[in] pin_no The pin number of the button pressed.
* @param[in] button_action Action button.
*/
static void bsp_button_event_handler(uint8_t pin_no, uint8_t button_action)
{
bsp_event_t event = BSP_EVENT_NOTHING;
uint32_t button = 0;
uint32_t err_code;
static uint8_t current_long_push_pin_no; /**< Pin number of a currently pushed button, that could become a long push if held long enough. */
static bsp_event_t release_event_at_push[BUTTONS_NUMBER]; /**< Array of what the release event of each button was last time it was pushed, so that no release event is sent if the event was bound after the push of the button. */
button = bsp_board_pin_to_button_idx(pin_no);
if (button < BUTTONS_NUMBER)
{
switch (button_action)
{
case APP_BUTTON_PUSH:
event = m_events_list[button].push_event;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Anyone have any ideas on how this could be approached?

Thanks!