Mercurial > sdl-ios-xcode
comparison src/joystick/bsd/SDL_sysjoystick.c @ 461:1d36f593078a
Date: Thu, 18 Jul 2002 23:51:40 +0200 (MEST)
From: Krister Walfridsson
Subject: [SDL] src/joystick/bsd/SDL_sysjoystick.c patch
The *BSD USB HID joystick code has two serious bugs:
1. If a joystick reports unhandled hid_input usage (for example HUG_RZ or
HUG_DIAL), then the last handled value will be overwritten with an
arbitrary value. (Fixed in the patch below by adding a default case.)
2. The current code does only handle logical coordinates in the range 0-255,
while a big part of available joysticks report -128 - 127. (This is solved
in the patch below by first center the range around 0, and then stretch
it to the correct range.)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 20 Aug 2002 06:08:42 +0000 |
parents | 33712e5d1ec8 |
children | 2ee72e47ca08 |
comparison
equal
deleted
inserted
replaced
460:a888b3ae31ff | 461:1d36f593078a |
---|---|
330 naxe = JOYAXE_SLIDER; | 330 naxe = JOYAXE_SLIDER; |
331 goto scaleaxe; | 331 goto scaleaxe; |
332 case HUG_WHEEL: | 332 case HUG_WHEEL: |
333 naxe = JOYAXE_WHEEL; | 333 naxe = JOYAXE_WHEEL; |
334 goto scaleaxe; | 334 goto scaleaxe; |
335 default: | |
336 continue; | |
335 } | 337 } |
336 scaleaxe: | 338 scaleaxe: |
337 v = (Sint32)hid_get_data(REP_BUF_DATA(rep), | 339 v = (Sint32)hid_get_data(REP_BUF_DATA(rep), |
338 &hitem); | 340 &hitem); |
339 if (v != 127) { | 341 v -= (hitem.logical_maximum + hitem.logical_minimum + 1)/2; |
340 if (v < 127) { | 342 v *= 32768/((hitem.logical_maximum - hitem.logical_minimum + 1)/2); |
341 v = -(256 - v); | |
342 v <<= 7; | |
343 v++; | |
344 } else { | |
345 v++; | |
346 v <<= 7; | |
347 v--; | |
348 } | |
349 } else { | |
350 v = 0; | |
351 } | |
352 if (v != joy->axes[naxe]) { | 343 if (v != joy->axes[naxe]) { |
353 SDL_PrivateJoystickAxis(joy, naxe, v); | 344 SDL_PrivateJoystickAxis(joy, naxe, v); |
354 } | 345 } |
355 break; | 346 break; |
356 case HUP_BUTTON: | 347 case HUP_BUTTON: |