src/joystick/android/SDL_sysjoystick.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 26 Aug 2016 12:18:08 -0700
changeset 10281 cb13d22b7f09
parent 10278 74c39dbe8d30
permissions -rw-r--r--
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved() Updated the removal code to iterate over all joystick add messages instead of just the first one.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     1
/*
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     2
  Simple DirectMedia Layer
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9751
diff changeset
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     4
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     5
  This software is provided 'as-is', without any express or implied
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     7
  arising from the use of this software.
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     8
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    11
  freely, subject to the following restrictions:
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    12
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    14
     claim that you wrote the original software. If you use this software
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    16
     appreciated but is not required.
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    18
     misrepresented as being the original software.
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    20
*/
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    21
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8075
diff changeset
    22
#include "../../SDL_internal.h"
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    23
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    24
#ifdef SDL_JOYSTICK_ANDROID
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    25
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    26
#include <stdio.h>              /* For the definition of NULL */
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    27
#include "SDL_error.h"
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    28
#include "SDL_events.h"
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
    29
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    30
#include "SDL_joystick.h"
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
    31
#include "SDL_hints.h"
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    32
#include "SDL_assert.h"
8060
d1948d163145 [Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8057
diff changeset
    33
#include "SDL_timer.h"
8074
acf83dce00d1 Fixed implicit declaration of SDL_Log() warning in joystick source for Android.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8060
diff changeset
    34
#include "SDL_log.h"
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
    35
#include "SDL_sysjoystick_c.h"
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    36
#include "../SDL_joystick_c.h"
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    37
#include "../../core/android/SDL_android.h"
8008
5e5819ca19db Fixed implicit function declaration warning in joystick source for Android.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7956
diff changeset
    38
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    39
#include "android/keycodes.h"
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    40
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    41
/* As of platform android-14, android/keycodes.h is missing these defines */
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    42
#ifndef AKEYCODE_BUTTON_1
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    43
#define AKEYCODE_BUTTON_1 188
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    44
#define AKEYCODE_BUTTON_2 189
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    45
#define AKEYCODE_BUTTON_3 190
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    46
#define AKEYCODE_BUTTON_4 191
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    47
#define AKEYCODE_BUTTON_5 192
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    48
#define AKEYCODE_BUTTON_6 193
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    49
#define AKEYCODE_BUTTON_7 194
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    50
#define AKEYCODE_BUTTON_8 195
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    51
#define AKEYCODE_BUTTON_9 196
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    52
#define AKEYCODE_BUTTON_10 197
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    53
#define AKEYCODE_BUTTON_11 198
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    54
#define AKEYCODE_BUTTON_12 199
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    55
#define AKEYCODE_BUTTON_13 200
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    56
#define AKEYCODE_BUTTON_14 201
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    57
#define AKEYCODE_BUTTON_15 202
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    58
#define AKEYCODE_BUTTON_16 203
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    59
#endif
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    60
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
    61
#define ANDROID_ACCELEROMETER_NAME "Android Accelerometer"
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
    62
#define ANDROID_ACCELEROMETER_DEVICE_ID INT_MIN
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    63
#define ANDROID_MAX_NBUTTONS 36
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
    64
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
    65
static SDL_joylist_item * JoystickByDeviceId(int device_id);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
    66
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
    67
static SDL_joylist_item *SDL_joylist = NULL;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
    68
static SDL_joylist_item *SDL_joylist_tail = NULL;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
    69
static int numjoysticks = 0;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
    70
static int instance_counter = 0;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
    71
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
    72
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
    73
/* Function to convert Android keyCodes into SDL ones.
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
    74
 * This code manipulation is done to get a sequential list of codes.
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    75
 * FIXME: This is only suited for the case where we use a fixed number of buttons determined by ANDROID_MAX_NBUTTONS
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
    76
 */
7929
e3b38a3cdd60 Changed function to be static.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7928
diff changeset
    77
static int
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
    78
keycode_to_SDL(int keycode)
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
    79
{
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    80
    /* FIXME: If this function gets too unwiedly in the future, replace with a lookup table */
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    81
    int button = 0;
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    82
    switch(keycode) 
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    83
    {
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
    84
        /* Some gamepad buttons (API 9) */
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
    85
        case AKEYCODE_BUTTON_A:
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
    86
            button = SDL_CONTROLLER_BUTTON_A;
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    87
            break;
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    88
        case AKEYCODE_BUTTON_B:
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
    89
            button = SDL_CONTROLLER_BUTTON_B;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
    90
            break;
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    91
        case AKEYCODE_BUTTON_X:
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
    92
            button = SDL_CONTROLLER_BUTTON_X;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
    93
            break;
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    94
        case AKEYCODE_BUTTON_Y:
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
    95
            button = SDL_CONTROLLER_BUTTON_Y;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
    96
            break;
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
    97
        case AKEYCODE_BUTTON_L1:
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
    98
            button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
    99
            break;
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   100
        case AKEYCODE_BUTTON_R1:
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   101
            button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   102
            break;
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   103
        case AKEYCODE_BUTTON_THUMBL:
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   104
            button = SDL_CONTROLLER_BUTTON_LEFTSTICK;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   105
            break;
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   106
        case AKEYCODE_BUTTON_THUMBR:
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   107
            button = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   108
            break;
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   109
        case AKEYCODE_BUTTON_START:
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   110
            button = SDL_CONTROLLER_BUTTON_START;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   111
            break;
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   112
        case AKEYCODE_BUTTON_SELECT:
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   113
            button = SDL_CONTROLLER_BUTTON_BACK;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   114
            break;
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   115
        case AKEYCODE_BUTTON_MODE:
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   116
            button = SDL_CONTROLLER_BUTTON_GUIDE;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   117
            break;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   118
        case AKEYCODE_BUTTON_L2:
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   119
            button = SDL_CONTROLLER_BUTTON_MAX; /* Not supported by GameController */
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   120
            break;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   121
        case AKEYCODE_BUTTON_R2:
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   122
            button = SDL_CONTROLLER_BUTTON_MAX+1; /* Not supported by GameController */
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   123
            break;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   124
        case AKEYCODE_BUTTON_C:
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   125
            button = SDL_CONTROLLER_BUTTON_MAX+2; /* Not supported by GameController */
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   126
            break;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   127
        case AKEYCODE_BUTTON_Z:
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   128
            button = SDL_CONTROLLER_BUTTON_MAX+3; /* Not supported by GameController */
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   129
            break;
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   130
                        
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   131
        /* D-Pad key codes (API 1) */
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   132
        case AKEYCODE_DPAD_UP:
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   133
            button = SDL_CONTROLLER_BUTTON_DPAD_UP;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   134
            break;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   135
        case AKEYCODE_DPAD_DOWN:
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   136
            button = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   137
            break;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   138
        case AKEYCODE_DPAD_LEFT:
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   139
            button = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   140
            break;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   141
        case AKEYCODE_DPAD_RIGHT:
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   142
            button = SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   143
            break;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   144
        case AKEYCODE_DPAD_CENTER:
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   145
            button = SDL_CONTROLLER_BUTTON_MAX+4; /* Not supported by GameController */
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   146
            break;
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   147
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   148
        /* More gamepad buttons (API 12), these get mapped to 20...35*/
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   149
        case AKEYCODE_BUTTON_1:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   150
        case AKEYCODE_BUTTON_2:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   151
        case AKEYCODE_BUTTON_3:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   152
        case AKEYCODE_BUTTON_4:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   153
        case AKEYCODE_BUTTON_5:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   154
        case AKEYCODE_BUTTON_6:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   155
        case AKEYCODE_BUTTON_7:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   156
        case AKEYCODE_BUTTON_8:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   157
        case AKEYCODE_BUTTON_9:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   158
        case AKEYCODE_BUTTON_10:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   159
        case AKEYCODE_BUTTON_11:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   160
        case AKEYCODE_BUTTON_12:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   161
        case AKEYCODE_BUTTON_13:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   162
        case AKEYCODE_BUTTON_14:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   163
        case AKEYCODE_BUTTON_15:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   164
        case AKEYCODE_BUTTON_16:
8122
7e01e3908f41 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8119
diff changeset
   165
            button = keycode - AKEYCODE_BUTTON_1 + SDL_CONTROLLER_BUTTON_MAX + 5;
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   166
            break;
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   167
            
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   168
        default:
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   169
            return -1;
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   170
            break;
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   171
    }
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   172
    
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   173
    /* This is here in case future generations, probably with six fingers per hand, 
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   174
     * happily add new cases up above and forget to update the max number of buttons. 
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   175
     */
7944
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   176
    SDL_assert(button < ANDROID_MAX_NBUTTONS);
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   177
    return button;
f19c0aca56aa Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7930
diff changeset
   178
    
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   179
}
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   180
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   181
int
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   182
Android_OnPadDown(int device_id, int keycode)
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   183
{
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   184
    SDL_joylist_item *item;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   185
    int button = keycode_to_SDL(keycode);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   186
    if (button >= 0) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   187
        item = JoystickByDeviceId(device_id);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   188
        if (item && item->joystick) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   189
            SDL_PrivateJoystickButton(item->joystick, button , SDL_PRESSED);
9751
47ae0a3aa68f Fixed bug 2948 - [Android] Arrow keys from external keyboard are not received
Sam Lantinga <slouken@libsdl.org>
parents: 9742
diff changeset
   190
            return 0;
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   191
        }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   192
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   193
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   194
    return -1;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   195
}
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   196
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   197
int
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   198
Android_OnPadUp(int device_id, int keycode)
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   199
{
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   200
    SDL_joylist_item *item;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   201
    int button = keycode_to_SDL(keycode);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   202
    if (button >= 0) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   203
        item = JoystickByDeviceId(device_id);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   204
        if (item && item->joystick) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   205
            SDL_PrivateJoystickButton(item->joystick, button, SDL_RELEASED);
9751
47ae0a3aa68f Fixed bug 2948 - [Android] Arrow keys from external keyboard are not received
Sam Lantinga <slouken@libsdl.org>
parents: 9742
diff changeset
   206
            return 0;
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   207
        }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   208
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   209
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   210
    return -1;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   211
}
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   212
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   213
int
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   214
Android_OnJoy(int device_id, int axis, float value)
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   215
{
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   216
    /* Android gives joy info normalized as [-1.0, 1.0] or [0.0, 1.0] */
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   217
    SDL_joylist_item *item = JoystickByDeviceId(device_id);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   218
    if (item && item->joystick) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   219
        SDL_PrivateJoystickAxis(item->joystick, axis, (Sint16) (32767.*value) );
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   220
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   221
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   222
    return 0;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   223
}
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   224
8140
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   225
int
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   226
Android_OnHat(int device_id, int hat_id, int x, int y)
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   227
{
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   228
    const Uint8 position_map[3][3] = {
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   229
        {SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP},
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   230
        {SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT},
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   231
        {SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN}
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   232
    };
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   233
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   234
    if (x >= -1 && x <=1 && y >= -1 && y <= 1) {
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   235
        SDL_joylist_item *item = JoystickByDeviceId(device_id);
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   236
        if (item && item->joystick) {
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   237
            SDL_PrivateJoystickHat(item->joystick, hat_id, position_map[y+1][x+1] );
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   238
        }
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   239
        return 0;
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   240
    }
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   241
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   242
    return -1;
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   243
}
8372466c003c fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents: 8129
diff changeset
   244
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   245
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   246
int
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   247
Android_AddJoystick(int device_id, const char *name, SDL_bool is_accelerometer, int nbuttons, int naxes, int nhats, int nballs)
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   248
{
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   249
    SDL_JoystickGUID guid;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   250
    SDL_joylist_item *item;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   251
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   252
    if(JoystickByDeviceId(device_id) != NULL || name == NULL) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   253
        return -1;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   254
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   255
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   256
    /* the GUID is just the first 16 chars of the name for now */
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   257
    SDL_zero( guid );
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   258
    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   259
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   260
    item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   261
    if (item == NULL) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   262
        return -1;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   263
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   264
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   265
    SDL_zerop(item);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   266
    item->guid = guid;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   267
    item->device_id = device_id;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   268
    item->name = SDL_strdup(name);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   269
    if ( item->name == NULL ) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   270
         SDL_free(item);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   271
         return -1;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   272
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   273
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   274
    item->is_accelerometer = is_accelerometer;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   275
    if (nbuttons > -1) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   276
        item->nbuttons = nbuttons;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   277
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   278
    else {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   279
        item->nbuttons = ANDROID_MAX_NBUTTONS;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   280
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   281
    item->naxes = naxes;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   282
    item->nhats = nhats;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   283
    item->nballs = nballs;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   284
    item->device_instance = instance_counter++;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   285
    if (SDL_joylist_tail == NULL) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   286
        SDL_joylist = SDL_joylist_tail = item;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   287
    } else {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   288
        SDL_joylist_tail->next = item;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   289
        SDL_joylist_tail = item;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   290
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   291
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   292
    /* Need to increment the joystick count before we post the event */
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   293
    ++numjoysticks;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   294
10281
cb13d22b7f09 Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents: 10278
diff changeset
   295
    SDL_PrivateJoystickAdded(numjoysticks - 1);
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   296
9579
9a5b4bf6f4d1 Android: Deactivated debug log messages on joystick device events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9561
diff changeset
   297
#ifdef DEBUG_JOYSTICK
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   298
    SDL_Log("Added joystick %s with device_id %d", name, device_id);
9579
9a5b4bf6f4d1 Android: Deactivated debug log messages on joystick device events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9561
diff changeset
   299
#endif
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   300
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   301
    return numjoysticks;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   302
}
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   303
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   304
int 
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   305
Android_RemoveJoystick(int device_id)
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   306
{
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   307
    SDL_joylist_item *item = SDL_joylist;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   308
    SDL_joylist_item *prev = NULL;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   309
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   310
    /* Don't call JoystickByDeviceId here or there'll be an infinite loop! */
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   311
    while (item != NULL) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   312
        if (item->device_id == device_id) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   313
            break;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   314
        }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   315
        prev = item;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   316
        item = item->next;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   317
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   318
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   319
    if (item == NULL) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   320
        return -1;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   321
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   322
8119
df0bf33be2ca Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8093
diff changeset
   323
    if (item->joystick) {
df0bf33be2ca Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8093
diff changeset
   324
        item->joystick->hwdata = NULL;
df0bf33be2ca Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8093
diff changeset
   325
    }
df0bf33be2ca Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8093
diff changeset
   326
        
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   327
    if (prev != NULL) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   328
        prev->next = item->next;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   329
    } else {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   330
        SDL_assert(SDL_joylist == item);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   331
        SDL_joylist = item->next;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   332
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   333
    if (item == SDL_joylist_tail) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   334
        SDL_joylist_tail = prev;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   335
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   336
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   337
    /* Need to decrement the joystick count before we post the event */
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   338
    --numjoysticks;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   339
10281
cb13d22b7f09 Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents: 10278
diff changeset
   340
    SDL_PrivateJoystickRemoved(item->device_instance);
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   341
9579
9a5b4bf6f4d1 Android: Deactivated debug log messages on joystick device events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9561
diff changeset
   342
#ifdef DEBUG_JOYSTICK
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   343
    SDL_Log("Removed joystick with device_id %d", device_id);
9579
9a5b4bf6f4d1 Android: Deactivated debug log messages on joystick device events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9561
diff changeset
   344
#endif
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   345
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   346
    SDL_free(item->name);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   347
    SDL_free(item);
10073
2455bf5d1866 Android: Changed an internal joystick function to return count instead of id.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9998
diff changeset
   348
    return numjoysticks;
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   349
}
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   350
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   351
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   352
int
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   353
SDL_SYS_JoystickInit(void)
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   354
{
8274
8b1f8feb42a6 Changed SDL_HINT_ACCEL_AS_JOY to SDL_HINT_ACCELEROMETER_AS_JOYSTICK to be more clear.
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   355
    const char *hint;
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   356
    SDL_SYS_JoystickDetect();
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   357
    
8274
8b1f8feb42a6 Changed SDL_HINT_ACCEL_AS_JOY to SDL_HINT_ACCELEROMETER_AS_JOYSTICK to be more clear.
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   358
    hint = SDL_GetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK);
