{"id":13007,"url":"https://patchwork.libcamera.org/api/patches/13007/?format=json","web_url":"https://patchwork.libcamera.org/patch/13007/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210716105631.158153-2-paul.elder@ideasonboard.com>","date":"2021-07-16T10:56:11","name":"[libcamera-devel,RFC,v4,01/21] controls: Add boolean constructor for ControlInfo","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c57c94dc7dee94eb5bae0cdc24dd8336dae643ad","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13007/mbox/","series":[{"id":2244,"url":"https://patchwork.libcamera.org/api/series/2244/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2244","date":"2021-07-16T10:56:10","name":"Preliminary FULL plumbing","version":4,"mbox":"https://patchwork.libcamera.org/series/2244/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13007/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13007/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id CBDB7C3228\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 16 Jul 2021 10:56:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 857D26853D;\n\tFri, 16 Jul 2021 12:56:53 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C09AA68521\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Jul 2021 12:56:52 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4A6893F0;\n\tFri, 16 Jul 2021 12:56:50 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"mxIudply\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1626433012;\n\tbh=BPZBq6x+H0sRnEkGXy/xXyY/8oWC14x3uxAaMyLQu1E=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=mxIudplyQTujPE7LdwSsNSa1jxiw7fF8f4odnbdj8xgW71UI0eZVusqr+Eb/PGmwI\n\t9dVQXAzVu97EYu4PPxw4lHyf6Zgr+KU6PvyAQaMk1YyMGP9Cb0GZI0Qy4hrWEeO0ni\n\tVM7jQqS1ri+3pnYdZQNAfGsh64J9sSlhvnJaSRck=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 16 Jul 2021 19:56:11 +0900","Message-Id":"<20210716105631.158153-2-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20210716105631.158153-1-paul.elder@ideasonboard.com>","References":"<20210716105631.158153-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC PATCH v4 01/21] controls: Add boolean\n\tconstructor for ControlInfo","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"It would be convenient to be able to iterate over available boolean\nvalues, for example for controls that designate if some function can be\nenabled/disabled. The current min/max/def constructor is insufficient,\nas .values() is empty, so the values cannot be easily iterated over, and\ncreating a Span of booleans does not work for the values constructor.\n\nAdd a new constructor to ControlInfo that takes a set of booleans (to\nallow specifiying one or two available values), and a default. The\ndefault value is not optional, as it doesn't make sense to have a silent\ndefault for boolean values.\n\nUpdate the ControlInfo test accordingly.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nChanges in v2:\n- use set instead of span of bools\n- add assertion to make sure that the default is a valid value\n- update the test\n---\n include/libcamera/controls.h   |  2 ++\n src/libcamera/controls.cpp     | 28 ++++++++++++++++++++++++++++\n test/controls/control_info.cpp | 33 +++++++++++++++++++++++++++++++++\n 3 files changed, 63 insertions(+)","diff":"diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex 1bc958a4..707dc335 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -9,6 +9,7 @@\n #define __LIBCAMERA_CONTROLS_H__\n \n #include <assert.h>\n+#include <set>\n #include <stdint.h>\n #include <string>\n #include <unordered_map>\n@@ -272,6 +273,7 @@ public:\n \t\t\t     const ControlValue &def = 0);\n \texplicit ControlInfo(Span<const ControlValue> values,\n \t\t\t     const ControlValue &def = {});\n+\texplicit ControlInfo(std::set<bool> values, bool def);\n \n \tconst ControlValue &min() const { return min_; }\n \tconst ControlValue &max() const { return max_; }\ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex 34317fa0..f6351c01 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -514,6 +514,34 @@ ControlInfo::ControlInfo(Span<const ControlValue> values,\n \t\tvalues_.push_back(value);\n }\n \n+/**\n+ * \\brief Construct a ControlInfo from a list of valid boolean values\n+ * \\param[in] values The control valid boolean vaalues\n+ * \\param[in] def The control default boolean value\n+ *\n+ * Construct a ControlInfo from a list of valid boolean values. The ControlInfo\n+ * minimum and maximum values are set to the first and last members of the\n+ * values list respectively. The default value is set to \\a def.\n+ */\n+ControlInfo::ControlInfo(std::set<bool> values, bool def)\n+\t: def_(def)\n+{\n+\tif (values.size() == 1) {\n+\t\tmin_ = max_ = *values.begin();\n+\t} else {\n+\t\tmin_ = false;\n+\t\tmax_ = true;\n+\t}\n+\n+\tdef_ = def;\n+\n+\tassert(values.count(def));\n+\n+\tvalues_.reserve(2);\n+\tfor (const bool &value : values)\n+\t\tvalues_.push_back(value);\n+}\n+\n /**\n  * \\fn ControlInfo::min()\n  * \\brief Retrieve the minimum value of the control\ndiff --git a/test/controls/control_info.cpp b/test/controls/control_info.cpp\nindex 1e05e131..b3d2bd54 100644\n--- a/test/controls/control_info.cpp\n+++ b/test/controls/control_info.cpp\n@@ -44,6 +44,39 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\t/*\n+\t\t * Test information retrieval from a control with boolean\n+\t\t * values.\n+\t\t */\n+\t\tControlInfo aeEnable({ false, true }, false);\n+\n+\t\tif (aeEnable.min().get<bool>() != false ||\n+\t\t    aeEnable.def().get<bool>() != false ||\n+\t\t    aeEnable.max().get<bool>() != true) {\n+\t\t\tcout << \"Invalid control range for AeEnable\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (aeEnable.values()[0].get<bool>() != false ||\n+\t\t    aeEnable.values()[1].get<bool>() != true) {\n+\t\t\tcout << \"Invalid control values for AeEnable\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tControlInfo awbEnable({ true }, true);\n+\n+\t\tif (awbEnable.min().get<bool>() != true ||\n+\t\t    awbEnable.def().get<bool>() != true ||\n+\t\t    awbEnable.max().get<bool>() != true) {\n+\t\t\tcout << \"Invalid control range for AwbEnable\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (awbEnable.values()[0].get<bool>() != true) {\n+\t\t\tcout << \"Invalid control values for AwbEnable\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\treturn TestPass;\n \t}\n };\n","prefixes":["libcamera-devel","RFC","v4","01/21"]}