From patchwork Mon Feb 17 14:26:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 2841 Return-Path: Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC817617B6 for ; Mon, 17 Feb 2020 15:28:20 +0100 (CET) Received: by mail-wr1-x431.google.com with SMTP id y17so19967095wrh.5 for ; Mon, 17 Feb 2020 06:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ylPR30yh3hEPaSqmXUBgYdKNFJBSVfN9rHKln9M5vmQ=; b=qqjpDoxjrRY3h4njTn8Gbe0jUHg2ejUf3pBXxPM6IRgKgzzqwLhO8zKnki1MGKSgcZ NyiIws951D3lp6swK+ZwdCba2gkKNnSW71DlSUj6w0Q70XRsN6NhdQInEFMzJtEIQfCw 5SLOV0wNwJiUf6s0vEyaasGDbLF1thP1WTyblmhlQbEyy5viH/SOAAgFCmYUlT+FrZ5/ JG0DZK9af3CXT5DwJFnTP3BH+IymPoSOtETLpE/GAHRO79LTy7vzGfKGDbQww6xaIf6b yU2XlVSbMge2KjG4JVIURJJbLFowsVRjca2ifDoAg9s0L4BZEYcB/G4WFMV8+V7D4iBx 6M4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ylPR30yh3hEPaSqmXUBgYdKNFJBSVfN9rHKln9M5vmQ=; b=S7Gv9b4xeFBORPWkcqKriOQEm8x45Rx8iMJ8Q1LVitFR+3tAniT78vRMe2FZUJrj78 PqKVAfWlEwVh2PR4J4jjWF6oZf3JgxHETZI7LVDSFwHgji9NNgBDV5Ae9NKNK7w0ofDp fXik3WYIt/EDAir0cg+SrMYrCJWMFZTqrZBV/UaPtEH/BFYp87xgUtk8gF6t+zy1gmZ2 Mt4RPIbCj074VT5ntzQhIAR4EmX41mVj/cIBv6BKAkny9TWWsbAHWScEoi1WYXoqHm27 2vSlI8mrvkYUr9uSi1yK8z8xIahahP2mudXw6BDOz6H7sk06ovDYxJj3uRBgJfGh3MBw bhfg== X-Gm-Message-State: APjAAAXRu6MMhyCMJy0bPQUhztN0gH+CTQTVg+EDQ2K5DSsjN3/swnKw jgPYxHlyV1/Sf8XoKXVzG9xZ3f6IPF9ZOg== X-Google-Smtp-Source: APXvYqwOb1NItIJZSplNcKEb+eZ9J7dGD+RTjaXGoG5OjuZAzKbfC0OFNfGj91cEl75xPChmTdWArA== X-Received: by 2002:adf:b605:: with SMTP id f5mr21452730wre.383.1581949700134; Mon, 17 Feb 2020 06:28:20 -0800 (PST) Received: from naushir-VirtualBox.pitowers.org (cust51-dsl50.idnet.net. [212.69.50.51]) by smtp.gmail.com with ESMTPSA id p15sm760960wma.40.2020.02.17.06.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 06:28:19 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 17 Feb 2020 14:26:07 +0000 Message-Id: <20200217142609.22837-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200217142609.22837-1-naush@raspberrypi.com> References: <20200217142609.22837-1-naush@raspberrypi.com> Subject: [libcamera-devel] [PATCH 1/3] libcamera: controls: Add std::string and double ControlValue type. 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, 17 Feb 2020 14:28:20 -0000 Strings are a convenient control type for controls such as AWB mode ("indoor", "outdoor", "halogen", etc.) or AGC mode ("sports", "long exposure", "spot", etc.). Double control values are useful for control values such as EV and even gains. This commit adds support for std::string and double control types. Functionality such as ControlRange on std::string types do not really make sense, so do nothing with that for now. Also add appropriate test for the new ControlValue types. Signed-off-by: Naushir Patuck --- include/libcamera/controls.h | 6 +++ src/libcamera/controls.cpp | 72 ++++++++++++++++++++++++++++++++- test/controls/control_value.cpp | 26 ++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 458b84e..ac74122 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -20,6 +20,8 @@ enum ControlType { ControlTypeBool, ControlTypeInteger32, ControlTypeInteger64, + ControlTypeString, + ControlTypeDouble, }; class ControlValue @@ -29,6 +31,8 @@ public: ControlValue(bool value); ControlValue(int32_t value); ControlValue(int64_t value); + ControlValue(std::string value); + ControlValue(double value); ControlType type() const { return type_; } bool isNone() const { return type_ == ControlTypeNone; } @@ -53,7 +57,9 @@ private: bool bool_; int32_t integer32_; int64_t integer64_; + double double_; }; + std::string string_; }; class ControlId diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 0031cd0..6eb79c9 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -58,6 +58,10 @@ LOG_DEFINE_CATEGORY(Controls) * The control stores a 32-bit integer value * \var ControlTypeInteger64 * The control stores a 64-bit integer value + * \var ControlTypeString + * The control stores a std::string value + * \var ControlTypeDouble + * The control stores a double value */ /** @@ -100,6 +104,24 @@ ControlValue::ControlValue(int64_t value) { } +/** + * \brief Construct a std::string ControlValue + * \param[in] value String value to store + */ +ControlValue::ControlValue(std::string value) + : type_(ControlTypeString), string_(value) +{ +} + +/** + * \brief Construct a double ControlValue + * \param[in] value Double value to store + */ +ControlValue::ControlValue(double value) + : type_(ControlTypeDouble), double_(value) +{ +} + /** * \fn ControlValue::type() * \brief Retrieve the data type of the value @@ -153,6 +175,18 @@ const int64_t &ControlValue::get() const return integer64_; } +template<> +const std::string &ControlValue::get() const +{ + return string_; +} + +template<> +const double &ControlValue::get() const +{ + return double_; +} + template<> void ControlValue::set(const bool &value) { @@ -173,6 +207,21 @@ void ControlValue::set(const int64_t &value) type_ = ControlTypeInteger64; integer64_ = value; } + +template<> +void ControlValue::set(const std::string &value) +{ + type_ = ControlTypeString; + string_ = value; +} + +template<> +void ControlValue::set(const double &value) +{ + type_ = ControlTypeDouble; + double_ = value; +} + #endif /* __DOXYGEN__ */ /** @@ -190,6 +239,10 @@ std::string ControlValue::toString() const return std::to_string(integer32_); case ControlTypeInteger64: return std::to_string(integer64_); + case ControlTypeString: + return string_; + case ControlTypeDouble: + return std::to_string(double_); } return ""; @@ -211,6 +264,10 @@ bool ControlValue::operator==(const ControlValue &other) const return integer32_ == other.integer32_; case ControlTypeInteger64: return integer64_ == other.integer64_; + case ControlTypeString: + return string_ == other.string_; + case ControlTypeDouble: + return double_ == other.double_; default: return false; } @@ -341,6 +398,18 @@ Control::Control(unsigned int id, const char *name) : ControlId(id, name, ControlTypeInteger64) { } + +template<> +Control::Control(unsigned int id, const char *name) + : ControlId(id, name, ControlTypeString) +{ +} + +template<> +Control::Control(unsigned int id, const char *name) + : ControlId(id, name, ControlTypeDouble) +{ +} #endif /* __DOXYGEN__ */ /** @@ -583,7 +652,8 @@ void ControlInfoMap::generateIdmap() idmap_.clear(); for (const auto &ctrl : *this) { - if (ctrl.first->type() != ctrl.second.min().type()) { + if (ctrl.first->type() != ControlTypeString && + (ctrl.first->type() != ctrl.second.min().type())) { LOG(Controls, Error) << "Control " << utils::hex(ctrl.first->id()) << " type and range type mismatch"; diff --git a/test/controls/control_value.cpp b/test/controls/control_value.cpp index a1ffa84..55174da 100644 --- a/test/controls/control_value.cpp +++ b/test/controls/control_value.cpp @@ -21,10 +21,14 @@ protected: { ControlValue integer(1234); ControlValue boolean(true); + ControlValue fractional(3.142); + ControlValue string(std::string("MyString")); /* Just a string conversion output test... no validation */ cout << "Int: " << integer.toString() << " Bool: " << boolean.toString() + << " Frac: " << fractional.toString() + << " String: " << string.toString() << endl; if (integer.get() != 1234) { @@ -37,6 +41,16 @@ protected: return TestFail; } + if (fractional.get() != 3.142) { + cerr << "Failed to get Fractional" << endl; + return TestFail; + } + + if (string.get() != std::string("MyString")) { + cerr << "Failed to get String" << endl; + return TestFail; + } + /* Test an uninitialised value, and updating it. */ ControlValue value; @@ -62,6 +76,18 @@ protected: return TestFail; } + value.set(2.718); + if (value.get() != 2.718) { + cerr << "Failed to get Fractional" << endl; + return TestFail; + } + + value.set(std::string("Test")); + if (value.get() != std::string("Test")) { + cerr << "Failed to get String" << endl; + return TestFail; + } + return TestPass; } };