src/haptic/linux/SDL_syshaptic.c
branchgsoc2008_force_feedback
changeset 2476 242d8a668ebb
parent 2475 4b874e3a3a2c
child 2477 97f75ea43a93
--- 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;
+
+   }
 }