|
37 | 37 | #endif |
38 | 38 |
|
39 | 39 |
|
40 | | -FN_INTERNAL int fnusb_num_devices(fnusb_ctx *ctx) |
| 40 | +FN_INTERNAL int fnusb_num_devices(freenect_context *ctx) |
41 | 41 | { |
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; |
49 | 48 | struct libusb_device_descriptor desc; |
50 | | - for (i = 0; i < cnt; ++i) |
| 49 | + for (i = 0; i < count; ++i) |
51 | 50 | { |
52 | 51 | int r = libusb_get_device_descriptor (devs[i], &desc); |
53 | 52 | if (r < 0) |
| 53 | + { |
| 54 | + FN_WARNING("Failed to query USB device descriptor.\n"); |
54 | 55 | 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 | + } |
57 | 69 | } |
| 70 | + |
58 | 71 | libusb_free_device_list (devs, 1); |
59 | | - // free the list, unref the devices in it |
60 | | - return nr; |
| 72 | + return number_found; |
61 | 73 | } |
62 | 74 |
|
63 | 75 | // 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 |
107 | 119 | return NULL; |
108 | 120 | } |
109 | 121 |
|
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) |
111 | 123 | { |
112 | | - // todo: figure out how to log without freenect_context |
113 | | - |
114 | 124 | *attribute_list = NULL; // initialize some return value in case the user is careless. |
115 | 125 | 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); |
117 | 127 | if (count < 0) |
118 | 128 | { |
119 | | - return -1; |
| 129 | + return (count >= INT_MIN) ? (int)count : -1; |
120 | 130 | } |
121 | 131 |
|
122 | 132 | 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 |
173 | 183 | res = libusb_get_device_descriptor(audio_device, &audio_desc); |
174 | 184 | if (res != 0) |
175 | 185 | { |
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); |
177 | 187 | } |
178 | 188 | else |
179 | 189 | { |
180 | 190 | libusb_device_handle * audio_handle = NULL; |
181 | 191 | res = libusb_open(audio_device, &audio_handle); |
182 | 192 | if (res != 0) |
183 | 193 | { |
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); |
185 | 195 | } |
186 | 196 | else |
187 | 197 | { |
188 | 198 | res = libusb_get_string_descriptor_ascii(audio_handle, audio_desc.iSerialNumber, serial, 256); |
189 | 199 | libusb_close(audio_handle); |
190 | 200 | if (res != 0) |
191 | 201 | { |
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); |
193 | 203 | } |
194 | 204 | } |
195 | 205 | } |
|
0 commit comments