libcamera: fix compilation errors for libcamera v0.3.2+rpt20241119 (#168)

* libcamera: add support for ControlTypePoint

Signed-off-by: Patrick Gehrsitz <mryel00.github@gmail.com>

* libcamera: fix compile error on missing ControlType

This adds a runtime error for missing ControlTypes to fix compilation errors if there are new ControlTypes that are not implemented yet.

Signed-off-by: Patrick Gehrsitz <mryel00.github@gmail.com>

* chore: remove whitespaces

Signed-off-by: Patrick Gehrsitz <mryel00.github@gmail.com>

* libcamera: only use ControlTypePoint for libcamera>=0.3.2

Signed-off-by: Patrick Gehrsitz <mryel00.github@gmail.com>

* fix: add version check to second switch case

Signed-off-by: Patrick Gehrsitz <mryel00.github@gmail.com>

* fix: add version check to libcamera_parse_point

Signed-off-by: Patrick Gehrsitz <mryel00.github@gmail.com>

---------

Signed-off-by: Patrick Gehrsitz <mryel00.github@gmail.com>
This commit is contained in:
Patrick Gehrsitz 2025-06-08 17:34:29 +02:00 committed by GitHub
parent 4203f89df1
commit 68de1189df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -217,6 +217,16 @@ static int libcamera_device_dump_control_option(device_option_fn fn, void *opaqu
case libcamera::ControlTypeString: case libcamera::ControlTypeString:
opt.type = device_option_type_string; opt.type = device_option_type_string;
break; break;
#if LIBCAMERA_VERSION_MAJOR == 0 && LIBCAMERA_VERSION_MINOR > 3 && LIBCAMERA_VERSION_PATCH >= 2 // Support for older libcamera versions
case libcamera::ControlTypePoint:
opt.type = device_option_type_float;
opt.elems = 2;
break;
#endif
default:
throw std::runtime_error("ControlType unsupported or not implemented");
} }
auto named_values = libcamera_find_control_ids(control_id.id()); auto named_values = libcamera_find_control_ids(control_id.id());
@ -349,6 +359,29 @@ static libcamera::Size libcamera_parse_size(const char *value)
return libcamera::Size(); return libcamera::Size();
} }
#if LIBCAMERA_VERSION_MAJOR == 0 && LIBCAMERA_VERSION_MINOR > 3 && LIBCAMERA_VERSION_PATCH >= 2 // Support for older libcamera versions
static libcamera::Point libcamera_parse_point(const char *value)
{
static const char *POINT_PATTERNS[] =
{
"(%d,%d)",
"%d,%d",
NULL
};
for (int i = 0; POINT_PATTERNS[i]; i++) {
libcamera::Point point;
if (2 == sscanf(value, POINT_PATTERNS[i],
&point.x, &point.y)) {
return point;
}
}
return libcamera::Point();
}
#endif
template<typename T, typename F> template<typename T, typename F>
static bool libcamera_parse_control_value(libcamera::ControlValue &control_value, const char *value, const F &fn) static bool libcamera_parse_control_value(libcamera::ControlValue &control_value, const char *value, const F &fn)
{ {
@ -436,6 +469,16 @@ int libcamera_device_set_option(device_t *dev, const char *keyp, const char *val
case libcamera::ControlTypeString: case libcamera::ControlTypeString:
break; break;
#if LIBCAMERA_VERSION_MAJOR == 0 && LIBCAMERA_VERSION_MINOR > 3 && LIBCAMERA_VERSION_PATCH >= 2 // Support for older libcamera versions
case libcamera::ControlTypePoint:
libcamera_parse_control_value<libcamera::Point>(
control_value, value, libcamera_parse_point);
break;
#endif
default:
throw std::runtime_error("ControlType unsupported or not implemented");
} }
if (control_value.isNone()) { if (control_value.isNone()) {