Mercurial > sdl-ios-xcode
comparison src/haptic/linux/SDL_syshaptic.c @ 2500:5251d0510b7e gsoc2008_force_feedback
Implemented polar coordinates in linux.
SDL_ConditionEffect now takes into account both axes.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Sun, 06 Jul 2008 21:47:41 +0000 |
parents | 8f840a6cdf01 |
children | 5356ca0c36a3 |
comparison
equal
deleted
inserted
replaced
2499:cc2b270608b2 | 2500:5251d0510b7e |
---|---|
109 EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER); | 109 EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER); |
110 | 110 |
111 return ret; | 111 return ret; |
112 } | 112 } |
113 | 113 |
114 /* | |
115 * Initializes the haptic subsystem by finding available devices. | |
116 */ | |
114 int | 117 int |
115 SDL_SYS_HapticInit(void) | 118 SDL_SYS_HapticInit(void) |
116 { | 119 { |
117 const char joydev_pattern[] = "/dev/input/event%d"; | 120 const char joydev_pattern[] = "/dev/input/event%d"; |
118 dev_t dev_nums[MAX_HAPTICS]; | 121 dev_t dev_nums[MAX_HAPTICS]; |
326 SDL_free(SDL_hapticlist[i].fname); | 329 SDL_free(SDL_hapticlist[i].fname); |
327 } | 330 } |
328 SDL_hapticlist[0].fname = NULL; | 331 SDL_hapticlist[0].fname = NULL; |
329 } | 332 } |
330 | 333 |
334 /* | |
335 * Returns the ff_effect usable direction from a SDL_HapticDirection. | |
336 */ | |
337 static Uint16 | |
338 SDL_SYS_ToDirection( SDL_HapticDirection * dir ) | |
339 { | |
340 Uint32 tmp; | |
341 | |
342 switch (dir->type) { | |
343 case SDL_HAPTIC_POLAR: | |
344 tmp = ((dir->dir[0] % 36000) * 0xFFFF) / 36000; | |
345 return (Uint16) tmp; | |
346 break; | |
347 case SDL_HAPTIC_CARTESIAN: | |
348 /* TODO implement cartesian for linux since it's not supported | |
349 * by driver */ | |
350 break; | |
351 | |
352 default: | |
353 return -1; | |
354 } | |
355 | |
356 return 0; | |
357 } | |
358 | |
331 #define CLAMP(x) (((x) > 32767) ? 32767 : x) | 359 #define CLAMP(x) (((x) > 32767) ? 32767 : x) |
332 /* | 360 /* |
333 * Initializes the linux effect struct from a haptic_effect. | 361 * Initializes the linux effect struct from a haptic_effect. |
334 * Values above 32767 (for unsigned) are unspecified so we must clamp. | 362 * Values above 32767 (for unsigned) are unspecified so we must clamp. |
335 */ | 363 */ |
349 case SDL_HAPTIC_CONSTANT: | 377 case SDL_HAPTIC_CONSTANT: |
350 constant = &src->constant; | 378 constant = &src->constant; |
351 | 379 |
352 /* Header */ | 380 /* Header */ |
353 dest->type = FF_CONSTANT; | 381 dest->type = FF_CONSTANT; |
354 dest->direction = CLAMP(constant->direction); | 382 dest->direction = SDL_SYS_ToDirection(&constant->direction); |
355 | 383 |
356 /* Replay */ | 384 /* Replay */ |
357 dest->replay.length = CLAMP(constant->length); | 385 dest->replay.length = CLAMP(constant->length); |
358 dest->replay.delay = CLAMP(constant->delay); | 386 dest->replay.delay = CLAMP(constant->delay); |
359 | 387 |
379 case SDL_HAPTIC_SAWTOOTHDOWN: | 407 case SDL_HAPTIC_SAWTOOTHDOWN: |
380 periodic = &src->periodic; | 408 periodic = &src->periodic; |
381 | 409 |
382 /* Header */ | 410 /* Header */ |
383 dest->type = FF_PERIODIC; | 411 dest->type = FF_PERIODIC; |
384 dest->direction = CLAMP(periodic->direction); | 412 dest->direction = SDL_SYS_ToDirection(&periodic->direction); |
385 | 413 |
386 /* Replay */ | 414 /* Replay */ |
387 dest->replay.length = CLAMP(periodic->length); | 415 dest->replay.length = CLAMP(periodic->length); |
388 dest->replay.delay = CLAMP(periodic->delay); | 416 dest->replay.delay = CLAMP(periodic->delay); |
389 | 417 |
428 dest->type = FF_DAMPER; | 456 dest->type = FF_DAMPER; |
429 else if (dest->type == SDL_HAPTIC_INERTIA) | 457 else if (dest->type == SDL_HAPTIC_INERTIA) |
430 dest->type = FF_INERTIA; | 458 dest->type = FF_INERTIA; |
431 else if (dest->type == SDL_HAPTIC_FRICTION) | 459 else if (dest->type == SDL_HAPTIC_FRICTION) |
432 dest->type = FF_FRICTION; | 460 dest->type = FF_FRICTION; |
433 dest->direction = CLAMP(condition->direction); | 461 dest->direction = 0; /* Handled by the condition-specifics. */ |
434 | 462 |
435 /* Replay */ | 463 /* Replay */ |
436 dest->replay.length = CLAMP(condition->length); | 464 dest->replay.length = CLAMP(condition->length); |
437 dest->replay.delay = CLAMP(condition->delay); | 465 dest->replay.delay = CLAMP(condition->delay); |
438 | 466 |
439 /* Trigger */ | 467 /* Trigger */ |
440 dest->trigger.button = CLAMP(condition->button); | 468 dest->trigger.button = CLAMP(condition->button); |
441 dest->trigger.interval = CLAMP(condition->interval); | 469 dest->trigger.interval = CLAMP(condition->interval); |
442 | 470 |
443 /* Condition - TODO handle axes */ | 471 /* Condition */ |
444 dest->u.condition[0].right_saturation = CLAMP(condition->right_sat); | 472 /* X axis */ |
445 dest->u.condition[0].left_saturation = CLAMP(condition->left_sat); | 473 dest->u.condition[0].right_saturation = CLAMP(condition->right_sat[0]); |
446 dest->u.condition[0].right_coeff = condition->right_coeff; | 474 dest->u.condition[0].left_saturation = CLAMP(condition->left_sat[0]); |
447 dest->u.condition[0].left_coeff = condition->left_coeff; | 475 dest->u.condition[0].right_coeff = condition->right_coeff[0]; |
448 dest->u.condition[0].deadband = CLAMP(condition->deadband); | 476 dest->u.condition[0].left_coeff = condition->left_coeff[0]; |
449 dest->u.condition[0].center = condition->center; | 477 dest->u.condition[0].deadband = CLAMP(condition->deadband[0]); |
478 dest->u.condition[0].center = condition->center[0]; | |
479 /* Y axis */ | |
480 dest->u.condition[1].right_saturation = CLAMP(condition->right_sat[1]); | |
481 dest->u.condition[1].left_saturation = CLAMP(condition->left_sat[1]); | |
482 dest->u.condition[1].right_coeff = condition->right_coeff[1]; | |
483 dest->u.condition[1].left_coeff = condition->left_coeff[1]; | |
484 dest->u.condition[1].deadband = CLAMP(condition->deadband[1]); | |
485 dest->u.condition[1].center = condition->center[1]; | |
450 | 486 |
451 break; | 487 break; |
452 | 488 |
453 case SDL_HAPTIC_RAMP: | 489 case SDL_HAPTIC_RAMP: |
454 ramp = &src->ramp; | 490 ramp = &src->ramp; |
455 | 491 |
456 /* Header */ | 492 /* Header */ |
457 dest->type = FF_RAMP; | 493 dest->type = FF_RAMP; |
458 dest->direction = CLAMP(ramp->direction); | 494 dest->direction = SDL_SYS_ToDirection(&ramp->direction); |
459 | 495 |
460 /* Replay */ | 496 /* Replay */ |
461 dest->replay.length = CLAMP(ramp->length); | 497 dest->replay.length = CLAMP(ramp->length); |
462 dest->replay.delay = CLAMP(ramp->delay); | 498 dest->replay.delay = CLAMP(ramp->delay); |
463 | 499 |