You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/12/08 11:39:02 UTC
[nuttx-apps] 01/04: examples/camera: Fix the style issue
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit ca855f3f230a6e005d9aa5d14a17aedd5dd0ccb1
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Dec 6 19:20:55 2022 +0800
examples/camera: Fix the style issue
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
examples/camera/camera_bkgd.c | 15 +++++++--------
examples/camera/camera_fileutil.c | 30 +++++++++++++-----------------
examples/camera/camera_main.c | 26 +++++++++-----------------
3 files changed, 29 insertions(+), 42 deletions(-)
diff --git a/examples/camera/camera_bkgd.c b/examples/camera/camera_bkgd.c
index 436b02f83..32e07e746 100644
--- a/examples/camera/camera_bkgd.c
+++ b/examples/camera/camera_bkgd.c
@@ -47,7 +47,7 @@ struct nximage_data_s
/* The NX handles */
NXHANDLE hnx;
- NXHANDLE hbkgd;
+ NXWINDOW hbkgd;
bool connected;
/* The screen resolution */
@@ -115,7 +115,7 @@ static struct nximage_data_s g_nximage =
* NX event listener for an event from NX server.
****************************************************************************/
-FAR void *nximage_listener(FAR void *arg)
+static FAR void *nximage_listener(FAR void *arg)
{
int ret;
@@ -162,7 +162,7 @@ FAR void *nximage_listener(FAR void *arg)
****************************************************************************/
static void nximage_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
- bool more, FAR void *arg)
+ bool more, FAR void *arg)
{
ginfo("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
@@ -281,7 +281,7 @@ int nximage_initialize(void)
while (!g_nximage.havepos)
{
- (void) sem_wait(&g_nximage.sem);
+ sem_wait(&g_nximage.sem);
}
printf("nximage_initialize: Screen resolution (%d,%d)\n",
@@ -291,7 +291,7 @@ int nximage_initialize(void)
}
/****************************************************************************
- * Name: nximage_image
+ * Name: nximage_draw
*
* Description:
* Put the NuttX logo in the center of the display.
@@ -317,11 +317,11 @@ void nximage_draw(FAR void *image, int w, int h)
src[0] = image;
- ret = nx_bitmap((NXWINDOW)g_nximage.hbkgd, &dest, src, &origin,
+ ret = nx_bitmap(g_nximage.hbkgd, &dest, src, &origin,
g_nximage.xres * sizeof(nxgl_mxpixel_t));
if (ret < 0)
{
- printf("nximage_image: nx_bitmapwindow failed: %d\n", errno);
+ printf("nximage_image: nx_bitmap failed: %d\n", errno);
}
}
@@ -336,4 +336,3 @@ void nximage_finalize(void)
{
nx_disconnect(g_nximage.hnx);
}
-
diff --git a/examples/camera/camera_fileutil.c b/examples/camera/camera_fileutil.c
index 743b0c7b3..0e8cdd0bf 100644
--- a/examples/camera/camera_fileutil.c
+++ b/examples/camera/camera_fileutil.c
@@ -40,7 +40,8 @@
* Private Data
****************************************************************************/
-static const char *save_dir;
+static const char *g_save_dir;
+static int g_framecount;
/****************************************************************************
* Public Functions
@@ -65,14 +66,14 @@ const char *futil_initialize(void)
ret = stat("/mnt/sd0", &stat_buf);
if (ret < 0)
{
- save_dir = "/mnt/spif";
+ g_save_dir = "/mnt/spif";
}
else
{
- save_dir = "/mnt/sd0";
+ g_save_dir = "/mnt/sd0";
}
- return save_dir;
+ return g_save_dir;
}
/****************************************************************************
@@ -84,27 +85,23 @@ const char *futil_initialize(void)
int futil_writeimage(uint8_t *data, size_t len, const char *fsuffix)
{
- static char s_fname[IMAGE_FILENAME_LEN];
- static int s_framecount = 0;
-
+ char fname[IMAGE_FILENAME_LEN];
FILE *fp;
- s_framecount++;
- if (s_framecount >= 1000)
+ g_framecount++;
+ if (g_framecount >= 1000)
{
- s_framecount = 1;
+ g_framecount = 1;
}
- memset(s_fname, 0, sizeof(s_fname));
-
- snprintf(s_fname,
+ snprintf(fname,
IMAGE_FILENAME_LEN,
"%s/VIDEO%03d.%s",
- save_dir, s_framecount, fsuffix);
+ g_save_dir, g_framecount, fsuffix);
- printf("FILENAME:%s\n", s_fname);
+ printf("FILENAME:%s\n", fname);
- fp = fopen(s_fname, "wb");
+ fp = fopen(fname, "wb");
if (NULL == fp)
{
printf("fopen error : %d\n", errno);
@@ -119,4 +116,3 @@ int futil_writeimage(uint8_t *data, size_t len, const char *fsuffix)
fclose(fp);
return 0;
}
-
diff --git a/examples/camera/camera_main.c b/examples/camera/camera_main.c
index 1fe7485e4..024d68f13 100644
--- a/examples/camera/camera_main.c
+++ b/examples/camera/camera_main.c
@@ -36,12 +36,7 @@
#include <nuttx/video/video.h>
#include "camera_fileutil.h"
-
-#ifdef CONFIG_EXAMPLES_CAMERA_OUTPUT_LCD
-#include <nuttx/nx/nx.h>
-#include <nuttx/nx/nxglib.h>
#include "camera_bkgd.h"
-#endif
/****************************************************************************
* Pre-processor Definitions
@@ -88,7 +83,7 @@ static void free_buffer(struct v_buffer *buffers, uint8_t bufnum);
static int parse_arguments(int argc, char *argv[],
int *capture_num, enum v4l2_buf_type *type);
static int get_camimage(int fd, struct v4l2_buffer *v4l2_buf,
- enum v4l2_buf_type buf_type);
+ enum v4l2_buf_type buf_type);
static int release_camimage(int fd, struct v4l2_buffer *v4l2_buf);
static int start_stillcapture(int v_fd, enum v4l2_buf_type capture_type);
static int stop_stillcapture(int v_fd, enum v4l2_buf_type capture_type);
@@ -109,7 +104,7 @@ static int stop_stillcapture(int v_fd, enum v4l2_buf_type capture_type);
* Name: camera_prepare()
*
* Description:
- * Allocate frame buffer for camera and Queue the allocated buffer
+ * Allocate frame buffer for camera and queue the allocated buffer
* into video driver.
****************************************************************************/
@@ -168,7 +163,6 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
/* Prepare video memory to store images */
*vbuf = malloc(sizeof(v_buffer_t) * buffernum);
-
if (!(*vbuf))
{
printf("Out of memory for array of v_buffer_t[%d]\n", buffernum);
@@ -184,7 +178,7 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
* Buffer pointer must be 32bytes aligned.
*/
- (*vbuf)[cnt].start = memalign(32, buffersize);
+ (*vbuf)[cnt].start = memalign(32, buffersize);
if (!(*vbuf)[cnt].start)
{
printf("Out of memory for image buffer of %d/%d\n",
@@ -192,9 +186,8 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
/* Release allocated memory. */
- while (cnt)
+ while (cnt--)
{
- cnt--;
free((*vbuf)[cnt].start);
}
@@ -288,7 +281,7 @@ static int parse_arguments(int argc, char *argv[],
else
{
*capture_num = atoi(argv[1]);
- if ((*capture_num < 0) || (*capture_num > MAX_CAPTURE_NUM))
+ if (*capture_num < 0 || *capture_num > MAX_CAPTURE_NUM)
{
printf("Invalid capture num(%d). must be >=0 and <=%d\n",
*capture_num, MAX_CAPTURE_NUM);
@@ -303,7 +296,7 @@ static int parse_arguments(int argc, char *argv[],
if (strncmp(argv[1], "-jpg", 5) == 0)
{
*capture_num = atoi(argv[2]);
- if ((*capture_num < 0) || (*capture_num > MAX_CAPTURE_NUM))
+ if (*capture_num < 0 || *capture_num > MAX_CAPTURE_NUM)
{
printf("Invalid capture num(%d). must be >=0 and <=%d\n",
*capture_num, MAX_CAPTURE_NUM);
@@ -335,7 +328,7 @@ static int parse_arguments(int argc, char *argv[],
****************************************************************************/
static int get_camimage(int fd, struct v4l2_buffer *v4l2_buf,
- enum v4l2_buf_type buf_type)
+ enum v4l2_buf_type buf_type)
{
int ret;
@@ -636,7 +629,7 @@ int main(int argc, FAR char *argv[])
wait.tv_usec = 0;
printf("Take %d pictures as %s file in %s after %d seconds.\n",
capture_num,
- (capture_type == V4L2_BUF_TYPE_STILL_CAPTURE) ? "JPEG" : "RGB",
+ capture_type == V4L2_BUF_TYPE_STILL_CAPTURE ? "JPEG" : "RGB",
save_dir, START_CAPTURE_TIME);
printf(" After finishing taking pictures,"
" this app will be finished after %d seconds.\n",
@@ -720,7 +713,7 @@ int main(int argc, FAR char *argv[])
futil_writeimage(
(uint8_t *)v4l2_buf.m.userptr,
(size_t)v4l2_buf.bytesused,
- (capture_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ?
+ capture_type == V4L2_BUF_TYPE_VIDEO_CAPTURE ?
"RGB" : "JPG");
ret = release_camimage(v_fd, &v4l2_buf);
@@ -770,4 +763,3 @@ exit_without_cleaning_videodriver:
#endif
return ret;
}
-