From 655528ff8a08b34ab20cf512f20330fd2037f5b5 Mon Sep 17 00:00:00 2001 From: "Sameer .I. Siddiqui" Date: Sun, 21 Sep 2025 03:26:53 +0530 Subject: [PATCH] fix(hal): add v4l2 control helper --- .../tab5/main/hal/components/hal_camera.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/platforms/tab5/main/hal/components/hal_camera.cpp b/platforms/tab5/main/hal/components/hal_camera.cpp index 73ecca0d..49e454d0 100644 --- a/platforms/tab5/main/hal/components/hal_camera.cpp +++ b/platforms/tab5/main/hal/components/hal_camera.cpp @@ -5,6 +5,7 @@ */ #include #include +#include #include #include #include @@ -80,6 +81,31 @@ typedef enum EXAMPLE_VIDEO_FMT_YUV420 = V4L2_PIX_FMT_YUV420, } example_fmt_t; +static bool set_sensor_control(int fd, uint32_t control_id, int32_t value, const char* control_name) +{ + struct v4l2_control control = {}; + control.id = control_id; + control.value = value; + + if (ioctl(fd, VIDIOC_S_CTRL, &control) == 0) + { + ESP_LOGI(TAG, + "Set %s (0x%08" PRIx32 ") to %" PRId32, + control_name != NULL ? control_name : "control", + control_id, + value); + return true; + } + + ESP_LOGW(TAG, + "Failed to set %s (0x%08" PRIx32 ") to %" PRId32 ": %s", + control_name != NULL ? control_name : "control", + control_id, + value, + strerror(errno)); + return false; +} + /** * @brief Open the video device and initialize the video device to use `init_fmt` as the output * format.