Skip to content

Commit 631760a

Browse files
authored
Merge pull request #168 from baba-dev/codex/add-static-helper-for-v4l2-ioctl
fix(hal): add v4l2 control helper
2 parents 32e3840 + 655528f commit 631760a

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

platforms/tab5/main/hal/components/hal_camera.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include <driver/gpio.h>
77
#include <fcntl.h>
8+
#include <inttypes.h>
89
#include <memory>
910
#include <mutex>
1011
#include <mooncake_log.h>
@@ -81,6 +82,31 @@ typedef enum
8182
EXAMPLE_VIDEO_FMT_YUV420 = V4L2_PIX_FMT_YUV420,
8283
} example_fmt_t;
8384

85+
static bool set_sensor_control(int fd, uint32_t control_id, int32_t value, const char* control_name)
86+
{
87+
struct v4l2_control control = {};
88+
control.id = control_id;
89+
control.value = value;
90+
91+
if (ioctl(fd, VIDIOC_S_CTRL, &control) == 0)
92+
{
93+
ESP_LOGI(TAG,
94+
"Set %s (0x%08" PRIx32 ") to %" PRId32,
95+
control_name != NULL ? control_name : "control",
96+
control_id,
97+
value);
98+
return true;
99+
}
100+
101+
ESP_LOGW(TAG,
102+
"Failed to set %s (0x%08" PRIx32 ") to %" PRId32 ": %s",
103+
control_name != NULL ? control_name : "control",
104+
control_id,
105+
value,
106+
strerror(errno));
107+
return false;
108+
}
109+
84110
/**
85111
* @brief Open the video device and initialize the video device to use `init_fmt` as the output
86112
* format.

0 commit comments

Comments
 (0)