-
Notifications
You must be signed in to change notification settings - Fork 7.3k
drivers: video: Add the video shell #88566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Because of the limitation of the shell API, a hack was used using This is not expected to take more RAM, only more ROM/Flash. |
11760ae
to
d34be47
Compare
Force-push:
|
The controls were just tested again with HFLIP/VFLIP and we observe the image being mirrored left/right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for a video shell in the video driver by introducing a new API function, video_convert_ctrl_name, which converts human-friendly video control names into canonical identifiers for software use. Additionally, necessary header updates and modifications in the video_ctrls.c file ensure the new function is integrated into the control printing process.
- Added function video_convert_ctrl_name with corresponding documentation in video.h.
- Updated video_ctrls.c to include ctype.h, implement video_convert_ctrl_name, and integrate it into video_print_ctrl.
- Enhanced logging to use converted control names for improved usability.
Reviewed Changes
Copilot reviewed 3 out of 7 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
include/zephyr/drivers/video.h | Adds function declaration and documentation for video_convert_ctrl_name. |
drivers/video/video_ctrls.c | Implements video_convert_ctrl_name and updates printing of control names. |
Files not reviewed (4)
- drivers/video/CMakeLists.txt: Language not supported
- drivers/video/Kconfig: Language not supported
- drivers/video/Kconfig.shell: Language not supported
- tests/drivers/build_all/video/prj.conf: Language not supported
My bad, here we go again. No complain from:
|
drivers/video/video_shell.c
Outdated
SHELL_DYNAMIC_CMD_CREATE(dsub_##name##n, complete_##name##n) | ||
|
||
/* Maximum size for a video control name, be it standard one or custom device-specific one */ | ||
#define VIDEO_SHELL_NAME_MAX_SIZE 40 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be a Kconfig?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted for a more global CONFIG_VIDEO_CTRL_NAME_MAX_SIZE
if that is fit.
drivers/video/video_ctrls.c
Outdated
@@ -462,6 +480,7 @@ void video_print_ctrl(const struct device *const dev, const struct video_ctrl_qu | |||
uint8_t i = 0; | |||
const char *type = NULL; | |||
char typebuf[8]; | |||
char namebuf[40]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
char namebuf[40]; | |
char namebuf[VIDEO_SHELL_NAME_MAX_SIZE]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied, good point.
drivers/video/video_ctrls.c
Outdated
for (i = 0; i + 1 < dst_size && src[i] != '\0'; i++) { | ||
if (isalnum(src[i])) { | ||
dst[i] = tolower(src[i]); | ||
add_underscore = true; | ||
} else if (add_underscore && src[i + 1] != '\0') { | ||
dst[i] = '_'; | ||
add_underscore = false; | ||
} | ||
} | ||
dst[i] = '\0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test corner cases (including your own example "White Balance, Automatic")?
Using the same index for both strings seems like asking for trouble.
char dest[20];
const char *examples[] = {
"hello world",
" hello",
"hello!",
"White Balance, Automatic",
};
for (int i = 0; i < sizeof(examples) / sizeof(examples[0]); i++) {
video_convert_ctrl_name(examples[i], dest, sizeof(dest));
printf("Input: '%s' => Output: '%s'\n", examples[i], dest);
}
/*
Input: 'hello world' => Output: 'hello_'
Input: ' hello' => Output: 'hehello'
Input: 'hello!' => Output: 'hellol'
Input: 'White Balance, Automatic' => Output: 'white_balance_'
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good opportunity to add unit tests...
tests/drivers/video/ctrl/src/main.c
Outdated
{" _ leading special characters", "leading_special_characters"}, | ||
{"trailing special characters!@#$%^", "trailing_special_characters_"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so trailing special characters are folded into 1 underscore and leading special characters end up being discarded? the lack of symmetry seems odd, maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the lack of symmetry seems odd, maybe?
I agree. This was assuming a control would never be named i.e. Misc +
.
Latest push also covers this edge case instead of asserting a mis-handling.
This permits to generate control names similar to v4l2-ctl that can be used as string identifiers for the controls. Signed-off-by: Josuah Demangeon <me@josuah.net>
Add tests to cover video_ctrls.c functions. For now only video_convert_ctrl_name(). Signed-off-by: Josuah Demangeon <me@josuah.net>
Introduce the video shell and implement some video shell commands. Make use of the various querying API to implement tab-completion, and validiate the data, as well as convert string names into integers. Commands provided: frmival, format, ctrl, start, stop, capture Signed-off-by: Josuah Demangeon <me@josuah.net>
Dependencies:
Replaces:
Now that we have a nice shell control querying API, it is possible to tab-complete in-depth every control value.
To test on
native_sim
withVIDEO_SW_GENERATOR
:On another terminal, using your favorite serial console client, and likely
COM#
on Windows instead of/dev/pts/3
: