Skip to content

Commit 234c24a

Browse files
author
Matlo
committed
[G29 emulation] Force feedback doesn't work on Raspbian Jessie #353
1 parent c6629d2 commit 234c24a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

shared/async/src/linux/usbhidasync.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#define USBHIDASYNC_MAX_DEVICES 256
1515

16+
#define USBHIDASYNC_OUT_TIMEOUT 20 // ms
17+
1618
typedef struct {
1719
int configuration;
1820
struct {
@@ -65,8 +67,6 @@ static void print_error_libusb(const char * file, int line, const char * func, c
6567

6668
static libusb_context* ctx = NULL;
6769

68-
#define REPORTS_MAX 2
69-
7070
static struct libusb_transfer ** transfers = NULL;
7171
static unsigned int transfers_nb = 0;
7272

@@ -240,7 +240,10 @@ static void usb_callback(struct libusb_transfer* transfer) {
240240
int device = (unsigned long) transfer->user_data;
241241

242242
//make sure the device still exists, in case something went wrong
243-
USBHIDASYNC_CHECK_DEVICE(device,/* void */)
243+
if(usbhidasync_check_device(device, __FILE__, __LINE__, __func__) < 0) {
244+
remove_transfer(transfer);
245+
return;
246+
}
244247

245248
if (transfer->type == LIBUSB_TRANSFER_TYPE_INTERRUPT) {
246249
if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
@@ -251,7 +254,11 @@ static void usb_callback(struct libusb_transfer* transfer) {
251254
usbdevices[device].callback.fp_write(usbdevices[device].callback.user);
252255
}
253256
} else {
254-
if (transfer->status != LIBUSB_TRANSFER_TIMED_OUT && transfer->status != LIBUSB_TRANSFER_CANCELLED) {
257+
if (transfer->endpoint == usbdevices[device].config.endpoints.out.address) {
258+
usbdevices[device].callback.fp_write(usbdevices[device].callback.user);
259+
}
260+
if (transfer->endpoint == usbdevices[device].config.endpoints.out.address
261+
|| (transfer->status != LIBUSB_TRANSFER_TIMED_OUT && transfer->status != LIBUSB_TRANSFER_CANCELLED)) {
255262
fprintf(stderr, "libusb_transfer failed with status %s (endpoint=0x%02x)\n",
256263
libusb_error_name(transfer->status), transfer->endpoint);
257264
}
@@ -909,7 +916,7 @@ int usbhidasync_write(int device, const void * buf, unsigned int count) {
909916
}
910917

911918
libusb_fill_interrupt_transfer(transfer, usbdevices[device].devh, usbdevices[device].config.endpoints.out.address,
912-
buffer, count, (libusb_transfer_cb_fn) usb_callback, (void *) (unsigned long) device, 1000);
919+
buffer, count, (libusb_transfer_cb_fn) usb_callback, (void *) (unsigned long) device, USBHIDASYNC_OUT_TIMEOUT);
913920

914921
return submit_transfer(transfer);
915922
}

0 commit comments

Comments
 (0)