Mercurial > sdl-ios-xcode
comparison src/joystick/iphoneos/SDL_sysjoystick.m @ 2348:dd32c95434f4 gsoc2008_iphone
Just the sysjoystick file for the iPhone accelerometer. It doesn't reveal anything under NDA, but I just wanted to make sure that adding files to the repository is working under XCode right now.
author | Holmes Futrell <hfutrell@umail.ucsb.edu> |
---|---|
date | Fri, 11 Jul 2008 00:54:04 +0000 |
parents | |
children | 49b243db2e04 |
comparison
equal
deleted
inserted
replaced
2347:1971045cbfc1 | 2348:dd32c95434f4 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2006 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 #include "SDL_config.h" | |
23 | |
24 /* This is the system specific header for the SDL joystick API */ | |
25 | |
26 #include "SDL_joystick.h" | |
27 #include "../SDL_sysjoystick.h" | |
28 #include "../SDL_joystick_c.h" | |
29 #import "SDLUIAccelerationDelegate.h" | |
30 | |
31 const char *accelerometerName = "iPhone accelerometer"; | |
32 | |
33 /* Function to scan the system for joysticks. | |
34 * This function should set SDL_numjoysticks to the number of available | |
35 * joysticks. Joystick 0 should be the system default joystick. | |
36 * It should return 0, or -1 on an unrecoverable fatal error. | |
37 */ | |
38 int | |
39 SDL_SYS_JoystickInit(void) | |
40 { | |
41 SDL_numjoysticks = 1; | |
42 return (1); | |
43 } | |
44 | |
45 /* Function to get the device-dependent name of a joystick */ | |
46 const char * | |
47 SDL_SYS_JoystickName(int index) | |
48 { | |
49 switch(index) { | |
50 case 0: | |
51 return accelerometerName; | |
52 default: | |
53 SDL_SetError("No joystick available with that index"); | |
54 return NULL; | |
55 } | |
56 } | |
57 | |
58 /* Function to open a joystick for use. | |
59 The joystick to open is specified by the index field of the joystick. | |
60 This should fill the nbuttons and naxes fields of the joystick structure. | |
61 It returns 0, or -1 if there is an error. | |
62 */ | |
63 int | |
64 SDL_SYS_JoystickOpen(SDL_Joystick * joystick) | |
65 { | |
66 if (joystick->index == 0) { | |
67 joystick->naxes = 3; | |
68 joystick->nhats = 0; | |
69 joystick->nballs = 0; | |
70 joystick->nbuttons = 0; | |
71 joystick->name = accelerometerName; | |
72 [[SDLUIAccelerationDelegate sharedDelegate] startup]; | |
73 return 0; | |
74 } | |
75 else { | |
76 SDL_SetError("No joystick available with that index"); | |
77 return (-1); | |
78 } | |
79 | |
80 } | |
81 | |
82 /* Function to update the state of a joystick - called as a device poll. | |
83 * This function shouldn't update the joystick structure directly, | |
84 * but instead should call SDL_PrivateJoystick*() to deliver events | |
85 * and update joystick device state. | |
86 */ | |
87 void | |
88 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) | |
89 { | |
90 | |
91 Sint16 orientation[3]; | |
92 [[SDLUIAccelerationDelegate sharedDelegate] getLastOrientation: orientation]; | |
93 | |
94 if ([[SDLUIAccelerationDelegate sharedDelegate] hasNewData]) { | |
95 | |
96 [[SDLUIAccelerationDelegate sharedDelegate] setHasNewData: NO]; | |
97 | |
98 SDL_PrivateJoystickAxis(joystick, 0, orientation[0]); | |
99 SDL_PrivateJoystickAxis(joystick, 1, orientation[1]); | |
100 SDL_PrivateJoystickAxis(joystick, 2, orientation[2]); | |
101 | |
102 } | |
103 | |
104 return; | |
105 } | |
106 | |
107 /* Function to close a joystick after use */ | |
108 void | |
109 SDL_SYS_JoystickClose(SDL_Joystick * joystick) | |
110 { | |
111 if (joystick->index == 0 && [[SDLUIAccelerationDelegate sharedDelegate] isRunning]) { | |
112 [[SDLUIAccelerationDelegate sharedDelegate] shutdown]; | |
113 } | |
114 SDL_SetError("No joystick open with that index"); | |
115 | |
116 return; | |
117 } | |
118 | |
119 /* Function to perform any system-specific joystick related cleanup */ | |
120 void | |
121 SDL_SYS_JoystickQuit(void) | |
122 { | |
123 return; | |
124 } | |
125 /* vi: set ts=4 sw=4 expandtab: */ |