More verbose errors. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Sun, 20 Jul 2008 21:50:01 +0000
branchgsoc2008_force_feedback
changeset 2541f2649eaa552e
parent 2540 56cf872c723a
child 2542 4e055fa7acb9
More verbose errors.
src/haptic/darwin/SDL_syshaptic.c
     1.1 --- a/src/haptic/darwin/SDL_syshaptic.c	Sun Jul 20 21:34:04 2008 +0000
     1.2 +++ b/src/haptic/darwin/SDL_syshaptic.c	Sun Jul 20 21:50:01 2008 +0000
     1.3 @@ -74,6 +74,62 @@
     1.4  static int HIDGetDeviceProduct(io_service_t dev, char * name);
     1.5  
     1.6  
     1.7 +/* 
     1.8 + * Like strerror but for force feedback errors.
     1.9 + */
    1.10 +static const char *
    1.11 +FFStrError(HRESULT err)
    1.12 +{
    1.13 +   switch (err) {
    1.14 +      case FFERR_DEVICEFULL:
    1.15 +         return "device full";
    1.16 +      case FFERR_DEVICENOTREG:
    1.17 +         return "device not registered";
    1.18 +      case FFERR_DEVICEPAUSED:
    1.19 +         return "device paused";
    1.20 +      case FFERR_DEVICERELEASED:
    1.21 +         return "device released";
    1.22 +      case FFERR_EFFECTPLAYING:
    1.23 +         return "effect playing";
    1.24 +      case FFERR_EFFECTTYPEMISMATCH:
    1.25 +         return "effect type mismatch";
    1.26 +      case FFERR_EFFECTTYPENOTSUPPORTED:
    1.27 +         return "effect type not supported";
    1.28 +      case FFERR_GENERIC:
    1.29 +         return "undetermined error";
    1.30 +      case FFERR_HASEFFECTS:
    1.31 +         return "device has effects";
    1.32 +      case FFERR_INCOMPLETEEFFECT:
    1.33 +         return "incomplete effect";
    1.34 +      case FFERR_INTERNAL:
    1.35 +         return "internal fault";
    1.36 +      case FFERR_INVALIDDOWNLOADID:
    1.37 +         return "invalid download id";
    1.38 +      case FFERR_INVALIDPARAM:
    1.39 +         return "invalid parameter";
    1.40 +      case FFERR_MOREDATA:
    1.41 +         return "more data";
    1.42 +      case FFERR_NOINTERFACE:
    1.43 +         return "interface not supported";
    1.44 +      case FFERR_NOTDOWNLOADED:
    1.45 +         return "effect is not downloaded";
    1.46 +      case FFERR_NOTINITIALIZED:
    1.47 +         return "object has not been initialized";
    1.48 +      case FFERR_OUTOFMEMORY:
    1.49 +         return "out of memory";
    1.50 +      case FFERR_UNPLUGGED:
    1.51 +         return "device is unplugged";
    1.52 +      case FFERR_UNSUPPORTED:
    1.53 +         return "function call unsupported";
    1.54 +      case FFERR_UNSUPPORTEDAXIS:
    1.55 +         return "axis unsupported";
    1.56 +
    1.57 +      default:
    1.58 +         return "unknown error";
    1.59 +   }
    1.60 +}
    1.61 +
    1.62 +
    1.63  /*
    1.64   * Initializes the haptic subsystem.
    1.65   */
    1.66 @@ -244,7 +300,8 @@
    1.67                                            &val, sizeof(val));
    1.68     if (ret == FF_OK) supported |= SDL_HAPTIC_GAIN;
    1.69     else if (ret != FFERR_UNSUPPORTED) {
    1.70 -      SDL_SetError("Haptic: Unable to get if device supports gain.");
    1.71 +      SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
    1.72 +                   FFStrError(ret););
    1.73        return 0;
    1.74     }
    1.75  
    1.76 @@ -253,7 +310,8 @@
    1.77                                            &val, sizeof(val));
    1.78     if (ret == FF_OK) supported |= SDL_HAPTIC_AUTOCENTER;
    1.79     else if (ret != FFERR_UNSUPPORTED) {
    1.80 -      SDL_SetError("Haptic: Unable to get if device supports autocenter.");
    1.81 +      SDL_SetError("Haptic: Unable to get if device supports autocenter: %s.",
    1.82 +                   FFStrError(ret));
    1.83        return 0;
    1.84     }
    1.85  
    1.86 @@ -273,6 +331,8 @@
    1.87  static int
    1.88  SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
    1.89  {
    1.90 +   HRESULT ret;
    1.91 +
    1.92     /* Allocate the hwdata */
    1.93     haptic->hwdata = (struct haptic_hwdata *)
    1.94           SDL_malloc(sizeof(*haptic->hwdata));
    1.95 @@ -283,8 +343,10 @@
    1.96     SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
    1.97    
    1.98     /* Open the device */
    1.99 -   if (FFCreateDevice( service, &haptic->hwdata->device ) != FF_OK) {
   1.100 -      SDL_SetError("Haptic: Unable to create device from service.");
   1.101 +   ret = FFCreateDevice( service, &haptic->hwdata->device);
   1.102 +   if (ret != FF_OK) {
   1.103 +      SDL_SetError("Haptic: Unable to create device from service: %s.",
   1.104 +                   FFStrError(ret));
   1.105        goto creat_err;
   1.106     }
   1.107  
   1.108 @@ -840,9 +902,8 @@
   1.109     /* Create the actual effect. */
   1.110     ret = FFDeviceCreateEffect(haptic->hwdata->device, type,
   1.111           &effect->hweffect->effect, &effect->hweffect->ref);
   1.112 -
   1.113     if (ret != FF_OK) {
   1.114 -      SDL_SetError("Haptic: Unable to create effect.");
   1.115 +      SDL_SetError("Haptic: Unable to create effect: %s.", FFStrError(ret));
   1.116        goto err_effectdone;
   1.117     }
   1.118  
   1.119 @@ -885,7 +946,7 @@
   1.120                                 &temp, flags);
   1.121  
   1.122     if (ret != FF_OK) {
   1.123 -      SDL_SetError("Haptic: Unable to update effect.");
   1.124 +      SDL_SetError("Haptic: Unable to update effect: %s.", FFStrError(ret));
   1.125        goto err_update;
   1.126     }
   1.127  
   1.128 @@ -921,7 +982,7 @@
   1.129     /* Run the effect. */
   1.130     ret = FFEffectStart(effect->hweffect->ref, iter, 0);
   1.131     if (ret != FF_OK) {
   1.132 -      SDL_SetError("Haptic: Unable to run the effect.");
   1.133 +      SDL_SetError("Haptic: Unable to run the effect: %s.", FFStrError(ret));
   1.134        return -1;
   1.135     }
   1.136  
   1.137 @@ -939,7 +1000,7 @@
   1.138  
   1.139     ret = FFEffectStop(effect->hweffect->ref);
   1.140     if (ret != FF_OK) {
   1.141 -      SDL_SetError("Haptic: Unable to stop the effect.");
   1.142 +      SDL_SetError("Haptic: Unable to stop the effect: %s.", FFStrError(ret));
   1.143        return -1;
   1.144     }
   1.145  
   1.146 @@ -957,7 +1018,8 @@
   1.147  
   1.148     ret = FFDeviceReleaseEffect(haptic->hwdata->device, effect->hweffect->ref);
   1.149     if (ret != FF_OK) {
   1.150 -      SDL_SetError("Haptic: Error removing the effect from the device.");
   1.151 +      SDL_SetError("Haptic: Error removing the effect from the device: %s.",
   1.152 +                   FFStrError(ret));
   1.153     }
   1.154     SDL_free(effect->hweffect->effect.lpvTypeSpecificParams);
   1.155     effect->hweffect->effect.lpvTypeSpecificParams = NULL;
   1.156 @@ -977,7 +1039,7 @@
   1.157  
   1.158     ret = FFEffectGetEffectStatus(effect->hweffect->ref, &status);
   1.159     if (ret != FF_OK) {
   1.160 -      SDL_SetError("Haptic: Unable to get effect status.");
   1.161 +      SDL_SetError("Haptic: Unable to get effect status: %s.", FFStrError(ret));
   1.162        return -1;
   1.163     }
   1.164  
   1.165 @@ -998,7 +1060,7 @@
   1.166     val = gain * 100; /* Mac OS X uses 0 to 10,000 */
   1.167     ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, FFPROP_FFGAIN, &val);
   1.168     if (ret != FF_OK) {
   1.169 -      SDL_SetError("Haptic: Error setting gain.");
   1.170 +      SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret));
   1.171        return -1;
   1.172     }
   1.173  
   1.174 @@ -1022,7 +1084,7 @@
   1.175     ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
   1.176                 FFPROP_AUTOCENTER, &val);
   1.177     if (ret != FF_OK) {
   1.178 -      SDL_SetError("Haptic: Error setting autocenter.");
   1.179 +      SDL_SetError("Haptic: Error setting autocenter: %s.", FFStrError(ret));
   1.180        return -1;
   1.181     }
   1.182    
   1.183 @@ -1031,4 +1093,4 @@
   1.184  }
   1.185  
   1.186  
   1.187 -#endif /* SDL_HAPTIC_LINUX */
   1.188 +#endif /* SDL_HAPTIC_IOKIT */