zenilib: zenilib/jni/external/sdl/src/joystick/iphoneos/SDL_sysjoystick.m Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_sysjoystick.m
Go to the documentation of this file.
1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "SDL_config.h"
22
23 /* This is the system specific header for the SDL joystick API */
24
25 #include "SDL_joystick.h"
26 #include "../SDL_sysjoystick.h"
27 #include "../SDL_joystick_c.h"
28 #import "SDLUIAccelerationDelegate.h"
29
30 const char *accelerometerName = "iPhone accelerometer";
31
32 /* Function to scan the system for joysticks.
33 * This function should set SDL_numjoysticks to the number of available
34 * joysticks. Joystick 0 should be the system default joystick.
35 * It should return 0, or -1 on an unrecoverable fatal error.
36 */
37 int
38 SDL_SYS_JoystickInit(void)
39 {
40 return (1);
41 }
42
43 int SDL_SYS_NumJoysticks()
44 {
45 return 1;
46 }
47
48 void SDL_SYS_JoystickDetect()
49 {
50 }
51
52 SDL_bool SDL_SYS_JoystickNeedsPolling()
53 {
54 return SDL_FALSE;
55 }
56
57 /* Function to get the device-dependent name of a joystick */
58 const char *
59 SDL_SYS_JoystickNameForDeviceIndex(int device_index)
60 {
61 return accelerometerName;
62 }
63
64 /* Function to perform the mapping from device index to the instance id for this index */
65 SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
66 {
67 return device_index;
68 }
69
70 /* Function to open a joystick for use.
71 The joystick to open is specified by the index field of the joystick.
72 This should fill the nbuttons and naxes fields of the joystick structure.
73 It returns 0, or -1 if there is an error.
74 */
75 int
76 SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
77 {
78 joystick->naxes = 3;
79 joystick->nhats = 0;
80 joystick->nballs = 0;
81 joystick->nbuttons = 0;
82 [[SDLUIAccelerationDelegate sharedDelegate] startup];
83 return 0;
84 }
85
86 /* Function to determine is this joystick is attached to the system right now */
87 SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
88 {
89 return SDL_TRUE;
90 }
91
92 /* Function to update the state of a joystick - called as a device poll.
93 * This function shouldn't update the joystick structure directly,
94 * but instead should call SDL_PrivateJoystick*() to deliver events
95 * and update joystick device state.
96 */
97 void
98 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
99 {
100
101 Sint16 orientation[3];
102
103 if ([[SDLUIAccelerationDelegate sharedDelegate] hasNewData]) {
104
105 [[SDLUIAccelerationDelegate sharedDelegate] getLastOrientation: orientation];
106 [[SDLUIAccelerationDelegate sharedDelegate] setHasNewData: NO];
107
108 SDL_PrivateJoystickAxis(joystick, 0, orientation[0]);
109 SDL_PrivateJoystickAxis(joystick, 1, orientation[1]);
110 SDL_PrivateJoystickAxis(joystick, 2, orientation[2]);
111
112 }
113
114 return;
115 }
116
117 /* Function to close a joystick after use */
118 void
119 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
120 {
121 if ([[SDLUIAccelerationDelegate sharedDelegate] isRunning]) {
122 [[SDLUIAccelerationDelegate sharedDelegate] shutdown];
123 }
124 SDL_SetError("No joystick open with that index");
125 }
126
127 /* Function to perform any system-specific joystick related cleanup */
128 void
129 SDL_SYS_JoystickQuit(void)
130 {
131 }
132
133 SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
134 {
135 SDL_JoystickGUID guid;
136 /* the GUID is just the first 16 chars of the name for now */
137 const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
138 SDL_zero( guid );
139 SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
140 return guid;
141 }
142
143 SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
144 {
145 SDL_JoystickGUID guid;
146 /* the GUID is just the first 16 chars of the name for now */
147 const char *name = joystick->name;
148 SDL_zero( guid );
149 SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
150 return guid;
151 }
152
153 /* vi: set ts=4 sw=4 expandtab: */
-[SDLUIAccelerationDelegate getLastOrientation:]
void getLastOrientation:(Sint16 *data)
Definition: SDLUIAccelerationDelegate.m:70
SDLUIAccelerationDelegate
Definition: SDLUIAccelerationDelegate.h:26
SDL_joystick.h
SDL_SYS_NumJoysticks
int SDL_SYS_NumJoysticks()
Definition: SDL_sysjoystick.m:43
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:116
SDL_JoystickID
Sint32 SDL_JoystickID
Definition: SDL_joystick.h:72
SDL_TRUE
Definition: SDL_stdinc.h:119
accelerometerName
const char * accelerometerName
Definition: SDL_sysjoystick.m:30
name
EGLImageKHR EGLint * name
Definition: eglext.h:284
SDL_SYS_JoystickQuit
void SDL_SYS_JoystickQuit(void)
Definition: SDL_sysjoystick.m:129
SDL_FALSE
Definition: SDL_stdinc.h:118
SDLUIAccelerationDelegate.h
SDL_config.h
SDL_PrivateJoystickAxis
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
Definition: SDL_joystick.c:496
_SDL_Joystick::nballs
int nballs
Definition: SDL_sysjoystick.h:40
SDL_SYS_JoystickAttached
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
Definition: SDL_sysjoystick.m:87
SDL_SYS_JoystickDetect
void SDL_SYS_JoystickDetect()
Definition: SDL_sysjoystick.m:48
SDL_SetError
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
SDL_SYS_JoystickNameForDeviceIndex
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
Definition: SDL_sysjoystick.m:59
sharedDelegate
static SDLUIAccelerationDelegate * sharedDelegate
Definition: SDLUIAccelerationDelegate.m:26
SDL_SYS_JoystickUpdate
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
Definition: SDL_sysjoystick.m:98
-[SDLUIAccelerationDelegate shutdown]
void shutdown()
Definition: SDLUIAccelerationDelegate.m:116
SDL_SYS_JoystickGetGUID
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
Definition: SDL_sysjoystick.m:143
SDL_SYS_JoystickNeedsPolling
SDL_bool SDL_SYS_JoystickNeedsPolling()
Definition: SDL_sysjoystick.m:52
SDL_strlen
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
Definition: SDL_string.c:389
SDL_SYS_JoystickInit
int SDL_SYS_JoystickInit(void)
Definition: SDL_sysjoystick.m:38
_SDL_Joystick::name
char * name
Definition: SDL_sysjoystick.h:32
-[SDLUIAccelerationDelegate startup]
void startup()
Definition: SDLUIAccelerationDelegate.m:109
SDL_memcpy
DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len)
Definition: SDL_string.c:293
SDL_JoystickGUID
Definition: SDL_joystick.h:68
Sint16
int16_t Sint16
A signed 16-bit integer type.
Definition: SDL_stdinc.h:133
_SDL_Joystick
Definition: SDL_sysjoystick.h:29
SDL_SYS_GetInstanceIdOfDeviceIndex
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
Definition: SDL_sysjoystick.m:65
SDL_SYS_JoystickOpen
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
Definition: SDL_sysjoystick.m:76
_SDL_Joystick::nbuttons
int nbuttons
Definition: SDL_sysjoystick.h:46
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:254
SDL_min
#define SDL_min(x, y)
Definition: SDL_stdinc.h:244
SDL_SYS_JoystickClose
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_sysjoystick.m:119
_SDL_Joystick::naxes
int naxes
Definition: SDL_sysjoystick.h:34
SDL_SYS_JoystickGetDeviceGUID
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index)
Definition: SDL_sysjoystick.m:133
+[SDLUIAccelerationDelegate sharedDelegate]
SDLUIAccelerationDelegate * sharedDelegate()
Definition: SDLUIAccelerationDelegate.m:33
-[SDLUIAccelerationDelegate setHasNewData:]
void setHasNewData:(BOOL value)
Definition: SDLUIAccelerationDelegate.m:137
_SDL_Joystick::nhats
int nhats
Definition: SDL_sysjoystick.h:37