summaryrefslogtreecommitdiff
path: root/src/libcamera/camera_sensor.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-04-28 00:53:01 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-04-28 23:13:22 +0300
commit68863657530812a21073fa463987fd414e1236bb (patch)
tree28144993d66774da93104e3836e28b85fd66ee2e /src/libcamera/camera_sensor.cpp
parent79ab0e925a782a6781d38237435fcfc29ddd2e20 (diff)
libcamera: camera_sensor: Add model() function
Add a new model() function to the CameraSensor class to report the camera sensor model. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/libcamera/camera_sensor.cpp')
-rw-r--r--src/libcamera/camera_sensor.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index 7c1d9b9e..3d7cedca 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -12,6 +12,7 @@
#include <iomanip>
#include <limits.h>
#include <math.h>
+#include <regex>
#include <libcamera/property_ids.h>
@@ -87,6 +88,35 @@ int CameraSensor::init()
return -EINVAL;
}
+ /*
+ * Extract the camera sensor model name from the media entity name.
+ *
+ * There is no standardized naming scheme for sensor entities in the
+ * Linux kernel at the moment.
+ *
+ * - The most common rule, used by I2C sensors, associates the model
+ * name with the I2C bus number and address (e.g. 'imx219 0-0010').
+ *
+ * - When the sensor exposes multiple subdevs, the model name is
+ * usually followed by a function name, as in the smiapp driver (e.g.
+ * 'jt8ew9 pixel_array 0-0010').
+ *
+ * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'.
+ *
+ * Other schemes probably exist. As a best effort heuristic, use the
+ * part of the entity name before the first space if the name contains
+ * an I2C address, and use the full entity name otherwise.
+ */
+ std::string entityName = entity_->name();
+ std::regex i2cRegex{ " [0-9]+-[0-9a-f]{4}" };
+ std::smatch match;
+
+ if (std::regex_search(entityName, match, i2cRegex))
+ model_ = entityName.substr(0, entityName.find(' '));
+ else
+ model_ = entityName;
+
+ /* Open the subdev. */
ret = subdev_->open();
if (ret < 0)
return ret;
@@ -164,6 +194,16 @@ int CameraSensor::init()
}
/**
+ * \fn CameraSensor::model()
+ * \brief Retrieve the sensor model name
+ *
+ * The sensor model name is a free-formed string that uniquely identifies the
+ * sensor model.
+ *
+ * \return The sensor model name
+ */
+
+/**
* \fn CameraSensor::entity()
* \brief Retrieve the sensor media entity
* \return The sensor media entity