[{"id":4625,"web_url":"https://patchwork.libcamera.org/comment/4625/","msgid":"<20200428200925.nxo25hz6frruf44q@uno.localdomain>","date":"2020-04-28T20:09:25","subject":"Re: [libcamera-devel] [PATCH v2 1/3] libcamera: camera_sensor: Add\n\tmodel() function","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Tue, Apr 28, 2020 at 09:16:48PM +0300, Laurent Pinchart wrote:\n> Add a new model() function to the CameraSensor class to report the\n> camera sensor model.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n> Changes 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(+)\n>\n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index 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\nThis will then be \"jt8ew9 pixel_array\". I like it!\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\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\n> diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\n> index 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> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6382E60AF4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Apr 2020 22:06:18 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 7F1442000B;\n\tTue, 28 Apr 2020 20:06:17 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Tue, 28 Apr 2020 22:09:25 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200428200925.nxo25hz6frruf44q@uno.localdomain>","References":"<20200428181650.5071-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200428181650.5071-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [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 20:06:18 -0000"}}]