{"id":3596,"url":"https://patchwork.libcamera.org/api/patches/3596/?format=json","web_url":"https://patchwork.libcamera.org/patch/3596/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200428181650.5071-1-laurent.pinchart@ideasonboard.com>","date":"2020-04-28T18:16:48","name":"[libcamera-devel,v2,1/3] libcamera: camera_sensor: Add model() function","commit_ref":"68863657530812a21073fa463987fd414e1236bb","pull_url":null,"state":"accepted","archived":false,"hash":"0706a629b5addb164753407b84823222d5d9d6b7","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3596/mbox/","series":[{"id":845,"url":"https://patchwork.libcamera.org/api/series/845/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=845","date":"2020-04-28T18:16:48","name":"[libcamera-devel,v2,1/3] libcamera: camera_sensor: Add model() function","version":2,"mbox":"https://patchwork.libcamera.org/series/845/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3596/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3596/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A392160AF4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Apr 2020 20:16:54 +0200 (CEST)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 18AF372C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Apr 2020 20:16:54 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"TCVSAzWS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1588097814;\n\tbh=Mys000+TXrEX3rmHgdxpT7YRh+J5NPJZ/gtSK71fm1Q=;\n\th=From:To:Subject:Date:From;\n\tb=TCVSAzWSReN3jhDkc0FB5w+Xyc5nXNN96Tg7HzgnEmsRkPyAjuD2XtHJ1G71sTOpm\n\tX7NmNWdcJzwIjan3njKWNtpqG1KbzssqBnv4U7FGz7c29U0IkEM48vScbbXmBT/VJE\n\tgDITI6foEFmZZOQwJzK0xPjpP+w/p63Kv1V4MKaE=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 28 Apr 2020 21:16:48 +0300","Message-Id":"<20200428181650.5071-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.25.3","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 1/3] libcamera: camera_sensor: Add\n\tmodel() function","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 28 Apr 2020 18:16:54 -0000"},"content":"Add a new model() function to the CameraSensor class to report the\ncamera sensor model.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges since v1:\n\n- Improve heuristics to extract the sensor model\n- Cache the model in the CameraSensorClass\n---\n src/libcamera/camera_sensor.cpp       | 40 +++++++++++++++++++++++++++\n src/libcamera/include/camera_sensor.h |  2 ++\n 2 files changed, 42 insertions(+)","diff":"diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 70fd5feaae3b..4d1082105504 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -12,6 +12,7 @@\n #include <iomanip>\n #include <limits.h>\n #include <math.h>\n+#include <regex>\n \n #include <libcamera/property_ids.h>\n \n@@ -87,6 +88,35 @@ int CameraSensor::init()\n \t\treturn -EINVAL;\n \t}\n \n+\t/*\n+\t * Extract the camera sensor model name from the media entity name.\n+\t *\n+\t * There is no standardized naming scheme for sensor entities in the\n+\t * Linux kernel at the moment.\n+\t *\n+\t * - The most common rule, used by I2C sensors, associates the model\n+\t *   name with the I2C bus number and address (e.g. 'imx219 0-0010').\n+\t *\n+\t * - When the sensor exposes multiple subdevs, the model name is\n+\t *   usually followed by a function name, as in the smiapp driver (e.g.\n+\t *   'jt8ew9 pixel_array 0-0010').\n+\t *\n+\t * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'.\n+\t *\n+\t * Other schemes probably exist. As a best effort heuristic, use the\n+\t * part of the entity name before the first space if the name contains\n+\t * an I2C address, and use the full entity name otherwise.\n+\t */\n+\tstd::string entityName = entity_->name();\n+\tstd::regex i2cRegex{ \" [0-9]+-[0-9a-f]{4}\" };\n+\tstd::smatch match;\n+\n+\tif (std::regex_search(entityName, match, i2cRegex))\n+\t\tmodel_ = entityName.substr(0, entityName.find(' '));\n+\telse\n+\t\tmodel_ = entityName;\n+\n+\t/* Open the subdev. */\n \tret = subdev_->open();\n \tif (ret < 0)\n \t\treturn ret;\n@@ -163,6 +193,16 @@ int CameraSensor::init()\n \treturn 0;\n }\n \n+/**\n+ * \\fn CameraSensor::model()\n+ * \\brief Retrieve the sensor model name\n+ *\n+ * The sensor model name is a free-formed string that uniquely identifies the\n+ * sensor model.\n+ *\n+ * \\return The sensor model name\n+ */\n+\n /**\n  * \\fn CameraSensor::entity()\n  * \\brief Retrieve the sensor media entity\ndiff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\nindex 5277f7f7fe87..4524661be8ce 100644\n--- a/src/libcamera/include/camera_sensor.h\n+++ b/src/libcamera/include/camera_sensor.h\n@@ -33,6 +33,7 @@ public:\n \n \tint init();\n \n+\tconst std::string &model() const { return model_; }\n \tconst MediaEntity *entity() const { return entity_; }\n \tconst std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }\n \tconst std::vector<Size> &sizes() const { return sizes_; }\n@@ -54,6 +55,7 @@ protected:\n private:\n \tconst MediaEntity *entity_;\n \tV4L2Subdevice *subdev_;\n+\tstd::string model_;\n \n \tstd::vector<unsigned int> mbusCodes_;\n \tstd::vector<Size> sizes_;\n","prefixes":["libcamera-devel","v2","1/3"]}