Mercurial > sdl-ios-xcode
diff src/joystick/android/SDL_sysjoystick.c @ 5000:6a10693e66c3
Cleaned up internal accelerometer interface
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 13 Jan 2011 18:03:56 -0800 |
parents | 7bb9d3a3f257 |
children | 327f181542f1 |
line wrap: on
line diff
--- a/src/joystick/android/SDL_sysjoystick.c Thu Jan 13 17:13:00 2011 -0800 +++ b/src/joystick/android/SDL_sysjoystick.c Thu Jan 13 18:03:56 2011 -0800 @@ -32,10 +32,9 @@ #include "SDL_joystick.h" #include "../SDL_sysjoystick.h" #include "../SDL_joystick_c.h" +#include "../../SDL_android.h" -extern float fLastAccelerometer[3]; - -const char *accelerometerName = "Android accelerometer"; +static const char *accelerometerName = "Android accelerometer"; /* Function to scan the system for joysticks. * This function should set SDL_numjoysticks to the number of available @@ -47,17 +46,19 @@ { SDL_numjoysticks = 1; -return (1); + return (1); } /* Function to get the device-dependent name of a joystick */ const char * SDL_SYS_JoystickName(int index) { - if (!index) + if (index == 0) { return accelerometerName; - SDL_SetError("No joystick available with that index"); - return (NULL); + } else { + SDL_SetError("No joystick available with that index"); + return (NULL); + } } /* Function to open a joystick for use. @@ -82,12 +83,16 @@ * but instead should call SDL_PrivateJoystick*() to deliver events * and update joystick device state. */ - void +void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) { - int i=0; - for(i=0;i<3;i++){ - SDL_PrivateJoystickAxis(joystick, i, fLastAccelerometer[i]); + int i; + float values[3]; + + Android_JNI_GetAccelerometerValues(values); + + for ( i = 0; i < 3; i++ ) { + SDL_PrivateJoystickAxis(joystick, i, values[i]); } } @@ -104,3 +109,5 @@ } #endif /* SDL_JOYSTICK_NDS */ + +/* vi: set ts=4 sw=4 expandtab: */