Skip to content

Commit 541326f

Browse files
committed
For Kinects with 0000000000000000 Serial No - use Audio Serial as a
fallback -- implemented, fixes OpenKinect#360
1 parent 9b671cd commit 541326f

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/usb_libusb10.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,43 @@ FN_INTERNAL int fnusb_list_device_attributes(fnusb_ctx *ctx, struct freenect_dev
110110

111111
*camera_prev_next = new_dev_attrs;
112112
// Copy string with serial number
113-
new_dev_attrs->camera_serial = strdup((char*)string_desc);
113+
if (strncmp((const char*)string_desc, K4W_AND_1473_SERIAL_NO, 16) == 0){
114+
printf("\n k4w detected\n");
115+
int j;
116+
struct libusb_device_descriptor audio_desc;
117+
for (j=0; j< count; j++) {
118+
int result = libusb_get_device_descriptor (devs[j], &audio_desc);
119+
if (result < 0)
120+
continue;
121+
122+
if (audio_desc.idVendor == VID_MICROSOFT && audio_desc.idProduct == PID_K4W_AUDIO) {
123+
// Verify that a serial number exists to query. If not, don't touch the device.
124+
if (audio_desc.iSerialNumber == 0) {
125+
continue;
126+
}
127+
int audio_bus_num = libusb_get_bus_number(libusb_get_parent(devs[j]));
128+
int audio_port_num = libusb_get_port_number(libusb_get_parent(devs[j]));
129+
if (libusb_get_bus_number(libusb_get_parent(devs[i])) == audio_bus_num &&
130+
libusb_get_port_number(libusb_get_parent(devs[i])) == audio_port_num &&
131+
audio_bus_num != 0 && audio_port_num != 0) {
132+
int result_audio;
133+
libusb_device_handle *this_audio_device;
134+
result_audio = libusb_open(devs[j], &this_audio_device);
135+
if (result_audio != 0) {
136+
continue;
137+
}
138+
result_audio = libusb_get_string_descriptor_ascii(this_device, audio_desc.iSerialNumber, string_desc, 256);
139+
if (result_audio < 0) {
140+
continue;
141+
}
142+
libusb_close(this_audio_device);
143+
}
144+
}
145+
}
146+
new_dev_attrs->camera_serial = strdup((char*)string_desc);
147+
} else {
148+
new_dev_attrs->camera_serial = strdup((char*)string_desc);
149+
}
114150
camera_prev_next = &(new_dev_attrs->next);
115151
// Increment number of cameras found
116152
num_cams++;

src/usb_libusb10.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
#define VIDEO_PKTBUF 1920
6161
#endif
6262

63+
#define K4W_AND_1473_SERIAL_NO "0000000000000000"
64+
6365
typedef struct {
6466
libusb_context *ctx;
6567
int should_free_ctx;

0 commit comments

Comments
 (0)