You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/06/27 03:47:05 UTC

[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on a diff in pull request #1211: Added Neopixel Example

xiaoxiang781216 commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r906946953


##########
examples/neopixel/neopixel_main.c:
##########
@@ -38,6 +38,196 @@
 
 #include <nuttx/leds/neopixel.h>
 
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+  char      * path;
+  int         loops;
+  int         leds;
+  int         delay;
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+struct neo_config_s config =
+{
+  .path      =   NULL,
+  .loops     =      4, /* all colors 4 times */
+  .leds      =      1,
+  .delay     =  20000  /* µs -- ~50Hz */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: help
+ ****************************************************************************/
+
+static void help(FAR struct neo_config_s  * conf)
+{
+  printf("Usage: neopixel [OPTIONS]\n");
+
+  printf("\nArguments are \"sticky\".  "
+         "For example, once the device path is\n");
+  printf("specified, that path will be re-used until it is changed.\n");
+
+  printf("  [-p path] selects the Neopixel device.  "
+         "Default: %s Current: %s\n",
+         CONFIG_EXAMPLE_NEOPIXEL_DEFAULT_DEV, conf->path ? conf->path
+                                                           : "NONE");
+
+  printf("  [-l leds] selects number of neopixels in the chain.  "
+         "Default: %d Current: %d\n",
+         1, conf->leds);
+
+  printf("  [-r repeat] selects the number change cycles.  "
+         "Default: %d Current: %d\n",
+         4, conf->loops);
+
+  printf("  [-d delay] selects delay between updates.  "
+         "Default: %d us Current: %d us\n",
+         20000, conf->delay);
+}
+
+/****************************************************************************
+ * Name: set_devpath
+ ****************************************************************************/
+
+static void set_devpath(FAR struct neo_config_s  * conf,
+                        FAR const char           * devpath)

Review Comment:
   ditto



##########
examples/neopixel/neopixel_main.c:
##########
@@ -38,6 +38,196 @@
 
 #include <nuttx/leds/neopixel.h>
 
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+  char      * path;
+  int         loops;
+  int         leds;
+  int         delay;
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+struct neo_config_s config =
+{
+  .path      =   NULL,
+  .loops     =      4, /* all colors 4 times */
+  .leds      =      1,
+  .delay     =  20000  /* µs -- ~50Hz */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: help
+ ****************************************************************************/
+
+static void help(FAR struct neo_config_s  * conf)

Review Comment:
   remove space before conf



##########
examples/neopixel/neopixel_main.c:
##########
@@ -48,48 +238,53 @@
 
 int neopixel_main(int argc, FAR char *argv[])
 {
-  printf("Hello, World, from neopixel!!\n");
-
-  char      * path      = CONFIG_EXAMPLE_NEOPIXEL_DEFAULT_DEV;
-  int         loops     =   1024; /* all colors 4 times */
-  int         leds      =      1;
-  int         delay     =  20000; /* µs -- ~50Hz */
   uint32_t  * buffer;
   uint32_t  * bp;

Review Comment:
   add FAR and remove space before variables



##########
examples/neopixel/neopixel_main.c:
##########
@@ -38,6 +38,196 @@
 
 #include <nuttx/leds/neopixel.h>
 
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+  char      * path;
+  int         loops;
+  int         leds;
+  int         delay;
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+struct neo_config_s config =
+{
+  .path      =   NULL,
+  .loops     =      4, /* all colors 4 times */
+  .leds      =      1,
+  .delay     =  20000  /* µs -- ~50Hz */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: help
+ ****************************************************************************/
+
+static void help(FAR struct neo_config_s  * conf)
+{
+  printf("Usage: neopixel [OPTIONS]\n");
+
+  printf("\nArguments are \"sticky\".  "
+         "For example, once the device path is\n");
+  printf("specified, that path will be re-used until it is changed.\n");
+
+  printf("  [-p path] selects the Neopixel device.  "
+         "Default: %s Current: %s\n",
+         CONFIG_EXAMPLE_NEOPIXEL_DEFAULT_DEV, conf->path ? conf->path
+                                                           : "NONE");
+
+  printf("  [-l leds] selects number of neopixels in the chain.  "
+         "Default: %d Current: %d\n",
+         1, conf->leds);
+
+  printf("  [-r repeat] selects the number change cycles.  "
+         "Default: %d Current: %d\n",
+         4, conf->loops);
+
+  printf("  [-d delay] selects delay between updates.  "
+         "Default: %d us Current: %d us\n",
+         20000, conf->delay);
+}
+
+/****************************************************************************
+ * Name: set_devpath
+ ****************************************************************************/
+
+static void set_devpath(FAR struct neo_config_s  * conf,
+                        FAR const char           * devpath)
+{
+  /* Get rid of any old device path */
+
+  if (conf->path != NULL)
+    {
+      free(conf->path);
+    }
+
+  /* Then set-up the new device path by copying the string */
+
+  conf->path = strdup(devpath);
+}
+
+/****************************************************************************
+ * Name: arg_string
+ ****************************************************************************/
+
+static int arg_string(FAR char **arg, FAR char **value)
+{
+  FAR char *ptr = *arg;
+
+  if (ptr[2] == '\0')
+    {
+      *value = arg[1];
+      return 2;
+    }
+  else
+    {
+      *value = &ptr[2];
+      return 1;
+    }
+}
+
+/****************************************************************************
+ * Name: arg_decimal
+ ****************************************************************************/
+
+static int arg_decimal(FAR char **arg, FAR long *value)
+{
+  FAR char *string;
+  int ret;
+
+  ret = arg_string(arg, &string);
+  *value = strtol(string, NULL, 10);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: parse_args
+ ****************************************************************************/
+
+static void parse_args(FAR struct neo_config_s  * conf,

Review Comment:
   ditto



##########
examples/neopixel/neopixel_main.c:
##########
@@ -0,0 +1,106 @@
+/****************************************************************************
+ * apps/examples/neopixel/neopixel_main.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <debug.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include <nuttx/leds/neopixel.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * hello_main
+ ****************************************************************************/
+
+int neopixel_main(int argc, FAR char *argv[])

Review Comment:
   change main, the build system will rename it for you automatically.



##########
examples/neopixel/neopixel_main.c:
##########
@@ -38,6 +38,196 @@
 
 #include <nuttx/leds/neopixel.h>
 
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+  char      * path;
+  int         loops;
+  int         leds;
+  int         delay;
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+struct neo_config_s config =
+{
+  .path      =   NULL,
+  .loops     =      4, /* all colors 4 times */
+  .leds      =      1,
+  .delay     =  20000  /* µs -- ~50Hz */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: help
+ ****************************************************************************/
+
+static void help(FAR struct neo_config_s  * conf)
+{
+  printf("Usage: neopixel [OPTIONS]\n");
+
+  printf("\nArguments are \"sticky\".  "
+         "For example, once the device path is\n");
+  printf("specified, that path will be re-used until it is changed.\n");
+
+  printf("  [-p path] selects the Neopixel device.  "
+         "Default: %s Current: %s\n",
+         CONFIG_EXAMPLE_NEOPIXEL_DEFAULT_DEV, conf->path ? conf->path
+                                                           : "NONE");
+
+  printf("  [-l leds] selects number of neopixels in the chain.  "
+         "Default: %d Current: %d\n",
+         1, conf->leds);
+
+  printf("  [-r repeat] selects the number change cycles.  "
+         "Default: %d Current: %d\n",
+         4, conf->loops);
+
+  printf("  [-d delay] selects delay between updates.  "
+         "Default: %d us Current: %d us\n",
+         20000, conf->delay);
+}
+
+/****************************************************************************
+ * Name: set_devpath
+ ****************************************************************************/
+
+static void set_devpath(FAR struct neo_config_s  * conf,
+                        FAR const char           * devpath)
+{
+  /* Get rid of any old device path */
+
+  if (conf->path != NULL)
+    {
+      free(conf->path);
+    }
+
+  /* Then set-up the new device path by copying the string */
+
+  conf->path = strdup(devpath);
+}
+
+/****************************************************************************
+ * Name: arg_string
+ ****************************************************************************/
+
+static int arg_string(FAR char **arg, FAR char **value)
+{
+  FAR char *ptr = *arg;
+
+  if (ptr[2] == '\0')
+    {
+      *value = arg[1];
+      return 2;
+    }
+  else
+    {
+      *value = &ptr[2];
+      return 1;
+    }
+}
+
+/****************************************************************************
+ * Name: arg_decimal
+ ****************************************************************************/
+
+static int arg_decimal(FAR char **arg, FAR long *value)
+{
+  FAR char *string;
+  int ret;
+
+  ret = arg_string(arg, &string);
+  *value = strtol(string, NULL, 10);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: parse_args
+ ****************************************************************************/
+
+static void parse_args(FAR struct neo_config_s  * conf,
+                       int argc,
+                       FAR char **argv)
+{
+  FAR char  * ptr;
+  FAR char  * str;

Review Comment:
   ditto



##########
examples/neopixel/neopixel_main.c:
##########
@@ -38,6 +38,196 @@
 
 #include <nuttx/leds/neopixel.h>
 
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+  char      * path;

Review Comment:
   remove space before path, and add FAR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org