Mercurial > sdl-ios-xcode
annotate src/haptic/SDL_haptic.c @ 2513:55fd9103a330 gsoc2008_force_feedback
Prefixed all haptic errors with "Haptic:" for easier readability.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Thu, 10 Jul 2008 11:39:28 +0000 |
parents | ef147ee4896c |
children | 840e1b6325c0 |
rev | line source |
---|---|
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
1 /* |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
3 Copyright (C) 2008 Edgar Simo |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
4 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
9 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
14 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
18 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
19 Sam Lantinga |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
20 slouken@libsdl.org |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
21 */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
23 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
24 #include "SDL_syshaptic.h" |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
25 #include "../joystick/SDL_joystick_c.h" /* For SDL_PrivateJoystickValid */ |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
26 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
27 |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
28 Uint8 SDL_numhaptics = 0; |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
29 SDL_Haptic **SDL_haptics = NULL; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
30 static SDL_Haptic *default_haptic = NULL; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
31 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
32 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
33 /* |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
34 * Initializes the Haptic devices. |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
35 */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
36 int |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
37 SDL_HapticInit(void) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
38 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
39 int arraylen; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
40 int status; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
41 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
42 SDL_numhaptics = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
43 status = SDL_SYS_HapticInit(); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
44 if (status >= 0) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
45 arraylen = (status + 1) * sizeof(*SDL_haptics); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
46 SDL_haptics = (SDL_Haptic **) SDL_malloc(arraylen); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
47 if (SDL_haptics == NULL) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
48 SDL_numhaptics = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
49 } else { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
50 SDL_memset(SDL_haptics, 0, arraylen); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
51 SDL_numhaptics = status; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
52 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
53 status = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
54 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
55 default_haptic = NULL; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
56 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
57 return status; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
58 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
59 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
60 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
61 /* |
2505 | 62 * Checks to see if the haptic device is valid |
63 */ | |
64 static int | |
65 ValidHaptic(SDL_Haptic ** haptic) | |
66 { | |
67 int valid; | |
68 | |
69 if (*haptic == NULL) { | |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
70 SDL_SetError("Haptic: Device hasn't been opened yet"); |
2505 | 71 valid = 0; |
72 } else { | |
73 valid = 1; | |
74 } | |
75 return valid; | |
76 } | |
77 | |
78 | |
79 /* | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
80 * Returns the number of available devices. |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
81 */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
82 int |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
83 SDL_NumHaptics(void) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
84 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
85 return SDL_numhaptics; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
86 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
87 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
88 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
89 /* |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
90 * Gets the name of a Haptic device by index. |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
91 */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
92 const char * |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
93 SDL_HapticName(int device_index) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
94 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
95 if ((device_index < 0) || (device_index >= SDL_numhaptics)) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
96 SDL_SetError("Haptic: There are %d haptic devices available", SDL_numhaptics); |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
97 return NULL; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
98 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
99 return SDL_SYS_HapticName(device_index); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
100 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
101 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
102 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
103 /* |
2475 | 104 * Opens a Haptic device. |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
105 */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
106 SDL_Haptic * |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
107 SDL_HapticOpen(int device_index) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
108 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
109 int i; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
110 SDL_Haptic *haptic; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
111 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
112 if ((device_index < 0) || (device_index >= SDL_numhaptics)) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
113 SDL_SetError("Haptic: There are %d haptic devices available", SDL_numhaptics); |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
114 return NULL; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
115 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
116 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
117 /* If the haptic is already open, return it */ |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
118 for (i=0; SDL_haptics[i]; i++) { |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
119 if (device_index == SDL_haptics[i]->index) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
120 haptic = SDL_haptics[i]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
121 ++haptic->ref_count; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
122 return haptic; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
123 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
124 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
125 |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
126 /* Create the haptic device */ |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
127 haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic)); |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
128 if (haptic == NULL) { |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
129 SDL_OutOfMemory(); |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
130 return NULL; |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
131 } |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
132 |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
133 /* Initialize the haptic device */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
134 SDL_memset(haptic, 0, (sizeof *haptic)); |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
135 haptic->index = device_index; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
136 if (SDL_SYS_HapticOpen(haptic) < 0) { |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
137 SDL_free(haptic); |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
138 return NULL; |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
139 } |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
140 |
2507
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
141 /* Disable autocenter and set gain to max. */ |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
142 if (haptic->supported & SDL_HAPTIC_GAIN) |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
143 SDL_HapticSetGain(haptic,100); |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
144 if (haptic->supported & SDL_HAPTIC_AUTOCENTER) |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
145 SDL_HapticSetAutocenter(haptic,0); |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
146 |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
147 /* Add haptic to list */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
148 ++haptic->ref_count; |
2490 | 149 for (i=0; SDL_haptics[i]; i++) |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
150 /* Skip to next haptic */ ; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
151 SDL_haptics[i] = haptic; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
152 |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
153 return haptic; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
154 } |
2474
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
155 |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
156 |
2475 | 157 /* |
2506 | 158 * Returns 1 if the device has been opened. |
159 */ | |
160 int | |
161 SDL_HapticOpened(int device_index) | |
162 { | |
163 int i, opened; | |
164 | |
165 opened = 0; | |
166 for (i=0; SDL_haptics[i]; i++) { | |
167 if (SDL_haptics[i]->index == (Uint8) device_index) { | |
168 opened = 1; | |
169 break; | |
170 } | |
171 } | |
172 return opened; | |
173 } | |
174 | |
175 | |
176 /* | |
2505 | 177 * Returns the index to a haptic device. |
178 */ | |
179 int | |
180 SDL_HapticIndex(SDL_Haptic * haptic) | |
181 { | |
182 if (!ValidHaptic(&haptic)) { | |
183 return -1; | |
184 } | |
185 | |
186 return haptic->index; | |
187 } | |
188 | |
189 | |
190 /* | |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
191 * Returns SDL_TRUE if mouse is haptic, SDL_FALSE if it isn't. |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
192 */ |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
193 int |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
194 SDL_MouseIsHaptic(void) |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
195 { |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
196 if (SDL_SYS_HapticMouse() < 0) |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
197 return SDL_FALSE; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
198 return SDL_TRUE; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
199 } |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
200 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
201 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
202 /* |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
203 * Returns the haptic device if mouse is haptic or NULL elsewise. |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
204 */ |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
205 SDL_Haptic * |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
206 SDL_HapticOpenFromMouse(void) |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
207 { |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
208 int device_index; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
209 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
210 device_index = SDL_SYS_HapticMouse(); |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
211 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
212 if (device_index < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
213 SDL_SetError("Haptic: Mouse isn't a haptic device."); |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
214 return NULL; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
215 } |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
216 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
217 return SDL_HapticOpen(device_index); |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
218 } |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
219 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
220 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2507
diff
changeset
|
221 /* |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
222 * Returns SDL_TRUE if joystick has haptic features. |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
223 */ |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
224 int |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
225 SDL_JoystickIsHaptic(SDL_Joystick * joystick) |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
226 { |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
227 int ret; |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
228 |
2490 | 229 /* Must be a valid joystick */ |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
230 if (!SDL_PrivateJoystickValid(&joystick)) { |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
231 return -1; |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
232 } |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
233 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
234 ret = SDL_SYS_JoystickIsHaptic(joystick); |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
235 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
236 if (ret > 0) return SDL_TRUE; |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
237 else if (ret == 0) return SDL_FALSE; |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
238 else return -1; |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
239 } |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
240 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
241 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
242 /* |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
243 * Opens a haptic device from a joystick. |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
244 */ |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
245 SDL_Haptic * |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
246 SDL_HapticOpenFromJoystick(SDL_Joystick * joystick) |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
247 { |
2490 | 248 int i; |
249 SDL_Haptic *haptic; | |
250 | |
251 /* Must be a valid joystick */ | |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
252 if (!SDL_PrivateJoystickValid(&joystick)) { |
2490 | 253 return NULL; |
254 } | |
255 | |
256 /* Joystick must be haptic */ | |
257 if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) { | |
258 return NULL; | |
259 } | |
260 | |
261 /* Check to see if joystick's haptic is already open */ | |
262 for (i=0; SDL_haptics[i]; i++) { | |
2491 | 263 if (SDL_SYS_JoystickSameHaptic(SDL_haptics[i],joystick)) { |
2490 | 264 haptic = SDL_haptics[i]; |
265 ++haptic->ref_count; | |
266 return haptic; | |
267 } | |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
268 } |
2490 | 269 |
270 /* Create the haptic device */ | |
271 haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic)); | |
272 if (haptic == NULL) { | |
273 SDL_OutOfMemory(); | |
274 return NULL; | |
275 } | |
276 | |
277 /* Initialize the haptic device */ | |
278 SDL_memset(haptic, 0, (sizeof *haptic)); | |
279 if (SDL_SYS_HapticOpenFromJoystick(haptic,joystick) < 0) { | |
280 SDL_free(haptic); | |
281 return NULL; | |
282 } | |
283 | |
284 /* Add haptic to list */ | |
285 ++haptic->ref_count; | |
286 for (i=0; SDL_haptics[i]; i++) | |
287 /* Skip to next haptic */ ; | |
288 SDL_haptics[i] = haptic; | |
289 | |
290 return haptic; | |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
291 } |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
292 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
293 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
294 /* |
2475 | 295 * Closes a SDL_Haptic device. |
296 */ | |
297 void | |
298 SDL_HapticClose(SDL_Haptic * haptic) | |
299 { | |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
300 int i; |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
301 |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
302 /* Must be valid */ |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
303 if (!ValidHaptic(&haptic)) { |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
304 return; |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
305 } |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
306 |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
307 /* Check if it's still in use */ |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
308 if (--haptic->ref_count < 0) { |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
309 return; |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
310 } |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
311 |
2480 | 312 /* Close it, properly removing effects if needed */ |
313 for (i=0; i<haptic->neffects; i++) { | |
314 if (haptic->effects[i].hweffect != NULL) { | |
315 SDL_HapticDestroyEffect(haptic,i); | |
316 } | |
317 } | |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
318 SDL_SYS_HapticClose(haptic); |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
319 |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
320 /* Remove from the list */ |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
321 for (i = 0; SDL_haptics[i]; ++i) { |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
322 if (haptic == SDL_haptics[i]) { |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
323 SDL_memcpy(&SDL_haptics[i], &SDL_haptics[i + 1], |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
324 (SDL_numhaptics - i) * sizeof(haptic)); |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
325 break; |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
326 } |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
327 } |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
328 |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
329 /* Free */ |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
330 SDL_free(haptic); |
2475 | 331 } |
332 | |
333 /* | |
334 * Cleans up after the subsystem. | |
335 */ | |
2474
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
336 void |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
337 SDL_HapticQuit(void) |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
338 { |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
339 SDL_numhaptics = 0; |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
340 |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
341 SDL_SYS_HapticQuit(); |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
342 if (SDL_haptics != NULL) { |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
343 SDL_free(SDL_haptics); |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
344 SDL_haptics = NULL; |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
345 } |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
346 } |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
347 |
2478
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
348 /* |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
349 * Returns the number of effects a haptic device has. |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
350 */ |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
351 int |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
352 SDL_HapticNumEffects(SDL_Haptic * haptic) |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
353 { |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
354 if (!ValidHaptic(&haptic)) { |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
355 return -1; |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
356 } |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
357 |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
358 return haptic->neffects; |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
359 } |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
360 |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
361 /* |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
362 * Returns supported effects by the device. |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
363 */ |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
364 unsigned int |
2497
0893fbf73b3d
Renamed SDL_HapticQueryEffects to SDL_HapticQuery.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
365 SDL_HapticQuery(SDL_Haptic * haptic) |
2478
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
366 { |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
367 if (!ValidHaptic(&haptic)) { |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
368 return -1; |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
369 } |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
370 |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
371 return haptic->supported; |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
372 } |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
373 |
2486
24dd8b8669fa
Added SDL_HAPTIC_CUSTOM (not supported on linux).
Edgar Simo <bobbens@gmail.com>
parents:
2485
diff
changeset
|
374 /* |
24dd8b8669fa
Added SDL_HAPTIC_CUSTOM (not supported on linux).
Edgar Simo <bobbens@gmail.com>
parents:
2485
diff
changeset
|
375 * Checks to see if the device can support the effect. |
24dd8b8669fa
Added SDL_HAPTIC_CUSTOM (not supported on linux).
Edgar Simo <bobbens@gmail.com>
parents:
2485
diff
changeset
|
376 */ |
2478
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
377 int |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
378 SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect) |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
379 { |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
380 if (!ValidHaptic(&haptic)) { |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
381 return -1; |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
382 } |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
383 |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
384 if ((haptic->supported & effect->type) != 0) |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
385 return SDL_TRUE; |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
386 return SDL_FALSE; |
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
387 } |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
388 |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
389 /* |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
390 * Creates a new haptic effect. |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
391 */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
392 int |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
393 SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect) |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
394 { |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
395 int i; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
396 |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
397 /* Check for device validity. */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
398 if (!ValidHaptic(&haptic)) { |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
399 return -1; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
400 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
401 |
2480 | 402 /* Check to see if effect is supported */ |
403 if (SDL_HapticEffectSupported(haptic,effect)==SDL_FALSE) { | |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
404 SDL_SetError("Haptic: Effect not supported by haptic device."); |
2480 | 405 return -1; |
406 } | |
407 | |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
408 /* See if there's a free slot */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
409 for (i=0; i<haptic->neffects; i++) { |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
410 if (haptic->effects[i].hweffect == NULL) { |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
411 |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
412 /* Now let the backend create the real effect */ |
2480 | 413 if (SDL_SYS_HapticNewEffect(haptic,&haptic->effects[i],effect) != 0) { |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
414 return -1; /* Backend failed to create effect */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
415 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
416 return i; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
417 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
418 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
419 |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
420 SDL_SetError("Haptic: Device has no free space left."); |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
421 return -1; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
422 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
423 |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
424 /* |
2480 | 425 * Checks to see if an effect is valid. |
426 */ | |
427 static int | |
428 ValidEffect(SDL_Haptic * haptic, int effect) | |
429 { | |
430 if ((effect < 0) || (effect >= haptic->neffects)) { | |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
431 SDL_SetError("Haptic: Invalid effect identifier."); |
2480 | 432 return 0; |
433 } | |
434 return 1; | |
435 } | |
436 | |
437 /* | |
2488
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
438 * Updates an effect. |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
439 */ |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
440 int |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
441 SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data) |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
442 { |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
443 if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) { |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
444 return -1; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
445 } |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
446 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
447 /* Updates the effect */ |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
448 if (SDL_SYS_HapticUpdateEffect(haptic,&haptic->effects[effect],data) < 0) { |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
449 return -1; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
450 } |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
451 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
452 return 0; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
453 } |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
454 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
455 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
456 /* |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
457 * Runs the haptic effect on the device. |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
458 */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
459 int |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
460 SDL_HapticRunEffect(SDL_Haptic * haptic, int effect) |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
461 { |
2480 | 462 if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) { |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
463 return -1; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
464 } |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
465 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
466 /* Run the effect */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
467 if (SDL_SYS_HapticRunEffect(haptic,&haptic->effects[effect]) < 0) { |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
468 return -1; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
469 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
470 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
471 return 0; |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
472 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
473 |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
474 /* |
2485
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
475 * Stops the haptic effect on the device. |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
476 */ |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
477 int |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
478 SDL_HapticStopEffect(SDL_Haptic * haptic, int effect) |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
479 { |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
480 if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) { |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
481 return -1; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
482 } |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
483 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
484 /* Stop the effect */ |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
485 if (SDL_SYS_HapticStopEffect(haptic,&haptic->effects[effect]) < 0) { |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
486 return -1; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
487 } |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
488 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
489 return 0; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
490 } |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
491 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
492 /* |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
493 * Gets rid of a haptic effect. |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
494 */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
495 void |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
496 SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect) |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
497 { |
2480 | 498 if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) { |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
499 return; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
500 } |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
501 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
502 /* Not allocated */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
503 if (haptic->effects[effect].hweffect == NULL) { |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
504 return; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
505 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
506 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
507 SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]); |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
508 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
509 |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
510 /* |
2495
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
511 * Gets the status of a haptic effect. |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
512 */ |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
513 int |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
514 SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect) |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
515 { |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
516 if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) { |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
517 return -1; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
518 } |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
519 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
520 if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
521 SDL_SetError("Haptic: Device does not support status queries."); |
2495
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
522 return -1; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
523 } |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
524 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
525 return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]); |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
526 } |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
527 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
528 /* |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
529 * Sets the global gain of the device. |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
530 */ |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
531 int |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
532 SDL_HapticSetGain(SDL_Haptic * haptic, int gain ) |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
533 { |
2507
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
534 const char *env; |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
535 int real_gain, max_gain; |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
536 |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
537 if (!ValidHaptic(&haptic)) { |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
538 return -1; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
539 } |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
540 |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
541 if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
542 SDL_SetError("Haptic: Device does not support setting gain."); |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
543 return -1; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
544 } |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
545 |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
546 if ((gain < 0) || (gain > 100)) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
547 SDL_SetError("Haptic: Gain must be between 0 and 100."); |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
548 return -1; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
549 } |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
550 |
2507
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
551 /* We use the envvar to get the maximum gain. */ |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
552 env = SDL_getenv("SDL_HAPTIC_GAIN_MAX"); |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
553 if (env != NULL) { |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
554 max_gain = SDL_atoi(env); |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
555 |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
556 /* Check for sanity. */ |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
557 if (max_gain < 0) max_gain = 0; |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
558 else if (max_gain > 100) max_gain = 100; |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
559 |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
560 /* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */ |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
561 real_gain = (gain * max_gain) / 100; |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
562 } |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
563 else { |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
564 real_gain = gain; |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
565 } |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
566 |
8ef1d0f4d0c1
Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents:
2506
diff
changeset
|
567 if (SDL_SYS_HapticSetGain(haptic,real_gain) < 0) { |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
568 return -1; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
569 } |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
570 |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
571 return 0; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
572 } |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
573 |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
574 /* |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
575 * Makes the device autocenter, 0 disables. |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
576 */ |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
577 int |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
578 SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter ) |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
579 { |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
580 if (!ValidHaptic(&haptic)) { |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
581 return -1; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
582 } |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2480
diff
changeset
|
583 |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
584 if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
585 SDL_SetError("Haptic: Device does not support setting autocenter."); |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
586 return -1; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
587 } |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
588 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
589 if ((autocenter < 0) || (autocenter > 100)) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
590 SDL_SetError("Haptic: Autocenter must be between 0 and 100."); |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
591 return -1; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
592 } |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
593 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
594 if (SDL_SYS_HapticSetAutocenter(haptic,autocenter) < 0) { |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
595 return -1; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
596 } |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
597 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
598 return 0; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
599 } |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
600 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
601 |