[libcamera-devel] [PATCH v4 10/10] cam: Add option to list camera properties
Jacopo Mondi
jacopo at jmondi.org
Wed Jan 8 17:34:34 CET 2020
Add the '-p'|'--list-properties' option to the cam application to list
the properties of a camera.
Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
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 <string.h>
#include <libcamera/libcamera.h>
+#include <libcamera/property_ids.h>
#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<bool>();
+ std::cout << (val ? "True" : "False") << std::endl;
+ break;
+ }
+ case ControlTypeInteger32: {
+ int32_t val = value.get<int32_t>();
+ std::cout << val << std::endl;
+ break;
+ }
+ case ControlTypeInteger64: {
+ int64_t val = value.get<int64_t>();
+ 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',
};
--
2.24.0
More information about the libcamera-devel
mailing list