From 4e3f835126b5116f5cec88634e18f3d54900892d Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 1 Mar 2020 17:51:42 +0200 Subject: libcamera: controls: Add support for string controls String controls are stored internally as an array of char, but the ControlValue constructor, get() and set() functions operate on an std::string for convenience. Array of strings are thus not supported. Unlike for other control types, the ControlInfo range reports the minimum and maximum allowed lengths of the string (the minimum will usually be 0), not the minimum and maximum value of each element. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/control_serializer.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/libcamera/control_serializer.cpp') diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp index eef875f4..808419f2 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -314,6 +314,22 @@ ControlValue ControlSerializer::loadControlValue(ByteStreamBuffer &buffer, return value; } +template<> +ControlValue ControlSerializer::loadControlValue(ByteStreamBuffer &buffer, + bool isArray, + unsigned int count) +{ + ControlValue value; + + const char *data = buffer.read(count); + if (!data) + return value; + + value.set(std::string{ data, count }); + + return value; +} + ControlValue ControlSerializer::loadControlValue(ControlType type, ByteStreamBuffer &buffer, bool isArray, @@ -335,6 +351,9 @@ ControlValue ControlSerializer::loadControlValue(ControlType type, case ControlTypeFloat: return loadControlValue(buffer, isArray, count); + case ControlTypeString: + return loadControlValue(buffer, isArray, count); + case ControlTypeNone: return ControlValue(); } @@ -345,6 +364,9 @@ ControlValue ControlSerializer::loadControlValue(ControlType type, ControlInfo ControlSerializer::loadControlInfo(ControlType type, ByteStreamBuffer &b) { + if (type == ControlTypeString) + type = ControlTypeInteger32; + ControlValue min = loadControlValue(type, b); ControlValue max = loadControlValue(type, b); -- cgit v1.2.1