Add a function to retrieve a button by index
This commit is contained in:
parent
180a52b4ff
commit
a8c9931257
|
@ -43,7 +43,7 @@ PROCESS_THREAD(button_hal_example, ev, data)
|
||||||
|
|
||||||
PROCESS_BEGIN();
|
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("Button HAL example.\n");
|
||||||
printf("Device button count: %u.\n", button_hal_button_count);
|
printf("Device button count: %u.\n", button_hal_button_count);
|
||||||
|
|
|
@ -141,6 +141,16 @@ button_hal_get_by_id(uint8_t unique_id)
|
||||||
return NULL;
|
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
|
uint8_t
|
||||||
button_hal_get_state(button_hal_button_t *button)
|
button_hal_get_state(button_hal_button_t *button)
|
||||||
{
|
{
|
||||||
|
|
|
@ -247,6 +247,13 @@ void button_hal_init(void);
|
||||||
*/
|
*/
|
||||||
button_hal_button_t *button_hal_get_by_id(uint8_t unique_id);
|
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)
|
* \brief Get the state of a button (pressed / released)
|
||||||
* \param button A pointer to the button
|
* \param button A pointer to the button
|
||||||
|
|
Loading…
Reference in New Issue