summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2024-09-16 01:24:18 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-09-25 23:53:44 +0300
commit9bbccb97fa0debc86d906fdfc1fbedbd50de5d06 (patch)
tree5794a9de150d8800bcfc4de2631fe6b06588ac1c /src
parent44b49af7a0a870d5fce5c162e3998ef3696912d5 (diff)
libcamera: controls: Add enum names and values map to ControlId
Add to ControlId information about the names and values of enum, in the event that the ControlId is an enum type. This allows applications to query the ControlId for the names of the enum values, so that they can be displayed on a UI, for example. Without this, it was necessary to use macros of NameOfControlNameValueMap, which is difficult to use and is very inflexible. There already exists a map from name -> value in generated code. Reuse this and pass it to the ControlId constructor, which in turn generates the reverse map. The reverse map is then exposed to applications. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/control_ids.cpp.in4
-rw-r--r--src/libcamera/controls.cpp15
2 files changed, 18 insertions, 1 deletions
diff --git a/src/libcamera/control_ids.cpp.in b/src/libcamera/control_ids.cpp.in
index 05c8fb38..3a204931 100644
--- a/src/libcamera/control_ids.cpp.in
+++ b/src/libcamera/control_ids.cpp.in
@@ -89,8 +89,10 @@ extern const std::map<std::string, {{ctrl.type}}> {{ctrl.name}}NameValueMap = {
{ "{{enum.name}}", {{enum.name}} },
{%- endfor %}
};
-{% endif -%}
+extern const Control<{{ctrl.type}}> {{ctrl.name}}({{ctrl.name|snake_case|upper}}, "{{ctrl.name}}", {{ctrl.name}}NameValueMap);
+{% else -%}
extern const Control<{{ctrl.type}}> {{ctrl.name}}({{ctrl.name|snake_case|upper}}, "{{ctrl.name}}");
+{% endif -%}
{%- endfor %}
{% if vendor != 'libcamera' %}
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index dba74404..a46c431a 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -389,7 +389,15 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen
* \param[in] id The control numerical ID
* \param[in] name The control name
* \param[in] type The control data type
+ * \param[in] enumStrMap The map from enum names to values (optional)
*/
+ControlId::ControlId(unsigned int id, const std::string &name, ControlType type,
+ const std::map<std::string, int32_t> &enumStrMap)
+ : id_(id), name_(name), type_(type), enumStrMap_(enumStrMap)
+{
+ for (const auto &pair : enumStrMap_)
+ reverseMap_[pair.second] = pair.first;
+}
/**
* \fn unsigned int ControlId::id() const
@@ -410,6 +418,12 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen
*/
/**
+ * \fn const std::map<int32_t, std::string> &ControlId::enumerators() const
+ * \brief Retrieve the map of enum values to enum names
+ * \return The map of enum values to enum names
+ */
+
+/**
* \fn bool operator==(unsigned int lhs, const ControlId &rhs)
* \brief Compare a ControlId with a control numerical ID
* \param[in] lhs Left-hand side numerical ID
@@ -459,6 +473,7 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen
* \brief Construct a Control instance
* \param[in] id The control numerical ID
* \param[in] name The control name
+ * \param[in] enumStrMap The map from enum names to values (optional)
*
* The control data type is automatically deduced from the template type T.
*/