Skip to content

Commit 4696c80

Browse files
committed
Add notices about Kinect v2
Fixes #485 Signed-off-by: Benn Snyder <[email protected]>
1 parent 873a2cc commit 4696c80

File tree

5 files changed

+40
-27
lines changed

5 files changed

+40
-27
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ It runs on Linux, OSX, and Windows and supports
1010
- LED
1111
- Audio
1212

13+
Notice: If you have the newer Kinect v2 (XBox One), use [OpenKinect/libfreenect2](OpenKinect/libfreenect2) instead.
14+
1315

1416
# Build Instructions
1517

src/core.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ FREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_
4747

4848
memset(*ctx, 0, sizeof(freenect_context));
4949

50-
(*ctx)->log_level = LL_WARNING;
50+
(*ctx)->log_level = LL_NOTICE;
5151
(*ctx)->enabled_subdevices = (freenect_device_flags)(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA);
5252
res = fnusb_init(&(*ctx)->usb, usb_ctx);
5353
if (res < 0) {
@@ -101,12 +101,12 @@ FREENECTAPI int freenect_process_events_timeout(freenect_context *ctx, struct ti
101101

102102
FREENECTAPI int freenect_num_devices(freenect_context *ctx)
103103
{
104-
return fnusb_num_devices(&ctx->usb);
104+
return fnusb_num_devices(ctx);
105105
}
106106

107107
FREENECTAPI int freenect_list_device_attributes(freenect_context *ctx, struct freenect_device_attributes **attribute_list)
108108
{
109-
return fnusb_list_device_attributes(&ctx->usb, attribute_list);
109+
return fnusb_list_device_attributes(ctx, attribute_list);
110110
}
111111

112112
FREENECTAPI void freenect_free_device_attributes(struct freenect_device_attributes *attribute_list)
@@ -185,7 +185,7 @@ FREENECTAPI int freenect_open_device_by_camera_serial(freenect_context *ctx, fre
185185
// freenect_open_device with that index.
186186
struct freenect_device_attributes* attrlist;
187187
struct freenect_device_attributes* item;
188-
int count = fnusb_list_device_attributes(&ctx->usb, &attrlist);
188+
int count = fnusb_list_device_attributes(ctx, &attrlist);
189189
if (count < 0) {
190190
FN_ERROR("freenect_open_device_by_camera_serial: Couldn't enumerate serial numbers\n");
191191
return count;

src/freenect_internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static inline int32_t fn_le32s(int32_t s)
139139
#define PID_NUI_CAMERA 0x02ae
140140
#define PID_NUI_MOTOR 0x02b0
141141
#define PID_K4W_CAMERA 0x02bf
142+
#define PID_KV2_CAMERA 0x02d9 // This identifies the Kinect v2 (XBox One). Use https://github.com/OpenKinect/libfreenect2 instead.
142143

143144
// For K4W: first pid is what it starts out as,
144145
// second is how it appears with lastest firmware from SDK,

src/usb_libusb10.c

+31-21
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,39 @@
3737
#endif
3838

3939

40-
FN_INTERNAL int fnusb_num_devices(fnusb_ctx *ctx)
40+
FN_INTERNAL int fnusb_num_devices(freenect_context *ctx)
4141
{
42-
libusb_device **devs;
43-
//pointer to pointer of device, used to retrieve a list of devices
44-
ssize_t cnt = libusb_get_device_list (ctx->ctx, &devs);
45-
//get the list of devices
46-
if (cnt < 0)
47-
return (-1);
48-
int nr = 0, i = 0;
42+
libusb_device **devs; // pointer to pointer of device, used to retrieve a list of devices
43+
ssize_t count = libusb_get_device_list (ctx->usb.ctx, &devs);
44+
if (count < 0)
45+
return (count >= INT_MIN) ? (int)count : -1;
46+
47+
int number_found = 0, i = 0;
4948
struct libusb_device_descriptor desc;
50-
for (i = 0; i < cnt; ++i)
49+
for (i = 0; i < count; ++i)
5150
{
5251
int r = libusb_get_device_descriptor (devs[i], &desc);
5352
if (r < 0)
53+
{
54+
FN_WARNING("Failed to query USB device descriptor.\n");
5455
continue;
55-
if (desc.idVendor == VID_MICROSOFT && (desc.idProduct == PID_NUI_CAMERA || desc.idProduct == PID_K4W_CAMERA))
56-
nr++;
56+
}
57+
58+
if (desc.idVendor == VID_MICROSOFT)
59+
{
60+
if (desc.idProduct == PID_NUI_CAMERA || desc.idProduct == PID_K4W_CAMERA)
61+
{
62+
number_found++;
63+
}
64+
else if (desc.idProduct == PID_KV2_CAMERA)
65+
{
66+
FN_NOTICE("Skipping Kinect v2 device (needs https://github.com/libfreenect2).\n");
67+
}
68+
}
5769
}
70+
5871
libusb_free_device_list (devs, 1);
59-
// free the list, unref the devices in it
60-
return nr;
72+
return number_found;
6173
}
6274

6375
// Returns 1 if `pid` identifies K4W audio, 0 otherwise
@@ -107,16 +119,14 @@ FN_INTERNAL libusb_device * fnusb_find_connected_audio_device(libusb_device * ca
107119
return NULL;
108120
}
109121

110-
FN_INTERNAL int fnusb_list_device_attributes(fnusb_ctx *ctx, struct freenect_device_attributes** attribute_list)
122+
FN_INTERNAL int fnusb_list_device_attributes(freenect_context *ctx, struct freenect_device_attributes** attribute_list)
111123
{
112-
// todo: figure out how to log without freenect_context
113-
114124
*attribute_list = NULL; // initialize some return value in case the user is careless.
115125
libusb_device **devs; // pointer to pointer of device, used to retrieve a list of devices
116-
ssize_t count = libusb_get_device_list (ctx->ctx, &devs);
126+
ssize_t count = libusb_get_device_list (ctx->usb.ctx, &devs);
117127
if (count < 0)
118128
{
119-
return -1;
129+
return (count >= INT_MIN) ? (int)count : -1;
120130
}
121131

122132
struct freenect_device_attributes** next_attr = attribute_list;
@@ -173,23 +183,23 @@ FN_INTERNAL int fnusb_list_device_attributes(fnusb_ctx *ctx, struct freenect_dev
173183
res = libusb_get_device_descriptor(audio_device, &audio_desc);
174184
if (res != 0)
175185
{
176-
//FN_ERROR("Failed to get audio serial descriptors of K4W or 1473 device: %d\n", res);
186+
FN_WARNING("Failed to get audio serial descriptors of K4W or 1473 device: %d\n", res);
177187
}
178188
else
179189
{
180190
libusb_device_handle * audio_handle = NULL;
181191
res = libusb_open(audio_device, &audio_handle);
182192
if (res != 0)
183193
{
184-
//FN_ERROR("Failed to open audio device for serial of K4W or 1473 device: %d\n", res);
194+
FN_WARNING("Failed to open audio device for serial of K4W or 1473 device: %d\n", res);
185195
}
186196
else
187197
{
188198
res = libusb_get_string_descriptor_ascii(audio_handle, audio_desc.iSerialNumber, serial, 256);
189199
libusb_close(audio_handle);
190200
if (res != 0)
191201
{
192-
//FN_ERROR("Failed to get audio serial of K4W or 1473 device: %d\n", res);
202+
FN_WARNING("Failed to get audio serial of K4W or 1473 device: %d\n", res);
193203
}
194204
}
195205
}

src/usb_libusb10.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ typedef struct {
7474
int dead_xfers;
7575
} fnusb_isoc_stream;
7676

77-
int fnusb_num_devices(fnusb_ctx *ctx);
78-
int fnusb_list_device_attributes(fnusb_ctx *ctx, struct freenect_device_attributes** attribute_list);
77+
int fnusb_num_devices(freenect_context *ctx);
78+
int fnusb_list_device_attributes(freenect_context *ctx, struct freenect_device_attributes** attribute_list);
7979

8080
int fnusb_init(fnusb_ctx *ctx, freenect_usb_context *usb_ctx);
8181
int fnusb_shutdown(fnusb_ctx *ctx);

0 commit comments

Comments
 (0)