Add a way to retrieve device button count

This commit is contained in:
George Oikonomou 2018-03-18 12:37:44 +00:00
parent 708127dfb8
commit 180a52b4ff
2 changed files with 9 additions and 1 deletions

View File

@ -46,6 +46,7 @@ PROCESS_THREAD(button_hal_example, ev, data)
btn = button_hal_get_by_id(BUTTON_HAL_ID_BUTTON_ZERO);
printf("Button HAL example.\n");
printf("Device button count: %u.\n", button_hal_button_count);
printf("%s on pin %u with ID=0, Logic=%s, Pull=%s\n",
BUTTON_HAL_GET_DESCRIPTION(btn), btn->pin,
btn->negative_logic ? "Negative" : "Positive",

View File

@ -211,7 +211,14 @@ struct button_hal_button_s {
#endif
/*---------------------------------------------------------------------------*/
#define BUTTON_HAL_BUTTONS(...) \
button_hal_button_t *button_hal_buttons[] = {__VA_ARGS__, NULL};
button_hal_button_t *button_hal_buttons[] = {__VA_ARGS__, NULL}; \
const uint8_t button_hal_button_count = \
(sizeof(button_hal_buttons) / sizeof(button_hal_buttons[0])) - 1;
/*---------------------------------------------------------------------------*/
/**
* \brief The number of buttons on a device
*/
extern const uint8_t button_hal_button_count;
/*---------------------------------------------------------------------------*/
/**
* \brief A broadcast event generated when a button gets pressed