Backed out changeset: a713101e1d25
authorGabriel Jacobo <gabomdq@gmail.com>
Mon, 01 Apr 2013 13:21:08 -0300
changeset 704067ec89740ad1
parent 7039 f69b305b053d
child 7041 eb0b541c9722
Backed out changeset: a713101e1d25
src/joystick/android/SDL_androidjoystick.c
src/joystick/android/SDL_androidjoystick.h
     1.1 --- a/src/joystick/android/SDL_androidjoystick.c	Mon Apr 01 13:20:22 2013 -0300
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,239 +0,0 @@
     1.4 -/*
     1.5 -  Simple DirectMedia Layer
     1.6 -  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     1.7 -
     1.8 -  This software is provided 'as-is', without any express or implied
     1.9 -  warranty.  In no event will the authors be held liable for any damages
    1.10 -  arising from the use of this software.
    1.11 -
    1.12 -  Permission is granted to anyone to use this software for any purpose,
    1.13 -  including commercial applications, and to alter it and redistribute it
    1.14 -  freely, subject to the following restrictions:
    1.15 -
    1.16 -  1. The origin of this software must not be misrepresented; you must not
    1.17 -     claim that you wrote the original software. If you use this software
    1.18 -     in a product, an acknowledgment in the product documentation would be
    1.19 -     appreciated but is not required.
    1.20 -  2. Altered source versions must be plainly marked as such, and must not be
    1.21 -     misrepresented as being the original software.
    1.22 -  3. This notice may not be removed or altered from any source distribution.
    1.23 -*/
    1.24 -
    1.25 -#include "SDL_config.h"
    1.26 -
    1.27 -#ifdef SDL_JOYSTICK_ANDROID
    1.28 -
    1.29 -/* This is the system specific header for the SDL joystick API */
    1.30 -#include <stdio.h>              /* For the definition of NULL */
    1.31 -
    1.32 -#include "SDL_error.h"
    1.33 -#include "SDL_events.h"
    1.34 -#include "SDL_joystick.h"
    1.35 -#include "../SDL_sysjoystick.h"
    1.36 -#include "../SDL_joystick_c.h"
    1.37 -#include "../../core/android/SDL_android.h"
    1.38 -
    1.39 -//HACK!!
    1.40 -static SDL_Joystick **SYS_Joysticks;
    1.41 -static char **SYS_JoystickNames;
    1.42 -static int SYS_numjoysticks;
    1.43 -
    1.44 -/* Function to convert Android keyCodes into SDL ones.
    1.45 - * This code manipulation is done to get a sequential list of codes.
    1.46 - */
    1.47 -int
    1.48 -keycode_to_SDL(int keycode)
    1.49 -{
    1.50 -    /* D-Pad key codes (API 1):
    1.51 -     * KEYCODE_DPAD_UP=19, KEYCODE_DPAD_DOWN 
    1.52 -     * KEYCODE_DPAD_LEFT, KEYCODE_DPAD_RIGHT, KEYCODE_DPAD_CENTER
    1.53 -     */
    1.54 -    if(keycode < 96)
    1.55 -        return keycode-19;
    1.56 -    /* Some gamepad buttons (API 9):
    1.57 -     * KEYCODE_BUTTON_A=96, KEYCODE_BUTTON_B, KEYCODE_BUTTON_C,
    1.58 -     * KEYCODE_BUTTON_X, KEYCODE_BUTTON_Y, KEYCODE_BUTTON_Z,
    1.59 -     * KEYCODE_BUTTON_L1, KEYCODE_BUTTON_L2,
    1.60 -     * KEYCODE_BUTTON_R1, KEYCODE_BUTTON_R2,
    1.61 -     * KEYCODE_BUTTON_THUMBL, KEYCODE_BUTTON_THUMBR,
    1.62 -     * KEYCODE_BUTTON_START, KEYCODE_BUTTON_SELECT, KEYCODE_BUTTON_MODE
    1.63 -     */
    1.64 -    else if(keycode < 188)
    1.65 -        return keycode-91;
    1.66 -    /* More gamepad buttons (API 12):
    1.67 -     * KEYCODE_BUTTON_1=188 to KEYCODE_BUTTON_16
    1.68 -     */
    1.69 -    else
    1.70 -        return keycode-168;
    1.71 -}
    1.72 -
    1.73 -/* Function to scan the system for joysticks.
    1.74 - * This function should set SYS_numjoysticks to the number of available
    1.75 - * joysticks.  Joystick 0 should be the system default joystick.
    1.76 - * It should return 0, or -1 on an unrecoverable fatal error.
    1.77 - */
    1.78 -int
    1.79 -SDL_SYS_JoystickInit(void)
    1.80 -{
    1.81 -    int i = 0;
    1.82 -    if (Android_JNI_JoystickInit() < 0)
    1.83 -        return -1;
    1.84 -    SYS_numjoysticks = Android_JNI_GetNumJoysticks();
    1.85 -    SYS_Joysticks = (SDL_Joystick **)SDL_malloc(SYS_numjoysticks*sizeof(SDL_Joystick *));
    1.86 -    if (SYS_Joysticks == NULL) {
    1.87 -        return SDL_OutOfMemory();
    1.88 -    }
    1.89 -    SYS_JoystickNames = (char **)SDL_malloc(SYS_numjoysticks*sizeof(char *));
    1.90 -    if (SYS_JoystickNames == NULL) {
    1.91 -        SDL_free(SYS_Joysticks);
    1.92 -        SYS_Joysticks = NULL;
    1.93 -        return SDL_OutOfMemory();
    1.94 -    }
    1.95 -    SDL_memset(SYS_JoystickNames, 0, (SYS_numjoysticks*sizeof(char *)));
    1.96 -    SDL_memset(SYS_Joysticks, 0, (SYS_numjoysticks*sizeof(SDL_Joystick *)));
    1.97 -
    1.98 -    for (i = 0; i < SYS_numjoysticks; i++) {
    1.99 -        SYS_JoystickNames[i] = Android_JNI_GetJoystickName(i);
   1.100 -    }
   1.101 -
   1.102 -    return SYS_numjoysticks;
   1.103 -}
   1.104 -
   1.105 -int SDL_SYS_NumJoysticks()
   1.106 -{
   1.107 -    return SYS_numjoysticks;
   1.108 -}
   1.109 -
   1.110 -void SDL_SYS_JoystickDetect()
   1.111 -{
   1.112 -}
   1.113 -
   1.114 -SDL_bool SDL_SYS_JoystickNeedsPolling()
   1.115 -{
   1.116 -    return SDL_FALSE;
   1.117 -}
   1.118 -
   1.119 -/* Function to get the device-dependent name of a joystick */
   1.120 -const char *
   1.121 -SDL_SYS_JoystickNameForDeviceIndex(int device_index)
   1.122 -{
   1.123 -    return SYS_JoystickNames[device_index];
   1.124 -}
   1.125 -
   1.126 -/* Function to perform the mapping from device index to the instance id for this index */
   1.127 -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
   1.128 -{
   1.129 -    return device_index;
   1.130 -}
   1.131 -
   1.132 -/* Function to open a joystick for use.
   1.133 -   The joystick to open is specified by the index field of the joystick.
   1.134 -   This should fill the nbuttons and naxes fields of the joystick structure.
   1.135 -   It returns 0, or -1 if there is an error.
   1.136 - */
   1.137 -int
   1.138 -SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
   1.139 -{
   1.140 -    if( device_index < SYS_numjoysticks )
   1.141 -    {
   1.142 -        // TODO: How to get the rest of the info??
   1.143 -        // 36 is the maximum number of handled buttons
   1.144 -        joystick->nbuttons = 36;
   1.145 -        joystick->nhats = 0;
   1.146 -        joystick->nballs = 0;
   1.147 -        joystick->naxes = Android_JNI_GetJoystickNumOfAxes(device_index);
   1.148 -    }
   1.149 -    else
   1.150 -    {
   1.151 -        return -1;
   1.152 -    }
   1.153 -
   1.154 -    // Extremely hacky
   1.155 -    SYS_Joysticks[device_index] = joystick;
   1.156 -
   1.157 -    return 0;
   1.158 -}
   1.159 -
   1.160 -
   1.161 -/* Function to update the state of a joystick - called as a device poll.
   1.162 - * This function shouldn't update the joystick structure directly,
   1.163 - * but instead should call SDL_PrivateJoystick*() to deliver events
   1.164 - * and update joystick device state.
   1.165 - */
   1.166 -void
   1.167 -SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
   1.168 -{
   1.169 -}
   1.170 -
   1.171 -/* Function to determine is this joystick is attached to the system right now */
   1.172 -SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
   1.173 -{
   1.174 -    return SDL_TRUE;
   1.175 -}
   1.176 -
   1.177 -/* Function to close a joystick after use */
   1.178 -void
   1.179 -SDL_SYS_JoystickClose(SDL_Joystick * joystick)
   1.180 -{
   1.181 -}
   1.182 -
   1.183 -/* Function to perform any system-specific joystick related cleanup */
   1.184 -void
   1.185 -SDL_SYS_JoystickQuit(void)
   1.186 -{
   1.187 -    SDL_free(SYS_JoystickNames);
   1.188 -    SDL_free(SYS_Joysticks);
   1.189 -    SYS_JoystickNames = NULL;
   1.190 -    SYS_Joysticks = NULL;
   1.191 -    Android_JNI_JoystickQuit();
   1.192 -}
   1.193 -
   1.194 -SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
   1.195 -{
   1.196 -    SDL_JoystickGUID guid;
   1.197 -    // the GUID is just the first 16 chars of the name for now
   1.198 -    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
   1.199 -    SDL_zero( guid );
   1.200 -    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   1.201 -    return guid;
   1.202 -}
   1.203 -
   1.204 -SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
   1.205 -{
   1.206 -    SDL_JoystickGUID guid;
   1.207 -    // the GUID is just the first 16 chars of the name for now
   1.208 -    const char *name = joystick->name;
   1.209 -    SDL_zero( guid );
   1.210 -    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   1.211 -    return guid;
   1.212 -}
   1.213 -
   1.214 -int
   1.215 -Android_OnPadDown(int padId, int keycode)
   1.216 -{
   1.217 -    SDL_PrivateJoystickButton(SYS_Joysticks[padId], keycode_to_SDL(keycode), SDL_PRESSED);
   1.218 -
   1.219 -    return 0;
   1.220 -}
   1.221 -
   1.222 -int
   1.223 -Android_OnPadUp(int padId, int keycode)
   1.224 -{
   1.225 -    SDL_PrivateJoystickButton(SYS_Joysticks[padId], keycode_to_SDL(keycode), SDL_RELEASED);
   1.226 -
   1.227 -    return 0;
   1.228 -}
   1.229 -
   1.230 -int
   1.231 -Android_OnJoy(int joyId, int axisnum, float value)
   1.232 -{
   1.233 -    // Android gives joy info normalized as [-1.0, 1.0] or [0.0, 1.0]
   1.234 -    // TODO: Are the reported values right?
   1.235 -    SDL_PrivateJoystickAxis(SYS_Joysticks[joyId], axisnum, (Sint16) (32767.*value) );
   1.236 -
   1.237 -    return 0;
   1.238 -}
   1.239 -
   1.240 -#endif /* SDL_JOYSTICK_ANDROID */
   1.241 -
   1.242 -/* vi: set ts=4 sw=4 expandtab: */
     2.1 --- a/src/joystick/android/SDL_androidjoystick.h	Mon Apr 01 13:20:22 2013 -0300
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,27 +0,0 @@
     2.4 -/*
     2.5 -  Simple DirectMedia Layer
     2.6 -  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     2.7 -
     2.8 -  This software is provided 'as-is', without any express or implied
     2.9 -  warranty.  In no event will the authors be held liable for any damages
    2.10 -  arising from the use of this software.
    2.11 -
    2.12 -  Permission is granted to anyone to use this software for any purpose,
    2.13 -  including commercial applications, and to alter it and redistribute it
    2.14 -  freely, subject to the following restrictions:
    2.15 -
    2.16 -  1. The origin of this software must not be misrepresented; you must not
    2.17 -     claim that you wrote the original software. If you use this software
    2.18 -     in a product, an acknowledgment in the product documentation would be
    2.19 -     appreciated but is not required.
    2.20 -  2. Altered source versions must be plainly marked as such, and must not be
    2.21 -     misrepresented as being the original software.
    2.22 -  3. This notice may not be removed or altered from any source distribution.
    2.23 -*/
    2.24 -#include "SDL_config.h"
    2.25 -
    2.26 -extern int Android_OnPadDown(int padId, int keycode);
    2.27 -extern int Android_OnPadUp(int padId, int keycode);
    2.28 -extern int Android_OnJoy(int joyId, int axisnum, float value);
    2.29 -
    2.30 -/* vi: set ts=4 sw=4 expandtab: */