[libcamera-devel] [RFC PATCH v3 01/16] controls: Add boolean constructor for ControlInfo
Paul Elder
paul.elder at ideasonboard.com
Fri Jul 2 12:37:45 CEST 2021
It would be convenient to be able to iterate over available boolean
values, for example for controls that designate if some function can be
enabled/disabled. The current min/max/def constructor is insufficient,
as .values() is empty, so the values cannot be easily iterated over, and
creating a Span of booleans does not work for the values constructor.
Add a new constructor to ControlInfo that takes a Span of booleans (to
allow specifiying one or two available values), and a default. The
default value is not optional, as it doesn't make sense to have a silent
default for boolean values.
Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
---
New in v3
---
include/libcamera/controls.h | 1 +
src/libcamera/controls.cpp | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 1bc958a4..2dd147c8 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -272,6 +272,7 @@ public:
const ControlValue &def = 0);
explicit ControlInfo(Span<const ControlValue> values,
const ControlValue &def = {});
+ explicit ControlInfo(Span<const bool> values, bool def);
const ControlValue &min() const { return min_; }
const ControlValue &max() const { return max_; }
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index 34317fa0..e32e22e2 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -514,6 +514,26 @@ ControlInfo::ControlInfo(Span<const ControlValue> values,
values_.push_back(value);
}
+/**
+ * \brief Construct a ControlInfo from a list of valid boolean values
+ * \param[in] values The control valid boolean vaalues
+ * \param[in] def The control default boolean value
+ *
+ * Construct a ControlInfo from a list of valid boolean values. The ControlInfo
+ * minimum and maximum values are set to the first and last members of the
+ * values list respectively. The default value is set to \a def.
+ */
+ControlInfo::ControlInfo(Span<const bool> values, bool def)
+ : def_(def)
+{
+ min_ = values.front();
+ max_ = values.back();
+
+ values_.reserve(2);
+ for (const bool &value : values)
+ values_.push_back(value);
+}
+
/**
* \fn ControlInfo::min()
* \brief Retrieve the minimum value of the control
--
2.27.0
More information about the libcamera-devel
mailing list