Fixed bug 1368 - Enabling joystick subsystem cause an infinite loop
morgan.devel@gmail.com 2012-01-13 00:32:23 PST The android version of SDL_SYS_JoystickUpdate doesn't check if there is actually new data and always generate the SDL_JOYAXISMOTION event. Consequently, doing a while(SDL_PollEvent()) will result in an endless loop. The attached patch fix this issue. It also scale the incoming values properly in the Sint16 range. The scale from [-gravity;+gravity] is done directly in the java part because one may want to map the sensor values with a non-linear method for example.
This commit is contained in:
parent
3fe05cfb55
commit
40c6294290
4 changed files with 26 additions and 13 deletions
|
@ -86,12 +86,14 @@ void
|
|||
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
|
||||
{
|
||||
int i;
|
||||
Sint16 value;
|
||||
float values[3];
|
||||
|
||||
Android_JNI_GetAccelerometerValues(values);
|
||||
|
||||
for ( i = 0; i < 3; i++ ) {
|
||||
SDL_PrivateJoystickAxis(joystick, i, values[i]);
|
||||
if (Android_JNI_GetAccelerometerValues(values)) {
|
||||
for ( i = 0; i < 3; i++ ) {
|
||||
value = (Sint16)(values[i] * 32767.0f);
|
||||
SDL_PrivateJoystickAxis(joystick, i, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue