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