@@ -47,7 +47,7 @@ FN_INTERNAL int fnusb_num_devices(fnusb_ctx *ctx)
4747 int r = libusb_get_device_descriptor (devs [i ], & desc );
4848 if (r < 0 )
4949 continue ;
50- if (desc .idVendor == VID_MICROSOFT && desc .idProduct == PID_NUI_CAMERA )
50+ if (desc .idVendor == VID_MICROSOFT && ( desc .idProduct == PID_NUI_CAMERA || desc . idProduct == PID_K4W_CAMERA ) )
5151 nr ++ ;
5252 }
5353 libusb_free_device_list (devs , 1 );
@@ -76,7 +76,7 @@ FN_INTERNAL int fnusb_list_device_attributes(fnusb_ctx *ctx, struct freenect_dev
7676 int r = libusb_get_device_descriptor (devs [i ], & desc );
7777 if (r < 0 )
7878 continue ;
79- if (desc .idVendor == VID_MICROSOFT && desc .idProduct == PID_NUI_CAMERA ) {
79+ if (desc .idVendor == VID_MICROSOFT && ( desc .idProduct == PID_NUI_CAMERA || desc . idProduct == PID_K4W_CAMERA ) ) {
8080 // Verify that a serial number exists to query. If not, don't touch the device.
8181 if (desc .iSerialNumber == 0 ) {
8282 continue ;
@@ -188,9 +188,9 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
188188
189189 if (desc .idVendor != VID_MICROSOFT )
190190 continue ;
191-
191+ res = 0 ;
192192 // Search for the camera
193- if ((ctx -> enabled_subdevices & FREENECT_DEVICE_CAMERA ) && !dev -> usb_cam .dev && desc .idProduct == PID_NUI_CAMERA ) {
193+ if ((ctx -> enabled_subdevices & FREENECT_DEVICE_CAMERA ) && !dev -> usb_cam .dev && ( desc .idProduct == PID_NUI_CAMERA || desc . idProduct == PID_K4W_CAMERA ) ) {
194194 // If the index given by the user matches our camera index
195195 if (nr_cam == index ) {
196196 res = libusb_open (devs [i ], & dev -> usb_cam .dev );
@@ -199,6 +199,15 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
199199 dev -> usb_cam .dev = NULL ;
200200 break ;
201201 }
202+ if (desc .idProduct == PID_K4W_CAMERA || desc .bcdDevice != fn_le32 (267 )){
203+ /* Not the old kinect so we only set up the camera*/
204+ ctx -> enabled_subdevices = FREENECT_DEVICE_CAMERA ;
205+ ctx -> zero_plane_res = 334 ;
206+ }else {
207+ /* The good old kinect that tilts and tweets */
208+ ctx -> zero_plane_res = 322 ;
209+ }
210+
202211#ifndef _WIN32
203212 // Detach an existing kernel driver for the device
204213 res = libusb_kernel_driver_active (dev -> usb_cam .dev , 0 );
@@ -219,12 +228,33 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
219228 dev -> usb_cam .dev = NULL ;
220229 break ;
221230 }
231+ if (desc .idProduct == PID_K4W_CAMERA ){
232+ res = libusb_set_interface_alt_setting (dev -> usb_cam .dev , 0 , 1 );
233+ if (res != 0 ) {
234+ FN_ERROR ("Failed to set alternate interface #1 for K4W: %d\n" , res );
235+ libusb_close (dev -> usb_cam .dev );
236+ dev -> usb_cam .dev = NULL ;
237+ break ;
238+ }
239+
240+ }
222241 } else {
223242 nr_cam ++ ;
224243 }
225244 }
226-
245+ }
246+
247+ if (ctx -> enabled_subdevices == FREENECT_DEVICE_CAMERA || res < 0 ) cnt = 0 ;
248+
227249 // Search for the motor
250+
251+ for (i = 0 ; i < cnt ; i ++ ) {
252+ int r = libusb_get_device_descriptor (devs [i ], & desc );
253+ if (r < 0 )
254+ continue ;
255+
256+ if (desc .idVendor != VID_MICROSOFT )
257+ continue ;
228258 if ((ctx -> enabled_subdevices & FREENECT_DEVICE_MOTOR ) && !dev -> usb_motor .dev && desc .idProduct == PID_NUI_MOTOR ) {
229259 // If the index given by the user matches our camera index
230260 if (nr_mot == index ) {
@@ -249,7 +279,7 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
249279#ifdef BUILD_AUDIO
250280 // TODO: check that the firmware has already been loaded; if not, upload firmware.
251281 // Search for the audio
252- if ((ctx -> enabled_subdevices & FREENECT_DEVICE_AUDIO ) && !dev -> usb_audio .dev && desc .idProduct == PID_NUI_AUDIO ) {
282+ if ((ctx -> enabled_subdevices & FREENECT_DEVICE_AUDIO ) && !dev -> usb_audio .dev && ( desc .idProduct == PID_NUI_AUDIO || desc . idProduct == PID_K4W_AUDIO ) ) {
253283 // If the index given by the user matches our audio index
254284 if (nr_audio == index ) {
255285 res = libusb_open (devs [i ], & dev -> usb_audio .dev );
0 commit comments