Mercurial > sdl-ios-xcode
comparison src/joystick/android/SDL_sysjoystick.c @ 5000:6a10693e66c3
Cleaned up internal accelerometer interface
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 13 Jan 2011 18:03:56 -0800 |
parents | 7bb9d3a3f257 |
children | 327f181542f1 |
comparison
equal
deleted
inserted
replaced
4999:55fccf89b340 | 5000:6a10693e66c3 |
---|---|
30 #include "SDL_error.h" | 30 #include "SDL_error.h" |
31 #include "SDL_events.h" | 31 #include "SDL_events.h" |
32 #include "SDL_joystick.h" | 32 #include "SDL_joystick.h" |
33 #include "../SDL_sysjoystick.h" | 33 #include "../SDL_sysjoystick.h" |
34 #include "../SDL_joystick_c.h" | 34 #include "../SDL_joystick_c.h" |
35 #include "../../SDL_android.h" | |
35 | 36 |
36 extern float fLastAccelerometer[3]; | 37 static const char *accelerometerName = "Android accelerometer"; |
37 | |
38 const char *accelerometerName = "Android accelerometer"; | |
39 | 38 |
40 /* Function to scan the system for joysticks. | 39 /* Function to scan the system for joysticks. |
41 * This function should set SDL_numjoysticks to the number of available | 40 * This function should set SDL_numjoysticks to the number of available |
42 * joysticks. Joystick 0 should be the system default joystick. | 41 * joysticks. Joystick 0 should be the system default joystick. |
43 * It should return 0, or -1 on an unrecoverable fatal error. | 42 * It should return 0, or -1 on an unrecoverable fatal error. |
45 int | 44 int |
46 SDL_SYS_JoystickInit(void) | 45 SDL_SYS_JoystickInit(void) |
47 { | 46 { |
48 SDL_numjoysticks = 1; | 47 SDL_numjoysticks = 1; |
49 | 48 |
50 return (1); | 49 return (1); |
51 } | 50 } |
52 | 51 |
53 /* Function to get the device-dependent name of a joystick */ | 52 /* Function to get the device-dependent name of a joystick */ |
54 const char * | 53 const char * |
55 SDL_SYS_JoystickName(int index) | 54 SDL_SYS_JoystickName(int index) |
56 { | 55 { |
57 if (!index) | 56 if (index == 0) { |
58 return accelerometerName; | 57 return accelerometerName; |
59 SDL_SetError("No joystick available with that index"); | 58 } else { |
60 return (NULL); | 59 SDL_SetError("No joystick available with that index"); |
60 return (NULL); | |
61 } | |
61 } | 62 } |
62 | 63 |
63 /* Function to open a joystick for use. | 64 /* Function to open a joystick for use. |
64 The joystick to open is specified by the index field of the joystick. | 65 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 This should fill the nbuttons and naxes fields of the joystick structure. |
80 /* Function to update the state of a joystick - called as a device poll. | 81 /* Function to update the state of a joystick - called as a device poll. |
81 * This function shouldn't update the joystick structure directly, | 82 * This function shouldn't update the joystick structure directly, |
82 * but instead should call SDL_PrivateJoystick*() to deliver events | 83 * but instead should call SDL_PrivateJoystick*() to deliver events |
83 * and update joystick device state. | 84 * and update joystick device state. |
84 */ | 85 */ |
85 void | 86 void |
86 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) | 87 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
87 { | 88 { |
88 int i=0; | 89 int i; |
89 for(i=0;i<3;i++){ | 90 float values[3]; |
90 SDL_PrivateJoystickAxis(joystick, i, fLastAccelerometer[i]); | 91 |
92 Android_JNI_GetAccelerometerValues(values); | |
93 | |
94 for ( i = 0; i < 3; i++ ) { | |
95 SDL_PrivateJoystickAxis(joystick, i, values[i]); | |
91 } | 96 } |
92 } | 97 } |
93 | 98 |
94 /* Function to close a joystick after use */ | 99 /* Function to close a joystick after use */ |
95 void | 100 void |
102 SDL_SYS_JoystickQuit(void) | 107 SDL_SYS_JoystickQuit(void) |
103 { | 108 { |
104 } | 109 } |
105 | 110 |
106 #endif /* SDL_JOYSTICK_NDS */ | 111 #endif /* SDL_JOYSTICK_NDS */ |
112 | |
113 /* vi: set ts=4 sw=4 expandtab: */ |