src/joystick/android/SDL_sysjoystick.c
changeset 5000 6a10693e66c3
parent 4721 7bb9d3a3f257
child 5090 327f181542f1
     1.1 --- a/src/joystick/android/SDL_sysjoystick.c	Thu Jan 13 17:13:00 2011 -0800
     1.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Thu Jan 13 18:03:56 2011 -0800
     1.3 @@ -32,10 +32,9 @@
     1.4  #include "SDL_joystick.h"
     1.5  #include "../SDL_sysjoystick.h"
     1.6  #include "../SDL_joystick_c.h"
     1.7 +#include "../../SDL_android.h"
     1.8  
     1.9 -extern float fLastAccelerometer[3];
    1.10 -
    1.11 -const char *accelerometerName = "Android accelerometer";
    1.12 +static const char *accelerometerName = "Android accelerometer";
    1.13  
    1.14  /* Function to scan the system for joysticks.
    1.15   * This function should set SDL_numjoysticks to the number of available
    1.16 @@ -47,17 +46,19 @@
    1.17  {
    1.18      SDL_numjoysticks = 1;
    1.19      
    1.20 -return (1);
    1.21 +    return (1);
    1.22  }
    1.23  
    1.24  /* Function to get the device-dependent name of a joystick */
    1.25  const char *
    1.26  SDL_SYS_JoystickName(int index)
    1.27  {
    1.28 -    if (!index)
    1.29 +    if (index == 0) {
    1.30          return accelerometerName;
    1.31 -    SDL_SetError("No joystick available with that index");
    1.32 -    return (NULL);
    1.33 +    } else {
    1.34 +        SDL_SetError("No joystick available with that index");
    1.35 +        return (NULL);
    1.36 +    }
    1.37  }
    1.38  
    1.39  /* Function to open a joystick for use.
    1.40 @@ -82,12 +83,16 @@
    1.41   * but instead should call SDL_PrivateJoystick*() to deliver events
    1.42   * and update joystick device state.
    1.43   */
    1.44 -    void
    1.45 +void
    1.46  SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
    1.47  {
    1.48 -    int i=0; 
    1.49 -    for(i=0;i<3;i++){
    1.50 -        SDL_PrivateJoystickAxis(joystick, i, fLastAccelerometer[i]);
    1.51 +    int i;
    1.52 +    float values[3];
    1.53 +
    1.54 +    Android_JNI_GetAccelerometerValues(values);
    1.55 +
    1.56 +    for ( i = 0; i < 3; i++ ) {
    1.57 +        SDL_PrivateJoystickAxis(joystick, i, values[i]);
    1.58      }
    1.59  }
    1.60  
    1.61 @@ -104,3 +109,5 @@
    1.62  }
    1.63  
    1.64  #endif /* SDL_JOYSTICK_NDS */
    1.65 +
    1.66 +/* vi: set ts=4 sw=4 expandtab: */