/**@brief Function for handling the timeout that delays reporting buttons as pushed. * * @details The detection_delay_timeout_handler(...) is a call-back issued from the app_timer * module. It is called with the p_context parameter. The p_context parameter is * provided to the app_timer module when a timer is started, using the call * @ref app_timer_start. On @ref app_timer_start the p_context will be holding the * currently pressed buttons. * * @param[in] p_context Pointer used for passing information app_start_timer() was called. * In the app_button module the p_context holds information on pressed * buttons. */ static void detection_delay_timeout_handler(void * p_context) { uint32_t err_code; uint32_t current_state_pins; // Get current state of pins. err_code = app_gpiote_pins_state_get(m_gpiote_user_id, ¤t_state_pins); if (err_code != NRF_SUCCESS) { return; } uint8_t i; // Pushed button(s) detected, execute button handler(s). for (i = 0; i < m_button_count; i++) { app_button_cfg_t * p_btn = &mp_buttons[i]; if (((m_pin_transition.high_to_low & (1 << p_btn->pin_no)) != 0) && (p_btn->button_handler != NULL)) { //If it's active high then going from high to low was a release of the button. if(p_btn->active_state == APP_BUTTON_ACTIVE_HIGH) { button_handler_execute(p_btn, APP_BUTTON_RELEASE); } //If it's active low then going from high to low was a push of the button. else { button_handler_execute(p_btn, APP_BUTTON_PUSH); } } else if (((m_pin_transition.low_to_high & (1 << p_btn->pin_no)) != 0) && (p_btn->button_handler != NULL)) { //If it's active high then going from low to high was a push of the button. if(p_btn->active_state == APP_BUTTON_ACTIVE_HIGH) { button_handler_execute(p_btn,APP_BUTTON_PUSH); } //If it's active low then going from low to high was a release of the button. else { button_handler_execute(p_btn,APP_BUTTON_RELEASE); } } } }
/**@brief Timeout handler for delaying reporting buttons as pushed. * * @details The detection_delay_timeout_handler(...) is a call-back issued from the app_timer * module. It is called with the p_context parameter. The p_context parameter is * provided to the app_timer module when a timer is started, using the call * @ref app_timer_start. On @ref app_timer_start the p_context will be holding the * currently pressed buttons. * * @param[in] p_context Pointer used for passing information app_start_timer() was called. * In the app_button module the p_context holds information on pressed * buttons. */ static void detection_delay_timeout_handler(void * p_context) { uint32_t err_code; uint32_t event_pins_mask; uint32_t current_state_pins; uint32_t active_pins = 0; // Get state of pins when timer was started. event_pins_mask = (uint32_t)p_context; // Get current state of pins. err_code = app_gpiote_pins_state_get(m_gpiote_user_id, ¤t_state_pins); if (err_code != NRF_SUCCESS) { return; } active_pins = current_state_pins & m_active_high_states_mask; active_pins |= (~current_state_pins & m_active_low_states_mask); event_pins_mask &= active_pins; // Check if any event generating pins are still active. if (event_pins_mask != 0) { uint8_t i; // Pushed button(s) detected, execute button handler(s). for (i = 0; i < m_button_count; i++) { app_button_cfg_t * p_btn = &mp_buttons[i]; if (((event_pins_mask & (1 << p_btn->pin_no)) != 0) && (p_btn->button_handler != NULL)) { button_handler_execute(p_btn); } } } }