From patchwork Fri Mar 6 15:59:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2991 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4ABF0628DF for ; Fri, 6 Mar 2020 17:00:23 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C9E3924B; Fri, 6 Mar 2020 17:00:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1583510423; bh=JoPAu7quIBVbZUUCeWbJNQsxj2THxryMiJOlJLG4FH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j0poidfuRq7/UxkZj+ZbqDpD2WQ1DRqKY2Zmac6AgjQNaG/dPZrcTtc3QT4T41cA9 B60adAA0769s8JRbSm+B02SfLg1CGh7Evl2TIfwlx2I2rer2JcFJKTOtrkJhMdcT3M w6kGvhK0qGcY+oM1PVhbfUc6x86+TWDbw1yBMMn4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Mar 2020 17:59:49 +0200 Message-Id: <20200306160002.30549-20-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200306160002.30549-1-laurent.pinchart@ideasonboard.com> References: <20200306160002.30549-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 19/32] libcamera: controls: Add support for float controls X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Mar 2020 16:00:24 -0000 From: Jacopo Mondi Add support for float values in Control<> and ControlValue classes. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/controls.h | 6 ++++++ src/libcamera/control_serializer.cpp | 12 ++++++++++++ src/libcamera/controls.cpp | 14 +++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 2102d5711384..0ad442b9e192 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -24,6 +24,7 @@ enum ControlType { ControlTypeBool, ControlTypeInteger32, ControlTypeInteger64, + ControlTypeFloat, }; namespace details { @@ -52,6 +53,11 @@ struct control_type { static constexpr ControlType value = ControlTypeInteger64; }; +template<> +struct control_type { + static constexpr ControlType value = ControlTypeFloat; +}; + template struct control_type> : public control_type> { }; diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp index 2b66ab978f81..5feaaa965cc5 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -165,6 +165,12 @@ void ControlSerializer::store(const ControlValue &value, break; } + case ControlTypeFloat: { + float data = value.get(); + buffer.write(&data); + break; + } + default: break; } @@ -337,6 +343,12 @@ ControlValue ControlSerializer::load(ControlType type, return ControlValue(value); } + case ControlTypeFloat: { + float value; + b.read(&value); + return ControlValue(value); + } + default: return ControlValue(); } diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 3dd740e5f17e..d095efd45b91 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -55,6 +55,7 @@ static constexpr size_t ControlValueSize[] = { [ControlTypeBool] = sizeof(bool), [ControlTypeInteger32] = sizeof(int32_t), [ControlTypeInteger64] = sizeof(int64_t), + [ControlTypeFloat] = sizeof(float), }; } /* namespace */ @@ -70,6 +71,8 @@ static constexpr size_t ControlValueSize[] = { * The control stores a 32-bit integer value * \var ControlTypeInteger64 * The control stores a 64-bit integer value + * \var ControlTypeFloat + * The control stores a 32-bit floating point value */ /** @@ -205,6 +208,11 @@ std::string ControlValue::toString() const str += std::to_string(*value); break; } + case ControlTypeFloat: { + const float *value = reinterpret_cast(data); + str += std::to_string(*value); + break; + } case ControlTypeNone: break; } @@ -374,9 +382,9 @@ void ControlValue::set(ControlType type, bool isArray, const void *data, * instead of Control. * * Controls of any type can be defined through template specialisation, but - * libcamera only supports the bool, int32_t and int64_t types natively (this - * includes types that are equivalent to the supported types, such as int and - * long int). + * libcamera only supports the bool, int32_t, int64_t and float types natively + * (this includes types that are equivalent to the supported types, such as int + * and long int). * * Controls IDs shall be unique. While nothing prevents multiple instances of * the Control class to be created with the same ID for the same object, doing