From patchwork Wed Oct 21 15:40:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 10176 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 BC71BBDB13 for ; Wed, 21 Oct 2020 15:40:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 477F360BE7; Wed, 21 Oct 2020 17:40:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="eB6aqnWN"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B52B5603F9 for ; Wed, 21 Oct 2020 17:40:46 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4C45F92; Wed, 21 Oct 2020 17:40:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1603294846; bh=xD6Ju89V7gYM6IvxbQ2kbTAJlq6tQAhuq5u6qeJg2Ag=; h=From:To:Cc:Subject:Date:From; b=eB6aqnWNLkzx5aFkCSnQHHZimVEYyLlHTLx1Qx6qAJyU9AwsU1l0SsADTGp/dFqTs 4s2FBUJCupLmTe97LM7SBOx4Uun8JElFra80GOM0ILrEcZy0lkvZDMvW0VXBdJfWxI ZnjKgXI8K7TFwqy2obqIflSN52eZFvKE2IHK2lyw= From: Kieran Bingham To: libcamera devel Date: Wed, 21 Oct 2020 16:40:43 +0100 Message-Id: <20201021154043.511274-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [Simple-Cam: PATCH] simple-cam: Use 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" Take the example code for generating a camera name from 'cam' and use it when reporting cameras within the simple-cam application. Signed-off-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- I wonder if this cameraName() might be something that should go into libcamera::utils as a public API helper? I know we want to allow applications to decide their own naming too, but I think we've discussed in the past about having a helper library on top to make things easier for application developers ? simple-cam.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/simple-cam.cpp b/simple-cam.cpp index 727bb6d86480..1b6fd3939bf6 100644 --- a/simple-cam.cpp +++ b/simple-cam.cpp @@ -60,6 +60,30 @@ static void requestComplete(Request *request) camera->queueRequest(request); } +std::string cameraName(std::shared_ptr 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; +} + int main() { /* @@ -77,11 +101,11 @@ int main() cm->start(); /* - * Just as a test, list all id's of the Camera registered in the - * system. They are indexed by name by the CameraManager. + * Just as a test, generate names of the Cameras registered in the + * system, and list them. */ for (auto const &camera : cm->cameras()) - std::cout << camera->id() << std::endl; + std::cout << " - " << cameraName(camera) << std::endl; /* * --------------------------------------------------------------------