annotate src/joystick/android/SDL_sysjoystick.c @ 4966:a130bc2f0a18

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