Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
113 lines (92 loc) · 3.05 KB

SDL_sysjoystick.c

File metadata and controls

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