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:30:07 UTC
[GitHub] [incubator-nuttx-apps] curuvar opened a new pull request, #1211: Added Neopixel Example
curuvar opened a new pull request, #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211
## Summary
Example app using the neopixel driver that displays a rainbow pattern.
## Impact
Should not impact other apps.
## Testing
Tested app with single and multiple pixel chains with various update speeds.
--
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
[GitHub] [incubator-nuttx-apps] curuvar commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
curuvar commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r906961866
##########
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:
I am not sure what you mean by "change main".
--
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r912336177
##########
examples/ws2812/Makefile:
##########
@@ -0,0 +1,32 @@
+############################################################################
+# apps/apps/examples/ws2812/Makefile
Review Comment:
```suggestion
# apps/examples/ws2812/Makefile
```
--
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907410436
##########
examples/neopixel/Make.defs:
##########
@@ -0,0 +1,23 @@
+############################################################################
+# apps/examples/hello/Make.defs
Review Comment:
```suggestion
# apps/examples/neopixel/Make.defs
```
--
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907418899
##########
examples/neopixel/neopixel_main.c:
##########
@@ -0,0 +1,301 @@
+/****************************************************************************
+ * 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>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+ FAR 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;
+ long value;
+ int index;
+ int nargs;
+
+ for (index = 1; index < argc; )
+ {
+ ptr = argv[index];
+ if (ptr[0] != '-')
+ {
+ printf("Invalid options format: %s\n", ptr);
+ exit(0);
Review Comment:
```suggestion
exit(1);
```
Since this is an error scenario, it should return non-zero.
##########
examples/neopixel/neopixel_main.c:
##########
@@ -0,0 +1,301 @@
+/****************************************************************************
+ * 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>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+ FAR 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;
+ long value;
+ int index;
+ int nargs;
+
+ for (index = 1; index < argc; )
+ {
+ ptr = argv[index];
+ if (ptr[0] != '-')
+ {
+ printf("Invalid options format: %s\n", ptr);
+ exit(0);
+ }
+
+ switch (ptr[1])
+ {
+ case 'l':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Led count out of range: %ld\n", value);
+ exit(1);
+ }
+
+ conf->leds = (uint32_t)value;
+ index += nargs;
+ break;
+
+ case 'r':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Repeat out of range: %ld\n", value);
+ exit(1);
+ }
+
+ conf->loops = (uint32_t)value;
+ index += nargs;
+ break;
+
+ case 'p':
+ nargs = arg_string(&argv[index], &str);
+ set_devpath(conf, str);
+ index += nargs;
+ break;
+
+ case 'd':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Delay out of range: %ld\n", value);
Review Comment:
```suggestion
fprintf(stderr, "Delay out of range: %ld\n", value);
```
--
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
[GitHub] [incubator-nuttx-apps] pkarashchenko commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r911096544
##########
examples/ws2812/ws2812_main.c:
##########
@@ -0,0 +1,315 @@
+/****************************************************************************
+ * apps/examples/ws2812/ws2812_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 <debug.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include <nuttx/leds/ws2812.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+ FAR 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 */
Review Comment:
Can we stick with C89 init if possible?
##########
.gitignore:
##########
@@ -31,3 +31,5 @@ Make.dep
.context
# nuttx/$(TOPDIR)/Makefile.[unix|win]::$(DIRLINKS_EXTERNAL_DIRS)
.dirlinks
+.vscode
+.DS_Store
Review Comment:
```suggestion
.DS_Store
```
--
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907410201
##########
.gitignore:
##########
@@ -31,3 +31,5 @@ Make.dep
.context
# nuttx/$(TOPDIR)/Makefile.[unix|win]::$(DIRLINKS_EXTERNAL_DIRS)
.dirlinks
+.vscode
+.DS_Store
Review Comment:
```suggestion
```
`.gitignore` should only consider patterns related to files which are generated by the NuttX build system.
--
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
[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#issuecomment-1172904436
> @xiaoxiang781216, yes, I have been trying to remember to squash before I push changes. It turns out the change in question was make when I clicked the "Commit Suggestion" button on gustavonihei's comment. Is it best to avoid this practice, or is there some way to have it squash from the GitHub site itself?
I normally update the change locally instead from the web interface. Another way is enable Squash and Merge:
<img width="225" alt="image" src="https://user-images.githubusercontent.com/18066964/177004117-6b8a0992-6459-4fd8-9e08-61c700faddd0.png">
--
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
[GitHub] [incubator-nuttx-apps] xiaoxiang781216 merged pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211
--
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907419232
##########
examples/neopixel/neopixel_main.c:
##########
@@ -0,0 +1,301 @@
+/****************************************************************************
+ * 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>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+ FAR 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;
+ long value;
+ int index;
+ int nargs;
+
+ for (index = 1; index < argc; )
+ {
+ ptr = argv[index];
+ if (ptr[0] != '-')
+ {
+ printf("Invalid options format: %s\n", ptr);
+ exit(0);
+ }
+
+ switch (ptr[1])
+ {
+ case 'l':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Led count out of range: %ld\n", value);
+ exit(1);
+ }
+
+ conf->leds = (uint32_t)value;
+ index += nargs;
+ break;
+
+ case 'r':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Repeat out of range: %ld\n", value);
+ exit(1);
+ }
+
+ conf->loops = (uint32_t)value;
+ index += nargs;
+ break;
+
+ case 'p':
+ nargs = arg_string(&argv[index], &str);
+ set_devpath(conf, str);
+ index += nargs;
+ break;
+
+ case 'd':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Delay out of range: %ld\n", value);
+ exit(1);
+ }
+
+ conf->delay = (int)value;
+ index += nargs;
+ break;
+
+ case 'h':
+ help(conf);
+ exit(0);
+
+ default:
+ printf("Unsupported option: %s\n", ptr);
Review Comment:
```suggestion
fprintf(stderr, "Unsupported option: %s\n", ptr);
```
--
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907412611
##########
examples/neopixel/Kconfig:
##########
@@ -0,0 +1,33 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config EXAMPLE_NEOPIXEL
+ tristate "Neopixel Demo Program"
+ default n
+ ---help---
+ Enable the Neopixel demo
+
+if EXAMPLE_NEOPIXEL
+
+config EXAMPLE_NEOPIXEL_PROGNAME
+ string "Program Name"
+ default "neopixel"
+ ---help---
+ This is the name of the program that will be used when the NSH ELF
+ program is installed.
+
+config EXAMPLE_NEOPIXEL_PRIORITY
+ int "Task Priority"
+ default 100
+
+config EXAMPLE_NEOPIXEL_STACKSIZE
+ int "Stack Size"
+ default DEFAULT_TASK_STACKSIZE
+
+config EXAMPLE_NEOPIXEL_DEFAULT_DEV
+ string "Default Device"
+ default "/dev/neopixel"
+
+endif
Review Comment:
```suggestion
config EXAMPLES_NEOPIXEL
tristate "Neopixel Demo Program"
default n
---help---
Enable the Neopixel demo
if EXAMPLES_NEOPIXEL
config EXAMPLES_NEOPIXEL_PROGNAME
string "Program Name"
default "neopixel"
---help---
This is the name of the program that will be used when the NSH ELF
program is installed.
config EXAMPLES_NEOPIXEL_PRIORITY
int "Task Priority"
default 100
config EXAMPLES_NEOPIXEL_STACKSIZE
int "Stack Size"
default DEFAULT_TASK_STACKSIZE
config EXAMPLES_NEOPIXEL_DEFAULT_DEV
string "Default Device"
default "/dev/neopixel"
endif
```
The prefix on Kconfig options should be consistent to the actual file path.
--
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
[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#issuecomment-1170693084
why not squash the rename patch into the first?
--
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907415347
##########
examples/neopixel/neopixel_main.c:
##########
@@ -0,0 +1,301 @@
+/****************************************************************************
+ * 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>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+ FAR 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:
```suggestion
static void set_devpath(FAR struct neo_config_s *conf,
FAR const char *devpath)
```
--
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907416260
##########
examples/neopixel/neopixel_main.c:
##########
@@ -0,0 +1,301 @@
+/****************************************************************************
+ * 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>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+ FAR 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;
+ long value;
+ int index;
+ int nargs;
+
+ for (index = 1; index < argc; )
+ {
+ ptr = argv[index];
+ if (ptr[0] != '-')
+ {
+ printf("Invalid options format: %s\n", ptr);
+ exit(0);
+ }
+
+ switch (ptr[1])
+ {
+ case 'l':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Led count out of range: %ld\n", value);
+ exit(1);
+ }
+
+ conf->leds = (uint32_t)value;
+ index += nargs;
+ break;
+
+ case 'r':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Repeat out of range: %ld\n", value);
+ exit(1);
+ }
+
+ conf->loops = (uint32_t)value;
+ index += nargs;
+ break;
+
+ case 'p':
+ nargs = arg_string(&argv[index], &str);
+ set_devpath(conf, str);
+ index += nargs;
+ break;
+
+ case 'd':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Delay out of range: %ld\n", value);
+ exit(1);
+ }
+
+ conf->delay = (int)value;
+ index += nargs;
+ break;
+
+ case 'h':
+ help(conf);
+ exit(0);
+
+ default:
+ printf("Unsupported option: %s\n", ptr);
+ help(conf);
+ exit(1);
+ }
+ }
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * neopixel_main
+ ****************************************************************************/
+
+int neopixel_main(int argc, FAR char *argv[])
+{
+ FAR uint32_t *buffer;
+ FAR uint32_t *bp;
+ ssize_t result;
Review Comment:
```suggestion
FAR uint32_t *buffer;
FAR uint32_t *bp;
ssize_t result;
```
--
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
[GitHub] [incubator-nuttx-apps] curuvar commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
curuvar commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907629441
##########
.gitignore:
##########
@@ -31,3 +31,5 @@ Make.dep
.context
# nuttx/$(TOPDIR)/Makefile.[unix|win]::$(DIRLINKS_EXTERNAL_DIRS)
.dirlinks
+.vscode
+.DS_Store
Review Comment:
The .vscode is added by VSCode and surely should not be saved in the repository. Likewise .DS_Store is added to folder by MacOS and is also unwanted.
--
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
[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907024774
##########
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:
neopixel_main->main
--
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
[GitHub] [incubator-nuttx-apps] curuvar commented on pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
curuvar commented on PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#issuecomment-1172899876
@xiaoxiang781216, yes, I have been trying to remember to squash before I push changes. It turns out the change in question was make when I clicked the "Commit Suggestion" button on gustavonihei's comment. Is it best to avoid this practice, or is there some way to have it squash from the GitHub site itself?
--
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907418201
##########
examples/neopixel/neopixel_main.c:
##########
@@ -0,0 +1,301 @@
+/****************************************************************************
+ * 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>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+ FAR 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;
+ long value;
+ int index;
+ int nargs;
+
+ for (index = 1; index < argc; )
+ {
+ ptr = argv[index];
+ if (ptr[0] != '-')
+ {
+ printf("Invalid options format: %s\n", ptr);
+ exit(0);
+ }
+
+ switch (ptr[1])
+ {
+ case 'l':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Led count out of range: %ld\n", value);
+ exit(1);
+ }
+
+ conf->leds = (uint32_t)value;
+ index += nargs;
+ break;
+
+ case 'r':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Repeat out of range: %ld\n", value);
Review Comment:
```suggestion
fprintf(stderr, "Repeat out of range: %ld\n", value);
```
--
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
[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#issuecomment-1169073027
@curuvar could you squash all patch into one by:
git rebase --interactive HEAD~5
--
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907426496
##########
examples/neopixel/neopixel_main.c:
##########
@@ -0,0 +1,301 @@
+/****************************************************************************
+ * 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>
Review Comment:
```suggestion
#include <debug.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <unistd.h>
```
All these are system headers, so they could be grouped and sorted alphabetically.
--
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
[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907417764
##########
examples/neopixel/neopixel_main.c:
##########
@@ -0,0 +1,301 @@
+/****************************************************************************
+ * 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>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+ FAR 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;
+ long value;
+ int index;
+ int nargs;
+
+ for (index = 1; index < argc; )
+ {
+ ptr = argv[index];
+ if (ptr[0] != '-')
+ {
+ printf("Invalid options format: %s\n", ptr);
Review Comment:
```suggestion
fprintf(stderr, "Invalid options format: %s\n", ptr);
```
It is better to output the error message to `stderr`.
##########
examples/neopixel/neopixel_main.c:
##########
@@ -0,0 +1,301 @@
+/****************************************************************************
+ * 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>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+ FAR 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;
+ long value;
+ int index;
+ int nargs;
+
+ for (index = 1; index < argc; )
+ {
+ ptr = argv[index];
+ if (ptr[0] != '-')
+ {
+ printf("Invalid options format: %s\n", ptr);
+ exit(0);
+ }
+
+ switch (ptr[1])
+ {
+ case 'l':
+ nargs = arg_decimal(&argv[index], &value);
+ if (value < 1 || value > INT_MAX)
+ {
+ printf("Led count out of range: %ld\n", value);
Review Comment:
```suggestion
fprintf(stderr, "Led count out of range: %ld\n", value);
```
--
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
[GitHub] [incubator-nuttx-apps] gustavonihei commented on a diff in pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
gustavonihei commented on code in PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#discussion_r907413606
##########
examples/neopixel/neopixel_main.c:
##########
@@ -0,0 +1,301 @@
+/****************************************************************************
+ * 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>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct neo_config_s
+{
+ FAR 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:
```suggestion
static void help(FAR struct neo_config_s *conf)
```
nit: double whitespace
--
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
[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on pull request #1211: Added Neopixel Example
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #1211:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1211#issuecomment-1172884128
@curuvar it's better to squash the change for comment in the main patch .
--
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