1 /*********************************************************************
2 * Software License Agreement (BSD License)
4 * Copyright (C) 2010-2012 Ken Tossell
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the author nor other contributors may be
18 * used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
35 * @defgroup ctrl Video capture and processing controls
36 * @brief Functions for manipulating device settings and stream parameters
38 * The `uvc_get_*` and `uvc_set_*` functions are used to read and write the settings associated
39 * with the device's input, processing and output units.
42 #include "libuvc/libuvc.h"
43 #include "libuvc/libuvc_internal.h"
45 static const int REQ_TYPE_SET = 0x21;
46 static const int REQ_TYPE_GET = 0xa1;
48 /***** GENERIC CONTROLS *****/
50 * @brief Get the length of a control on a terminal or unit.
52 * @param devh UVC device handle
53 * @param unit Unit or Terminal ID; obtain this from the uvc_extension_unit_t describing the extension unit
54 * @param ctrl Vendor-specific control number to query
55 * @return On success, the length of the control as reported by the device. Otherwise,
56 * a uvc_error_t error describing the error encountered.
59 int uvc_get_ctrl_len(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl) {
62 int ret = libusb_control_transfer(
64 REQ_TYPE_GET, UVC_GET_LEN,
66 unit << 8 | devh->info->ctrl_if.bInterfaceNumber, // XXX saki
74 return (unsigned short)SW_TO_SHORT(buf);
78 * @brief Perform a GET_* request from an extension unit.
80 * @param devh UVC device handle
81 * @param unit Unit ID; obtain this from the uvc_extension_unit_t describing the extension unit
82 * @param ctrl Control number to query
83 * @param data Data buffer to be filled by the device
84 * @param len Size of data buffer
85 * @param req_code GET_* request to execute
86 * @return On success, the number of bytes actually transferred. Otherwise,
87 * a uvc_error_t error describing the error encountered.
90 int uvc_get_ctrl(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl, void *data, int len, enum uvc_req_code req_code) {
91 return libusb_control_transfer(
93 REQ_TYPE_GET, req_code,
95 unit << 8 | devh->info->ctrl_if.bInterfaceNumber, // XXX saki
102 * @brief Perform a SET_CUR request to a terminal or unit.
104 * @param devh UVC device handle
105 * @param unit Unit or Terminal ID
106 * @param ctrl Control number to set
107 * @param data Data buffer to be sent to the device
108 * @param len Size of data buffer
109 * @return On success, the number of bytes actually transferred. Otherwise,
110 * a uvc_error_t error describing the error encountered.
113 int uvc_set_ctrl(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl, void *data, int len) {
114 return libusb_control_transfer(
116 REQ_TYPE_SET, UVC_SET_CUR,
118 unit << 8 | devh->info->ctrl_if.bInterfaceNumber, // XXX saki
124 /***** INTERFACE CONTROLS *****/
125 uvc_error_t uvc_get_power_mode(uvc_device_handle_t *devh, enum uvc_device_power_mode *mode, enum uvc_req_code req_code) {
129 ret = libusb_control_transfer(
131 REQ_TYPE_GET, req_code,
132 UVC_VC_VIDEO_POWER_MODE_CONTROL << 8,
133 devh->info->ctrl_if.bInterfaceNumber, // XXX saki
146 uvc_error_t uvc_set_power_mode(uvc_device_handle_t *devh, enum uvc_device_power_mode mode) {
147 uint8_t mode_char = mode;
150 ret = libusb_control_transfer(
152 REQ_TYPE_SET, UVC_SET_CUR,
153 UVC_VC_VIDEO_POWER_MODE_CONTROL << 8,
154 devh->info->ctrl_if.bInterfaceNumber, // XXX saki
165 /** @todo Request Error Code Control (UVC 1.5, 4.2.1.2) */