From patchwork Thu Aug 6 13:09:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9257 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id EABC3BD87A for ; Thu, 6 Aug 2020 13:09:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BCBB66071B; Thu, 6 Aug 2020 15:09:51 +0200 (CEST) Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 71F9260CBE for ; Thu, 6 Aug 2020 15:09:49 +0200 (CEST) X-Halon-ID: 18c9ae47-d7e6-11ea-b48b-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de [84.172.82.168]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 18c9ae47-d7e6-11ea-b48b-0050569116f7; Thu, 06 Aug 2020 15:09:45 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Aug 2020 15:09:36 +0200 Message-Id: <20200806130937.2991606-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200806130937.2991606-1-niklas.soderlund@ragnatech.se> References: <20200806130937.2991606-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/7] cam: Print user-friendly camera names 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Instead of only printing the camera ID which is not intended for humans to read and parse create a more user friendly string when prating 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 --- src/cam/main.cpp | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index cc3facd5a5b22092..5af76f6965ef2387 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -21,6 +21,39 @@ using namespace libcamera; +std::string cameraName(const Camera *camera) +{ + const ControlList &props = camera->properties(); + std::string name; + + if (props.contains(properties::Model)) + name += props.get(properties::Model) + " "; + + if (props.contains(properties::Location)) { + switch (props.get(properties::Location)) { + case properties::CameraLocationFront: + name += "facing front "; + break; + case properties::CameraLocationBack: + name += "facing back "; + break; + case properties::CameraLocationExternal: + name += "external "; + break; + } + } + + if (props.contains(properties::Rotation)) + name += "rotated " + std::to_string(props.get(properties::Rotation)) + " degrees "; + + if (!name.empty()) + name += "with id "; + + name += camera->id(); + + return name; +} + class CamApp { public: @@ -117,7 +150,7 @@ int CamApp::init(int argc, char **argv) return -EINVAL; } - std::cout << "Using camera " << camera_->id() << std::endl; + std::cout << "Using camera " << cameraName(camera_.get()) << std::endl; ret = prepareConfig(); if (ret) { @@ -323,12 +356,12 @@ int CamApp::infoConfiguration() void CamApp::cameraAdded(std::shared_ptr cam) { - std::cout << "Camera Added: " << cam->id() << std::endl; + std::cout << "Camera Added: " << cameraName(cam.get()) << std::endl; } void CamApp::cameraRemoved(std::shared_ptr cam) { - std::cout << "Camera Removed: " << cam->id() << std::endl; + std::cout << "Camera Removed: " << cameraName(cam.get()) << std::endl; } int CamApp::run() @@ -340,7 +373,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++; } }