src/joystick/android/SDL_sysjoystick.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 24 Jan 2011 21:20:30 -0800
changeset 5090 327f181542f1
parent 5000 6a10693e66c3
child 5262 b530ef003506
permissions -rw-r--r--
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.

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