Skip to content

Commit 3f705d5

Browse files
ofTheopiedar
authored andcommitted
Use non-infinite timeouts for bulk tilt / led commands
Reset the audio device before using it to ensure the commands can be sent correctly Fixes #390 Signed-off-by: Benn Snyder <benn.snyder@gmail.com>
1 parent a35642f commit 3f705d5

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/tilt.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int get_reply(libusb_device_handle* dev, freenect_context *ctx){
6262
memset(buffer, 0, 512);
6363
int transferred = 0;
6464
int res = 0;
65-
res = libusb_bulk_transfer(dev, 0x81, buffer, 512, &transferred, 0);
65+
res = libusb_bulk_transfer(dev, 0x81, buffer, 512, &transferred, 100);
6666
if (res != 0) {
6767
FN_ERROR("get_reply(): libusb_bulk_transfer failed: %d (transferred = %d)\n", res, transferred);
6868
} else if (transferred != 12) {
@@ -112,12 +112,12 @@ int update_tilt_state_alt(freenect_device *dev){
112112
unsigned char buffer[256];
113113
memcpy(buffer, &cmd, 16);
114114

115-
res = libusb_bulk_transfer(dev->usb_audio.dev, 0x01, buffer, 16, &transferred, 0);
115+
res = libusb_bulk_transfer(dev->usb_audio.dev, 0x01, buffer, 16, &transferred, 250);
116116
if (res != 0) {
117117
return res;
118118
}
119119

120-
res = libusb_bulk_transfer(dev->usb_audio.dev, 0x81, buffer, 256, &transferred, 0); // 104 bytes
120+
res = libusb_bulk_transfer(dev->usb_audio.dev, 0x81, buffer, 256, &transferred, 250); // 104 bytes
121121
if (res != 0) {
122122
return res;
123123
} else {
@@ -209,7 +209,7 @@ int freenect_set_tilt_degs_alt(freenect_device *dev, int tilt_degrees)
209209
unsigned char buffer[20];
210210
memcpy(buffer, &cmd, 20);
211211

212-
res = libusb_bulk_transfer(dev->usb_audio.dev, 0x01, buffer, 20, &transferred, 0);
212+
res = libusb_bulk_transfer(dev->usb_audio.dev, 0x01, buffer, 20, &transferred, 250);
213213
if (res != 0) {
214214
FN_ERROR("freenect_set_tilt_alt(): libusb_bulk_transfer failed: %d (transferred = %d)\n", res, transferred);
215215
return res;
@@ -281,7 +281,7 @@ FN_INTERNAL int fnusb_set_led_alt(libusb_device_handle * dev, freenect_context *
281281
unsigned char buffer[20];
282282
memcpy(buffer, &cmd, 20);
283283

284-
res = libusb_bulk_transfer(dev, 0x01, buffer, 20, &transferred, 0);
284+
res = libusb_bulk_transfer(dev, 0x01, buffer, 20, &transferred, 100);
285285
if (res != 0) {
286286
FN_WARNING("fnusb_set_led_alt(): libusb_bulk_transfer failed: %d (transferred = %d)\n", res, transferred);
287287
return res;

src/usb_libusb10.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
277277
if( res != 0 ){
278278
FN_ERROR("Failed to set the LED of K4W or 1473 device: %d\n", res);
279279
}else{
280+
281+
//we need to do this as it is possible that the device was not closed properly in a previous session
282+
//if we don't do this and the device wasn't closed properly - it can cause infinite hangs on LED and TILT functions
283+
libusb_reset_device(audioHandle);
284+
libusb_close(audioHandle);
285+
286+
res = libusb_open(audioDevice, &audioHandle);
287+
if( res == 0 ){
280288
res = libusb_claim_interface(audioHandle, 0);
281289
if( res != 0 ){
282290
FN_ERROR("Unable to claim interface %d\n", res);
@@ -287,6 +295,7 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
287295
libusb_close(audioHandle);
288296
}
289297
}
298+
}
290299
#else
291300
//Legacy: For older versions of libusb we use this approach which doesn't do well when multiple K4W or 1473 devices are attached to the system.
292301
//lets also set the LED ON

0 commit comments

Comments
 (0)