src/joystick/android/SDL_sysjoystick.c
author Paul Hunkin <paul@bieh.net>
Tue, 27 Jul 2010 21:20:17 +0200
changeset 4721 7bb9d3a3f257
child 5000 6a10693e66c3
permissions -rw-r--r--
Added accelerometer 'joystick'
paul@4721
     1
/*
paul@4721
     2
    SDL - Simple DirectMedia Layer
paul@4721
     3
    Copyright (C) 1997-2010 Sam Lantinga
paul@4721
     4
paul@4721
     5
    This library is free software; you can redistribute it and/or
paul@4721
     6
    modify it under the terms of the GNU Lesser General Public
paul@4721
     7
    License as published by the Free Software Foundation; either
paul@4721
     8
    version 2.1 of the License, or (at your option) any later version.
paul@4721
     9
paul@4721
    10
    This library is distributed in the hope that it will be useful,
paul@4721
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@4721
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
paul@4721
    13
    Lesser General Public License for more details.
paul@4721
    14
paul@4721
    15
    You should have received a copy of the GNU Lesser General Public
paul@4721
    16
    License along with this library; if not, write to the Free Software
paul@4721
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
paul@4721
    18
paul@4721
    19
    Sam Lantinga
paul@4721
    20
    slouken@libsdl.org
paul@4721
    21
*/
paul@4721
    22
paul@4721
    23
#include "SDL_config.h"
paul@4721
    24
paul@4721
    25
#ifdef SDL_JOYSTICK_ANDROID
paul@4721
    26
paul@4721
    27
/* This is the system specific header for the SDL joystick API */
paul@4721
    28
#include <stdio.h>              /* For the definition of NULL */
paul@4721
    29
paul@4721
    30
#include "SDL_error.h"
paul@4721
    31
#include "SDL_events.h"
paul@4721
    32
#include "SDL_joystick.h"
paul@4721
    33
#include "../SDL_sysjoystick.h"
paul@4721
    34
#include "../SDL_joystick_c.h"
paul@4721
    35
paul@4721
    36
extern float fLastAccelerometer[3];
paul@4721
    37
paul@4721
    38
const char *accelerometerName = "Android accelerometer";
paul@4721
    39
paul@4721
    40
/* Function to scan the system for joysticks.
paul@4721
    41
 * This function should set SDL_numjoysticks to the number of available
paul@4721
    42
 * joysticks.  Joystick 0 should be the system default joystick.
paul@4721
    43
 * It should return 0, or -1 on an unrecoverable fatal error.
paul@4721
    44
 */
paul@4721
    45
int
paul@4721
    46
SDL_SYS_JoystickInit(void)
paul@4721
    47
{
paul@4721
    48
    SDL_numjoysticks = 1;
paul@4721
    49
    
paul@4721
    50
return (1);
paul@4721
    51
}
paul@4721
    52
paul@4721
    53
/* Function to get the device-dependent name of a joystick */
paul@4721
    54
const char *
paul@4721
    55
SDL_SYS_JoystickName(int index)
paul@4721
    56
{
paul@4721
    57
    if (!index)
paul@4721
    58
        return accelerometerName;
paul@4721
    59
    SDL_SetError("No joystick available with that index");
paul@4721
    60
    return (NULL);
paul@4721
    61
}
paul@4721
    62
paul@4721
    63
/* Function to open a joystick for use.
paul@4721
    64
   The joystick to open is specified by the index field of the joystick.
paul@4721
    65
   This should fill the nbuttons and naxes fields of the joystick structure.
paul@4721
    66
   It returns 0, or -1 if there is an error.
paul@4721
    67
 */
paul@4721
    68
int
paul@4721
    69
SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
paul@4721
    70
{
paul@4721
    71
    joystick->nbuttons = 0;
paul@4721
    72
    joystick->nhats = 0;
paul@4721
    73
    joystick->nballs = 0;
paul@4721
    74
    joystick->naxes = 3;
paul@4721
    75
    joystick->name = accelerometerName;
paul@4721
    76
    return 0;
paul@4721
    77
}
paul@4721
    78
paul@4721
    79
paul@4721
    80
/* Function to update the state of a joystick - called as a device poll.
paul@4721
    81
 * This function shouldn't update the joystick structure directly,
paul@4721
    82
 * but instead should call SDL_PrivateJoystick*() to deliver events
paul@4721
    83
 * and update joystick device state.
paul@4721
    84
 */
paul@4721
    85
    void
paul@4721
    86
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
paul@4721
    87
{
paul@4721
    88
    int i=0; 
paul@4721
    89
    for(i=0;i<3;i++){
paul@4721
    90
        SDL_PrivateJoystickAxis(joystick, i, fLastAccelerometer[i]);
paul@4721
    91
    }
paul@4721
    92
}
paul@4721
    93
paul@4721
    94
/* Function to close a joystick after use */
paul@4721
    95
void
paul@4721
    96
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
paul@4721
    97
{
paul@4721
    98
}
paul@4721
    99
paul@4721
   100
/* Function to perform any system-specific joystick related cleanup */
paul@4721
   101
void
paul@4721
   102
SDL_SYS_JoystickQuit(void)
paul@4721
   103
{
paul@4721
   104
}
paul@4721
   105
paul@4721
   106
#endif /* SDL_JOYSTICK_NDS */