Mercurial > sdl-ios-xcode
comparison src/haptic/darwin/SDL_syshaptic.c @ 2522:0877146be013 gsoc2008_force_feedback
Now compiles cleanly (has yet to work though).
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Tue, 15 Jul 2008 17:35:06 +0000 |
parents | 7aa91c21ce5f |
children | 924a32719b6f |
comparison
equal
deleted
inserted
replaced
2521:7aa91c21ce5f | 2522:0877146be013 |
---|---|
27 #include "../SDL_syshaptic.h" | 27 #include "../SDL_syshaptic.h" |
28 #include "SDL_joystick.h" | 28 #include "SDL_joystick.h" |
29 #include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */ | 29 #include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */ |
30 /*#include "../../joystick/dawrin/SDL_sysjoystick_c.h"*/ /* For joystick hwdata */ | 30 /*#include "../../joystick/dawrin/SDL_sysjoystick_c.h"*/ /* For joystick hwdata */ |
31 | 31 |
32 #include <IOKit/IOTypes.h> | 32 #include <IOKit/IOKitLib.h> |
33 #include <IOKit/hid/IOHIDKeys.h> | |
33 #include <ForceFeedback/ForceFeedback.h> | 34 #include <ForceFeedback/ForceFeedback.h> |
34 #include <ForceFeedback/ForceFeedbackConstants.h> | 35 #include <ForceFeedback/ForceFeedbackConstants.h> |
35 | 36 |
36 | 37 |
37 #define MAX_HAPTICS 32 | 38 #define MAX_HAPTICS 32 |
163 FF_TEST(FFCAP_ET_FRICTION, SDL_HAPTIC_FRICTION); | 164 FF_TEST(FFCAP_ET_FRICTION, SDL_HAPTIC_FRICTION); |
164 FF_TEST(FFCAP_ET_CUSTOMFORCE, SDL_HAPTIC_CUSTOM); | 165 FF_TEST(FFCAP_ET_CUSTOMFORCE, SDL_HAPTIC_CUSTOM); |
165 | 166 |
166 /* Check if supports gain. */ | 167 /* Check if supports gain. */ |
167 ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFGAIN, | 168 ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFGAIN, |
168 val, sizeof(val)); | 169 &val, sizeof(val)); |
169 if (ret == FF_OK) supported |= SDL_HAPTIC_GAIN; | 170 if (ret == FF_OK) supported |= SDL_HAPTIC_GAIN; |
170 else if (ret != FFERR_UNSUPPORTED) { | 171 else if (ret != FFERR_UNSUPPORTED) { |
171 SDL_SetError("Haptic: Unable to get if device supports gain."); | 172 SDL_SetError("Haptic: Unable to get if device supports gain."); |
172 return 0; | 173 return 0; |
173 } | 174 } |
174 | 175 |
175 /* Checks if supports autocenter. */ | 176 /* Checks if supports autocenter. */ |
176 ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER, | 177 ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER, |
177 val, sizeof(val)); | 178 &val, sizeof(val)); |
178 if (ret == FF_OK) supported |= SDL_HAPTIC_AUTOCENTER; | 179 if (ret == FF_OK) supported |= SDL_HAPTIC_AUTOCENTER; |
179 else if (ret != FFERR_UNSUPPORTED) { | 180 else if (ret != FFERR_UNSUPPORTED) { |
180 SDL_SetError("Haptic: Unable to get if device supports autocenter."); | 181 SDL_SetError("Haptic: Unable to get if device supports autocenter."); |
181 return 0; | 182 return 0; |
182 } | 183 } |
201 goto creat_err; | 202 goto creat_err; |
202 } | 203 } |
203 SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); | 204 SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); |
204 | 205 |
205 /* Open the device */ | 206 /* Open the device */ |
206 if (FFCreateDevice( &service, &haptic->hwdata->device ) != FF_OK) { | 207 if (FFCreateDevice( service, &haptic->hwdata->device ) != FF_OK) { |
207 SDL_SetError("Haptic: Unable to create device from service."); | 208 SDL_SetError("Haptic: Unable to create device from service."); |
208 goto creat_err; | 209 goto creat_err; |
209 } | 210 } |
210 | 211 |
211 /* Get supported features. */ | 212 /* Get supported features. */ |
244 */ | 245 */ |
245 int | 246 int |
246 SDL_SYS_HapticOpen(SDL_Haptic * haptic) | 247 SDL_SYS_HapticOpen(SDL_Haptic * haptic) |
247 { | 248 { |
248 return SDL_SYS_HapticOpenFromService(haptic, | 249 return SDL_SYS_HapticOpenFromService(haptic, |
249 SDL_hapticlist[haptic->index].device); | 250 SDL_hapticlist[haptic->index].dev); |
250 } | 251 } |
251 | 252 |
252 | 253 |
253 /* | 254 /* |
254 * Opens a haptic device from first mouse it finds for usage. | 255 * Opens a haptic device from first mouse it finds for usage. |
353 case SDL_HAPTIC_POLAR: | 354 case SDL_HAPTIC_POLAR: |
354 effect->dwFlags |= FFEFF_POLAR; | 355 effect->dwFlags |= FFEFF_POLAR; |
355 rglDir[0] = dir->dir[0]; | 356 rglDir[0] = dir->dir[0]; |
356 return 0; | 357 return 0; |
357 case SDL_HAPTIC_CARTESIAN: | 358 case SDL_HAPTIC_CARTESIAN: |
358 effects->dwFlags |= FFEFF_CARTESIAN; | 359 effect->dwFlags |= FFEFF_CARTESIAN; |
359 rglDir[0] = dir->dir[0]; | 360 rglDir[0] = dir->dir[0]; |
360 rglDir[1] = dir->dir[1]; | 361 rglDir[1] = dir->dir[1]; |
361 rglDir[2] = dir->dir[2]; | 362 rglDir[2] = dir->dir[2]; |
362 return 0; | 363 return 0; |
363 case SDL_HAPTIC_SPHERICAL: | 364 case SDL_HAPTIC_SPHERICAL: |
364 effects->dwFlags |= FFEFF_SPHERICAL; | 365 effect->dwFlags |= FFEFF_SPHERICAL; |
365 rglDir[0] = dir->dir[0]; | 366 rglDir[0] = dir->dir[0]; |
366 rglDir[1] = dir->dir[1]; | 367 rglDir[1] = dir->dir[1]; |
367 rglDir[2] = dir->dir[2]; | 368 rglDir[2] = dir->dir[2]; |
368 return 0; | 369 return 0; |
369 | 370 |
383 FFCONSTANTFORCE *constant; | 384 FFCONSTANTFORCE *constant; |
384 FFPERIODIC *periodic; | 385 FFPERIODIC *periodic; |
385 FFCONDITION *condition; | 386 FFCONDITION *condition; |
386 FFRAMPFORCE *ramp; | 387 FFRAMPFORCE *ramp; |
387 FFCUSTOMFORCE *custom; | 388 FFCUSTOMFORCE *custom; |
389 FFENVELOPE *envelope; | |
388 SDL_HapticConstant *hap_constant; | 390 SDL_HapticConstant *hap_constant; |
389 SDL_HapticPeriodic *hap_periodic; | 391 SDL_HapticPeriodic *hap_periodic; |
390 SDL_HapticCondition *hap_condition; | 392 SDL_HapticCondition *hap_condition; |
391 SDL_HapticRamp *hap_ramp; | 393 SDL_HapticRamp *hap_ramp; |
392 | 394 |
393 /* Set global stuff. */ | 395 /* Set global stuff. */ |
394 SDL_memset(dest, 0, sizeof(FFEFFECT)); | 396 SDL_memset(dest, 0, sizeof(FFEFFECT)); |
395 dest->dwSize = sizeof(FFEFFECT); /* Set the structure size. */ | 397 dest->dwSize = sizeof(FFEFFECT); /* Set the structure size. */ |
396 dest->dwSamplePeriod = 0; /* Not used by us. */ | 398 dest->dwSamplePeriod = 0; /* Not used by us. */ |
397 dest->dwGain = 10000; /* Gain is set globally, not locally. */ | 399 dest->dwGain = 10000; /* Gain is set globally, not locally. */ |
398 dest->lpEnvelope.dwSize = sizeof(FFENVELOPE); /* Always should be this. */ | 400 |
401 /* Envelope. */ | |
402 envelope = SDL_malloc( sizeof(FFENVELOPE) ); | |
403 if (envelope == NULL) { | |
404 SDL_OutOfMemory(); | |
405 return -1; | |
406 } | |
407 SDL_memset(envelope, 0, sizeof(FFENVELOPE)); | |
408 dest->lpEnvelope = envelope; | |
409 envelope->dwSize = sizeof(FFENVELOPE); /* Always should be this. */ | |
399 | 410 |
400 switch (src->type) { | 411 switch (src->type) { |
401 case SDL_HAPTIC_CONSTANT: | 412 case SDL_HAPTIC_CONSTANT: |
402 hap_constant = &src->constant; | 413 hap_constant = &src->constant; |
403 constant = SDL_malloc( sizeof(FFCONSTANTFORCE) ); | 414 constant = SDL_malloc( sizeof(FFCONSTANTFORCE) ); |
416 /* Axes */ | 427 /* Axes */ |
417 dest->cAxes = 2; /* TODO handle */ | 428 dest->cAxes = 2; /* TODO handle */ |
418 dest->rgdwAxes = 0; | 429 dest->rgdwAxes = 0; |
419 | 430 |
420 /* Direction. */ | 431 /* Direction. */ |
421 if (SDL_SYS_SetDirection(dest, hap_constant->direction, dest->cAxes) < 0) { | 432 if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) { |
422 return -1; | 433 return -1; |
423 } | 434 } |
424 | 435 |
425 /* Envelope */ | 436 /* Envelope */ |
426 dest->lpEnvelope.dwAttackLevel = CONVERT(hap_constant->attack_level); | 437 envelope->dwAttackLevel = CONVERT(hap_constant->attack_level); |
427 dest->lpEnvelope.dwAttackTime = hap_constant->attack_length * 1000; | 438 envelope->dwAttackTime = hap_constant->attack_length * 1000; |
428 dest->lpEnvelope.dwFadeLevel = CONVERT(hap_constant->fade_level); | 439 envelope->dwFadeLevel = CONVERT(hap_constant->fade_level); |
429 dest->lpEnvelope.dwFadeTime = hap_constant->fade_length * 1000; | 440 envelope->dwFadeTime = hap_constant->fade_length * 1000; |
430 | 441 |
431 break; | 442 break; |
432 | 443 |
433 /* TODO finish */ | 444 /* TODO finish */ |
434 | 445 |
435 case SDL_HAPTIC_SINE: | 446 case SDL_HAPTIC_SINE: |
436 case SDL_HAPTIC_SQUARE: | 447 case SDL_HAPTIC_SQUARE: |
437 case SDL_HAPTIC_TRIANGLE: | 448 case SDL_HAPTIC_TRIANGLE: |
438 case SDL_HAPTIC_SAWTOOTHUP: | 449 case SDL_HAPTIC_SAWTOOTHUP: |
439 case SDL_HAPTIC_SAWTOOTHDOWN: | 450 case SDL_HAPTIC_SAWTOOTHDOWN: |
440 periodic = &src->periodic; | 451 hap_periodic = &src->periodic; |
441 | 452 |
442 break; | 453 break; |
443 | 454 |
444 case SDL_HAPTIC_SPRING: | 455 case SDL_HAPTIC_SPRING: |
445 case SDL_HAPTIC_DAMPER: | 456 case SDL_HAPTIC_DAMPER: |
446 case SDL_HAPTIC_INERTIA: | 457 case SDL_HAPTIC_INERTIA: |
447 case SDL_HAPTIC_FRICTION: | 458 case SDL_HAPTIC_FRICTION: |
448 condition = &src->condition; | 459 hap_condition = &src->condition; |
449 | 460 |
450 break; | 461 break; |
451 | 462 |
452 case SDL_HAPTIC_RAMP: | 463 case SDL_HAPTIC_RAMP: |
453 ramp = &src->ramp; | 464 hap_ramp = &src->ramp; |
454 | 465 |
455 break; | 466 break; |
456 | 467 |
457 | 468 |
458 default: | 469 default: |