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