Skip to content

Commit

Permalink
changed audio and motor matching to be based on the camera parent hub…
Browse files Browse the repository at this point in the history
…. this results in more reliable uploading of audio firmware when there are multiple devices.

Signed-off-by: ofTheo <theo@openframeworks.cc>
  • Loading branch information
ofTheo authored and piedar committed Aug 26, 2016
1 parent 9994f58 commit e7ddd36
Showing 1 changed file with 60 additions and 25 deletions.
85 changes: 60 additions & 25 deletions src/usb_libusb10.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
if (cnt < 0)
return -1;

int i = 0, nr_cam = 0, nr_mot = 0;
int nr_audio = 0;
int i = 0, nr_cam = 0;

int res;
struct libusb_device_descriptor desc;

Expand Down Expand Up @@ -424,19 +424,32 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
if (ctx->enabled_subdevices == FREENECT_DEVICE_CAMERA || res < 0)
cnt = 0;

// Search for the motor
for (i = 0; i < cnt; i++)
{
//FIND MOTOR BASED ON PARENT HUB
if( (ctx->enabled_subdevices & FREENECT_DEVICE_MOTOR) && dev->usb_cam.dev != NULL )
{

libusb_device * camera = libusb_get_device( dev->usb_cam.dev );
libusb_device * cameraParent = libusb_get_parent( camera );

if( cameraParent != NULL )
{

for(i = 0; i < cnt; i++)
{

// Match audio based on camera parent
if( cameraParent == libusb_get_parent(devs[i]) )
{

int r = libusb_get_device_descriptor (devs[i], &desc);
if (r < 0)
continue;

if (desc.idVendor != VID_MICROSOFT)
continue;
if ((ctx->enabled_subdevices & FREENECT_DEVICE_MOTOR) && !dev->usb_motor.dev && desc.idProduct == PID_NUI_MOTOR)
{
// If the index given by the user matches our camera index
if (nr_mot == index)

// This has to be the device we are looking for as it is a Kinect motor device with the same parent as the camera
if ( !dev->usb_motor.dev && desc.idProduct == PID_NUI_MOTOR)
{
dev->usb_motor.VID = desc.idVendor;
dev->usb_motor.PID = desc.idProduct;
Expand All @@ -456,18 +469,39 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
dev->usb_motor.dev = NULL;
break;
}
}
else
{
nr_mot++;
}
}

// Search for the audio
if ((ctx->enabled_subdevices & FREENECT_DEVICE_AUDIO) && !dev->usb_audio.dev && (desc.idProduct == PID_NUI_AUDIO || fnusb_is_pid_k4w_audio(desc.idProduct)))
{
// If the index given by the user matches our audio index
if (nr_audio == index)

// This has to be the device we need, as it is matched by parent - so don't try any others
break;
}
}
}
}
}

// FIND AUDIO BASED ON PARENT HUB
if( (ctx->enabled_subdevices & FREENECT_DEVICE_AUDIO) && dev->usb_cam.dev != NULL )
{

libusb_device * camera = libusb_get_device( dev->usb_cam.dev );
libusb_device * cameraParent = libusb_get_parent( camera );

if( cameraParent != NULL )
{

for(i = 0; i < cnt; i++)
{
// Match audio based on camera parent
if( cameraParent == libusb_get_parent(devs[i]) )
{
int r = libusb_get_device_descriptor (devs[i], &desc);
if (r < 0)
continue;

if (desc.idVendor != VID_MICROSOFT)
continue;

// This has to be the device we are looking for as it is a Kinect audio device with the same parent as the camera
if ( !dev->usb_audio.dev && (desc.idProduct == PID_NUI_AUDIO || fnusb_is_pid_k4w_audio(desc.idProduct)))
{
dev->usb_audio.VID = desc.idVendor;
dev->usb_audio.PID = desc.idProduct;
Expand Down Expand Up @@ -625,10 +659,11 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
}
free(audio_serial);
}
}
else
{
nr_audio++;

// This has to be the device we need, as it is matched by parent - so don't try any others
break;
}
}
}
}
}
Expand Down

0 comments on commit e7ddd36

Please sign in to comment.