Fixed bug 2090 - Some joystick inputs are delayed on FreeBSD

kikuchan

Some joysticks with high sampling rate need to be read() more fast,
otherwise it delay user inputs due to internal queue.
Especially, an app that issues SDL_PollEvent() not so frequent
Sam Lantinga 2013-09-06 20:54:14 -07:00
parent 10ffa28a28
commit dc9ddf1f61
1 changed files with 80 additions and 84 deletions

View File

@ -446,9 +446,7 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
if (joy->hwdata->type == BSDJOY_JOY) {
if (read(joy->hwdata->fd, &gameport, sizeof gameport) !=
sizeof gameport)
return;
while (read(joy->hwdata->fd, &gameport, sizeof gameport) == sizeof gameport) {
if (abs(x - gameport.x) > 8) {
x = gameport.x;
if (x < xmin) {
@ -489,23 +487,22 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
if (gameport.b2 != joy->buttons[1]) {
SDL_PrivateJoystickButton(joy, 1, gameport.b2);
}
}
return;
}
#endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */
rep = &joy->hwdata->inreport;
if (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) != rep->size) {
return;
}
while (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) == rep->size) {
#if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_kernel_version >= 500111) || defined(__FreeBSD_kernel__)
hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input, rep->rid);
#else
hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input);
#endif
if (hdata == NULL) {
fprintf(stderr, "%s: Cannot start HID parser\n", joy->hwdata->path);
return;
/*fprintf(stderr, "%s: Cannot start HID parser\n", joy->hwdata->path);*/
continue;
}
for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) {
@ -552,8 +549,7 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
}
}
hid_end_parse(hdata);
return;
}
}
/* Function to close a joystick after use */