From 757fc307c33e44c2ab95eca11dc26a401f1f263b Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Mon, 16 Jan 2023 08:29:43 +0800 Subject: [PATCH] examples/lvgldemo: Select default demo The LVGL Example App `lvgldemo` currently requires 1 argument: the name of the demo to show. ```bash lvgldemo widgets ``` In this PR, we propose to make the argument optional if there is only one demo configured. This will enable PINE64 PinePhone to boot straight into `lvgldemo` and auto-start the LVGL App, without entering any `nsh` commands. ### Modified Files `examples/lvgldemo/lvgldemo.c`: If no arguments are specified and only 1 demo exists, select the demo --- examples/lvgldemo/lvgldemo.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/lvgldemo/lvgldemo.c b/examples/lvgldemo/lvgldemo.c index 63e26865d..076ab10f9 100644 --- a/examples/lvgldemo/lvgldemo.c +++ b/examples/lvgldemo/lvgldemo.c @@ -171,14 +171,27 @@ static demo_create_func_t find_demo_create_func(FAR const char *name) int main(int argc, FAR char *argv[]) { demo_create_func_t demo_create_func; + FAR const char *demo = NULL; + const int func_key_pair_len = sizeof(func_key_pair) / + sizeof(func_key_pair[0]); - if (argc != 2) + /* If no arguments are specified and only 1 demo exists, select the demo */ + + if (argc == 1 && func_key_pair_len == 2) /* 2 because of NULL sentinel */ + { + demo = func_key_pair[0].name; + } + else if (argc != 2) { show_usage(); return EXIT_FAILURE; } + else + { + demo = argv[1]; + } - demo_create_func = find_demo_create_func(argv[1]); + demo_create_func = find_demo_create_func(demo); if (demo_create_func == NULL) {