Skip to content

Commit

Permalink
Target control transfer to device
Browse files Browse the repository at this point in the history
- Currently, each `controlTransfer` by setting `bmRequestType` targets
the camera _interface_ rather than _device_.
- Using an interface would require claiming it, which is not performed.
- Claiming an interface would kill access for any other process
which may be using the camera (including the kernel?).
- This commit targets `controlTransfer` to the _device_ instead.
- There might be better ways to transfer control commands.

See

- makenai#58
- joelpurra/uvcc#2
  • Loading branch information
joelpurra committed Oct 10, 2019
1 parent fcc0e90 commit 4ad8a62
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
var usb = require('usb');

var LIBUSB_CONTROL_TRANSFER_UVC_GET = usb.LIBUSB_REQUEST_TYPE_CLASS | usb.LIBUSB_RECIPIENT_DEVICE | usb.LIBUSB_ENDPOINT_IN;
var LIBUSB_CONTROL_TRANSFER_UVC_SET = usb.LIBUSB_REQUEST_TYPE_CLASS | usb.LIBUSB_RECIPIENT_DEVICE | usb.LIBUSB_ENDPOINT_OUT;

var UVC_SET_CUR = 0x01;
var UVC_GET_CUR = 0x81;
var UVC_GET_MIN = 0x82;
Expand Down Expand Up @@ -170,7 +173,7 @@ UVCControl.prototype.close = function() {
UVCControl.prototype.get = function(id, callback) {
this.getControlParams(id, function(error, params) {
if (error) return callback(error);
this.device.controlTransfer(0b10100001, UVC_GET_CUR, params.wValue, params.wIndex, params.wLength, function(error,buffer) {
this.device.controlTransfer(LIBUSB_CONTROL_TRANSFER_UVC_GET, UVC_GET_CUR, params.wValue, params.wIndex, params.wLength, function(error,buffer) {
if (error) return callback(error);
callback(null, buffer.readIntLE(0,params.wLength));
});
Expand All @@ -188,7 +191,7 @@ UVCControl.prototype.set = function(id, value, callback) {
if (error) return callback(error);
var data = new Buffer(params.wLength);
data.writeIntLE(value, 0, params.wLength);
this.device.controlTransfer(0b00100001, UVC_SET_CUR, params.wValue, params.wIndex, data, callback);
this.device.controlTransfer(LIBUSB_CONTROL_TRANSFER_UVC_SET, UVC_SET_CUR, params.wValue, params.wIndex, data, callback);
}.bind(this));
}

Expand All @@ -201,7 +204,7 @@ UVCControl.prototype.set = function(id, value, callback) {
UVCControl.prototype.setRaw = function(id, value, callback) {
this.getControlParams(id, function(error, params) {
if (error) return callback(error);
this.device.controlTransfer(0b00100001, UVC_SET_CUR, params.wValue, params.wIndex, value, callback);
this.device.controlTransfer(LIBUSB_CONTROL_TRANSFER_UVC_SET, UVC_SET_CUR, params.wValue, params.wIndex, value, callback);
}.bind(this));
}

Expand All @@ -213,9 +216,9 @@ UVCControl.prototype.setRaw = function(id, value, callback) {
UVCControl.prototype.range = function(id, callback) {
this.getControlParams(id, function(error, params) {
if (error) return callback(error);
this.device.controlTransfer(0b10100001, UVC_GET_MIN, params.wValue, params.wIndex, params.wLength, function(error,min) {
this.device.controlTransfer(LIBUSB_CONTROL_TRANSFER_UVC_GET, UVC_GET_MIN, params.wValue, params.wIndex, params.wLength, function(error,min) {
if (error) return callback(error);
this.device.controlTransfer(0b10100001, UVC_GET_MAX, params.wValue, params.wIndex, params.wLength, function(error,max) {
this.device.controlTransfer(LIBUSB_CONTROL_TRANSFER_UVC_GET, UVC_GET_MAX, params.wValue, params.wIndex, params.wLength, function(error,max) {
if (error) return callback(error);
callback(null,[min.readIntLE(0,params.wLength), max.readIntLE(0,params.wLength)]);
}.bind(this));
Expand Down

0 comments on commit 4ad8a62

Please sign in to comment.