From patchwork Mon Jan 13 16:42:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2626 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8440C606EA for ; Mon, 13 Jan 2020 17:40:33 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 224C110000E; Mon, 13 Jan 2020 16:40:32 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Jan 2020 17:42:33 +0100 Message-Id: <20200113164245.52535-12-jacopo@jmondi.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200113164245.52535-1-jacopo@jmondi.org> References: <20200113164245.52535-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 11/23] 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: Mon, 13 Jan 2020 16:40:33 -0000 Add support for float values in Control<> and ControlValue classes. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- include/libcamera/controls.h | 3 +++ src/libcamera/control_serializer.cpp | 13 ++++++++++ src/libcamera/controls.cpp | 36 ++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 458b84e8fa8c..8fa33d93b088 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -20,6 +20,7 @@ enum ControlType { ControlTypeBool, ControlTypeInteger32, ControlTypeInteger64, + ControlTypeFloat, }; class ControlValue @@ -29,6 +30,7 @@ public: ControlValue(bool value); ControlValue(int32_t value); ControlValue(int64_t value); + ControlValue(float value); ControlType type() const { return type_; } bool isNone() const { return type_ == ControlTypeNone; } @@ -53,6 +55,7 @@ private: bool bool_; int32_t integer32_; int64_t integer64_; + float float_; }; }; diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp index a5d6d875c76f..fd91baf15156 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -34,6 +34,7 @@ static constexpr size_t ControlValueSize[] = { [ControlTypeBool] = sizeof(bool), [ControlTypeInteger32] = sizeof(int32_t), [ControlTypeInteger64] = sizeof(int64_t), + [ControlTypeFloat] = sizeof(float), }; } /* namespace */ @@ -176,6 +177,12 @@ void ControlSerializer::store(const ControlValue &value, break; } + case ControlTypeFloat: { + float data = value.get(); + buffer.write(&data); + break; + } + default: break; } @@ -348,6 +355,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 123a6f19974a..74ce5d0ba4f1 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -58,6 +58,8 @@ LOG_DEFINE_CATEGORY(Controls) * 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 */ /** @@ -100,6 +102,15 @@ ControlValue::ControlValue(int64_t value) { } +/** + * \brief Construct a float ControlValue + * \param[in] value Float value to store + */ +ControlValue::ControlValue(float value) + : type_(ControlTypeFloat), float_(value) +{ +} + /** * \fn ControlValue::type() * \brief Retrieve the data type of the value @@ -153,6 +164,14 @@ const int64_t &ControlValue::get() const return integer64_; } +template<> +const float &ControlValue::get() const +{ + ASSERT(type_ == ControlTypeFloat); + + return float_; +} + template<> void ControlValue::set(const bool &value) { @@ -173,6 +192,13 @@ void ControlValue::set(const int64_t &value) type_ = ControlTypeInteger64; integer64_ = value; } + +template<> +void ControlValue::set(const float &value) +{ + type_ = ControlTypeFloat; + float_ = value; +} #endif /* __DOXYGEN__ */ /** @@ -190,6 +216,8 @@ std::string ControlValue::toString() const return std::to_string(integer32_); case ControlTypeInteger64: return std::to_string(integer64_); + case ControlTypeFloat: + return std::to_string(float_); } return ""; @@ -211,6 +239,8 @@ bool ControlValue::operator==(const ControlValue &other) const return integer32_ == other.integer32_; case ControlTypeInteger64: return integer64_ == other.integer64_; + case ControlTypeFloat: + return float_ == other.float_; default: return false; } @@ -341,6 +371,12 @@ Control::Control(unsigned int id, const char *name) : ControlId(id, name, ControlTypeInteger64) { } + +template<> +Control::Control(unsigned int id, const char *name) + : ControlId(id, name, ControlTypeFloat) +{ +} #endif /* __DOXYGEN__ */ /**