diff 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
line wrap: on
line diff
--- a/src/haptic/linux/SDL_syshaptic.c	Sun Jun 01 19:11:49 2008 +0000
+++ b/src/haptic/linux/SDL_syshaptic.c	Mon Jun 23 09:01:58 2008 +0000
@@ -180,20 +180,29 @@
 int
 SDL_SYS_HapticOpen(SDL_Haptic * haptic)
 {
-   /* TODO finish
    int fd;
 
+   /* Open the character device */
    fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0);
-   
    if (fd < 0) {
       SDL_SetError("Unable to open %s\n", SDL_hapticlist[haptic->index]);
       return (-1);
    }
 
-   
+   /* Allocate the hwdata */
+   haptic->hwdata = (struct haptic_hwdata *)
+      SDL_malloc(sizeof(*haptic->hwdata));
+   if (haptic->hwdata == NULL) {
+      SDL_OutOfMemory();
+      close(fd);
+      return (-1);
+   }
+   SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
+
+   /* Set the hwdata */
+   haptic->hwdata->fd = fd;
 
    return 0;
-   */
 }
 
 
@@ -203,6 +212,16 @@
 void
 SDL_SYS_HapticClose(SDL_Haptic * haptic)
 {
+   if (haptic->hwdata) {
+
+      /* Clean up */
+      close(haptic->hwdata->fd);
+
+      /* Free */
+      SDL_free(haptic->hwdata);
+      haptic->hwdata = NULL;
+
+   }
 }