Skip to content

Commit 08737cd

Browse files
committed
Add missing interface number to USB Requests
1 parent 6ef3880 commit 08737cd

9 files changed

Lines changed: 53 additions & 39 deletions

CameraController/UVC/Extensions/IOUSBConfigurationDescriptorPtr+UVC.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@ extension IOUSBConfigurationDescriptorPtr {
1717
func proccessDescriptor() -> UVCDescriptor {
1818
var processingUnitID = 0
1919
var cameraTerminalID = 0
20+
var interfaceID = 0
2021

2122
let remaining = self.pointee.wTotalLength - UInt16(self.pointee.bLength)
2223
var pointer = UnsafeMutablePointer<UInt8>(OpaquePointer(self))
2324
pointer = pointer.advanced(by: Int(self.pointee.bLength))
2425

25-
browseDescriptor(remaining, pointer, &processingUnitID, &cameraTerminalID)
26+
browseDescriptor(remaining, pointer, &processingUnitID, &cameraTerminalID, &interfaceID)
2627

27-
return UVCDescriptor(processingUnitID: processingUnitID, cameraTerminalID: cameraTerminalID)
28+
return UVCDescriptor(processingUnitID: processingUnitID,
29+
cameraTerminalID: cameraTerminalID,
30+
interfaceID: interfaceID)
2831
}
2932

3033
fileprivate func browseDescriptor(_ memory: UInt16, _ pointer: UnsafeMutablePointer<UInt8>,
31-
_ processingUnitID: inout Int, _ cameraTerminalID: inout Int) {
34+
_ processingUnitID: inout Int, _ cameraTerminalID: inout Int,
35+
_ interfaceID: inout Int) {
3236
var remaining = memory
3337
var currentPointer = pointer
3438

@@ -41,7 +45,6 @@ extension IOUSBConfigurationDescriptorPtr {
4145
&& intDesc.pointee.bInterfaceSubClass == UVCConstants.subclassVideoControl) {
4246

4347
currentPointer = currentPointer.advanced(by: Int(intDesc.pointee.bLength))
44-
4548
continue
4649
}
4750

@@ -69,6 +72,7 @@ extension IOUSBConfigurationDescriptorPtr {
6972
}
7073

7174
getDeviceId(descriptorPointer, currentPointer, &processingUnitID, &cameraTerminalID)
75+
interfaceID = Int(intDesc.pointee.bInterfaceNumber)
7276

7377
remainingMemory -= UInt16(descriptorPointer.pointee.bLength)
7478
currentPointer = currentPointer.advanced(by: Int(descriptorPointer.pointee.bLength))

CameraController/UVC/Models/Controls/UVCBitmapControl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class UVCBitmapControl: UVCControl {
3232
var internalCurrent: BitmapValue = .manual
3333

3434
override init(_ interface: USBInterfacePointer, _ uvcSize: Int,
35-
_ uvcSelector: Selector, _ uvcUnit: Int) {
36-
super.init(interface, uvcSize, uvcSelector, uvcUnit)
35+
_ uvcSelector: Selector, _ uvcUnit: Int, _ uvcInterface: Int) {
36+
super.init(interface, uvcSize, uvcSelector, uvcUnit, uvcInterface)
3737
configure()
3838
}
3939

CameraController/UVC/Models/Controls/UVCBoolControl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class UVCBoolControl: UVCControl {
2626
private var _isEnabled = false
2727

2828
override init(_ interface: USBInterfacePointer, _ uvcSize: Int,
29-
_ uvcSelector: Selector, _ uvcUnit: Int) {
30-
super.init(interface, uvcSize, uvcSelector, uvcUnit)
29+
_ uvcSelector: Selector, _ uvcUnit: Int, _ uvcInterface: Int) {
30+
super.init(interface, uvcSize, uvcSelector, uvcUnit, uvcInterface)
3131
configure()
3232
}
3333

CameraController/UVC/Models/Controls/UVCControl.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ class UVCControl {
1717
let uvcSize: Int
1818
let uvcSelector: Int
1919
let uvcUnit: Int
20+
let uvcInterface: Int
2021

2122
var isCapable: Bool = false
2223

23-
init(_ interface: USBInterfacePointer, _ uvcSize: Int, _ uvcSelector: Selector, _ uvcUnit: Int) {
24+
init(_ interface: USBInterfacePointer, _ uvcSize: Int, _ uvcSelector: Selector,
25+
_ uvcUnit: Int, _ uvcInterface: Int) {
2426
self.interface = interface
2527
self.uvcSize = uvcSize
2628
self.uvcSelector = uvcSelector.raw()
2729
self.uvcUnit = uvcUnit
30+
self.uvcInterface = uvcInterface
2831
}
2932

3033
func getDataFor(type: UVCRequestCodes, length: Int) -> Int {
@@ -35,7 +38,7 @@ class UVCControl {
3538
var request: IOUSBDevRequest = IOUSBDevRequest(bmRequestType: requestType,
3639
bRequest: UInt8(type.rawValue),
3740
wValue: UInt16(uvcSelector<<8),
38-
wIndex: UInt16(uvcUnit<<8),
41+
wIndex: UInt16(uvcUnit<<8) | UInt16(uvcInterface),
3942
wLength: UInt16(length),
4043
pData: &value,
4144
wLenDone: 0)
@@ -57,7 +60,7 @@ class UVCControl {
5760
var request: IOUSBDevRequest = IOUSBDevRequest(bmRequestType: requestType,
5861
bRequest: UInt8(UVCRequestCodes.setCurrent.rawValue),
5962
wValue: UInt16(uvcSelector<<8),
60-
wIndex: UInt16(uvcUnit<<8),
63+
wIndex: UInt16(uvcUnit<<8) | UInt16(uvcInterface),
6164
wLength: UInt16(length),
6265
pData: &ref,
6366
wLenDone: 0)

CameraController/UVC/Models/Controls/UVCIntControl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class UVCIntControl: UVCControl {
2828
private var _current: Int = 0
2929

3030
override init(_ interface: USBInterfacePointer, _ uvcSize: Int,
31-
_ uvcSelector: Selector, _ uvcUnit: Int) {
32-
super.init(interface, uvcSize, uvcSelector, uvcUnit)
31+
_ uvcSelector: Selector, _ uvcUnit: Int, _ uvcInterface: Int) {
32+
super.init(interface, uvcSize, uvcSelector, uvcUnit, uvcInterface)
3333
configure()
3434
}
3535

CameraController/UVC/Models/Controls/UVCMultipleIntControl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class UVCMultipleIntControl: UVCControl {
4444
private var _current2: Int = 0
4545

4646
override init(_ interface: USBInterfacePointer, _ uvcSize: Int,
47-
_ uvcSelector: Selector, _ uvcUnit: Int) {
48-
super.init(interface, uvcSize, uvcSelector, uvcUnit)
47+
_ uvcSelector: Selector, _ uvcUnit: Int, _ uvcInterface: Int) {
48+
super.init(interface, uvcSize, uvcSelector, uvcUnit, uvcInterface)
4949
configure()
5050
}
5151

CameraController/UVC/Models/USBHeaders.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct UVC_InterfaceDescriptorHdr {
1212
uint8_t bLength;
1313
uint8_t bDescriptorType;
1414
uint8_t bDescriptorSubType;
15-
} __attribute__((packed));;
15+
} __attribute__((packed));
1616

1717
struct UVC_VCHeaderDescriptor {
1818
uint8_t bLength;

CameraController/UVC/Models/UVCDescriptor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ import Foundation
1111
struct UVCDescriptor {
1212
let processingUnitID: Int
1313
let cameraTerminalID: Int
14+
let interfaceID: Int
1415
}

CameraController/UVC/Models/UVCDeviceProperties.swift

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,36 @@ class UVCDeviceProperties {
3838
let interface = device.interface
3939
let camerTerminalId = device.descriptor.cameraTerminalID
4040
let processingUnitId = device.descriptor.processingUnitID
41+
let interfaceId = device.descriptor.interfaceID
4142

42-
scanningMode = UVCBoolControl(interface, 1, UVCCameraTerminal.scanningMode, camerTerminalId)
43-
exposureMode = UVCBitmapControl(interface, 1, UVCCameraTerminal.aeMode, camerTerminalId)
44-
exposurePriority = UVCIntControl(interface, 1, UVCCameraTerminal.aePriority, camerTerminalId)
45-
exposureTime = UVCIntControl(interface, 4, UVCCameraTerminal.exposureTimeAbsolute, camerTerminalId)
46-
focusAbsolute = UVCIntControl(interface, 2, UVCCameraTerminal.focusAbsolute, camerTerminalId)
47-
focusAuto = UVCBoolControl(interface, 1, UVCCameraTerminal.focusAuto, camerTerminalId)
48-
irisAbsolute = UVCIntControl(interface, 2, UVCCameraTerminal.irisAbsolute, camerTerminalId)
49-
zoomAbsolute = UVCIntControl(interface, 2, UVCCameraTerminal.zoomAbsolute, camerTerminalId)
50-
panTiltAbsolute = UVCMultipleIntControl(interface, 8, UVCCameraTerminal.pantiltAbsolute, camerTerminalId)
51-
rollAbsolute = UVCIntControl(interface, 2, UVCCameraTerminal.rollAbsolute, camerTerminalId)
43+
scanningMode = UVCBoolControl(interface, 1, UVCCameraTerminal.scanningMode, camerTerminalId, interfaceId)
44+
exposureMode = UVCBitmapControl(interface, 1, UVCCameraTerminal.aeMode, camerTerminalId, interfaceId)
45+
exposurePriority = UVCIntControl(interface, 1, UVCCameraTerminal.aePriority, camerTerminalId, interfaceId)
46+
exposureTime = UVCIntControl(interface, 4, UVCCameraTerminal.exposureTimeAbsolute, camerTerminalId, interfaceId)
47+
focusAbsolute = UVCIntControl(interface, 2, UVCCameraTerminal.focusAbsolute, camerTerminalId, interfaceId)
48+
focusAuto = UVCBoolControl(interface, 1, UVCCameraTerminal.focusAuto, camerTerminalId, interfaceId)
49+
irisAbsolute = UVCIntControl(interface, 2, UVCCameraTerminal.irisAbsolute, camerTerminalId, interfaceId)
50+
zoomAbsolute = UVCIntControl(interface, 2, UVCCameraTerminal.zoomAbsolute, camerTerminalId, interfaceId)
51+
panTiltAbsolute = UVCMultipleIntControl(interface, 8, UVCCameraTerminal.pantiltAbsolute,
52+
camerTerminalId, interfaceId)
53+
rollAbsolute = UVCIntControl(interface, 2, UVCCameraTerminal.rollAbsolute, camerTerminalId, interfaceId)
5254

53-
backlightCompensation = UVCIntControl(interface, 2, UVCProcessingUnit.backlightCompensation, processingUnitId)
54-
brightness = UVCIntControl(interface, 2, UVCProcessingUnit.brightness, processingUnitId)
55-
contrast = UVCIntControl(interface, 2, UVCProcessingUnit.contrast, processingUnitId)
56-
contrastAuto = UVCBoolControl(interface, 1, UVCProcessingUnit.contrastAuto, processingUnitId)
57-
gain = UVCIntControl(interface, 2, UVCProcessingUnit.gain, processingUnitId)
58-
powerLineFrequency = UVCIntControl(interface, 2, UVCProcessingUnit.powerLineFrequency, processingUnitId)
59-
hue = UVCIntControl(interface, 2, UVCProcessingUnit.hue, processingUnitId)
60-
hueAuto = UVCBoolControl(interface, 1, UVCProcessingUnit.hueAuto, processingUnitId)
61-
saturation = UVCIntControl(interface, 2, UVCProcessingUnit.saturation, processingUnitId)
62-
sharpness = UVCIntControl(interface, 2, UVCProcessingUnit.sharpness, processingUnitId)
63-
gamma = UVCIntControl(interface, 2, UVCProcessingUnit.gamma, processingUnitId)
64-
whiteBalance = UVCIntControl(interface, 2, UVCProcessingUnit.whiteBalanceTemperature, processingUnitId)
65-
whiteBalanceAuto = UVCBoolControl(interface, 1, UVCProcessingUnit.whiteBalanceTemperatureAuto, processingUnitId)
55+
backlightCompensation = UVCIntControl(interface, 2, UVCProcessingUnit.backlightCompensation,
56+
processingUnitId, interfaceId)
57+
brightness = UVCIntControl(interface, 2, UVCProcessingUnit.brightness, processingUnitId, interfaceId)
58+
contrast = UVCIntControl(interface, 2, UVCProcessingUnit.contrast, processingUnitId, interfaceId)
59+
contrastAuto = UVCBoolControl(interface, 1, UVCProcessingUnit.contrastAuto, processingUnitId, interfaceId)
60+
gain = UVCIntControl(interface, 2, UVCProcessingUnit.gain, processingUnitId, interfaceId)
61+
powerLineFrequency = UVCIntControl(interface, 2, UVCProcessingUnit.powerLineFrequency,
62+
processingUnitId, interfaceId)
63+
hue = UVCIntControl(interface, 2, UVCProcessingUnit.hue, processingUnitId, interfaceId)
64+
hueAuto = UVCBoolControl(interface, 1, UVCProcessingUnit.hueAuto, processingUnitId, interfaceId)
65+
saturation = UVCIntControl(interface, 2, UVCProcessingUnit.saturation, processingUnitId, interfaceId)
66+
sharpness = UVCIntControl(interface, 2, UVCProcessingUnit.sharpness, processingUnitId, interfaceId)
67+
gamma = UVCIntControl(interface, 2, UVCProcessingUnit.gamma, processingUnitId, interfaceId)
68+
whiteBalance = UVCIntControl(interface, 2, UVCProcessingUnit.whiteBalanceTemperature,
69+
processingUnitId, interfaceId)
70+
whiteBalanceAuto = UVCBoolControl(interface, 1, UVCProcessingUnit.whiteBalanceTemperatureAuto,
71+
processingUnitId, interfaceId)
6672
}
6773
}

0 commit comments

Comments
 (0)