From a14b6baca9afe5ad15b49a3ff25b01a6f582689e Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Wed, 20 Nov 2019 16:39:39 +0100 Subject: cam: Add option to list camera properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add the '-p'|'--list-properties' option to the cam application to list the properties of a camera. Signed-off-by: Laurent Pinchart Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- src/cam/main.cpp | 28 ++++++++++++++++++++++++++++ src/cam/main.h | 1 + 2 files changed, 29 insertions(+) (limited to 'src/cam') diff --git a/src/cam/main.cpp b/src/cam/main.cpp index a38cca95..ea6f7914 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,8 @@ 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 +272,24 @@ int CamApp::prepareConfig() return 0; } +int CamApp::listProperties() +{ + if (!camera_) { + std::cout << "Cannot list properties without a camera" + << std::endl; + return -EINVAL; + } + + for (const auto &prop : camera_->properties()) { + const ControlId *id = properties::properties.at(prop.first); + const ControlValue &value = prop.second; + + std::cout << "Property: " << id->name() << " = " << value.toString(); + } + + return 0; +} + int CamApp::infoConfiguration() { if (!config_) { @@ -312,6 +334,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 0997476b..afcad435 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', }; -- cgit v1.2.1