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

Button push and release event BSP

Hi all,

I have created a custom board file for my pcb that uses the nRF52832 (rigado module). I have 10 buttons attached to the board and am successfully reading a button press on all (using BSP). It also nicely handles the BLE advertising and sleep features and the debouncing of course.

How can I detect the button release in the bsp_event_handler below? My goal is to set a bit in m_custom_value[2] which corresponds to a button. If the button is held down, the value won't change, however, when the button is released (upon detecting the release event) the value will be reset.

Kind Regards,

Zoran

m_custom_value[2] is initialized to 0xFF

/**@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);
}
break; // BSP_EVENT_DISCONNECT

case BSP_EVENT_WHITELIST_OFF:
if (m_conn_handle == BLE_CONN_HANDLE_INVALID)
{
err_code = ble_advertising_restart_without_whitelist(&m_advertising);
if (err_code != NRF_ERROR_INVALID_STATE)
{
APP_ERROR_CHECK(err_code);
}
}
break; // BSP_EVENT_KEY_0

case BSP_EVENT_KEY_1:
m_custom_value[2] = m_custom_value[2] ^ 0x01;
break; // GL1 button pressed

case BSP_EVENT_KEY_2:
m_custom_value[2] = m_custom_value[2] ^ 0x02;
break; // GL2 button pressed

case BSP_EVENT_KEY_3:
m_custom_value[2] = m_custom_value[2] ^ 0x04;
break; // GL3 button pressed

case BSP_EVENT_KEY_4:
m_custom_value[2] = m_custom_value[2] ^ 0x08;
break; // GL4 button pressed

case BSP_EVENT_KEY_5:
m_custom_value[2] = m_custom_value[2] ^ 0x10;
break; // GL5 button pressed

case BSP_EVENT_KEY_6:
m_custom_value[2] = m_custom_value[2] ^ 0x20;
nrf_gpio_pin_toggle(LED_2);
break; // GL6 button pressed

case BSP_EVENT_KEY_7:
m_custom_value[2] = m_custom_value[2] ^ 0x40;
break; // Saf button pressed

case BSP_EVENT_KEY_8:
m_custom_value[2] = m_custom_value[2] ^ 0x80;
nrf_gpio_pin_toggle(LED_2);
break; // MRel button pressed

case BSP_EVENT_KEY_9:
m_custom_value[3] = m_custom_value[3] ^ 0x01;
break; // MRep button pressed

default:
break;
}
}

Parents Reply Children
No Data
Related