From patchwork Fri Apr 24 21:53:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3527 Return-Path: Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2194C62E5D for ; Fri, 24 Apr 2020 23:50:13 +0200 (CEST) X-Originating-IP: 87.3.55.240 Received: from uno.homenet.telecomitalia.it (host240-55-dynamic.3-87-r.retail.telecomitalia.it [87.3.55.240]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 4F43060002; Fri, 24 Apr 2020 21:50:12 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Apr 2020 23:53:00 +0200 Message-Id: <20200424215304.558317-10-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200424215304.558317-1-jacopo@jmondi.org> References: <20200424215304.558317-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 09/13] libcamera: v4l2_device: Add method to read a control X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Apr 2020 21:50:13 -0000 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 --- src/libcamera/include/v4l2_device.h | 18 ++++++++++++++++++ src/libcamera/v4l2_device.cpp | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index ce8edd98a01d..23cff08bbfd0 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -11,6 +11,7 @@ #include #include +#include #include #include "log.h" @@ -27,6 +28,23 @@ public: const ControlInfoMap &controls() const { return controls_; } int getControls(ControlList *ctrls); + template::value && + !std::is_same>::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(); + + return 0; + } + int setControls(ControlList *ctrls); const std::string &deviceNode() const { return deviceNode_; } diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 03e305165096..9d67e0f63b1e 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -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