PeterBee97 commented on code in PR #1449: URL: https://github.com/apache/nuttx-apps/pull/1449#discussion_r1041756681
########## system/nxcamera/nxcamera_main.c: ########## @@ -0,0 +1,564 @@ +/**************************************************************************** + * apps/system/nxcamera/nxcamera_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 <nuttx/video/video.h> + +#include <sys/types.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <assert.h> + +#include "system/readline.h" +#include "system/nxcamera.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define NXCAMERA_VER "1.00" + +#ifdef CONFIG_NXCAMERA_INCLUDE_HELP +# define NXCAMERA_HELP_TEXT(x) x +#else +# define NXCAMERA_HELP_TEXT(x) +#endif + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +typedef int (*nxcamera_func)(FAR struct nxcamera_s *plooper, char *pargs); + +struct mp_cmd_s +{ + FAR const char *cmd; /* The command text */ + FAR const char *arghelp; /* Text describing the args */ + nxcamera_func pfunc; /* Pointer to command handler */ + FAR const char *help; /* The help text */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int nxcamera_cmd_quit(FAR struct nxcamera_s *plooper, char *parg); +static int nxcamera_cmd_stream(FAR struct nxcamera_s *plooper, char *parg); + +#ifdef CONFIG_NXCAMERA_INCLUDE_PREFERRED_DEVICE +static int nxcamera_cmd_input(FAR struct nxcamera_s *plooper, char *parg); +#endif + +static int nxcamera_cmd_output(FAR struct nxcamera_s *plooper, char *parg); +static int nxcamera_cmd_stop(FAR struct nxcamera_s *plooper, char *parg); +static int nxcamera_cmd_set(FAR struct nxcamera_s *plooper, char *parg); + +#ifdef CONFIG_NXCAMERA_INCLUDE_HELP +static int nxcamera_cmd_help(FAR struct nxcamera_s *plooper, char *parg); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct mp_cmd_s g_nxcamera_cmds[] = +{ +#ifdef CONFIG_NXCAMERA_INCLUDE_PREFERRED_DEVICE + { + "input", + "videodev", + nxcamera_cmd_input, + NXCAMERA_HELP_TEXT("Specify a preferred capture device") + }, +#endif + { + "output", + "fbdev|filename", + nxcamera_cmd_output, + NXCAMERA_HELP_TEXT("Specify a display device or filename") + }, +#ifdef CONFIG_NXCAMERA_INCLUDE_HELP + { + "h", + "", + nxcamera_cmd_help, + NXCAMERA_HELP_TEXT("Display help for commands") + }, + { + "help", + "", + nxcamera_cmd_help, + NXCAMERA_HELP_TEXT("Display help for commands") + }, +#endif + { + "stream", + "width height framerate format", + nxcamera_cmd_stream, + NXCAMERA_HELP_TEXT("Video stream test (format is fourcc)") + }, + { + "stop", + "", + nxcamera_cmd_stop, + NXCAMERA_HELP_TEXT("Stop stream") + }, + { + "q", + "", + nxcamera_cmd_quit, + NXCAMERA_HELP_TEXT("Exit NxCamera") + }, + { + "quit", + "", + nxcamera_cmd_quit, + NXCAMERA_HELP_TEXT("Exit NxCamera") + }, + { + "set", + "parameter d%", + nxcamera_cmd_set, + NXCAMERA_HELP_TEXT("Set camera control parameters") + } +}; + +static const char *controls[] = +{ + "brightness", + "contrast", + "saturation", + "hue", + "while_balance_automatic", + "exposure", + "gain_automatic", + "gain", + "horizontal_flip", + "vertical_flip", + "power_line_frequency", + "sharpness", + "auto_exposure" +}; + +static const int g_nxcamera_cmd_count = sizeof(g_nxcamera_cmds) / + sizeof(struct mp_cmd_s); + +/**************************************************************************** + * Name: nxcamera_cmd_stream + * + * nxcamera_cmd_loop() play and record the raw data file using the nxcamera + * context. + * + ****************************************************************************/ + +static int nxcamera_cmd_stream(FAR struct nxcamera_s *plooper, char *parg) +{ + int ret; + uint16_t width = 0; + uint16_t height = 0; + uint32_t framerate = 0; + uint32_t format = 0; + char cc[4] = + { + 0 + }; + + sscanf(parg, "%hd %hd %d %s", &width, &height, &framerate, cc); + format = v4l2_fourcc(cc[0], cc[1], cc[2], cc[3]); + + /* Try to stream raw data with settings specified */ + + ret = nxcamera_stream(plooper, width, height, framerate, format); + + /* nxcamera_stream returned values: + * + * OK Stream is being run + * -EBUSY The media device is busy + * -ENOSYS The video format is not unsupported + * -ENODEV No video device suitable to capture media + */ + + switch (-ret) Review Comment: sure ########## system/nxcamera/nxcamera_main.c: ########## @@ -0,0 +1,564 @@ +/**************************************************************************** + * apps/system/nxcamera/nxcamera_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 <nuttx/video/video.h> + +#include <sys/types.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <assert.h> + +#include "system/readline.h" +#include "system/nxcamera.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define NXCAMERA_VER "1.00" + +#ifdef CONFIG_NXCAMERA_INCLUDE_HELP +# define NXCAMERA_HELP_TEXT(x) x +#else +# define NXCAMERA_HELP_TEXT(x) +#endif + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +typedef int (*nxcamera_func)(FAR struct nxcamera_s *plooper, char *pargs); + +struct mp_cmd_s +{ + FAR const char *cmd; /* The command text */ + FAR const char *arghelp; /* Text describing the args */ + nxcamera_func pfunc; /* Pointer to command handler */ + FAR const char *help; /* The help text */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int nxcamera_cmd_quit(FAR struct nxcamera_s *plooper, char *parg); +static int nxcamera_cmd_stream(FAR struct nxcamera_s *plooper, char *parg); + +#ifdef CONFIG_NXCAMERA_INCLUDE_PREFERRED_DEVICE +static int nxcamera_cmd_input(FAR struct nxcamera_s *plooper, char *parg); +#endif + +static int nxcamera_cmd_output(FAR struct nxcamera_s *plooper, char *parg); +static int nxcamera_cmd_stop(FAR struct nxcamera_s *plooper, char *parg); +static int nxcamera_cmd_set(FAR struct nxcamera_s *plooper, char *parg); + +#ifdef CONFIG_NXCAMERA_INCLUDE_HELP +static int nxcamera_cmd_help(FAR struct nxcamera_s *plooper, char *parg); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct mp_cmd_s g_nxcamera_cmds[] = +{ +#ifdef CONFIG_NXCAMERA_INCLUDE_PREFERRED_DEVICE + { + "input", + "videodev", + nxcamera_cmd_input, + NXCAMERA_HELP_TEXT("Specify a preferred capture device") + }, +#endif + { + "output", + "fbdev|filename", + nxcamera_cmd_output, + NXCAMERA_HELP_TEXT("Specify a display device or filename") + }, +#ifdef CONFIG_NXCAMERA_INCLUDE_HELP + { + "h", + "", + nxcamera_cmd_help, + NXCAMERA_HELP_TEXT("Display help for commands") + }, + { + "help", + "", + nxcamera_cmd_help, + NXCAMERA_HELP_TEXT("Display help for commands") + }, +#endif + { + "stream", + "width height framerate format", + nxcamera_cmd_stream, + NXCAMERA_HELP_TEXT("Video stream test (format is fourcc)") + }, + { + "stop", + "", + nxcamera_cmd_stop, + NXCAMERA_HELP_TEXT("Stop stream") + }, + { + "q", + "", + nxcamera_cmd_quit, + NXCAMERA_HELP_TEXT("Exit NxCamera") + }, + { + "quit", + "", + nxcamera_cmd_quit, + NXCAMERA_HELP_TEXT("Exit NxCamera") + }, + { + "set", + "parameter d%", + nxcamera_cmd_set, + NXCAMERA_HELP_TEXT("Set camera control parameters") + } +}; + +static const char *controls[] = +{ + "brightness", + "contrast", + "saturation", + "hue", + "while_balance_automatic", + "exposure", + "gain_automatic", + "gain", + "horizontal_flip", + "vertical_flip", + "power_line_frequency", + "sharpness", + "auto_exposure" +}; + +static const int g_nxcamera_cmd_count = sizeof(g_nxcamera_cmds) / + sizeof(struct mp_cmd_s); + +/**************************************************************************** + * Name: nxcamera_cmd_stream + * + * nxcamera_cmd_loop() play and record the raw data file using the nxcamera + * context. + * + ****************************************************************************/ + +static int nxcamera_cmd_stream(FAR struct nxcamera_s *plooper, char *parg) Review Comment: done -- 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-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org