Mercurial > sdl-ios-xcode
comparison src/joystick/bsd/SDL_sysjoystick.c @ 381:bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 28 May 2002 20:01:29 +0000 |
parents | 1f148809d972 |
children | 7efee6e36f00 |
comparison
equal
deleted
inserted
replaced
380:bce7171e7a85 | 381:bc1401311390 |
---|---|
40 #include <errno.h> | 40 #include <errno.h> |
41 | 41 |
42 #include <dev/usb/usb.h> | 42 #include <dev/usb/usb.h> |
43 #include <dev/usb/usbhid.h> | 43 #include <dev/usb/usbhid.h> |
44 | 44 |
45 #if defined(__FreeBSD__) | 45 #if defined(HAVE_USBHID_H) |
46 # include <libusb.h> | 46 #include <usbhid.h> |
47 #else | 47 #elif defined(HAVE_LIBUSB_H) |
48 # include <usbhid.h> | 48 #include <libusb.h> |
49 #elif defined(HAVE_LIBUSBHID_H) | |
50 #include <libusbhid.h> | |
49 #endif | 51 #endif |
50 | 52 |
51 #include "SDL_error.h" | 53 #include "SDL_error.h" |
52 #include "SDL_joystick.h" | 54 #include "SDL_joystick.h" |
53 #include "SDL_sysjoystick.h" | 55 #include "SDL_sysjoystick.h" |
110 static char *joynames[MAX_JOYS]; | 112 static char *joynames[MAX_JOYS]; |
111 static char *joydevnames[MAX_JOYS]; | 113 static char *joydevnames[MAX_JOYS]; |
112 | 114 |
113 static int report_alloc(struct report *, struct report_desc *, int); | 115 static int report_alloc(struct report *, struct report_desc *, int); |
114 static void report_free(struct report *); | 116 static void report_free(struct report *); |
117 | |
118 #ifdef USBHID_UCR_DATA | |
119 #define REP_BUF_DATA(rep) ((rep)->buf->ucr_data) | |
120 #else | |
121 #define REP_BUF_DATA(rep) ((rep)->buf->data) | |
122 #endif | |
115 | 123 |
116 int | 124 int |
117 SDL_SYS_JoystickInit(void) | 125 SDL_SYS_JoystickInit(void) |
118 { | 126 { |
119 char s[10]; | 127 char s[10]; |
272 } | 280 } |
273 | 281 |
274 void | 282 void |
275 SDL_SYS_JoystickUpdate(SDL_Joystick *joy) | 283 SDL_SYS_JoystickUpdate(SDL_Joystick *joy) |
276 { | 284 { |
277 static struct hid_item hitem; | 285 struct hid_item hitem; |
278 static struct hid_data *hdata; | 286 struct hid_data *hdata; |
279 static struct report *rep; | 287 struct report *rep; |
280 int nbutton, naxe = -1; | 288 int nbutton, naxe = -1; |
281 Sint32 v; | 289 Sint32 v; |
282 | 290 |
283 rep = &joy->hwdata->inreport; | 291 rep = &joy->hwdata->inreport; |
284 if (read(joy->hwdata->fd, rep->buf->data, rep->size) != rep->size) { | 292 |
293 if (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) != rep->size) { | |
285 return; | 294 return; |
286 } | 295 } |
287 hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input); | 296 hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input); |
288 if (hdata == NULL) { | 297 if (hdata == NULL) { |
289 fprintf(stderr, "%s: Cannot start HID parser\n", | 298 fprintf(stderr, "%s: Cannot start HID parser\n", |
314 case HUG_WHEEL: | 323 case HUG_WHEEL: |
315 naxe = JOYAXE_WHEEL; | 324 naxe = JOYAXE_WHEEL; |
316 goto scaleaxe; | 325 goto scaleaxe; |
317 } | 326 } |
318 scaleaxe: | 327 scaleaxe: |
319 v = (Sint32)hid_get_data(rep->buf->data, &hitem); | 328 v = (Sint32)hid_get_data(REP_BUF_DATA(rep), |
329 &hitem); | |
320 if (v != 127) { | 330 if (v != 127) { |
321 if (v < 127) { | 331 if (v < 127) { |
322 v = -(256 - v); | 332 v = -(256 - v); |
323 v <<= 7; | 333 v <<= 7; |
324 v++; | 334 v++; |
333 if (v != joy->axes[naxe]) { | 343 if (v != joy->axes[naxe]) { |
334 SDL_PrivateJoystickAxis(joy, naxe, v); | 344 SDL_PrivateJoystickAxis(joy, naxe, v); |
335 } | 345 } |
336 break; | 346 break; |
337 case HUP_BUTTON: | 347 case HUP_BUTTON: |
338 v = (Sint32)hid_get_data(rep->buf->data, | 348 v = (Sint32)hid_get_data(REP_BUF_DATA(rep), |
339 &hitem); | 349 &hitem); |
340 if (joy->buttons[nbutton] != v) { | 350 if (joy->buttons[nbutton] != v) { |
341 SDL_PrivateJoystickButton(joy, | 351 SDL_PrivateJoystickButton(joy, |
342 nbutton, v); | 352 nbutton, v); |
343 } | 353 } |
393 return (-1); | 403 return (-1); |
394 } | 404 } |
395 r->size = len; | 405 r->size = len; |
396 | 406 |
397 if (r->size > 0) { | 407 if (r->size > 0) { |
398 r->buf = malloc(sizeof(*r->buf) - sizeof(r->buf->data) + | 408 r->buf = malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) + |
399 r->size); | 409 r->size); |
400 if (r->buf == NULL) { | 410 if (r->buf == NULL) { |
401 SDL_OutOfMemory(); | 411 SDL_OutOfMemory(); |
402 return (-1); | 412 return (-1); |
403 } | 413 } |