More comments. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Mon, 11 Aug 2008 11:40:44 +0000
branchgsoc2008_force_feedback
changeset 2641e1e1be935178
parent 2640 e8a54b6fd512
child 2642 b04679da6627
More comments.
Implemented haptic<->mouse on darwin.
src/haptic/darwin/SDL_syshaptic.c
     1.1 --- a/src/haptic/darwin/SDL_syshaptic.c	Mon Aug 11 02:51:32 2008 +0000
     1.2 +++ b/src/haptic/darwin/SDL_syshaptic.c	Mon Aug 11 11:40:44 2008 +0000
     1.3 @@ -43,9 +43,14 @@
     1.4   */
     1.5  static struct
     1.6  {
     1.7 -   char name[256];
     1.8 -   io_service_t dev;
     1.9 -   SDL_Haptic *haptic;
    1.10 +   char name[256]; /* Name of the device. */
    1.11 +
    1.12 +   io_service_t dev; /* Node we use to create the device. */
    1.13 +   SDL_Haptic *haptic; /* Haptic currently assosciated with it. */
    1.14 +   
    1.15 +   /* Usage pages for determining if it's a mouse or not. */
    1.16 +   long usage;
    1.17 +   long usagePage;
    1.18  } SDL_hapticlist[MAX_HAPTICS];
    1.19  
    1.20  
    1.21 @@ -143,6 +148,8 @@
    1.22     io_iterator_t iter;
    1.23     CFDictionaryRef match;
    1.24     io_service_t device;
    1.25 +   CFMutableDictionaryRef hidProperties;
    1.26 +   CFTypeRef refCF;
    1.27  
    1.28     /* Clear all the memory. */
    1.29     SDL_memset(SDL_hapticlist, 0, sizeof(SDL_hapticlist));
    1.30 @@ -162,7 +169,7 @@
    1.31     }
    1.32     /* IOServiceGetMatchingServices consumes dictionary. */
    1.33  
    1.34 -   if (!iter) { /* No iterator. */
    1.35 +   if (!IOIteratorIsValid(iter)) { /* No iterator. */
    1.36        numhaptics = 0;
    1.37        return 0;
    1.38     }
    1.39 @@ -172,9 +179,35 @@
    1.40  
    1.41        /* Check for force feedback. */
    1.42        if (FFIsForceFeedback(device) == FF_OK) {
    1.43 +
    1.44 +         /* Set basic device data. */
    1.45           HIDGetDeviceProduct(device, SDL_hapticlist[numhaptics].name);
    1.46           SDL_hapticlist[numhaptics].dev = device;
    1.47           SDL_hapticlist[numhaptics].haptic = NULL;
    1.48 +
    1.49 +         /* Set usage pages. */
    1.50 +         hidProperties = 0;
    1.51 +         refCF = 0;
    1.52 +         result = IORegistryEntryCreateCFProperties(device,
    1.53 +               &hidProperties, kCFAllocatorDefault, kNilOptions);
    1.54 +         if ((result == KERN_SUCCESS) && hidProperties) {
    1.55 +            refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey));
    1.56 +            if (refCF) {
    1.57 +               if (!CFNumberGetValue(refCF, kCFNumberLongType,
    1.58 +                     &SDL_hapticlist[numhaptics].usagePage))
    1.59 +                  SDL_SetError("Haptic: CFNumberGetValue error retrieving pDevice->usagePage.");
    1.60 +               refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey));
    1.61 +               if (refCF) {
    1.62 +                  if (!CFNumberGetValue(refCF, kCFNumberLongType,
    1.63 +                        &SDL_hapticlist[numhaptics].usage))
    1.64 +                     SDL_SetError("Haptic: CFNumberGetValue error retrieving pDevice->usage.");
    1.65 +               }
    1.66 +            }
    1.67 +            CFRelease(hidProperties);
    1.68 +         }
    1.69 +
    1.70 +
    1.71 +         /* Device has been added. */
    1.72           numhaptics++;
    1.73        }
    1.74        else { /* Free the unused device. */
    1.75 @@ -246,7 +279,7 @@
    1.76           if (refCF) {
    1.77              if (!CFStringGetCString(refCF, name, 256,
    1.78                                      CFStringGetSystemEncoding())) {
    1.79 -               SDL_SetError("CFStringGetCString error retrieving pDevice->product.");
    1.80 +               SDL_SetError("Haptic: CFStringGetCString error retrieving pDevice->product.");
    1.81                 return -1;
    1.82              }
    1.83           }
    1.84 @@ -254,16 +287,16 @@
    1.85           CFRelease(usbProperties);
    1.86        }
    1.87        else {
    1.88 -         SDL_SetError("IORegistryEntryCreateCFProperties failed to create usbProperties.");
    1.89 +         SDL_SetError("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties.");
    1.90           return -1;
    1.91        }
    1.92  
    1.93        /* Release stuff. */
    1.94        if (kIOReturnSuccess != IOObjectRelease(parent2)) {
    1.95 -         SDL_SetError("IOObjectRelease error with parent2.");
    1.96 +         SDL_SetError("Haptic: IOObjectRelease error with parent2.");
    1.97        }
    1.98        if (kIOReturnSuccess != IOObjectRelease(parent1))  {
    1.99 -         SDL_SetError("IOObjectRelease error with parent1.");
   1.100 +         SDL_SetError("Haptic: IOObjectRelease error with parent1.");
   1.101        }
   1.102     }
   1.103     else {
   1.104 @@ -442,6 +475,14 @@
   1.105  int
   1.106  SDL_SYS_HapticMouse(void)
   1.107  {
   1.108 +   int i;
   1.109 +
   1.110 +   for (i=0; i<SDL_numhaptics; i++) {
   1.111 +      if ((SDL_hapticlist[i].usagePage == kHIDPage_GenericDesktop) &&
   1.112 +            (SDL_hapticlist[i].usage == kHIDUsage_GD_Mouse))
   1.113 +         return i;
   1.114 +   }
   1.115 +
   1.116     return -1;
   1.117  }
   1.118