From 070e0fae2ca37861e7cf173088949f4c2118ca34 Mon Sep 17 00:00:00 2001 From: Mouise Date: Sat, 13 Jun 2026 14:21:44 +0200 Subject: [PATCH] dynamic btns handle array allocation --- main/buttons/buttons.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main/buttons/buttons.c b/main/buttons/buttons.c index f69d993..c65779c 100644 --- a/main/buttons/buttons.c +++ b/main/buttons/buttons.c @@ -19,17 +19,11 @@ const action actions[] = { {.btnAcc = CUT, .name = "CUT", .pin = 9, .shortcut = 'i'}, {.btnAcc = HORN, .name = "HORN", .pin = 10, .shortcut = 'j'}, }; -void button_event_cb(void *arg, void *data) -{ - action *a = (action*)data; - - button_event_t event = iot_button_get_event(arg); - ESP_LOGI(TAG, "%s pin:%d name:%s shortcut:%c", iot_button_get_event_str(event), (int)a->pin, (char*)a->name, (char)a->shortcut); -} + void initialize_buttons(){ const button_config_t btn_cfg = {0}; - button_handle_t btns[10]; + button_handle_t btns[sizeof(actions) / sizeof(actions[0])]; for (size_t i = 0; i < sizeof(actions) / sizeof(actions[0]); i++) { @@ -41,4 +35,12 @@ void initialize_buttons(){ iot_button_register_cb(btns[i], BUTTON_PRESS_DOWN, NULL, button_event_cb, (void *) &actions[i]); iot_button_register_cb(btns[i], BUTTON_PRESS_UP, NULL, button_event_cb, (void *) &actions[i]); } +} + +void button_event_cb(void *arg, void *data) +{ + action *a = (action*)data; + + button_event_t event = iot_button_get_event(arg); + ESP_LOGI(TAG, "%s pin:%d name:%s shortcut:%c", iot_button_get_event_str(event), (int)a->pin, (char*)a->name, (char)a->shortcut); } \ No newline at end of file