From 78fcf8e17c84c79385af1b0943b83bef9327b355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Thu, 6 Aug 2020 14:24:22 +0200 Subject: cam: Print user-friendly camera names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of only printing the camera ID which is not intended for humans to read and parse create a more user-friendly string when printing camera names. The ID is still printed as it is one option used to select camera using the --camera option. Signed-off-by: Niklas Söderlund Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/cam/main.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/cam') diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 244720b4..b3a8d94f 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -45,6 +45,8 @@ private: int infoConfiguration(); int run(); + std::string const cameraName(const Camera *camera); + static CamApp *app_; OptionsParser::Options options_; CameraManager *cm_; @@ -340,7 +342,7 @@ int CamApp::run() unsigned int index = 1; for (const std::shared_ptr &cam : cm_->cameras()) { - std::cout << index << ": " << cam->id() << std::endl; + std::cout << index << ": " << cameraName(cam.get()) << std::endl; index++; } } @@ -378,6 +380,30 @@ int CamApp::run() return 0; } +std::string const CamApp::cameraName(const Camera *camera) +{ + const ControlList &props = camera->properties(); + std::string name; + + switch (props.get(properties::Location)) { + case properties::CameraLocationFront: + name = "Internal front camera"; + break; + case properties::CameraLocationBack: + name = "Internal back camera"; + break; + case properties::CameraLocationExternal: + name = "External camera"; + if (props.contains(properties::Model)) + name += " '" + props.get(properties::Model) + "'"; + break; + } + + name += " (" + camera->id() + ")"; + + return name; +} + void signalHandler([[maybe_unused]] int signal) { std::cout << "Exiting" << std::endl; -- cgit v1.2.1