UVCCamera向USB设备发送命令

简介: UVCCamera向USB设备发送命令

改变亮度


JAVA

UVCCameraHelper.setModelValue()

UVCCameraHandler.setValue()

UVCCamera.setBrightness()

nativeSetBrightness()

nativeSetBrightness

static jint nativeSetBrightness(JNIEnv *env, jobject thiz,
  ID_TYPE id_camera, jint brightness) {
  jint result = JNI_ERR;
  ENTER();
  UVCCamera *camera = reinterpret_cast<UVCCamera *>(id_camera);
  if (LIKELY(camera)) {
  result = camera->setBrightness(brightness);
  }
  RETURN(result, jint);
}

setBrightness

int UVCCamera::setBrightness(int brightness) {
  ENTER();
  int ret = UVC_ERROR_IO;
  if (mPUSupports & PU_BRIGHTNESS) {
  ret = internalSetCtrlValue(mBrightness, brightness, uvc_get_brightness, uvc_set_brightness);
  }
  RETURN(ret, int);
}

uvc_set_brightness

uvc_error_t uvc_set_brightness(uvc_device_handle_t *devh, short brightness) {
  uint8_t data[2];
  uvc_error_t ret;
  SHORT_TO_SW(brightness, data);
  ret = libusb_control_transfer(devh->usb_devh, REQ_TYPE_SET, UVC_SET_CUR,
    UVC_PU_BRIGHTNESS_CONTROL << 8,
    devh->info->ctrl_if.processing_unit_descs->request,
    data, sizeof(data), CTRL_TIMEOUT_MILLIS);
  if (LIKELY(ret == sizeof(data)))
  return UVC_SUCCESS;
  else
  return ret;
}

libusb_control_transfer

int API_EXPORTED libusb_control_transfer(libusb_device_handle *dev_handle,
  uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
  unsigned char *data, uint16_t wLength, unsigned int timeout)
{
  struct libusb_transfer *transfer = libusb_alloc_transfer(0);
  unsigned char *buffer;
  int completed = 0;
  int r;
  if (UNLIKELY(!transfer))
  return LIBUSB_ERROR_NO_MEM;
  buffer = (unsigned char*) malloc(LIBUSB_CONTROL_SETUP_SIZE + wLength);
  if (UNLIKELY(!buffer)) {
  libusb_free_transfer(transfer);
  return LIBUSB_ERROR_NO_MEM;
  }
  libusb_fill_control_setup(buffer, bmRequestType, bRequest, wValue, wIndex, wLength);
  if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT)
  memcpy(buffer + LIBUSB_CONTROL_SETUP_SIZE, data, wLength);
  libusb_fill_control_transfer(transfer, dev_handle, buffer,
  sync_transfer_cb, &completed, timeout);
  transfer->flags = LIBUSB_TRANSFER_FREE_BUFFER;
  r = libusb_submit_transfer(transfer);
  if (UNLIKELY(r < 0)) {
  libusb_free_transfer(transfer);
  return r;
  }
  sync_transfer_wait_for_completion(transfer);
  if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
  memcpy(data, libusb_control_transfer_get_data(transfer),
    transfer->actual_length);
  libusb_free_transfer(transfer);
  return r;
}


libusb_submit_transfer

r = usbi_backend.submit_transfer(itransfer);

op_submit_transfer

LIBUSB_TRANSFER_TYPE_BULK = 2U

submit_bulk_transfer


submit_bulk_transfer

ioctl

目录
相关文章
|
11月前
|
存储 网络协议 数据安全/隐私保护
逆向USB设备共享:利用内网穿透让远程设备访问本地USB设备
逆向USB设备共享:利用内网穿透让远程设备访问本地USB设备
逆向USB设备共享:利用内网穿透让远程设备访问本地USB设备
|
Windows
USB 设备:自定义批量传输及实现
USB 设备:自定义批量传输及实现
1088 0
|
C#
C# 获得设备usb信息
原文:C# 获得设备usb信息 本文告诉大家如何获得设备的usb来进行判断是否有哪些usb和找不到usb可能是什么。 需要在项目右击引用,点击程序集,搜索 System.
1677 0