From patchwork Sat Jul 18 13:23:17 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: 8851 X-Patchwork-Delegate: niklas.soderlund@ragnatech.se 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 8270DC0109 for ; Sat, 18 Jul 2020 13:23:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9D96660493; Sat, 18 Jul 2020 15:23:35 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E038C6053A for ; Sat, 18 Jul 2020 15:23:32 +0200 (CEST) X-Halon-ID: df6cc57f-c8f9-11ea-933e-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id df6cc57f-c8f9-11ea-933e-005056917a89; Sat, 18 Jul 2020 15:23:31 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sat, 18 Jul 2020 15:23:17 +0200 Message-Id: <20200718132324.867815-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200718132324.867815-1-niklas.soderlund@ragnatech.se> References: <20200718132324.867815-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/9] libcamera: camera_sensor: Expose a sensor ID 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" Expose a constant unique string ID for the sensor. The ID is generated from the sensors device and inherits the paths properties, it is unique and persistent across reboots of the system. To make ID a bit more user friendly drop '/sys/devices/' from the path. Signed-off-by: Niklas Söderlund --- include/libcamera/internal/camera_sensor.h | 2 ++ src/libcamera/camera_sensor.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 7f07413f95602881..4be25042a0d6b387 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -49,6 +49,7 @@ public: int init(); const std::string &model() const { return model_; } + const std::string &id() const { return id_; } const MediaEntity *entity() const { return entity_; } const std::vector &mbusCodes() const { return mbusCodes_; } const std::vector &sizes() const { return sizes_; } @@ -74,6 +75,7 @@ private: unsigned int pad_; std::string model_; + std::string id_; ImageFormats formats_; Size resolution_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 6e93cc51155ba678..733ddf6866bd1ec1 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -205,6 +205,12 @@ int CameraSensor::init() if (ret < 0) return ret; + /* Create ID from sysfs device path. */ + id_ = subdev_->devicePath(); + const std::string dropStr = "/sys/devices/"; + if (id_.find(dropStr) == 0) + id_.erase(0, dropStr.length()); + /* Retrieve and store the camera sensor properties. */ const ControlInfoMap &controls = subdev_->controls(); int32_t propertyValue; @@ -284,6 +290,17 @@ int CameraSensor::init() * \return The sensor model name */ +/** + * \fn CameraSensor::id() + * \brief Retrieve the sensor ID + * + * The sensor ID is a free-formed string that uniquely identifies the sensor in + * the system. The ID is persisted between different instances of libcamera and + * between resets of the system. + * + * \return The sensor ID + */ + /** * \fn CameraSensor::entity() * \brief Retrieve the sensor media entity