You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/01/16 11:41:25 UTC

[nuttx-apps] branch master updated: examples/lvgldemo: Select default demo

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 757fc307c examples/lvgldemo: Select default demo
757fc307c is described below

commit 757fc307c33e44c2ab95eca11dc26a401f1f263b
Author: Lee Lup Yuen <lu...@appkaki.com>
AuthorDate: Mon Jan 16 08:29:43 2023 +0800

    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)
     {