Change function to get button state to non-static

This commit is contained in:
George Oikonomou 2018-03-17 22:05:56 +00:00
parent 4882077a75
commit c87aadc390
2 changed files with 22 additions and 14 deletions

View File

@ -56,19 +56,6 @@ extern button_hal_button_t *button_hal_buttons[];
/* Common handler for all handler events, and register it with the GPIO HAL */
static gpio_hal_event_handler_t button_event_handler;
/*---------------------------------------------------------------------------*/
static uint8_t
get_state(button_hal_button_t *button)
{
uint8_t pin_state = gpio_hal_arch_read_pin(button->pin);
if((pin_state == 0 && button->negative_logic == true) ||
(pin_state == 1 && button->negative_logic == false)) {
return BUTTON_HAL_STATE_PRESSED;
}
return BUTTON_HAL_STATE_RELEASED;
}
/*---------------------------------------------------------------------------*/
static void
duration_exceeded_callback(void *btn)
{
@ -99,7 +86,7 @@ debounce_handler(void *btn)
expired = ctimer_expired(&button->duration_ctimer);
button_state = get_state(button);
button_state = button_hal_get_state(button);
/*
* A debounce timer expired. Inspect the button's state. If the button's
@ -164,6 +151,19 @@ button_hal_get_by_id(uint8_t unique_id)
return NULL;
}
/*---------------------------------------------------------------------------*/
uint8_t
button_hal_get_state(button_hal_button_t *button)
{
uint8_t pin_state = gpio_hal_arch_read_pin(button->pin);
if((pin_state == 0 && button->negative_logic == true) ||
(pin_state == 1 && button->negative_logic == false)) {
return BUTTON_HAL_STATE_PRESSED;
}
return BUTTON_HAL_STATE_RELEASED;
}
/*---------------------------------------------------------------------------*/
void
button_hal_init()
{

View File

@ -239,6 +239,14 @@ void button_hal_init(void);
* \return A pointer to the button or NULL if not found
*/
button_hal_button_t *button_hal_get_by_id(uint8_t unique_id);
/**
* \brief Get the state of a button (pressed / released)
* \param button A pointer to the button
* \retval BUTTON_HAL_STATE_RELEASED The button is currently released
* \retval BUTTON_HAL_STATE_PRESSED The button is currently pressed
*/
uint8_t button_hal_get_state(button_hal_button_t *button);
/*---------------------------------------------------------------------------*/
#endif /* BUTTON_HAL_H_ */
/*---------------------------------------------------------------------------*/