{"id":2405,"url":"https://patchwork.libcamera.org/api/patches/2405/?format=json","web_url":"https://patchwork.libcamera.org/patch/2405/","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":"<20191205204350.28196-11-jacopo@jmondi.org>","date":"2019-12-05T20:43:50","name":"[libcamera-devel,v2,10/10] cam: Add option to list camera properties","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"cc2d82074dd743081527ce64c2bd42e482e17004","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2405/mbox/","series":[{"id":582,"url":"https://patchwork.libcamera.org/api/series/582/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=582","date":"2019-12-05T20:43:40","name":"Introduce camera properties","version":2,"mbox":"https://patchwork.libcamera.org/series/582/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2405/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2405/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 58BCF61363\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  5 Dec 2019 21:41:59 +0100 (CET)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id DA7671BF205;\n\tThu,  5 Dec 2019 20:41:58 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  5 Dec 2019 21:43:50 +0100","Message-Id":"<20191205204350.28196-11-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.23.0","In-Reply-To":"<20191205204350.28196-1-jacopo@jmondi.org>","References":"<20191205204350.28196-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 10/10] cam: Add option to list camera\n\tproperties","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>","X-List-Received-Date":"Thu, 05 Dec 2019 20:41:59 -0000"},"content":"Add the '-p'|'--props' option to the cam application to list the\nproperties of a camera.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/cam/main.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++\n src/cam/main.h   |  1 +\n 2 files changed, 61 insertions(+)","diff":"diff --git a/src/cam/main.cpp b/src/cam/main.cpp\nindex a38cca959aca..7e1eb20d6df7 100644\n--- a/src/cam/main.cpp\n+++ b/src/cam/main.cpp\n@@ -11,6 +11,7 @@\n #include <string.h>\n \n #include <libcamera/libcamera.h>\n+#include <libcamera/property_ids.h>\n \n #include \"capture.h\"\n #include \"event_loop.h\"\n@@ -36,6 +37,7 @@ public:\n private:\n \tint parseOptions(int argc, char *argv[]);\n \tint prepareConfig();\n+\tint listProperties();\n \tint infoConfiguration();\n \tint run();\n \n@@ -180,6 +182,7 @@ int CamApp::parseOptions(int argc, char *argv[])\n \tparser.addOption(OptInfo, OptionNone,\n \t\t\t \"Display information about stream(s)\", \"info\");\n \tparser.addOption(OptList, OptionNone, \"List all cameras\", \"list\");\n+\tparser.addOption(OptProps, OptionNone, \"List the cameras properties\", \"props\");\n \n \toptions_ = parser.parse(argc, argv);\n \tif (!options_.valid())\n@@ -268,6 +271,47 @@ int CamApp::prepareConfig()\n \treturn 0;\n }\n \n+int CamApp::listProperties()\n+{\n+\tif (!camera_) {\n+\t\tstd::cout << \"Cannot list properties without a camera\"\n+\t\t\t  << std::endl;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tconst ControlList &properties = camera_->properties();\n+\tfor (const auto &prop : properties) {\n+\t\tunsigned int id = prop.first;\n+\t\tconst auto &ctrlId = properties::properties.find(id);\n+\t\tconst ControlId *ctrl = ctrlId->second;\n+\t\tconst ControlValue &value = prop.second;\n+\n+\t\tstd::cout << \"Property: \" << ctrl->name() << \" = \";\n+\n+\t\tswitch (ctrl->type()) {\n+\t\tcase ControlTypeBool: {\n+\t\t\tbool val = value.get<bool>();\n+\t\t\tstd::cout << (val ? \"True\" : \"False\") << std::endl;\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase ControlTypeInteger32: {\n+\t\t\tint32_t val = value.get<int32_t>();\n+\t\t\tstd::cout << val << std::endl;\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase ControlTypeInteger64: {\n+\t\t\tint64_t val = value.get<int64_t>();\n+\t\t\tstd::cout << val << std::endl;\n+\t\t\tbreak;\n+\t\t}\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n int CamApp::infoConfiguration()\n {\n \tif (!config_) {\n@@ -309,9 +353,25 @@ int CamApp::run()\n \t\tfor (const std::shared_ptr<Camera> &cam : cm_->cameras()) {\n \t\t\tstd::cout << index << \": \" << cam->name() << std::endl;\n \t\t\tindex++;\n+\n+\t\t\tconst ControlList &properties = cam->properties();\n+\t\t\tfor (const auto &prop : properties) {\n+\t\t\t\tauto it = properties::properties.find(prop.first);\n+\t\t\t\tif (it == properties::properties.end())\n+\t\t\t\t\tcontinue;\n+\n+\t\t\t\tstd::cout << it->second->name() << \": \" <<\n+\t\t\t\t\tprop.second.get<int32_t>() << \"\\n\";\n+\t\t\t}\n \t\t}\n \t}\n \n+\tif (options_.isSet(OptProps)) {\n+\t\tret = listProperties();\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n \tif (options_.isSet(OptInfo)) {\n \t\tret = infoConfiguration();\n \t\tif (ret)\ndiff --git a/src/cam/main.h b/src/cam/main.h\nindex 0997476bb335..afcad4353b7d 100644\n--- a/src/cam/main.h\n+++ b/src/cam/main.h\n@@ -14,6 +14,7 @@ enum {\n \tOptHelp = 'h',\n \tOptInfo = 'I',\n \tOptList = 'l',\n+\tOptProps = 'p',\n \tOptStream = 's',\n };\n \n","prefixes":["libcamera-devel","v2","10/10"]}