src/joystick/android/SDL_sysjoystick.c
changeset 4721 7bb9d3a3f257
child 5000 6a10693e66c3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Tue Jul 27 21:20:17 2010 +0200
     1.3 @@ -0,0 +1,106 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2010 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +
    1.26 +#include "SDL_config.h"
    1.27 +
    1.28 +#ifdef SDL_JOYSTICK_ANDROID
    1.29 +
    1.30 +/* This is the system specific header for the SDL joystick API */
    1.31 +#include <stdio.h>              /* For the definition of NULL */
    1.32 +
    1.33 +#include "SDL_error.h"
    1.34 +#include "SDL_events.h"
    1.35 +#include "SDL_joystick.h"
    1.36 +#include "../SDL_sysjoystick.h"
    1.37 +#include "../SDL_joystick_c.h"
    1.38 +
    1.39 +extern float fLastAccelerometer[3];
    1.40 +
    1.41 +const char *accelerometerName = "Android accelerometer";
    1.42 +
    1.43 +/* Function to scan the system for joysticks.
    1.44 + * This function should set SDL_numjoysticks to the number of available
    1.45 + * joysticks.  Joystick 0 should be the system default joystick.
    1.46 + * It should return 0, or -1 on an unrecoverable fatal error.
    1.47 + */
    1.48 +int
    1.49 +SDL_SYS_JoystickInit(void)
    1.50 +{
    1.51 +    SDL_numjoysticks = 1;
    1.52 +    
    1.53 +return (1);
    1.54 +}
    1.55 +
    1.56 +/* Function to get the device-dependent name of a joystick */
    1.57 +const char *
    1.58 +SDL_SYS_JoystickName(int index)
    1.59 +{
    1.60 +    if (!index)
    1.61 +        return accelerometerName;
    1.62 +    SDL_SetError("No joystick available with that index");
    1.63 +    return (NULL);
    1.64 +}
    1.65 +
    1.66 +/* Function to open a joystick for use.
    1.67 +   The joystick to open is specified by the index field of the joystick.
    1.68 +   This should fill the nbuttons and naxes fields of the joystick structure.
    1.69 +   It returns 0, or -1 if there is an error.
    1.70 + */
    1.71 +int
    1.72 +SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
    1.73 +{
    1.74 +    joystick->nbuttons = 0;
    1.75 +    joystick->nhats = 0;
    1.76 +    joystick->nballs = 0;
    1.77 +    joystick->naxes = 3;
    1.78 +    joystick->name = accelerometerName;
    1.79 +    return 0;
    1.80 +}
    1.81 +
    1.82 +
    1.83 +/* Function to update the state of a joystick - called as a device poll.
    1.84 + * This function shouldn't update the joystick structure directly,
    1.85 + * but instead should call SDL_PrivateJoystick*() to deliver events
    1.86 + * and update joystick device state.
    1.87 + */
    1.88 +    void
    1.89 +SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
    1.90 +{
    1.91 +    int i=0; 
    1.92 +    for(i=0;i<3;i++){
    1.93 +        SDL_PrivateJoystickAxis(joystick, i, fLastAccelerometer[i]);
    1.94 +    }
    1.95 +}
    1.96 +
    1.97 +/* Function to close a joystick after use */
    1.98 +void
    1.99 +SDL_SYS_JoystickClose(SDL_Joystick * joystick)
   1.100 +{
   1.101 +}
   1.102 +
   1.103 +/* Function to perform any system-specific joystick related cleanup */
   1.104 +void
   1.105 +SDL_SYS_JoystickQuit(void)
   1.106 +{
   1.107 +}
   1.108 +
   1.109 +#endif /* SDL_JOYSTICK_NDS */