author | Philipp Wiesemann <philipp.wiesemann@arcor.de> |
Thu, 25 Aug 2016 22:31:33 +0200 | |
changeset 10278 | 74c39dbe8d30 |
parent 10274 | 3501018c6df2 |
child 10281 | cb13d22b7f09 |
permissions | -rw-r--r-- |
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 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
30 |
#if !SDL_EVENTS_DISABLED |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
31 |
#include "../../events/SDL_events_c.h" |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
32 |
#endif |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
33 |
|
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
34 |
#include "SDL_joystick.h" |
7907
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
35 |
#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
|
36 |
#include "SDL_assert.h" |
8060
d1948d163145
[Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8057
diff
changeset
|
37 |
#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
|
38 |
#include "SDL_log.h" |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
39 |
#include "SDL_sysjoystick_c.h" |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
40 |
#include "../SDL_joystick_c.h" |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
41 |
#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
|
42 |
|
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
43 |
#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
|
44 |
|
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
45 |
/* 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
|
46 |
#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
|
47 |
#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
|
48 |
#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
|
49 |
#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
|
50 |
#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
|
51 |
#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
|
52 |
#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
|
53 |
#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
|
54 |
#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
|
55 |
#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
|
56 |
#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
|
57 |
#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
|
58 |
#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
|
59 |
#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
|
60 |
#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
|
61 |
#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
|
62 |
#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
|
63 |
#endif |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
64 |
|
7907
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
65 |
#define ANDROID_ACCELEROMETER_NAME "Android Accelerometer" |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
66 |
#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
|
67 |
#define ANDROID_MAX_NBUTTONS 36 |
7907
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
68 |
|
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
69 |
static SDL_joylist_item * JoystickByDeviceId(int device_id); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
70 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
71 |
static SDL_joylist_item *SDL_joylist = NULL; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
72 |
static SDL_joylist_item *SDL_joylist_tail = NULL; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
73 |
static int numjoysticks = 0; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
74 |
static int instance_counter = 0; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
75 |
|
7907
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
76 |
|
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
77 |
/* Function to convert Android keyCodes into SDL ones. |
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
78 |
* 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
|
79 |
* 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
|
80 |
*/ |
7929
e3b38a3cdd60
Changed function to be static.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7928
diff
changeset
|
81 |
static int |
7907
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
82 |
keycode_to_SDL(int keycode) |
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
83 |
{ |
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
84 |
/* 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
|
85 |
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
|
86 |
switch(keycode) |
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
87 |
{ |
8122
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
88 |
/* 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
|
89 |
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
|
90 |
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
|
91 |
break; |
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
break; |
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
95 |
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
|
96 |
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
|
97 |
break; |
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
break; |
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
101 |
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
|
102 |
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
|
103 |
break; |
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
104 |
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
|
105 |
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
|
106 |
break; |
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
break; |
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
110 |
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
|
111 |
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
|
112 |
break; |
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
113 |
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
|
114 |
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
|
115 |
break; |
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
116 |
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
|
117 |
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
|
118 |
break; |
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
break; |
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
122 |
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
|
123 |
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
|
124 |
break; |
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
125 |
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
|
126 |
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
|
127 |
break; |
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
128 |
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
|
129 |
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
|
130 |
break; |
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
131 |
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
|
132 |
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
|
133 |
break; |
8122
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
134 |
|
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
135 |
/* 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
|
136 |
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
|
137 |
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
|
138 |
break; |
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
break; |
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
142 |
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
|
143 |
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
|
144 |
break; |
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
145 |
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
|
146 |
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
|
147 |
break; |
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
148 |
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
|
149 |
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
|
150 |
break; |
7e01e3908f41
Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8119
diff
changeset
|
151 |
|
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
152 |
/* 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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
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
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
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 |
default: |
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
173 |
return -1; |
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
174 |
break; |
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
175 |
} |
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
176 |
|
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
177 |
/* 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
|
178 |
* 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
|
179 |
*/ |
7944
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
180 |
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
|
181 |
return button; |
f19c0aca56aa
Fixes bugs #2213 and #2214, improves the Android joystick code button handling
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7930
diff
changeset
|
182 |
|
7907
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
183 |
} |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
184 |
|
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
185 |
int |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
186 |
Android_OnPadDown(int device_id, int keycode) |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
187 |
{ |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
188 |
SDL_joylist_item *item; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
189 |
int button = keycode_to_SDL(keycode); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
190 |
if (button >= 0) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
191 |
item = JoystickByDeviceId(device_id); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
192 |
if (item && item->joystick) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
193 |
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
|
194 |
return 0; |
8057
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 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
198 |
return -1; |
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 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
201 |
int |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
202 |
Android_OnPadUp(int device_id, int keycode) |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
203 |
{ |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
204 |
SDL_joylist_item *item; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
205 |
int button = keycode_to_SDL(keycode); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
206 |
if (button >= 0) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
207 |
item = JoystickByDeviceId(device_id); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
208 |
if (item && item->joystick) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
209 |
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
|
210 |
return 0; |
8057
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 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
214 |
return -1; |
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 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
217 |
int |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
218 |
Android_OnJoy(int device_id, int axis, float value) |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
219 |
{ |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
220 |
/* 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
|
221 |
SDL_joylist_item *item = JoystickByDeviceId(device_id); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
222 |
if (item && item->joystick) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
223 |
SDL_PrivateJoystickAxis(item->joystick, axis, (Sint16) (32767.*value) ); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
224 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
225 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
226 |
return 0; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
227 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
228 |
|
8140
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
229 |
int |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
230 |
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
|
231 |
{ |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
232 |
const Uint8 position_map[3][3] = { |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
233 |
{SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP}, |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
234 |
{SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT}, |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
235 |
{SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN} |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
236 |
}; |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
237 |
|
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
238 |
if (x >= -1 && x <=1 && y >= -1 && y <= 1) { |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
239 |
SDL_joylist_item *item = JoystickByDeviceId(device_id); |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
240 |
if (item && item->joystick) { |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
241 |
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
|
242 |
} |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
243 |
return 0; |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
244 |
} |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
245 |
|
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
246 |
return -1; |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
247 |
} |
8372466c003c
fixed hat code validation.
dbrady <dbrady@telltalegames.com>
parents:
8129
diff
changeset
|
248 |
|
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
249 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
250 |
int |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
251 |
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
|
252 |
{ |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
253 |
SDL_JoystickGUID guid; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
254 |
SDL_joylist_item *item; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
255 |
#if !SDL_EVENTS_DISABLED |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
256 |
SDL_Event event; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
257 |
#endif |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
258 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
259 |
if(JoystickByDeviceId(device_id) != NULL || name == NULL) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
260 |
return -1; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
261 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
262 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
263 |
/* 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
|
264 |
SDL_zero( guid ); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
265 |
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
|
266 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
267 |
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
|
268 |
if (item == NULL) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
269 |
return -1; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
270 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
271 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
272 |
SDL_zerop(item); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
273 |
item->guid = guid; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
274 |
item->device_id = device_id; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
275 |
item->name = SDL_strdup(name); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
276 |
if ( item->name == NULL ) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
277 |
SDL_free(item); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
278 |
return -1; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
279 |
} |
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->is_accelerometer = is_accelerometer; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
282 |
if (nbuttons > -1) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
283 |
item->nbuttons = nbuttons; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
284 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
285 |
else { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
286 |
item->nbuttons = ANDROID_MAX_NBUTTONS; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
287 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
288 |
item->naxes = naxes; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
289 |
item->nhats = nhats; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
290 |
item->nballs = nballs; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
291 |
item->device_instance = instance_counter++; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
292 |
if (SDL_joylist_tail == NULL) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
293 |
SDL_joylist = SDL_joylist_tail = item; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
294 |
} else { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
295 |
SDL_joylist_tail->next = item; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
296 |
SDL_joylist_tail = item; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
297 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
298 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
299 |
/* 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
|
300 |
++numjoysticks; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
301 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
302 |
#if !SDL_EVENTS_DISABLED |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
303 |
event.type = SDL_JOYDEVICEADDED; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
304 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
305 |
if (SDL_GetEventState(event.type) == SDL_ENABLE) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
306 |
event.jdevice.which = (numjoysticks - 1); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
307 |
if ( (SDL_EventOK == NULL) || |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
308 |
(*SDL_EventOK) (SDL_EventOKParam, &event) ) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
309 |
SDL_PushEvent(&event); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
310 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
311 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
312 |
#endif /* !SDL_EVENTS_DISABLED */ |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
313 |
|
9579
9a5b4bf6f4d1
Android: Deactivated debug log messages on joystick device events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9561
diff
changeset
|
314 |
#ifdef DEBUG_JOYSTICK |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
315 |
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
|
316 |
#endif |
8057
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 |
return numjoysticks; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
319 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
320 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
321 |
int |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
322 |
Android_RemoveJoystick(int device_id) |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
323 |
{ |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
324 |
SDL_joylist_item *item = SDL_joylist; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
325 |
SDL_joylist_item *prev = NULL; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
326 |
#if !SDL_EVENTS_DISABLED |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
327 |
SDL_Event event; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
328 |
#endif |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
329 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
330 |
/* 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
|
331 |
while (item != NULL) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
332 |
if (item->device_id == device_id) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
333 |
break; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
334 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
335 |
prev = item; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
336 |
item = item->next; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
337 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
338 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
339 |
if (item == NULL) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
340 |
return -1; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
341 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
342 |
|
8119
df0bf33be2ca
Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8093
diff
changeset
|
343 |
if (item->joystick) { |
df0bf33be2ca
Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8093
diff
changeset
|
344 |
item->joystick->hwdata = NULL; |
df0bf33be2ca
Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8093
diff
changeset
|
345 |
} |
df0bf33be2ca
Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8093
diff
changeset
|
346 |
|
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
347 |
if (prev != NULL) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
348 |
prev->next = item->next; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
349 |
} else { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
350 |
SDL_assert(SDL_joylist == item); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
351 |
SDL_joylist = item->next; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
352 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
353 |
if (item == SDL_joylist_tail) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
354 |
SDL_joylist_tail = prev; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
355 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
356 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
357 |
/* 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
|
358 |
--numjoysticks; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
359 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
360 |
#if !SDL_EVENTS_DISABLED |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
361 |
event.type = SDL_JOYDEVICEREMOVED; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
362 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
363 |
if (SDL_GetEventState(event.type) == SDL_ENABLE) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
364 |
event.jdevice.which = item->device_instance; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
365 |
if ( (SDL_EventOK == NULL) || |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
366 |
(*SDL_EventOK) (SDL_EventOKParam, &event) ) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
367 |
SDL_PushEvent(&event); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
368 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
369 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
370 |
#endif /* !SDL_EVENTS_DISABLED */ |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
371 |
|
9579
9a5b4bf6f4d1
Android: Deactivated debug log messages on joystick device events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9561
diff
changeset
|
372 |
#ifdef DEBUG_JOYSTICK |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
373 |
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
|
374 |
#endif |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
375 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
376 |
SDL_free(item->name); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
377 |
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
|
378 |
return numjoysticks; |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
379 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
380 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
381 |
|
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
382 |
int |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
383 |
SDL_SYS_JoystickInit(void) |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
384 |
{ |
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
|
385 |
const char *hint; |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
386 |
SDL_SYS_JoystickDetect(); |
7907
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
387 |
|
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
|
388 |
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
|
389 |
if (!hint || SDL_atoi(hint)) { |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
390 |
/* Default behavior, accelerometer as joystick */ |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
391 |
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
|
392 |
} |
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
393 |
|
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
394 |
return (numjoysticks); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
395 |
|
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
396 |
} |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
397 |
|
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
398 |
int SDL_SYS_NumJoysticks() |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
399 |
{ |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
400 |
return numjoysticks; |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
401 |
} |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
402 |
|
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
403 |
void SDL_SYS_JoystickDetect() |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
404 |
{ |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
405 |
/* 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
|
406 |
* so we poll every three seconds |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
407 |
* 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
|
408 |
*/ |
8060
d1948d163145
[Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8057
diff
changeset
|
409 |
static Uint32 timeout = 0; |
d1948d163145
[Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8057
diff
changeset
|
410 |
if (SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) { |
d1948d163145
[Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8057
diff
changeset
|
411 |
timeout = SDL_GetTicks() + 3000; |
d1948d163145
[Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8057
diff
changeset
|
412 |
Android_JNI_PollInputDevices(); |
d1948d163145
[Android] Poll joysticks every three seconds
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8057
diff
changeset
|
413 |
} |
8057
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 |
static SDL_joylist_item * |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
417 |
JoystickByDevIndex(int device_index) |
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 |
SDL_joylist_item *item = SDL_joylist; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
420 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
421 |
if ((device_index < 0) || (device_index >= numjoysticks)) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
422 |
return NULL; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
423 |
} |
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 |
while (device_index > 0) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
426 |
SDL_assert(item != NULL); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
427 |
device_index--; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
428 |
item = item->next; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
429 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
430 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
431 |
return item; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
432 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
433 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
434 |
static SDL_joylist_item * |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
435 |
JoystickByDeviceId(int device_id) |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
436 |
{ |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
437 |
SDL_joylist_item *item = SDL_joylist; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
438 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
439 |
while (item != NULL) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
440 |
if (item->device_id == device_id) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
441 |
return item; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
442 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
443 |
item = item->next; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
444 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
445 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
446 |
/* Joystick not found, try adding it */ |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
447 |
SDL_SYS_JoystickDetect(); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
448 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
449 |
while (item != NULL) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
450 |
if (item->device_id == device_id) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
451 |
return item; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
452 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
453 |
item = item->next; |
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 |
return NULL; |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
457 |
} |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
458 |
|
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
459 |
/* Function to get the device-dependent name of a joystick */ |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
460 |
const char * |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
461 |
SDL_SYS_JoystickNameForDeviceIndex(int device_index) |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
462 |
{ |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
463 |
return JoystickByDevIndex(device_index)->name; |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
464 |
} |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
465 |
|
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
466 |
/* 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
|
467 |
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
468 |
{ |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
469 |
return JoystickByDevIndex(device_index)->device_instance; |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
470 |
} |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
471 |
|
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
472 |
/* Function to open a joystick for use. |
9380
07b7c1005a23
Updated internal documentation comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
8860
diff
changeset
|
473 |
The joystick to open is specified by the device index. |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
474 |
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
|
475 |
It returns 0, or -1 if there is an error. |
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 |
int |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
478 |
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
479 |
{ |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
480 |
SDL_joylist_item *item = JoystickByDevIndex(device_index); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
481 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
482 |
if (item == NULL ) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
483 |
return SDL_SetError("No such device"); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
484 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
485 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
486 |
if (item->joystick != NULL) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
487 |
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
|
488 |
} |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
489 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
490 |
joystick->instance_id = item->device_instance; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
491 |
joystick->hwdata = (struct joystick_hwdata *) item; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
492 |
item->joystick = joystick; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
493 |
joystick->nhats = item->nhats; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
494 |
joystick->nballs = item->nballs; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
495 |
joystick->nbuttons = item->nbuttons; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
496 |
joystick->naxes = item->naxes; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
497 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
498 |
return (0); |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
499 |
} |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
500 |
|
9561
d8ad01792399
Fixed typo in internal joystick documentation comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9433
diff
changeset
|
501 |
/* 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
|
502 |
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
503 |
{ |
9433
bd062398b648
Cleanups in the joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
9380
diff
changeset
|
504 |
return joystick->hwdata != NULL; |
7041
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 |
void |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
508 |
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
509 |
{ |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
510 |
int i; |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
511 |
Sint16 value; |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
512 |
float values[3]; |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
513 |
SDL_joylist_item *item = SDL_joylist; |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
514 |
|
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
515 |
while (item) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
516 |
if (item->is_accelerometer) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
517 |
if (item->joystick) { |
8129
47f67902b179
[Android] Fixes Bug 2370, don't send accelerometer changes when
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8122
diff
changeset
|
518 |
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
|
519 |
for ( i = 0; i < 3; i++ ) { |
9742 | 520 |
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
|
521 |
values[i] = 1.0f; |
9742 | 522 |
} 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
|
523 |
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
|
524 |
} |
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
|
525 |
|
8129
47f67902b179
[Android] Fixes Bug 2370, don't send accelerometer changes when
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8122
diff
changeset
|
526 |
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
|
527 |
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
|
528 |
} |
8057
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 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
531 |
break; |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
532 |
} |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
533 |
item = item->next; |
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 |
|
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
537 |
/* Function to close a joystick after use */ |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
538 |
void |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
539 |
SDL_SYS_JoystickClose(SDL_Joystick * joystick) |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
540 |
{ |
10274
3501018c6df2
Android: Fixed opening previously closed joystick (thanks, Sylvain!).
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
10082
diff
changeset
|
541 |
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
|
542 |
if (item) { |
74c39dbe8d30
Android: Fixed crash if closing removed joystick (thanks, Sylvain!).
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
10274
diff
changeset
|
543 |
item->joystick = NULL; |
74c39dbe8d30
Android: Fixed crash if closing removed joystick (thanks, Sylvain!).
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
10274
diff
changeset
|
544 |
} |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
545 |
} |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
546 |
|
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
547 |
/* Function to perform any system-specific joystick related cleanup */ |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
548 |
void |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
549 |
SDL_SYS_JoystickQuit(void) |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
550 |
{ |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
551 |
SDL_joylist_item *item = NULL; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
552 |
SDL_joylist_item *next = NULL; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
553 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
554 |
for (item = SDL_joylist; item; item = next) { |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
555 |
next = item->next; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
556 |
SDL_free(item->name); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
557 |
SDL_free(item); |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
558 |
} |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
559 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
560 |
SDL_joylist = SDL_joylist_tail = NULL; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
561 |
|
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
562 |
numjoysticks = 0; |
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
563 |
instance_counter = 0; |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
564 |
} |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
565 |
|
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
566 |
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
567 |
{ |
8057
801d84e26f91
[Android] Hotplugging support for joysticks
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8025
diff
changeset
|
568 |
return JoystickByDevIndex(device_index)->guid; |
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
569 |
} |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
570 |
|
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
571 |
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
572 |
{ |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
573 |
SDL_JoystickGUID guid; |
8119
df0bf33be2ca
Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8093
diff
changeset
|
574 |
|
df0bf33be2ca
Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8093
diff
changeset
|
575 |
if (joystick->hwdata != NULL) { |
df0bf33be2ca
Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8093
diff
changeset
|
576 |
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
|
577 |
} |
7907
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
578 |
|
8119
df0bf33be2ca
Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8093
diff
changeset
|
579 |
SDL_zero(guid); |
df0bf33be2ca
Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Gabriel Jacobo <gabomdq@gmail.com>
parents:
8093
diff
changeset
|
580 |
return guid; |
7907
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
581 |
} |
24b4e98c6010
Adds Joystick support for Android
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
582 |
|
7041
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
583 |
#endif /* SDL_JOYSTICK_ANDROID */ |
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
584 |
|
eb0b541c9722
Backed out changeset: a500a9dbfb41
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff
changeset
|
585 |
/* vi: set ts=4 sw=4 expandtab: */ |