8b1f8feb42a6 Changed SDL_HINT_ACCEL_AS_JOY to SDL_HINT_ACCELEROMETER_AS_JOYSTICK to be more clear.
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   359
    if (!hint || SDL_atoi(hint)) {
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   360
        /* Default behavior, accelerometer as joystick */
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   361
        Android_AddJoystick(ANDROID_ACCELEROMETER_DEVICE_ID, ANDROID_ACCELEROMETER_NAME, SDL_TRUE, 0, 3, 0, 0);
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   362
    }
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   363
   
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   364
    return (numjoysticks);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   365
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   366
}
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   367
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   368
int SDL_SYS_NumJoysticks()
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   369
{
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   370
    return numjoysticks;
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   371
}
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   372
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   373
void SDL_SYS_JoystickDetect()
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   374
{
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   375
    /* Support for device connect/disconnect is API >= 16 only,
8060
d1948d163145 [Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8057
diff changeset
   376
     * so we poll every three seconds
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   377
     * Ref: http://developer.android.com/reference/android/hardware/input/InputManager.InputDeviceListener.html
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   378
     */
8060
d1948d163145 [Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8057
diff changeset
   379
    static Uint32 timeout = 0;
d1948d163145 [Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8057
diff changeset
   380
    if (SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
d1948d163145 [Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8057
diff changeset
   381
        timeout = SDL_GetTicks() + 3000;
d1948d163145 [Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8057
diff changeset
   382
        Android_JNI_PollInputDevices();
d1948d163145 [Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8057
diff changeset
   383
    }
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   384
}
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   385
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   386
static SDL_joylist_item *
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   387
JoystickByDevIndex(int device_index)
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   388
{
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   389
    SDL_joylist_item *item = SDL_joylist;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   390
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   391
    if ((device_index < 0) || (device_index >= numjoysticks)) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   392
        return NULL;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   393
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   394
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   395
    while (device_index > 0) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   396
        SDL_assert(item != NULL);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   397
        device_index--;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   398
        item = item->next;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   399
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   400
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   401
    return item;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   402
}
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   403
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   404
static SDL_joylist_item *
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   405
JoystickByDeviceId(int device_id)
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   406
{
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   407
    SDL_joylist_item *item = SDL_joylist;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   408
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   409
    while (item != NULL) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   410
        if (item->device_id == device_id) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   411
            return item;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   412
        }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   413
        item = item->next;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   414
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   415
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   416
    /* Joystick not found, try adding it */
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   417
    SDL_SYS_JoystickDetect();
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   418
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   419
    while (item != NULL) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   420
        if (item->device_id == device_id) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   421
            return item;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   422
        }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   423
        item = item->next;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   424
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   425
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   426
    return NULL;
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   427
}
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   428
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   429
/* Function to get the device-dependent name of a joystick */
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   430
const char *
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   431
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   432
{
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   433
    return JoystickByDevIndex(device_index)->name;
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   434
}
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   435
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   436
/* Function to perform the mapping from device index to the instance id for this index */
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   437
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   438
{
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   439
    return JoystickByDevIndex(device_index)->device_instance;
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   440
}
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   441
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   442
/* Function to open a joystick for use.
9380
07b7c1005a23 Updated internal documentation comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8860
diff changeset
   443
   The joystick to open is specified by the device index.
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   444
   This should fill the nbuttons and naxes fields of the joystick structure.
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   445
   It returns 0, or -1 if there is an error.
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   446
 */
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   447
int
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   448
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   449
{
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   450
    SDL_joylist_item *item = JoystickByDevIndex(device_index);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   451
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   452
    if (item == NULL ) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   453
        return SDL_SetError("No such device");
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   454
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   455
    
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   456
    if (item->joystick != NULL) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   457
        return SDL_SetError("Joystick already opened");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7041
diff changeset
   458
    }
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   459
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   460
    joystick->instance_id = item->device_instance;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   461
    joystick->hwdata = (struct joystick_hwdata *) item;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   462
    item->joystick = joystick;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   463
    joystick->nhats = item->nhats;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   464
    joystick->nballs = item->nballs;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   465
    joystick->nbuttons = item->nbuttons;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   466
    joystick->naxes = item->naxes;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   467
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   468
    return (0);
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   469
}
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   470
9561
d8ad01792399 Fixed typo in internal joystick documentation comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9433
diff changeset
   471
/* Function to determine if this joystick is attached to the system right now */
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   472
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   473
{
9433
bd062398b648 Cleanups in the joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 9380
diff changeset
   474
    return joystick->hwdata != NULL;
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   475
}
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   476
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   477
void
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   478
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   479
{
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   480
    int i;
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   481
    Sint16 value;
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   482
    float values[3];
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   483
    SDL_joylist_item *item = SDL_joylist;
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   484
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   485
    while (item) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   486
        if (item->is_accelerometer) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   487
            if (item->joystick) {
8129
47f67902b179 [Android] Fixes Bug 2370, don't send accelerometer changes when
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8122
diff changeset
   488
                if (Android_JNI_GetAccelerometerValues(values)) {
47f67902b179 [Android] Fixes Bug 2370, don't send accelerometer changes when
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8122
diff changeset
   489
                    for ( i = 0; i < 3; i++ ) {
9742
4189503733ac Fixed style
Sam Lantinga <slouken@libsdl.org>
parents: 9741
diff changeset
   490
                        if (values[i] > 1.0f) {
9741
0ff5994253c2 Fixed bug 3012 - Android accelerometer joystick axis values overflow when values from Android are larger than gravity
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   491
                            values[i] = 1.0f;
9742
4189503733ac Fixed style
Sam Lantinga <slouken@libsdl.org>
parents: 9741
diff changeset
   492
                        } else if (values[i] < -1.0f) {
9741
0ff5994253c2 Fixed bug 3012 - Android accelerometer joystick axis values overflow when values from Android are larger than gravity
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   493
                            values[i] = -1.0f;
0ff5994253c2 Fixed bug 3012 - Android accelerometer joystick axis values overflow when values from Android are larger than gravity
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   494
                        }
0ff5994253c2 Fixed bug 3012 - Android accelerometer joystick axis values overflow when values from Android are larger than gravity
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   495
8129
47f67902b179 [Android] Fixes Bug 2370, don't send accelerometer changes when
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8122
diff changeset
   496
                        value = (Sint16)(values[i] * 32767.0f);
47f67902b179 [Android] Fixes Bug 2370, don't send accelerometer changes when
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8122
diff changeset
   497
                        SDL_PrivateJoystickAxis(item->joystick, i, value);
47f67902b179 [Android] Fixes Bug 2370, don't send accelerometer changes when
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8122
diff changeset
   498
                    }
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   499
                }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   500
            }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   501
            break;
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   502
        }
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   503
        item = item->next;
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   504
    }
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   505
}
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   506
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   507
/* Function to close a joystick after use */
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   508
void
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   509
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   510
{
10274
3501018c6df2 Android: Fixed opening previously closed joystick (thanks, Sylvain!).
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10082
diff changeset
   511
    SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
10278
74c39dbe8d30 Android: Fixed crash if closing removed joystick (thanks, Sylvain!).
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10274
diff changeset
   512
    if (item) {
74c39dbe8d30 Android: Fixed crash if closing removed joystick (thanks, Sylvain!).
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10274
diff changeset
   513
        item->joystick = NULL;
74c39dbe8d30 Android: Fixed crash if closing removed joystick (thanks, Sylvain!).
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10274
diff changeset
   514
    }
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   515
}
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   516
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   517
/* Function to perform any system-specific joystick related cleanup */
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   518
void
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   519
SDL_SYS_JoystickQuit(void)
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   520
{
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   521
    SDL_joylist_item *item = NULL;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   522
    SDL_joylist_item *next = NULL;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   523
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   524
    for (item = SDL_joylist; item; item = next) {
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   525
        next = item->next;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   526
        SDL_free(item->name);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   527
        SDL_free(item);
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   528
    }
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   529
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   530
    SDL_joylist = SDL_joylist_tail = NULL;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   531
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   532
    numjoysticks = 0;
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   533
    instance_counter = 0;
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   534
}
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   535
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   536
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   537
{
8057
801d84e26f91 [Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8025
diff changeset
   538
    return JoystickByDevIndex(device_index)->guid;
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   539
}
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   540
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   541
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   542
{
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   543
    SDL_JoystickGUID guid;
8119
df0bf33be2ca Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8093
diff changeset
   544
    
df0bf33be2ca Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8093
diff changeset
   545
    if (joystick->hwdata != NULL) {
df0bf33be2ca Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8093
diff changeset
   546
        return ((SDL_joylist_item*)joystick->hwdata)->guid;
7956
965b7e09c5a8 [Android] Fixes bug 2217, better joystick axes handling on Android.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7944
diff changeset
   547
    }
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   548
    
8119
df0bf33be2ca Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8093
diff changeset
   549
    SDL_zero(guid);
df0bf33be2ca Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8093
diff changeset
   550
    return guid;
7907
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   551
}
24b4e98c6010 Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   552
7041
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   553
#endif /* SDL_JOYSTICK_ANDROID */
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   554
eb0b541c9722 Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   555
/* vi: set ts=4 sw=4 expandtab: */