From patchwork Mon Jan 21 17:27:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 303 Return-Path: Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F62160C96 for ; Mon, 21 Jan 2019 18:27:04 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id BBFD91BF206; Mon, 21 Jan 2019 17:27:03 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Jan 2019 18:27:01 +0100 Message-Id: <20190121172705.19985-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121172705.19985-1-jacopo@jmondi.org> References: <20190121172705.19985-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/6] libcamera: v4l2_device: Add setControl function X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jan 2019 17:27:04 -0000 Add function to set controls on a V4L2Device object. Signed-off-by: Jacopo Mondi --- src/libcamera/include/v4l2_device.h | 2 ++ src/libcamera/v4l2_device.cpp | 38 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index c6f3d9a..2787847 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -51,6 +51,8 @@ public: const char *deviceName() const { return caps_.card(); } const char *busName() const { return caps_.bus_info(); } + int setControl(unsigned int control, int value); + private: std::string devnode_; int fd_; diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 59a1ad9..aef0996 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -195,4 +195,42 @@ void V4L2Device::close() * \return The string containing the device location */ +/** + * \brief Set a control value + * \param control The control identifier + * \param value The new control value + * + * Set a user control to the requested value. The function returns the + * new value actually assigned to the control, which might be different + * from the requested \a value one. + * + * \return The new control's value for success, or a negative error code otherwise + */ +int V4L2Device::setControl(unsigned int control, int value) +{ + struct v4l2_control v4l2_ctrl = { + .id = control, + .value = value, + }; + + int ret = ioctl(fd_, VIDIOC_S_CTRL, &v4l2_ctrl); + if (ret) { + ret = -errno; + LOG(Error) << "Failed to set control: " << strerror(-ret); + return ret; + } + + v4l2_ctrl = { }; + v4l2_ctrl.id = control; + + ret = ioctl(fd_, VIDIOC_G_CTRL, &v4l2_ctrl); + if (ret) { + ret = -errno; + LOG(Error) << "Failed to get control: " << strerror(-ret); + return ret; + } + + return v4l2_ctrl.value; +} + } /* namespace libcamera */