Skip to content

Commit 364322e

Browse files
josuahkartben
authored andcommitted
samples: drivers: video: use a macro to simplify format logging
A macro introduced allows to log four-character-codes (FOURCC) as one string instead of enumerating each individual character. This saves a bit of room in the code and is less error-prone. Signed-off-by: Josuah Demangeon <me@josuah.net>
1 parent 26db5c2 commit 364322e

File tree

2 files changed

+8
-11
lines changed
  • samples/drivers/video

2 files changed

+8
-11
lines changed

samples/drivers/video/capture/src/main.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,10 @@ int main(void)
120120
while (caps.format_caps[i].pixelformat) {
121121
const struct video_format_cap *fcap = &caps.format_caps[i];
122122
/* fourcc to string */
123-
LOG_INF(" %c%c%c%c width [%u; %u; %u] height [%u; %u; %u]",
124-
(char)fcap->pixelformat, (char)(fcap->pixelformat >> 8),
125-
(char)(fcap->pixelformat >> 16), (char)(fcap->pixelformat >> 24),
126-
fcap->width_min, fcap->width_max, fcap->width_step, fcap->height_min,
127-
fcap->height_max, fcap->height_step);
123+
LOG_INF(" %s width [%u; %u; %u] height [%u; %u; %u]",
124+
VIDEO_FOURCC_TO_STR(fcap->pixelformat),
125+
fcap->width_min, fcap->width_max, fcap->width_step,
126+
fcap->height_min, fcap->height_max, fcap->height_step);
128127
i++;
129128
}
130129

@@ -147,9 +146,8 @@ int main(void)
147146
fmt.pixelformat = VIDEO_FOURCC_FROM_STR(CONFIG_VIDEO_PIXEL_FORMAT);
148147
}
149148

150-
LOG_INF("- Video format: %c%c%c%c %ux%u", (char)fmt.pixelformat,
151-
(char)(fmt.pixelformat >> 8), (char)(fmt.pixelformat >> 16),
152-
(char)(fmt.pixelformat >> 24), fmt.width, fmt.height);
149+
LOG_INF("- Video format: %s %ux%u",
150+
VIDEO_FOURCC_TO_STR(fmt.pixelformat), fmt.width, fmt.height);
153151

154152
if (video_set_format(video_dev, VIDEO_EP_OUT, &fmt)) {
155153
LOG_ERR("Unable to set format");

samples/drivers/video/tcpserversink/src/main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ int main(void)
9494
return 0;
9595
}
9696

97-
printk("Video device detected, format: %c%c%c%c %ux%u\n", (char)fmt.pixelformat,
98-
(char)(fmt.pixelformat >> 8), (char)(fmt.pixelformat >> 16),
99-
(char)(fmt.pixelformat >> 24), fmt.width, fmt.height);
97+
printk("Video device detected, format: %s %ux%u\n",
98+
VIDEO_FOURCC_TO_STR(fmt.pixelformat), fmt.width, fmt.height);
10099

101100
if (caps.min_line_count != LINE_COUNT_HEIGHT) {
102101
LOG_ERR("Partial framebuffers not supported by this sample");

0 commit comments

Comments
 (0)