feat!: command processing moved to task
This commit is contained in:
1 parent
8dc7385a90
commit
4116a94c5c
5 files changed
+866
-188
No files matched your search
@@ -7,15 +7,15 @@ which is distributed under the Apache License, Version 2.0. The original code ha
|
||||
|
||||
## Features
|
||||
|
||||
1. Multi-level hierarchical menu with support for nested submenus up to a configurable depth limit.
|
||||
2. Abstract navigation commands (`ZH_MENU_ENTER`, `ZH_MENU_SHOW`, `ZH_MENU_UP`, `ZH_MENU_DOWN`, `ZH_MENU_SELECT`, `ZH_MENU_BACK`) independent of any input device.
|
||||
1. Multi-level hierarchical menu with support for nested submenus up to a maximum depth of 8 levels.
|
||||
2. Abstract navigation commands independent of any input device.
|
||||
3. Configurable callbacks for menu enter, menu exit and current position change.
|
||||
4. Support for selectable items that can enter a dedicated adjustment mode with repeated `ZH_MENU_SELECT` handling.
|
||||
4. Support for selectable items that enter a dedicated adjustment mode with repeated selection handling.
|
||||
5. Support for simple action items that trigger a one-shot callback on selection.
|
||||
6. Built-in navigation stack that allows returning to the previous menu level with `ZH_MENU_BACK`.
|
||||
6. Built-in navigation stack that allows returning to the previous menu level.
|
||||
7. Optional cyclic navigation mode for scrolling through menu items in a loop.
|
||||
8. Per-item selectable flag that separates stateful items from plain action items.
|
||||
9. Minimal memory footprint with a single dynamically allocated handle and no per-node heap usage.
|
||||
8. Minimal memory footprint with a single dynamically allocated handle and no per-node heap usage.
|
||||
9. Built-in statistics for queue overflow errors and task stack watermark.
|
||||
|
||||
## Using
|
||||
|
||||
@@ -98,6 +98,7 @@ void app_main(void)
|
||||
{
|
||||
esp_log_level_set("zh_menu", ESP_LOG_ERROR);
|
||||
esp_log_level_set("zh_encoder", ESP_LOG_ERROR);
|
||||
esp_log_level_set("zh_vector", ESP_LOG_ERROR);
|
||||
esp_event_loop_create_default();
|
||||
esp_event_handler_instance_register(ZH_ENCODER, ESP_EVENT_ANY_ID, &zh_encoder_event_handler, NULL, NULL);
|
||||
zh_encoder_init_config_t encoder_config = ZH_ENCODER_INIT_CONFIG_DEFAULT();
|
||||
@@ -112,11 +113,15 @@ void app_main(void)
|
||||
encoder_config.encoder_step = 1;
|
||||
encoder_config.encoder_number = ENCODER_NUMBER;
|
||||
zh_encoder_init(&encoder_config, &encoder_handle);
|
||||
zh_menu_init_config_t menu_config = {.root = &main_menu,
|
||||
.loop = true,
|
||||
.enter_cb = &zh_menu_enter_main_menu_callback, // Optional.
|
||||
.exit_cb = &zh_menu_exit_main_menu_callback, // Optional.
|
||||
.change_cb = &zh_menu_change_menu_callback};
|
||||
zh_menu_init_config_t menu_config = ZH_MENU_INIT_CONFIG_DEFAULT();
|
||||
menu_config.task_priority = 5;
|
||||
menu_config.stack_size = configMINIMAL_STACK_SIZE;
|
||||
menu_config.queue_size = 5;
|
||||
menu_config.root = &main_menu;
|
||||
menu_config.loop = true;
|
||||
menu_config.enter_cb = &zh_menu_enter_main_menu_callback; // Optional.
|
||||
menu_config.exit_cb = &zh_menu_exit_main_menu_callback; // Optional.
|
||||
menu_config.change_cb = &zh_menu_change_menu_callback;
|
||||
zh_menu_init(&menu_config, &menu_handle);
|
||||
}
|
||||
|
||||
@@ -131,8 +136,8 @@ void zh_encoder_event_handler(void *arg, esp_event_base_t event_base, int32_t ev
|
||||
zh_encoder_button_event_on_isr_t *button_event = event_data;
|
||||
if (button_event->button_status == true)
|
||||
{
|
||||
menu_status.is_active == false ? zh_menu_set(&menu_handle, ZH_MENU_ENTER, NULL) : menu_status.is_selected == false ? zh_menu_set(&menu_handle, ZH_MENU_SELECT, NULL)
|
||||
: zh_menu_set(&menu_handle, ZH_MENU_BACK, NULL);
|
||||
menu_status.is_active == false ? zh_menu_set(&menu_handle, ZH_MENU_ENTER, NULL, 0) : menu_status.is_selected == false ? zh_menu_set(&menu_handle, ZH_MENU_SELECT, NULL, 0)
|
||||
: zh_menu_set(&menu_handle, ZH_MENU_BACK, NULL, 0);
|
||||
}
|
||||
break;
|
||||
case ZH_ENCODER_EVENT:
|
||||
@@ -141,13 +146,14 @@ void zh_encoder_event_handler(void *arg, esp_event_base_t event_base, int32_t ev
|
||||
{
|
||||
if (menu_status.is_selected == true)
|
||||
{
|
||||
zh_menu_set(&menu_handle, ZH_MENU_SELECT, encoder_event);
|
||||
zh_menu_set(&menu_handle, ZH_MENU_SELECT, encoder_event, sizeof(zh_encoder_event_on_isr_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder_event->encoder_status == true ? zh_menu_set(&menu_handle, ZH_MENU_UP, NULL) : zh_menu_set(&menu_handle, ZH_MENU_DOWN, NULL);
|
||||
encoder_event->encoder_status == true ? zh_menu_set(&menu_handle, ZH_MENU_UP, NULL, 0) : zh_menu_set(&menu_handle, ZH_MENU_DOWN, NULL, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -197,6 +203,6 @@ void zh_menu_simple_item_callback(void *arg)
|
||||
void zh_menu_back_command_callback(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
zh_menu_set(&menu_handle, ZH_MENU_BACK, NULL);
|
||||
zh_menu_set(&menu_handle, ZH_MENU_BACK, NULL, 0);
|
||||
}
|
||||
```
|
||||
Reference in new issue
Block a user