@@ -11,6 +11,7 @@
#include <memory>
#include <vector>
+#include <libcamera/controls.h>
#include <linux/videodev2.h>
#include "log.h"
@@ -27,6 +28,23 @@ public:
const ControlInfoMap &controls() const { return controls_; }
int getControls(ControlList *ctrls);
+ template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
+ !std::is_same<std::string, std::remove_cv_t<T>>::value,
+ std::nullptr_t> = nullptr>
+ int getControl(unsigned int id, T *val)
+ {
+ ControlList list(controls_);
+ /* Reuse 'val' as we're only interested in reading. */
+ list.set(id, *val);
+
+ int ret = getControls(&list);
+ if (ret)
+ return ret;
+ *val = list.get(id).get<T>();
+
+ return 0;
+ }
+
int setControls(ControlList *ctrls);
const std::string &deviceNode() const { return deviceNode_; }
@@ -242,6 +242,17 @@ int V4L2Device::getControls(ControlList *ctrls)
return ret;
}
+/**
+ * \fn int V4L2Device::getControl(unsigned int id, T *val) const
+ * \brief Get the value of the V4L2 control \a id from the device
+ * \param[in] id The V4L2 control ID
+ * \param[out] val The control value
+ *
+ * \todo This only supports non-span and non-string controls.
+ *
+ * \return 0 on success, a negative error code otherwise
+ */
+
/**
* \brief Write controls to the device
* \param[in] ctrls The list of controls to write
Add a method to the V4L2Device class to read a single control from a device. The current procedure to read a V4L2 Control from a device requires the user to setup a list and populate it using ControlList::set(), with a value that is ignored if the only interest is reading the control out. Provide a method to read a single control by just providing its id. The newly added method only supports non-span e non-string control but could be easily expanded later. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> --- src/libcamera/include/v4l2_device.h | 18 ++++++++++++++++++ src/libcamera/v4l2_device.cpp | 11 +++++++++++ 2 files changed, 29 insertions(+)