From patchwork Mon Jan 13 16:42:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2625 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F07DB606BD for ; Mon, 13 Jan 2020 17:40:32 +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 1310A100003; Mon, 13 Jan 2020 16:40:31 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Jan 2020 17:42:32 +0100 Message-Id: <20200113164245.52535-11-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 10/23] cam: Add option to list camera properties 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 the '-p'|'--list-properties' option to the cam application to list the properties of a camera. Reviewed-by: Niklas Söderlund Signed-off-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/cam/main.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ src/cam/main.h | 1 + 2 files changed, 51 insertions(+) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index a38cca959aca..41aedea3ab17 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -11,6 +11,7 @@ #include #include +#include #include "capture.h" #include "event_loop.h" @@ -36,6 +37,7 @@ public: private: int parseOptions(int argc, char *argv[]); int prepareConfig(); + int listProperties(); int infoConfiguration(); int run(); @@ -180,6 +182,7 @@ int CamApp::parseOptions(int argc, char *argv[]) parser.addOption(OptInfo, OptionNone, "Display information about stream(s)", "info"); parser.addOption(OptList, OptionNone, "List all cameras", "list"); + parser.addOption(OptProps, OptionNone, "List cameras properties", "list-properties"); options_ = parser.parse(argc, argv); if (!options_.valid()) @@ -268,6 +271,47 @@ int CamApp::prepareConfig() return 0; } +int CamApp::listProperties() +{ + if (!camera_) { + std::cout << "Cannot list properties without a camera" + << std::endl; + return -EINVAL; + } + + const ControlList &properties = camera_->properties(); + for (const auto &prop : properties) { + unsigned int id = prop.first; + const auto &ctrlId = properties::properties.find(id); + const ControlId *ctrl = ctrlId->second; + const ControlValue &value = prop.second; + + std::cout << "Property: " << ctrl->name() << " = "; + + switch (ctrl->type()) { + case ControlTypeBool: { + bool val = value.get(); + std::cout << (val ? "True" : "False") << std::endl; + break; + } + case ControlTypeInteger32: { + int32_t val = value.get(); + std::cout << val << std::endl; + break; + } + case ControlTypeInteger64: { + int64_t val = value.get(); + std::cout << val << std::endl; + break; + } + default: + break; + } + } + + return 0; +} + int CamApp::infoConfiguration() { if (!config_) { @@ -312,6 +356,12 @@ int CamApp::run() } } + if (options_.isSet(OptProps)) { + ret = listProperties(); + if (ret) + return ret; + } + if (options_.isSet(OptInfo)) { ret = infoConfiguration(); if (ret) diff --git a/src/cam/main.h b/src/cam/main.h index 0997476bb335..afcad4353b7d 100644 --- a/src/cam/main.h +++ b/src/cam/main.h @@ -14,6 +14,7 @@ enum { OptHelp = 'h', OptInfo = 'I', OptList = 'l', + OptProps = 'p', OptStream = 's', };