Cleaned up internal accelerometer interface
authorSam Lantinga <slouken@libsdl.org>
Thu, 13 Jan 2011 18:03:56 -0800
changeset 50006a10693e66c3
parent 4999 55fccf89b340
child 5001 77df56570442
Cleaned up internal accelerometer interface
src/SDL_android.cpp
src/SDL_android.h
src/joystick/android/SDL_sysjoystick.c
     1.1 --- a/src/SDL_android.cpp	Thu Jan 13 17:13:00 2011 -0800
     1.2 +++ b/src/SDL_android.cpp	Thu Jan 13 18:03:56 2011 -0800
     1.3 @@ -57,7 +57,7 @@
     1.4  static jmethodID midAudioQuit;
     1.5  
     1.6  // Accelerometer data storage
     1.7 -float fLastAccelerometer[3];
     1.8 +static float fLastAccelerometer[3];
     1.9  
    1.10  
    1.11  /*******************************************************************************
    1.12 @@ -184,6 +184,14 @@
    1.13      }
    1.14  }
    1.15  
    1.16 +extern "C" void Android_JNI_GetAccelerometerValues(float values[3])
    1.17 +{
    1.18 +    int i;
    1.19 +    for (i = 0; i < 3; ++i) {
    1.20 +        values[i] = fLastAccelerometer[i];
    1.21 +    }
    1.22 +}
    1.23 +
    1.24  //
    1.25  // Audio support
    1.26  //
     2.1 --- a/src/SDL_android.h	Thu Jan 13 17:13:00 2011 -0800
     2.2 +++ b/src/SDL_android.h	Thu Jan 13 18:03:56 2011 -0800
     2.3 @@ -29,15 +29,16 @@
     2.4  #endif
     2.5  
     2.6  /* Interface from the SDL library into the Android Java activity */
     2.7 -void Android_JNI_CreateContext();
     2.8 -void Android_JNI_SwapWindow();
     2.9 -void Android_JNI_SetActivityTitle(const char *title);
    2.10 +extern void Android_JNI_CreateContext();
    2.11 +extern void Android_JNI_SwapWindow();
    2.12 +extern void Android_JNI_SetActivityTitle(const char *title);
    2.13 +extern void Android_JNI_GetAccelerometerValues(float values[3]);
    2.14  
    2.15  // Audio support
    2.16 -int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames);
    2.17 -void* Android_JNI_GetAudioBuffer();
    2.18 -void Android_JNI_WriteAudioBuffer();
    2.19 -void Android_JNI_CloseAudioDevice();
    2.20 +extern int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames);
    2.21 +extern void* Android_JNI_GetAudioBuffer();
    2.22 +extern void Android_JNI_WriteAudioBuffer();
    2.23 +extern void Android_JNI_CloseAudioDevice();
    2.24  
    2.25  /* Ends C function definitions when using C++ */
    2.26  #ifdef __cplusplus
     3.1 --- a/src/joystick/android/SDL_sysjoystick.c	Thu Jan 13 17:13:00 2011 -0800
     3.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Thu Jan 13 18:03:56 2011 -0800
     3.3 @@ -32,10 +32,9 @@
     3.4  #include "SDL_joystick.h"
     3.5  #include "../SDL_sysjoystick.h"
     3.6  #include "../SDL_joystick_c.h"
     3.7 +#include "../../SDL_android.h"
     3.8  
     3.9 -extern float fLastAccelerometer[3];
    3.10 -
    3.11 -const char *accelerometerName = "Android accelerometer";
    3.12 +static const char *accelerometerName = "Android accelerometer";
    3.13  
    3.14  /* Function to scan the system for joysticks.
    3.15   * This function should set SDL_numjoysticks to the number of available
    3.16 @@ -47,17 +46,19 @@
    3.17  {
    3.18      SDL_numjoysticks = 1;
    3.19      
    3.20 -return (1);
    3.21 +    return (1);
    3.22  }
    3.23  
    3.24  /* Function to get the device-dependent name of a joystick */
    3.25  const char *
    3.26  SDL_SYS_JoystickName(int index)
    3.27  {
    3.28 -    if (!index)
    3.29 +    if (index == 0) {
    3.30          return accelerometerName;
    3.31 -    SDL_SetError("No joystick available with that index");
    3.32 -    return (NULL);
    3.33 +    } else {
    3.34 +        SDL_SetError("No joystick available with that index");
    3.35 +        return (NULL);
    3.36 +    }
    3.37  }
    3.38  
    3.39  /* Function to open a joystick for use.
    3.40 @@ -82,12 +83,16 @@
    3.41   * but instead should call SDL_PrivateJoystick*() to deliver events
    3.42   * and update joystick device state.
    3.43   */
    3.44 -    void
    3.45 +void
    3.46  SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
    3.47  {
    3.48 -    int i=0; 
    3.49 -    for(i=0;i<3;i++){
    3.50 -        SDL_PrivateJoystickAxis(joystick, i, fLastAccelerometer[i]);
    3.51 +    int i;
    3.52 +    float values[3];
    3.53 +
    3.54 +    Android_JNI_GetAccelerometerValues(values);
    3.55 +
    3.56 +    for ( i = 0; i < 3; i++ ) {
    3.57 +        SDL_PrivateJoystickAxis(joystick, i, values[i]);
    3.58      }
    3.59  }
    3.60  
    3.61 @@ -104,3 +109,5 @@
    3.62  }
    3.63  
    3.64  #endif /* SDL_JOYSTICK_NDS */
    3.65 +
    3.66 +/* vi: set ts=4 sw=4 expandtab: */