Add a function to retrieve a button by index

This commit is contained in:
George Oikonomou 2018-03-18 12:39:19 +00:00
parent 180a52b4ff
commit a8c9931257
3 changed files with 18 additions and 1 deletions

View File

@ -43,7 +43,7 @@ PROCESS_THREAD(button_hal_example, ev, data)
PROCESS_BEGIN();
btn = button_hal_get_by_id(BUTTON_HAL_ID_BUTTON_ZERO);
btn = button_hal_get_by_index(0);
printf("Button HAL example.\n");
printf("Device button count: %u.\n", button_hal_button_count);

View File

@ -141,6 +141,16 @@ button_hal_get_by_id(uint8_t unique_id)
return NULL;
}
/*---------------------------------------------------------------------------*/
button_hal_button_t *
button_hal_get_by_index(uint8_t index)
{
if(index >= button_hal_button_count) {
return NULL;
}
return button_hal_buttons[index];
}
/*---------------------------------------------------------------------------*/
uint8_t
button_hal_get_state(button_hal_button_t *button)
{

View File

@ -247,6 +247,13 @@ void button_hal_init(void);
*/
button_hal_button_t *button_hal_get_by_id(uint8_t unique_id);
/**
* \brief Retrieve a button by its index
* \param index The button's index (0, 1, ... button_hal_button_count - 1)
* \return A pointer to the button or NULL if not found
*/
button_hal_button_t *button_hal_get_by_index(uint8_t index);
/**
* \brief Get the state of a button (pressed / released)
* \param button A pointer to the button