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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c
index c5816b6..41a8693 100644
--- a/src/joystick/bsd/SDL_sysjoystick.c
+++ b/src/joystick/bsd/SDL_sysjoystick.c
@@ -446,48 +446,47 @@ 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;
- if (abs(x - gameport.x) > 8) {
- x = gameport.x;
- if (x < xmin) {
- xmin = x;
- }
- if (x > xmax) {
- xmax = x;
- }
- if (xmin == xmax) {
- xmin--;
- xmax++;
+ while (read(joy->hwdata->fd, &gameport, sizeof gameport) == sizeof gameport) {
+ if (abs(x - gameport.x) > 8) {
+ x = gameport.x;
+ if (x < xmin) {
+ xmin = x;
+ }
+ if (x > xmax) {
+ xmax = x;
+ }
+ if (xmin == xmax) {
+ xmin--;
+ xmax++;
+ }
+ v = (Sint32) x;
+ v -= (xmax + xmin + 1) / 2;
+ v *= 32768 / ((xmax - xmin + 1) / 2);
+ SDL_PrivateJoystickAxis(joy, 0, v);
}
- v = (Sint32) x;
- v -= (xmax + xmin + 1) / 2;
- v *= 32768 / ((xmax - xmin + 1) / 2);
- SDL_PrivateJoystickAxis(joy, 0, v);
- }
- if (abs(y - gameport.y) > 8) {
- y = gameport.y;
- if (y < ymin) {
- ymin = y;
+ if (abs(y - gameport.y) > 8) {
+ y = gameport.y;
+ if (y < ymin) {
+ ymin = y;
+ }
+ if (y > ymax) {
+ ymax = y;
+ }
+ if (ymin == ymax) {
+ ymin--;
+ ymax++;
+ }
+ v = (Sint32) y;
+ v -= (ymax + ymin + 1) / 2;
+ v *= 32768 / ((ymax - ymin + 1) / 2);
+ SDL_PrivateJoystickAxis(joy, 1, v);
}
- if (y > ymax) {
- ymax = y;
+ if (gameport.b1 != joy->buttons[0]) {
+ SDL_PrivateJoystickButton(joy, 0, gameport.b1);
}
- if (ymin == ymax) {
- ymin--;
- ymax++;
+ if (gameport.b2 != joy->buttons[1]) {
+ SDL_PrivateJoystickButton(joy, 1, gameport.b2);
}
- v = (Sint32) y;
- v -= (ymax + ymin + 1) / 2;
- v *= 32768 / ((ymax - ymin + 1) / 2);
- SDL_PrivateJoystickAxis(joy, 1, v);
- }
- if (gameport.b1 != joy->buttons[0]) {
- SDL_PrivateJoystickButton(joy, 0, gameport.b1);
- }
- if (gameport.b2 != joy->buttons[1]) {
- SDL_PrivateJoystickButton(joy, 1, gameport.b2);
}
return;
}
@@ -495,65 +494,62 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
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);
+ hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input, rep->rid);
#else
- hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input);
+ 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;
- }
+ if (hdata == NULL) {
+ /*fprintf(stderr, "%s: Cannot start HID parser\n", joy->hwdata->path);*/
+ continue;
+ }
- for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) {
- switch (hitem.kind) {
- case hid_input:
- switch (HID_PAGE(hitem.usage)) {
- case HUP_GENERIC_DESKTOP:
- {
- unsigned usage = HID_USAGE(hitem.usage);
- int joyaxe = usage_to_joyaxe(usage);
- if (joyaxe >= 0) {
- naxe = joy->hwdata->axis_map[joyaxe];
- /* scaleaxe */
- v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
- v -= (hitem.logical_maximum +
- hitem.logical_minimum + 1) / 2;
- v *= 32768 /
- ((hitem.logical_maximum -
- hitem.logical_minimum + 1) / 2);
- if (v != joy->axes[naxe]) {
- SDL_PrivateJoystickAxis(joy, naxe, v);
+ for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) {
+ switch (hitem.kind) {
+ case hid_input:
+ switch (HID_PAGE(hitem.usage)) {
+ case HUP_GENERIC_DESKTOP:
+ {
+ unsigned usage = HID_USAGE(hitem.usage);
+ int joyaxe = usage_to_joyaxe(usage);
+ if (joyaxe >= 0) {
+ naxe = joy->hwdata->axis_map[joyaxe];
+ /* scaleaxe */
+ v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
+ v -= (hitem.logical_maximum +
+ hitem.logical_minimum + 1) / 2;
+ v *= 32768 /
+ ((hitem.logical_maximum -
+ hitem.logical_minimum + 1) / 2);
+ if (v != joy->axes[naxe]) {
+ SDL_PrivateJoystickAxis(joy, naxe, v);
+ }
+ } else if (usage == HUG_HAT_SWITCH) {
+ v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
+ SDL_PrivateJoystickHat(joy, 0,
+ hatval_to_sdl(v) -
+ hitem.logical_minimum);
}
- } else if (usage == HUG_HAT_SWITCH) {
- v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
- SDL_PrivateJoystickHat(joy, 0,
- hatval_to_sdl(v) -
- hitem.logical_minimum);
+ break;
+ }
+ case HUP_BUTTON:
+ v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
+ if (joy->buttons[nbutton] != v) {
+ SDL_PrivateJoystickButton(joy, nbutton, v);
}
+ nbutton++;
break;
+ default:
+ continue;
}
- case HUP_BUTTON:
- v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
- if (joy->buttons[nbutton] != v) {
- SDL_PrivateJoystickButton(joy, nbutton, v);
- }
- nbutton++;
break;
default:
- continue;
+ break;
}
- break;
- default:
- break;
}
+ hid_end_parse(hdata);
}
- hid_end_parse(hdata);
-
- return;
}
/* Function to close a joystick after use */