Mercurial > sdl-ios-xcode
comparison src/haptic/linux/SDL_syshaptic.c @ 2476:242d8a668ebb gsoc2008_force_feedback
* Implemented opening and closing of haptic devices.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Mon, 23 Jun 2008 09:01:58 +0000 |
parents | 4b874e3a3a2c |
children | 97f75ea43a93 |
comparison
equal
deleted
inserted
replaced
2475:4b874e3a3a2c | 2476:242d8a668ebb |
---|---|
178 * Opens a haptic device for usage. | 178 * Opens a haptic device for usage. |
179 */ | 179 */ |
180 int | 180 int |
181 SDL_SYS_HapticOpen(SDL_Haptic * haptic) | 181 SDL_SYS_HapticOpen(SDL_Haptic * haptic) |
182 { | 182 { |
183 /* TODO finish | 183 int fd; |
184 int fd; | 184 |
185 | 185 /* Open the character device */ |
186 fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0); | 186 fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0); |
187 | |
188 if (fd < 0) { | 187 if (fd < 0) { |
189 SDL_SetError("Unable to open %s\n", SDL_hapticlist[haptic->index]); | 188 SDL_SetError("Unable to open %s\n", SDL_hapticlist[haptic->index]); |
190 return (-1); | 189 return (-1); |
191 } | 190 } |
192 | 191 |
193 | 192 /* Allocate the hwdata */ |
193 haptic->hwdata = (struct haptic_hwdata *) | |
194 SDL_malloc(sizeof(*haptic->hwdata)); | |
195 if (haptic->hwdata == NULL) { | |
196 SDL_OutOfMemory(); | |
197 close(fd); | |
198 return (-1); | |
199 } | |
200 SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); | |
201 | |
202 /* Set the hwdata */ | |
203 haptic->hwdata->fd = fd; | |
194 | 204 |
195 return 0; | 205 return 0; |
196 */ | |
197 } | 206 } |
198 | 207 |
199 | 208 |
200 /* | 209 /* |
201 * Closes the haptic device. | 210 * Closes the haptic device. |
202 */ | 211 */ |
203 void | 212 void |
204 SDL_SYS_HapticClose(SDL_Haptic * haptic) | 213 SDL_SYS_HapticClose(SDL_Haptic * haptic) |
205 { | 214 { |
215 if (haptic->hwdata) { | |
216 | |
217 /* Clean up */ | |
218 close(haptic->hwdata->fd); | |
219 | |
220 /* Free */ | |
221 SDL_free(haptic->hwdata); | |
222 haptic->hwdata = NULL; | |
223 | |
224 } | |
206 } | 225 } |
207 | 226 |
208 | 227 |
209 /* Clean up after system specific haptic stuff */ | 228 /* Clean up after system specific haptic stuff */ |
210 void | 229 void |