src/haptic/linux/SDL_syshaptic.c
branchgsoc2008_force_feedback
changeset 2477 97f75ea43a93
parent 2476 242d8a668ebb
child 2478 4fd783e0f34b
equal deleted inserted replaced
2476:242d8a668ebb 2477:97f75ea43a93
    54  * Haptic system hardware data.
    54  * Haptic system hardware data.
    55  */
    55  */
    56 struct haptic_hwdata
    56 struct haptic_hwdata
    57 {
    57 {
    58    int fd;
    58    int fd;
       
    59 };
       
    60 
       
    61 
       
    62 /*
       
    63  * Haptic system effect data.
       
    64  */
       
    65 struct haptic_hweffect
       
    66 {
       
    67    int id;
    59 };
    68 };
    60 
    69 
    61 
    70 
    62 
    71 
    63 #define test_bit(nr, addr) \
    72 #define test_bit(nr, addr) \
   178  * Opens a haptic device for usage.
   187  * Opens a haptic device for usage.
   179  */
   188  */
   180 int
   189 int
   181 SDL_SYS_HapticOpen(SDL_Haptic * haptic)
   190 SDL_SYS_HapticOpen(SDL_Haptic * haptic)
   182 {
   191 {
       
   192    int i;
   183    int fd;
   193    int fd;
   184 
   194 
   185    /* Open the character device */
   195    /* Open the character device */
   186    fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0);
   196    fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0);
   187    if (fd < 0) {
   197    if (fd < 0) {
   188       SDL_SetError("Unable to open %s\n", SDL_hapticlist[haptic->index]);
   198       SDL_SetError("Unable to open %s\n", SDL_hapticlist[haptic->index]);
   189       return (-1);
   199       return -1;
   190    }
   200    }
   191 
   201 
   192    /* Allocate the hwdata */
   202    /* Allocate the hwdata */
   193    haptic->hwdata = (struct haptic_hwdata *)
   203    haptic->hwdata = (struct haptic_hwdata *)
   194       SDL_malloc(sizeof(*haptic->hwdata));
   204          SDL_malloc(sizeof(*haptic->hwdata));
   195    if (haptic->hwdata == NULL) {
   205    if (haptic->hwdata == NULL) {
   196       SDL_OutOfMemory();
   206       SDL_OutOfMemory();
   197       close(fd);
   207       goto open_err;
   198       return (-1);
       
   199    }
   208    }
   200    SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
   209    SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
   201 
       
   202    /* Set the hwdata */
   210    /* Set the hwdata */
   203    haptic->hwdata->fd = fd;
   211    haptic->hwdata->fd = fd;
   204 
   212 
       
   213    /* Set the effects */
       
   214    if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {
       
   215       SDL_SetError("Unable to query haptic device memory.");
       
   216       goto open_err;
       
   217    }
       
   218    haptic->effects = (struct haptic_effect *)
       
   219          SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
       
   220    if (haptic->effects == NULL) {
       
   221       SDL_OutOfMemory();
       
   222       goto open_err;
       
   223    }
       
   224 
   205    return 0;
   225    return 0;
       
   226 
       
   227    /* Error handling */
       
   228 open_err:
       
   229    close(fd);
       
   230    if (haptic->hwdata != NULL) {
       
   231       free(haptic->hwdata);
       
   232       haptic->hwdata = NULL;
       
   233    }
       
   234    return -1;
   206 }
   235 }
   207 
   236 
   208 
   237 
   209 /*
   238 /*
   210  * Closes the haptic device.
   239  * Closes the haptic device.
   218       close(haptic->hwdata->fd);
   247       close(haptic->hwdata->fd);
   219 
   248 
   220       /* Free */
   249       /* Free */
   221       SDL_free(haptic->hwdata);
   250       SDL_free(haptic->hwdata);
   222       haptic->hwdata = NULL;
   251       haptic->hwdata = NULL;
   223 
   252       SDL_free(haptic->effects);
   224    }
   253       haptic->neffects = 0;
   225 }
   254    }
   226 
   255 }
   227 
   256 
   228 /* Clean up after system specific haptic stuff */
   257 
       
   258 /* 
       
   259  * Clean up after system specific haptic stuff
       
   260  */
   229 void
   261 void
   230 SDL_SYS_HapticQuit(void)
   262 SDL_SYS_HapticQuit(void)
   231 {
   263 {
   232    int i;
   264    int i;
   233 
   265 
   235       SDL_free(SDL_hapticlist[i].fname);
   267       SDL_free(SDL_hapticlist[i].fname);
   236    }
   268    }
   237    SDL_hapticlist[0].fname = NULL;
   269    SDL_hapticlist[0].fname = NULL;
   238 }
   270 }
   239 
   271 
       
   272 /*
       
   273  * Creates a new haptic effect.
       
   274  */
       
   275 int
       
   276 SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
       
   277 {
       
   278    return -1;
       
   279 }
       
   280 
   240 
   281 
   241 #endif /* SDL_HAPTIC_LINUX */
   282 #endif /* SDL_HAPTIC_LINUX */