ctrl.c
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (C) 2010-2012 Ken Tossell
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
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.
20 *
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 *********************************************************************/
42 #include "libuvc.h"
43 #include "libuvc_internal.h"
44 
45 static const int REQ_TYPE_SET = 0x21;
46 static const int REQ_TYPE_GET = 0xa1;
47 
48 /***** GENERIC CONTROLS *****/
59 int uvc_get_ctrl_len(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl) {
60  unsigned char buf[2];
61 
62  int ret = libusb_control_transfer(
63  devh->usb_devh,
65  ctrl << 8,
66  unit << 8,
67  buf,
68  2,
69  0 /* timeout */);
70 
71  if (ret < 0)
72  return ret;
73  else
74  return (unsigned short)SW_TO_SHORT(buf);
75 }
76 
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(
92  devh->usb_devh,
93  REQ_TYPE_GET, req_code,
94  ctrl << 8,
95  unit << 8,
96  data,
97  len,
98  0 /* timeout */);
99 }
100 
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(
115  devh->usb_devh,
117  ctrl << 8,
118  unit << 8,
119  data,
120  len,
121  0 /* timeout */);
122 }
123 
124 /***** INTERFACE CONTROLS *****/
126  uint8_t mode_char;
127  uvc_error_t ret;
128 
129  ret = libusb_control_transfer(
130  devh->usb_devh,
131  REQ_TYPE_GET, req_code,
132  UVC_VC_VIDEO_POWER_MODE_CONTROL << 8,
133  0,
134  &mode_char,
135  sizeof(mode_char),
136  0);
137 
138  if (ret == 1) {
139  *mode = mode_char;
140  return UVC_SUCCESS;
141  } else {
142  return ret;
143  }
144 }
145 
147  uint8_t mode_char = mode;
148  uvc_error_t ret;
149 
150  ret = libusb_control_transfer(
151  devh->usb_devh,
153  UVC_VC_VIDEO_POWER_MODE_CONTROL << 8,
154  0,
155  &mode_char,
156  sizeof(mode_char),
157  0);
158 
159  if (ret == 1)
160  return UVC_SUCCESS;
161  else
162  return ret;
163 }
164 
uvc_req_code
Definition: libuvc.h:152
uvc_error_t uvc_set_power_mode(uvc_device_handle_t *devh, enum uvc_device_power_mode mode)
Definition: ctrl.c:146
enum uvc_error uvc_error_t
int uvc_set_ctrl(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl, void *data, int len)
Perform a SET_CUR request to a terminal or unit.
Definition: ctrl.c:113
static const int REQ_TYPE_GET
Definition: ctrl.c:46
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:2479
uvc_device_power_mode
Definition: libuvc.h:164
GLenum GLsizei len
Definition: glext.h:3213
Implementation-specific UVC constants and structures.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
Definition: glext.h:223
uvc_error_t uvc_get_power_mode(uvc_device_handle_t *devh, enum uvc_device_power_mode *mode, enum uvc_req_code req_code)
Definition: ctrl.c:125
GLenum mode
Definition: glext.h:1117
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)
Perform a GET_* request from an extension unit.
Definition: ctrl.c:90
struct uvc_device_handle uvc_device_handle_t
Definition: libuvc.h:268
int uvc_get_ctrl_len(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl)
Get the length of a control on a terminal or unit.
Definition: ctrl.c:59
static const int REQ_TYPE_SET
Definition: ctrl.c:45


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:17