dynamic btns handle array allocation

This commit is contained in:
2026-06-13 14:21:44 +02:00
parent 907abaf2a0
commit 070e0fae2c

View File

@@ -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);
}