Mercurial > sdl-ios-xcode
comparison src/haptic/darwin/SDL_syshaptic.c @ 2641:e1e1be935178 gsoc2008_force_feedback
More comments.
Implemented haptic<->mouse on darwin.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Mon, 11 Aug 2008 11:40:44 +0000 |
parents | 668fee3b268a |
children | b04679da6627 |
comparison
equal
deleted
inserted
replaced
2640:e8a54b6fd512 | 2641:e1e1be935178 |
---|---|
41 /* | 41 /* |
42 * List of available haptic devices. | 42 * List of available haptic devices. |
43 */ | 43 */ |
44 static struct | 44 static struct |
45 { | 45 { |
46 char name[256]; | 46 char name[256]; /* Name of the device. */ |
47 io_service_t dev; | 47 |
48 SDL_Haptic *haptic; | 48 io_service_t dev; /* Node we use to create the device. */ |
49 SDL_Haptic *haptic; /* Haptic currently assosciated with it. */ | |
50 | |
51 /* Usage pages for determining if it's a mouse or not. */ | |
52 long usage; | |
53 long usagePage; | |
49 } SDL_hapticlist[MAX_HAPTICS]; | 54 } SDL_hapticlist[MAX_HAPTICS]; |
50 | 55 |
51 | 56 |
52 /* | 57 /* |
53 * Haptic system hardware data. | 58 * Haptic system hardware data. |
141 int numhaptics; | 146 int numhaptics; |
142 IOReturn result; | 147 IOReturn result; |
143 io_iterator_t iter; | 148 io_iterator_t iter; |
144 CFDictionaryRef match; | 149 CFDictionaryRef match; |
145 io_service_t device; | 150 io_service_t device; |
151 CFMutableDictionaryRef hidProperties; | |
152 CFTypeRef refCF; | |
146 | 153 |
147 /* Clear all the memory. */ | 154 /* Clear all the memory. */ |
148 SDL_memset(SDL_hapticlist, 0, sizeof(SDL_hapticlist)); | 155 SDL_memset(SDL_hapticlist, 0, sizeof(SDL_hapticlist)); |
149 | 156 |
150 /* Get HID devices. */ | 157 /* Get HID devices. */ |
160 SDL_SetError("Haptic: Couldn't create a HID object iterator."); | 167 SDL_SetError("Haptic: Couldn't create a HID object iterator."); |
161 return -1; | 168 return -1; |
162 } | 169 } |
163 /* IOServiceGetMatchingServices consumes dictionary. */ | 170 /* IOServiceGetMatchingServices consumes dictionary. */ |
164 | 171 |
165 if (!iter) { /* No iterator. */ | 172 if (!IOIteratorIsValid(iter)) { /* No iterator. */ |
166 numhaptics = 0; | 173 numhaptics = 0; |
167 return 0; | 174 return 0; |
168 } | 175 } |
169 | 176 |
170 numhaptics = 0; | 177 numhaptics = 0; |
171 while ((device = IOIteratorNext(iter)) != IO_OBJECT_NULL) { | 178 while ((device = IOIteratorNext(iter)) != IO_OBJECT_NULL) { |
172 | 179 |
173 /* Check for force feedback. */ | 180 /* Check for force feedback. */ |
174 if (FFIsForceFeedback(device) == FF_OK) { | 181 if (FFIsForceFeedback(device) == FF_OK) { |
182 | |
183 /* Set basic device data. */ | |
175 HIDGetDeviceProduct(device, SDL_hapticlist[numhaptics].name); | 184 HIDGetDeviceProduct(device, SDL_hapticlist[numhaptics].name); |
176 SDL_hapticlist[numhaptics].dev = device; | 185 SDL_hapticlist[numhaptics].dev = device; |
177 SDL_hapticlist[numhaptics].haptic = NULL; | 186 SDL_hapticlist[numhaptics].haptic = NULL; |
187 | |
188 /* Set usage pages. */ | |
189 hidProperties = 0; | |
190 refCF = 0; | |
191 result = IORegistryEntryCreateCFProperties(device, | |
192 &hidProperties, kCFAllocatorDefault, kNilOptions); | |
193 if ((result == KERN_SUCCESS) && hidProperties) { | |
194 refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); | |
195 if (refCF) { | |
196 if (!CFNumberGetValue(refCF, kCFNumberLongType, | |
197 &SDL_hapticlist[numhaptics].usagePage)) | |
198 SDL_SetError("Haptic: CFNumberGetValue error retrieving pDevice->usagePage."); | |
199 refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); | |
200 if (refCF) { | |
201 if (!CFNumberGetValue(refCF, kCFNumberLongType, | |
202 &SDL_hapticlist[numhaptics].usage)) | |
203 SDL_SetError("Haptic: CFNumberGetValue error retrieving pDevice->usage."); | |
204 } | |
205 } | |
206 CFRelease(hidProperties); | |
207 } | |
208 | |
209 | |
210 /* Device has been added. */ | |
178 numhaptics++; | 211 numhaptics++; |
179 } | 212 } |
180 else { /* Free the unused device. */ | 213 else { /* Free the unused device. */ |
181 IOObjectRelease(device); | 214 IOObjectRelease(device); |
182 } | 215 } |
244 refCF = | 277 refCF = |
245 CFDictionaryGetValue(usbProperties, CFSTR("USB Product Name")); | 278 CFDictionaryGetValue(usbProperties, CFSTR("USB Product Name")); |
246 if (refCF) { | 279 if (refCF) { |
247 if (!CFStringGetCString(refCF, name, 256, | 280 if (!CFStringGetCString(refCF, name, 256, |
248 CFStringGetSystemEncoding())) { | 281 CFStringGetSystemEncoding())) { |
249 SDL_SetError("CFStringGetCString error retrieving pDevice->product."); | 282 SDL_SetError("Haptic: CFStringGetCString error retrieving pDevice->product."); |
250 return -1; | 283 return -1; |
251 } | 284 } |
252 } | 285 } |
253 | 286 |
254 CFRelease(usbProperties); | 287 CFRelease(usbProperties); |
255 } | 288 } |
256 else { | 289 else { |
257 SDL_SetError("IORegistryEntryCreateCFProperties failed to create usbProperties."); | 290 SDL_SetError("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties."); |
258 return -1; | 291 return -1; |
259 } | 292 } |
260 | 293 |
261 /* Release stuff. */ | 294 /* Release stuff. */ |
262 if (kIOReturnSuccess != IOObjectRelease(parent2)) { | 295 if (kIOReturnSuccess != IOObjectRelease(parent2)) { |
263 SDL_SetError("IOObjectRelease error with parent2."); | 296 SDL_SetError("Haptic: IOObjectRelease error with parent2."); |
264 } | 297 } |
265 if (kIOReturnSuccess != IOObjectRelease(parent1)) { | 298 if (kIOReturnSuccess != IOObjectRelease(parent1)) { |
266 SDL_SetError("IOObjectRelease error with parent1."); | 299 SDL_SetError("Haptic: IOObjectRelease error with parent1."); |
267 } | 300 } |
268 } | 301 } |
269 else { | 302 else { |
270 SDL_SetError("Haptic: Error getting registry entries."); | 303 SDL_SetError("Haptic: Error getting registry entries."); |
271 return -1; | 304 return -1; |
440 * Opens a haptic device from first mouse it finds for usage. | 473 * Opens a haptic device from first mouse it finds for usage. |
441 */ | 474 */ |
442 int | 475 int |
443 SDL_SYS_HapticMouse(void) | 476 SDL_SYS_HapticMouse(void) |
444 { | 477 { |
478 int i; | |
479 | |
480 for (i=0; i<SDL_numhaptics; i++) { | |
481 if ((SDL_hapticlist[i].usagePage == kHIDPage_GenericDesktop) && | |
482 (SDL_hapticlist[i].usage == kHIDUsage_GD_Mouse)) | |
483 return i; | |
484 } | |
485 | |
445 return -1; | 486 return -1; |
446 } | 487 } |
447 | 488 |
448 | 489 |
449 /* | 490 /* |