Atlas - SDL_haptic.h
Home / ext / SDL2 / include Lines: 5 | Size: 38818 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2018 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22/** 23 * \file SDL_haptic.h 24 * 25 * \brief The SDL haptic subsystem allows you to control haptic (force feedback) 26 * devices. 27 * 28 * The basic usage is as follows: 29 * - Initialize the subsystem (::SDL_INIT_HAPTIC). 30 * - Open a haptic device. 31 * - SDL_HapticOpen() to open from index. 32 * - SDL_HapticOpenFromJoystick() to open from an existing joystick. 33 * - Create an effect (::SDL_HapticEffect). 34 * - Upload the effect with SDL_HapticNewEffect(). 35 * - Run the effect with SDL_HapticRunEffect(). 36 * - (optional) Free the effect with SDL_HapticDestroyEffect(). 37 * - Close the haptic device with SDL_HapticClose(). 38 * 39 * \par Simple rumble example: 40 * \code 41 * SDL_Haptic *haptic; 42 * 43 * // Open the device 44 * haptic = SDL_HapticOpen( 0 ); 45 * if (haptic == NULL) 46 * return -1; 47 * 48 * // Initialize simple rumble 49 * if (SDL_HapticRumbleInit( haptic ) != 0) 50 * return -1; 51 * 52 * // Play effect at 50% strength for 2 seconds 53 * if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0) 54 * return -1; 55 * SDL_Delay( 2000 ); 56 * 57 * // Clean up 58 * SDL_HapticClose( haptic ); 59 * \endcode 60 * 61 * \par Complete example: 62 * \code 63 * int test_haptic( SDL_Joystick * joystick ) { 64 * SDL_Haptic *haptic; 65 * SDL_HapticEffect effect; 66 * int effect_id; 67 * 68 * // Open the device 69 * haptic = SDL_HapticOpenFromJoystick( joystick ); 70 * if (haptic == NULL) return -1; // Most likely joystick isn't haptic 71 * 72 * // See if it can do sine waves 73 * if ((SDL_HapticQuery(haptic) & SDL_HAPTIC_SINE)==0) { 74 * SDL_HapticClose(haptic); // No sine effect 75 * return -1; 76 * } 77 * 78 * // Create the effect 79 * memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default 80 * effect.type = SDL_HAPTIC_SINE; 81 * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates 82 * effect.periodic.direction.dir[0] = 18000; // Force comes from south 83 * effect.periodic.period = 1000; // 1000 ms 84 * effect.periodic.magnitude = 20000; // 20000/32767 strength 85 * effect.periodic.length = 5000; // 5 seconds long 86 * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength 87 * effect.periodic.fade_length = 1000; // Takes 1 second to fade away 88 * 89 * // Upload the effect 90 * effect_id = SDL_HapticNewEffect( haptic, &effect ); 91 * 92 * // Test the effect 93 * SDL_HapticRunEffect( haptic, effect_id, 1 ); 94 * SDL_Delay( 5000); // Wait for the effect to finish 95 * 96 * // We destroy the effect, although closing the device also does this 97 * SDL_HapticDestroyEffect( haptic, effect_id ); 98 * 99 * // Close the device 100 * SDL_HapticClose(haptic); 101 * 102 * return 0; // Success 103 * } 104 * \endcode 105 */ 106 107#ifndef SDL_haptic_h_ 108#define SDL_haptic_h_ 109 110#include "SDL_stdinc.h" 111#include "SDL_error.h" 112#include "SDL_joystick.h" 113 114#include "begin_code.h" 115/* Set up for C function definitions, even when using C++ */ 116#ifdef __cplusplus 117extern "C" { 118#endif /* __cplusplus */ 119 120/** 121 * \typedef SDL_Haptic 122 * 123 * \brief The haptic structure used to identify an SDL haptic. 124 * 125 * \sa SDL_HapticOpen 126 * \sa SDL_HapticOpenFromJoystick 127 * \sa SDL_HapticClose 128 */ 129struct _SDL_Haptic; 130typedef struct _SDL_Haptic SDL_Haptic; 131 132 133/** 134 * \name Haptic features 135 * 136 * Different haptic features a device can have. 137 */ 138/* @{ */ 139 140/** 141 * \name Haptic effects 142 */ 143/* @{ */ 144 145/** 146 * \brief Constant effect supported. 147 * 148 * Constant haptic effect. 149 * 150 * \sa SDL_HapticCondition 151 */ 152#define SDL_HAPTIC_CONSTANT (1u<<0) 153 154/** 155 * \brief Sine wave effect supported. 156 * 157 * Periodic haptic effect that simulates sine waves. 158 * 159 * \sa SDL_HapticPeriodic 160 */ 161#define SDL_HAPTIC_SINE (1u<<1) 162 163/** 164 * \brief Left/Right effect supported. 165 * 166 * Haptic effect for direct control over high/low frequency motors. 167 * 168 * \sa SDL_HapticLeftRight 169 * \warning this value was SDL_HAPTIC_SQUARE right before 2.0.0 shipped. Sorry, 170 * we ran out of bits, and this is important for XInput devices. 171 */ 172#define SDL_HAPTIC_LEFTRIGHT (1u<<2) 173 174/* !!! FIXME: put this back when we have more bits in 2.1 */ 175/* #define SDL_HAPTIC_SQUARE (1<<2) */ 176 177/** 178 * \brief Triangle wave effect supported. 179 * 180 * Periodic haptic effect that simulates triangular waves. 181 * 182 * \sa SDL_HapticPeriodic 183 */ 184#define SDL_HAPTIC_TRIANGLE (1u<<3) 185 186/** 187 * \brief Sawtoothup wave effect supported. 188 * 189 * Periodic haptic effect that simulates saw tooth up waves. 190 * 191 * \sa SDL_HapticPeriodic 192 */ 193#define SDL_HAPTIC_SAWTOOTHUP (1u<<4) 194 195/** 196 * \brief Sawtoothdown wave effect supported. 197 * 198 * Periodic haptic effect that simulates saw tooth down waves. 199 * 200 * \sa SDL_HapticPeriodic 201 */ 202#define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5) 203 204/** 205 * \brief Ramp effect supported. 206 * 207 * Ramp haptic effect. 208 * 209 * \sa SDL_HapticRamp 210 */ 211#define SDL_HAPTIC_RAMP (1u<<6) 212 213/** 214 * \brief Spring effect supported - uses axes position. 215 * 216 * Condition haptic effect that simulates a spring. Effect is based on the 217 * axes position. 218 * 219 * \sa SDL_HapticCondition 220 */ 221#define SDL_HAPTIC_SPRING (1u<<7) 222 223/** 224 * \brief Damper effect supported - uses axes velocity. 225 * 226 * Condition haptic effect that simulates dampening. Effect is based on the 227 * axes velocity. 228 * 229 * \sa SDL_HapticCondition 230 */ 231#define SDL_HAPTIC_DAMPER (1u<<8) 232 233/** 234 * \brief Inertia effect supported - uses axes acceleration. 235 * 236 * Condition haptic effect that simulates inertia. Effect is based on the axes 237 * acceleration. 238 * 239 * \sa SDL_HapticCondition 240 */ 241#define SDL_HAPTIC_INERTIA (1u<<9) 242 243/** 244 * \brief Friction effect supported - uses axes movement. 245 * 246 * Condition haptic effect that simulates friction. Effect is based on the 247 * axes movement. 248 * 249 * \sa SDL_HapticCondition 250 */ 251#define SDL_HAPTIC_FRICTION (1u<<10) 252 253/** 254 * \brief Custom effect is supported. 255 * 256 * User defined custom haptic effect. 257 */ 258#define SDL_HAPTIC_CUSTOM (1u<<11) 259 260/* @} *//* Haptic effects */ 261 262/* These last few are features the device has, not effects */ 263 264/** 265 * \brief Device can set global gain. 266 * 267 * Device supports setting the global gain. 268 * 269 * \sa SDL_HapticSetGain 270 */ 271#define SDL_HAPTIC_GAIN (1u<<12) 272 273/** 274 * \brief Device can set autocenter. 275 * 276 * Device supports setting autocenter. 277 * 278 * \sa SDL_HapticSetAutocenter 279 */ 280#define SDL_HAPTIC_AUTOCENTER (1u<<13) 281 282/** 283 * \brief Device can be queried for effect status. 284 * 285 * Device supports querying effect status. 286 * 287 * \sa SDL_HapticGetEffectStatus 288 */ 289#define SDL_HAPTIC_STATUS (1u<<14) 290 291/** 292 * \brief Device can be paused. 293 * 294 * Devices supports being paused. 295 * 296 * \sa SDL_HapticPause 297 * \sa SDL_HapticUnpause 298 */ 299#define SDL_HAPTIC_PAUSE (1u<<15) 300 301 302/** 303 * \name Direction encodings 304 */ 305/* @{ */ 306 307/** 308 * \brief Uses polar coordinates for the direction. 309 * 310 * \sa SDL_HapticDirection 311 */ 312#define SDL_HAPTIC_POLAR 0 313 314/** 315 * \brief Uses cartesian coordinates for the direction. 316 * 317 * \sa SDL_HapticDirection 318 */ 319#define SDL_HAPTIC_CARTESIAN 1 320 321/** 322 * \brief Uses spherical coordinates for the direction. 323 * 324 * \sa SDL_HapticDirection 325 */ 326#define SDL_HAPTIC_SPHERICAL 2 327 328/* @} *//* Direction encodings */ 329 330/* @} *//* Haptic features */ 331 332/* 333 * Misc defines. 334 */ 335 336/** 337 * \brief Used to play a device an infinite number of times. 338 * 339 * \sa SDL_HapticRunEffect 340 */ 341#define SDL_HAPTIC_INFINITY 4294967295U 342 343 344/** 345 * \brief Structure that represents a haptic direction. 346 * 347 * This is the direction where the force comes from, 348 * instead of the direction in which the force is exerted. 349 * 350 * Directions can be specified by: 351 * - ::SDL_HAPTIC_POLAR : Specified by polar coordinates. 352 * - ::SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates. 353 * - ::SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates. 354 * 355 * Cardinal directions of the haptic device are relative to the positioning 356 * of the device. North is considered to be away from the user. 357 * 358 * The following diagram represents the cardinal directions: 359 * \verbatim 360 .--. 361 |__| .-------. 362 |=.| |.-----.| 363 |--| || || 364 | | |'-----'| 365 |__|~')_____(' 366 [ COMPUTER ] 367 368 369 North (0,-1) 370 ^ 371 | 372 | 373 (-1,0) West <----[ HAPTIC ]----> East (1,0) 374 | 375 | 376 v 377 South (0,1) 378 379 380 [ USER ] 381 \|||/ 382 (o o) 383 ---ooO-(_)-Ooo--- 384 \endverbatim 385 * 386 * If type is ::SDL_HAPTIC_POLAR, direction is encoded by hundredths of a 387 * degree starting north and turning clockwise. ::SDL_HAPTIC_POLAR only uses 388 * the first \c dir parameter. The cardinal directions would be: 389 * - North: 0 (0 degrees) 390 * - East: 9000 (90 degrees) 391 * - South: 18000 (180 degrees) 392 * - West: 27000 (270 degrees) 393 * 394 * If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions 395 * (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses 396 * the first three \c dir parameters. The cardinal directions would be: 397 * - North: 0,-1, 0 398 * - East: 1, 0, 0 399 * - South: 0, 1, 0 400 * - West: -1, 0, 0 401 * 402 * The Z axis represents the height of the effect if supported, otherwise 403 * it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you 404 * can use any multiple you want, only the direction matters. 405 * 406 * If type is ::SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations. 407 * The first two \c dir parameters are used. The \c dir parameters are as 408 * follows (all values are in hundredths of degrees): 409 * - Degrees from (1, 0) rotated towards (0, 1). 410 * - Degrees towards (0, 0, 1) (device needs at least 3 axes). 411 * 412 * 413 * Example of force coming from the south with all encodings (force coming 414 * from the south means the user will have to pull the stick to counteract): 415 * \code 416 * SDL_HapticDirection direction; 417 * 418 * // Cartesian directions 419 * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding. 420 * direction.dir[0] = 0; // X position 421 * direction.dir[1] = 1; // Y position 422 * // Assuming the device has 2 axes, we don't need to specify third parameter. 423 * 424 * // Polar directions 425 * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding. 426 * direction.dir[0] = 18000; // Polar only uses first parameter 427 * 428 * // Spherical coordinates 429 * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding 430 * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters. 431 * \endcode 432 * 433 * \sa SDL_HAPTIC_POLAR 434 * \sa SDL_HAPTIC_CARTESIAN 435 * \sa SDL_HAPTIC_SPHERICAL 436 * \sa SDL_HapticEffect 437 * \sa SDL_HapticNumAxes 438 */ 439typedef struct SDL_HapticDirection 440{ 441 Uint8 type; /**< The type of encoding. */ 442 Sint32 dir[3]; /**< The encoded direction. */ 443} SDL_HapticDirection; 444 445 446/** 447 * \brief A structure containing a template for a Constant effect. 448 * 449 * This struct is exclusively for the ::SDL_HAPTIC_CONSTANT effect. 450 * 451 * A constant effect applies a constant force in the specified direction 452 * to the joystick. 453 * 454 * \sa SDL_HAPTIC_CONSTANT 455 * \sa SDL_HapticEffect 456 */ 457typedef struct SDL_HapticConstant 458{ 459 /* Header */ 460 Uint16 type; /**< ::SDL_HAPTIC_CONSTANT */ 461 SDL_HapticDirection direction; /**< Direction of the effect. */ 462 463 /* Replay */ 464 Uint32 length; /**< Duration of the effect. */ 465 Uint16 delay; /**< Delay before starting the effect. */ 466 467 /* Trigger */ 468 Uint16 button; /**< Button that triggers the effect. */ 469 Uint16 interval; /**< How soon it can be triggered again after button. */ 470 471 /* Constant */ 472 Sint16 level; /**< Strength of the constant effect. */ 473 474 /* Envelope */ 475 Uint16 attack_length; /**< Duration of the attack. */ 476 Uint16 attack_level; /**< Level at the start of the attack. */ 477 Uint16 fade_length; /**< Duration of the fade. */ 478 Uint16 fade_level; /**< Level at the end of the fade. */ 479} SDL_HapticConstant; 480 481/** 482 * \brief A structure containing a template for a Periodic effect. 483 * 484 * The struct handles the following effects: 485 * - ::SDL_HAPTIC_SINE 486 * - ::SDL_HAPTIC_LEFTRIGHT 487 * - ::SDL_HAPTIC_TRIANGLE 488 * - ::SDL_HAPTIC_SAWTOOTHUP 489 * - ::SDL_HAPTIC_SAWTOOTHDOWN 490 * 491 * A periodic effect consists in a wave-shaped effect that repeats itself 492 * over time. The type determines the shape of the wave and the parameters 493 * determine the dimensions of the wave. 494 * 495 * Phase is given by hundredth of a degree meaning that giving the phase a value 496 * of 9000 will displace it 25% of its period. Here are sample values: 497 * - 0: No phase displacement. 498 * - 9000: Displaced 25% of its period. 499 * - 18000: Displaced 50% of its period. 500 * - 27000: Displaced 75% of its period. 501 * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred. 502 * 503 * Examples: 504 * \verbatim 505 SDL_HAPTIC_SINE 506 __ __ __ __ 507 / \ / \ / \ / 508 / \__/ \__/ \__/ 509 510 SDL_HAPTIC_SQUARE 511 __ __ __ __ __ 512 | | | | | | | | | | 513 | |__| |__| |__| |__| | 514 515 SDL_HAPTIC_TRIANGLE 516 /\ /\ /\ /\ /\ 517 / \ / \ / \ / \ / 518 / \/ \/ \/ \/ 519 520 SDL_HAPTIC_SAWTOOTHUP 521 /| /| /| /| /| /| /| 522 / | / | / | / | / | / | / | 523 / |/ |/ |/ |/ |/ |/ | 524 525 SDL_HAPTIC_SAWTOOTHDOWN 526 \ |\ |\ |\ |\ |\ |\ | 527 \ | \ | \ | \ | \ | \ | \ | 528 \| \| \| \| \| \| \| 529 \endverbatim 530 * 531 * \sa SDL_HAPTIC_SINE 532 * \sa SDL_HAPTIC_LEFTRIGHT 533 * \sa SDL_HAPTIC_TRIANGLE 534 * \sa SDL_HAPTIC_SAWTOOTHUP 535 * \sa SDL_HAPTIC_SAWTOOTHDOWN 536 * \sa SDL_HapticEffect 537 */ 538typedef struct SDL_HapticPeriodic 539{ 540 /* Header */ 541 Uint16 type; /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_LEFTRIGHT, 542 ::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or 543 ::SDL_HAPTIC_SAWTOOTHDOWN */ 544 SDL_HapticDirection direction; /**< Direction of the effect. */ 545 546 /* Replay */ 547 Uint32 length; /**< Duration of the effect. */ 548 Uint16 delay; /**< Delay before starting the effect. */ 549 550 /* Trigger */ 551 Uint16 button; /**< Button that triggers the effect. */ 552 Uint16 interval; /**< How soon it can be triggered again after button. */ 553 554 /* Periodic */ 555 Uint16 period; /**< Period of the wave. */ 556 Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */ 557 Sint16 offset; /**< Mean value of the wave. */ 558 Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */ 559 560 /* Envelope */ 561 Uint16 attack_length; /**< Duration of the attack. */ 562 Uint16 attack_level; /**< Level at the start of the attack. */ 563 Uint16 fade_length; /**< Duration of the fade. */ 564 Uint16 fade_level; /**< Level at the end of the fade. */ 565} SDL_HapticPeriodic; 566 567/** 568 * \brief A structure containing a template for a Condition effect. 569 * 570 * The struct handles the following effects: 571 * - ::SDL_HAPTIC_SPRING: Effect based on axes position. 572 * - ::SDL_HAPTIC_DAMPER: Effect based on axes velocity. 573 * - ::SDL_HAPTIC_INERTIA: Effect based on axes acceleration. 574 * - ::SDL_HAPTIC_FRICTION: Effect based on axes movement. 575 * 576 * Direction is handled by condition internals instead of a direction member. 577 * The condition effect specific members have three parameters. The first 578 * refers to the X axis, the second refers to the Y axis and the third 579 * refers to the Z axis. The right terms refer to the positive side of the 580 * axis and the left terms refer to the negative side of the axis. Please 581 * refer to the ::SDL_HapticDirection diagram for which side is positive and 582 * which is negative. 583 * 584 * \sa SDL_HapticDirection 585 * \sa SDL_HAPTIC_SPRING 586 * \sa SDL_HAPTIC_DAMPER 587 * \sa SDL_HAPTIC_INERTIA 588 * \sa SDL_HAPTIC_FRICTION 589 * \sa SDL_HapticEffect 590 */ 591typedef struct SDL_HapticCondition 592{ 593 /* Header */ 594 Uint16 type; /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER, 595 ::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */ 596 SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */ 597 598 /* Replay */ 599 Uint32 length; /**< Duration of the effect. */ 600 Uint16 delay; /**< Delay before starting the effect. */ 601 602 /* Trigger */ 603 Uint16 button; /**< Button that triggers the effect. */ 604 Uint16 interval; /**< How soon it can be triggered again after button. */ 605 606 /* Condition */ 607 Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */ 608 Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */ 609 Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */ 610 Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */ 611 Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */ 612 Sint16 center[3]; /**< Position of the dead zone. */ 613} SDL_HapticCondition; 614 615/** 616 * \brief A structure containing a template for a Ramp effect. 617 * 618 * This struct is exclusively for the ::SDL_HAPTIC_RAMP effect. 619 * 620 * The ramp effect starts at start strength and ends at end strength. 621 * It augments in linear fashion. If you use attack and fade with a ramp 622 * the effects get added to the ramp effect making the effect become 623 * quadratic instead of linear. 624 * 625 * \sa SDL_HAPTIC_RAMP 626 * \sa SDL_HapticEffect 627 */ 628typedef struct SDL_HapticRamp 629{ 630 /* Header */ 631 Uint16 type; /**< ::SDL_HAPTIC_RAMP */ 632 SDL_HapticDirection direction; /**< Direction of the effect. */ 633 634 /* Replay */ 635 Uint32 length; /**< Duration of the effect. */ 636 Uint16 delay; /**< Delay before starting the effect. */ 637 638 /* Trigger */ 639 Uint16 button; /**< Button that triggers the effect. */ 640 Uint16 interval; /**< How soon it can be triggered again after button. */ 641 642 /* Ramp */ 643 Sint16 start; /**< Beginning strength level. */ 644 Sint16 end; /**< Ending strength level. */ 645 646 /* Envelope */ 647 Uint16 attack_length; /**< Duration of the attack. */ 648 Uint16 attack_level; /**< Level at the start of the attack. */ 649 Uint16 fade_length; /**< Duration of the fade. */ 650 Uint16 fade_level; /**< Level at the end of the fade. */ 651} SDL_HapticRamp; 652 653/** 654 * \brief A structure containing a template for a Left/Right effect. 655 * 656 * This struct is exclusively for the ::SDL_HAPTIC_LEFTRIGHT effect. 657 * 658 * The Left/Right effect is used to explicitly control the large and small 659 * motors, commonly found in modern game controllers. The small (right) motor 660 * is high frequency, and the large (left) motor is low frequency. 661 * 662 * \sa SDL_HAPTIC_LEFTRIGHT 663 * \sa SDL_HapticEffect 664 */ 665typedef struct SDL_HapticLeftRight 666{ 667 /* Header */ 668 Uint16 type; /**< ::SDL_HAPTIC_LEFTRIGHT */ 669 670 /* Replay */ 671 Uint32 length; /**< Duration of the effect in milliseconds. */ 672 673 /* Rumble */ 674 Uint16 large_magnitude; /**< Control of the large controller motor. */ 675 Uint16 small_magnitude; /**< Control of the small controller motor. */ 676} SDL_HapticLeftRight; 677 678/** 679 * \brief A structure containing a template for the ::SDL_HAPTIC_CUSTOM effect. 680 * 681 * This struct is exclusively for the ::SDL_HAPTIC_CUSTOM effect. 682 * 683 * A custom force feedback effect is much like a periodic effect, where the 684 * application can define its exact shape. You will have to allocate the 685 * data yourself. Data should consist of channels * samples Uint16 samples. 686 * 687 * If channels is one, the effect is rotated using the defined direction. 688 * Otherwise it uses the samples in data for the different axes. 689 * 690 * \sa SDL_HAPTIC_CUSTOM 691 * \sa SDL_HapticEffect 692 */ 693typedef struct SDL_HapticCustom 694{ 695 /* Header */ 696 Uint16 type; /**< ::SDL_HAPTIC_CUSTOM */ 697 SDL_HapticDirection direction; /**< Direction of the effect. */ 698 699 /* Replay */ 700 Uint32 length; /**< Duration of the effect. */ 701 Uint16 delay; /**< Delay before starting the effect. */ 702 703 /* Trigger */ 704 Uint16 button; /**< Button that triggers the effect. */ 705 Uint16 interval; /**< How soon it can be triggered again after button. */ 706 707 /* Custom */ 708 Uint8 channels; /**< Axes to use, minimum of one. */ 709 Uint16 period; /**< Sample periods. */ 710 Uint16 samples; /**< Amount of samples. */ 711 Uint16 *data; /**< Should contain channels*samples items. */ 712 713 /* Envelope */ 714 Uint16 attack_length; /**< Duration of the attack. */ 715 Uint16 attack_level; /**< Level at the start of the attack. */ 716 Uint16 fade_length; /**< Duration of the fade. */ 717 Uint16 fade_level; /**< Level at the end of the fade. */ 718} SDL_HapticCustom; 719 720/** 721 * \brief The generic template for any haptic effect. 722 * 723 * All values max at 32767 (0x7FFF). Signed values also can be negative. 724 * Time values unless specified otherwise are in milliseconds. 725 * 726 * You can also pass ::SDL_HAPTIC_INFINITY to length instead of a 0-32767 727 * value. Neither delay, interval, attack_length nor fade_length support 728 * ::SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends. 729 * 730 * Additionally, the ::SDL_HAPTIC_RAMP effect does not support a duration of 731 * ::SDL_HAPTIC_INFINITY. 732 * 733 * Button triggers may not be supported on all devices, it is advised to not 734 * use them if possible. Buttons start at index 1 instead of index 0 like 735 * the joystick. 736 * 737 * If both attack_length and fade_level are 0, the envelope is not used, 738 * otherwise both values are used. 739 * 740 * Common parts: 741 * \code 742 * // Replay - All effects have this 743 * Uint32 length; // Duration of effect (ms). 744 * Uint16 delay; // Delay before starting effect. 745 * 746 * // Trigger - All effects have this 747 * Uint16 button; // Button that triggers effect. 748 * Uint16 interval; // How soon before effect can be triggered again. 749 * 750 * // Envelope - All effects except condition effects have this 751 * Uint16 attack_length; // Duration of the attack (ms). 752 * Uint16 attack_level; // Level at the start of the attack. 753 * Uint16 fade_length; // Duration of the fade out (ms). 754 * Uint16 fade_level; // Level at the end of the fade. 755 * \endcode 756 * 757 * 758 * Here we have an example of a constant effect evolution in time: 759 * \verbatim 760 Strength 761 ^ 762 | 763 | effect level --> _________________ 764 | / \ 765 | / \ 766 | / \ 767 | / \ 768 | attack_level --> | \ 769 | | | <--- fade_level 770 | 771 +--------------------------------------------------> Time 772 [--] [---] 773 attack_length fade_length 774 775 [------------------][-----------------------] 776 delay length 777 \endverbatim 778 * 779 * Note either the attack_level or the fade_level may be above the actual 780 * effect level. 781 * 782 * \sa SDL_HapticConstant 783 * \sa SDL_HapticPeriodic 784 * \sa SDL_HapticCondition 785 * \sa SDL_HapticRamp 786 * \sa SDL_HapticLeftRight 787 * \sa SDL_HapticCustom 788 */ 789typedef union SDL_HapticEffect 790{ 791 /* Common for all force feedback effects */ 792 Uint16 type; /**< Effect type. */ 793 SDL_HapticConstant constant; /**< Constant effect. */ 794 SDL_HapticPeriodic periodic; /**< Periodic effect. */ 795 SDL_HapticCondition condition; /**< Condition effect. */ 796 SDL_HapticRamp ramp; /**< Ramp effect. */ 797 SDL_HapticLeftRight leftright; /**< Left/Right effect. */ 798 SDL_HapticCustom custom; /**< Custom effect. */ 799} SDL_HapticEffect; 800 801 802/* Function prototypes */ 803/** 804 * \brief Count the number of haptic devices attached to the system. 805 * 806 * \return Number of haptic devices detected on the system. 807 */ 808extern DECLSPEC int SDLCALL SDL_NumHaptics(void); 809 810/** 811 * \brief Get the implementation dependent name of a haptic device. 812 * 813 * This can be called before any joysticks are opened. 814 * If no name can be found, this function returns NULL. 815 * 816 * \param device_index Index of the device to get its name. 817 * \return Name of the device or NULL on error. 818 * 819 * \sa SDL_NumHaptics 820 */ 821extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index); 822 823/** 824 * \brief Opens a haptic device for use. 825 * 826 * The index passed as an argument refers to the N'th haptic device on this 827 * system. 828 * 829 * When opening a haptic device, its gain will be set to maximum and 830 * autocenter will be disabled. To modify these values use 831 * SDL_HapticSetGain() and SDL_HapticSetAutocenter(). 832 * 833 * \param device_index Index of the device to open. 834 * \return Device identifier or NULL on error. 835 * 836 * \sa SDL_HapticIndex 837 * \sa SDL_HapticOpenFromMouse 838 * \sa SDL_HapticOpenFromJoystick 839 * \sa SDL_HapticClose 840 * \sa SDL_HapticSetGain 841 * \sa SDL_HapticSetAutocenter 842 * \sa SDL_HapticPause 843 * \sa SDL_HapticStopAll 844 */ 845extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index); 846 847/** 848 * \brief Checks if the haptic device at index has been opened. 849 * 850 * \param device_index Index to check to see if it has been opened. 851 * \return 1 if it has been opened or 0 if it hasn't. 852 * 853 * \sa SDL_HapticOpen 854 * \sa SDL_HapticIndex 855 */ 856extern DECLSPEC int SDLCALL SDL_HapticOpened(int device_index); 857 858/** 859 * \brief Gets the index of a haptic device. 860 * 861 * \param haptic Haptic device to get the index of. 862 * \return The index of the haptic device or -1 on error. 863 * 864 * \sa SDL_HapticOpen 865 * \sa SDL_HapticOpened 866 */ 867extern DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic * haptic); 868 869/** 870 * \brief Gets whether or not the current mouse has haptic capabilities. 871 * 872 * \return SDL_TRUE if the mouse is haptic, SDL_FALSE if it isn't. 873 * 874 * \sa SDL_HapticOpenFromMouse 875 */ 876extern DECLSPEC int SDLCALL SDL_MouseIsHaptic(void); 877 878/** 879 * \brief Tries to open a haptic device from the current mouse. 880 * 881 * \return The haptic device identifier or NULL on error. 882 * 883 * \sa SDL_MouseIsHaptic 884 * \sa SDL_HapticOpen 885 */ 886extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void); 887 888/** 889 * \brief Checks to see if a joystick has haptic features. 890 * 891 * \param joystick Joystick to test for haptic capabilities. 892 * \return SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't 893 * or -1 if an error occurred. 894 * 895 * \sa SDL_HapticOpenFromJoystick 896 */ 897extern DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick * joystick); 898 899/** 900 * \brief Opens a haptic device for use from a joystick device. 901 * 902 * You must still close the haptic device separately. It will not be closed 903 * with the joystick. 904 * 905 * When opening from a joystick you should first close the haptic device before 906 * closing the joystick device. If not, on some implementations the haptic 907 * device will also get unallocated and you'll be unable to use force feedback 908 * on that device. 909 * 910 * \param joystick Joystick to create a haptic device from. 911 * \return A valid haptic device identifier on success or NULL on error. 912 * 913 * \sa SDL_HapticOpen 914 * \sa SDL_HapticClose 915 */ 916extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick * 917 joystick); 918 919/** 920 * \brief Closes a haptic device previously opened with SDL_HapticOpen(). 921 * 922 * \param haptic Haptic device to close. 923 */ 924extern DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic * haptic); 925 926/** 927 * \brief Returns the number of effects a haptic device can store. 928 * 929 * On some platforms this isn't fully supported, and therefore is an 930 * approximation. Always check to see if your created effect was actually 931 * created and do not rely solely on SDL_HapticNumEffects(). 932 * 933 * \param haptic The haptic device to query effect max. 934 * \return The number of effects the haptic device can store or 935 * -1 on error. 936 * 937 * \sa SDL_HapticNumEffectsPlaying 938 * \sa SDL_HapticQuery 939 */ 940extern DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic * haptic); 941 942/** 943 * \brief Returns the number of effects a haptic device can play at the same 944 * time. 945 * 946 * This is not supported on all platforms, but will always return a value. 947 * Added here for the sake of completeness. 948 * 949 * \param haptic The haptic device to query maximum playing effects. 950 * \return The number of effects the haptic device can play at the same time 951 * or -1 on error. 952 * 953 * \sa SDL_HapticNumEffects 954 * \sa SDL_HapticQuery 955 */ 956extern DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic); 957 958/** 959 * \brief Gets the haptic device's supported features in bitwise manner. 960 * 961 * Example: 962 * \code 963 * if (SDL_HapticQuery(haptic) & SDL_HAPTIC_CONSTANT) { 964 * printf("We have constant haptic effect!\n"); 965 * } 966 * \endcode 967 * 968 * \param haptic The haptic device to query. 969 * \return Haptic features in bitwise manner (OR'd). 970 * 971 * \sa SDL_HapticNumEffects 972 * \sa SDL_HapticEffectSupported 973 */ 974extern DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic * haptic); 975 976 977/** 978 * \brief Gets the number of haptic axes the device has. 979 * 980 * \sa SDL_HapticDirection 981 */ 982extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic); 983 984/** 985 * \brief Checks to see if effect is supported by haptic. 986 * 987 * \param haptic Haptic device to check on. 988 * \param effect Effect to check to see if it is supported. 989 * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error. 990 * 991 * \sa SDL_HapticQuery 992 * \sa SDL_HapticNewEffect 993 */ 994extern DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic * haptic, 995 SDL_HapticEffect * 996 effect); 997 998/** 999 * \brief Creates a new haptic effect on the device. 1000 * 1001 * \param haptic Haptic device to create the effect on. 1002 * \param effect Properties of the effect to create. 1003 * \return The identifier of the effect on success or -1 on error. 1004 * 1005 * \sa SDL_HapticUpdateEffect 1006 * \sa SDL_HapticRunEffect 1007 * \sa SDL_HapticDestroyEffect 1008 */ 1009extern DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic * haptic, 1010 SDL_HapticEffect * effect); 1011 1012/** 1013 * \brief Updates the properties of an effect. 1014 * 1015 * Can be used dynamically, although behavior when dynamically changing 1016 * direction may be strange. Specifically the effect may reupload itself 1017 * and start playing from the start. You cannot change the type either when 1018 * running SDL_HapticUpdateEffect(). 1019 * 1020 * \param haptic Haptic device that has the effect. 1021 * \param effect Identifier of the effect to update. 1022 * \param data New effect properties to use. 1023 * \return 0 on success or -1 on error. 1024 * 1025 * \sa SDL_HapticNewEffect 1026 * \sa SDL_HapticRunEffect 1027 * \sa SDL_HapticDestroyEffect 1028 */ 1029extern DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic * haptic, 1030 int effect, 1031 SDL_HapticEffect * data); 1032 1033/** 1034 * \brief Runs the haptic effect on its associated haptic device. 1035 * 1036 * If iterations are ::SDL_HAPTIC_INFINITY, it'll run the effect over and over 1037 * repeating the envelope (attack and fade) every time. If you only want the 1038 * effect to last forever, set ::SDL_HAPTIC_INFINITY in the effect's length 1039 * parameter. 1040 * 1041 * \param haptic Haptic device to run the effect on. 1042 * \param effect Identifier of the haptic effect to run. 1043 * \param iterations Number of iterations to run the effect. Use 1044 * ::SDL_HAPTIC_INFINITY for infinity. 1045 * \return 0 on success or -1 on error. 1046 * 1047 * \sa SDL_HapticStopEffect 1048 * \sa SDL_HapticDestroyEffect 1049 * \sa SDL_HapticGetEffectStatus 1050 */ 1051extern DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic * haptic, 1052 int effect, 1053 Uint32 iterations); 1054 1055/** 1056 * \brief Stops the haptic effect on its associated haptic device. 1057 * 1058 * \param haptic Haptic device to stop the effect on. 1059 * \param effect Identifier of the effect to stop. 1060 * \return 0 on success or -1 on error. 1061 * 1062 * \sa SDL_HapticRunEffect 1063 * \sa SDL_HapticDestroyEffect 1064 */ 1065extern DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic * haptic, 1066 int effect); 1067 1068/** 1069 * \brief Destroys a haptic effect on the device. 1070 * 1071 * This will stop the effect if it's running. Effects are automatically 1072 * destroyed when the device is closed. 1073 * 1074 * \param haptic Device to destroy the effect on. 1075 * \param effect Identifier of the effect to destroy. 1076 * 1077 * \sa SDL_HapticNewEffect 1078 */ 1079extern DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic * haptic, 1080 int effect); 1081 1082/** 1083 * \brief Gets the status of the current effect on the haptic device. 1084 * 1085 * Device must support the ::SDL_HAPTIC_STATUS feature. 1086 * 1087 * \param haptic Haptic device to query the effect status on. 1088 * \param effect Identifier of the effect to query its status. 1089 * \return 0 if it isn't playing, 1 if it is playing or -1 on error. 1090 * 1091 * \sa SDL_HapticRunEffect 1092 * \sa SDL_HapticStopEffect 1093 */ 1094extern DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic * haptic, 1095 int effect); 1096 1097/** 1098 * \brief Sets the global gain of the device. 1099 * 1100 * Device must support the ::SDL_HAPTIC_GAIN feature. 1101 * 1102 * The user may specify the maximum gain by setting the environment variable 1103 * SDL_HAPTIC_GAIN_MAX which should be between 0 and 100. All calls to 1104 * SDL_HapticSetGain() will scale linearly using SDL_HAPTIC_GAIN_MAX as the 1105 * maximum. 1106 * 1107 * \param haptic Haptic device to set the gain on. 1108 * \param gain Value to set the gain to, should be between 0 and 100. 1109 * \return 0 on success or -1 on error. 1110 * 1111 * \sa SDL_HapticQuery 1112 */ 1113extern DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic * haptic, int gain); 1114 1115/** 1116 * \brief Sets the global autocenter of the device. 1117 * 1118 * Autocenter should be between 0 and 100. Setting it to 0 will disable 1119 * autocentering. 1120 * 1121 * Device must support the ::SDL_HAPTIC_AUTOCENTER feature. 1122 * 1123 * \param haptic Haptic device to set autocentering on. 1124 * \param autocenter Value to set autocenter to, 0 disables autocentering. 1125 * \return 0 on success or -1 on error. 1126 * 1127 * \sa SDL_HapticQuery 1128 */ 1129extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic, 1130 int autocenter); 1131 1132/** 1133 * \brief Pauses a haptic device. 1134 * 1135 * Device must support the ::SDL_HAPTIC_PAUSE feature. Call 1136 * SDL_HapticUnpause() to resume playback. 1137 * 1138 * Do not modify the effects nor add new ones while the device is paused. 1139 * That can cause all sorts of weird errors. 1140 * 1141 * \param haptic Haptic device to pause. 1142 * \return 0 on success or -1 on error. 1143 * 1144 * \sa SDL_HapticUnpause 1145 */ 1146extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic); 1147 1148/** 1149 * \brief Unpauses a haptic device. 1150 * 1151 * Call to unpause after SDL_HapticPause(). 1152 * 1153 * \param haptic Haptic device to unpause. 1154 * \return 0 on success or -1 on error. 1155 * 1156 * \sa SDL_HapticPause 1157 */ 1158extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic); 1159 1160/** 1161 * \brief Stops all the currently playing effects on a haptic device. 1162 * 1163 * \param haptic Haptic device to stop. 1164 * \return 0 on success or -1 on error. 1165 */ 1166extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic); 1167 1168/** 1169 * \brief Checks to see if rumble is supported on a haptic device. 1170 * 1171 * \param haptic Haptic device to check to see if it supports rumble. 1172 * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error. 1173 * 1174 * \sa SDL_HapticRumbleInit 1175 * \sa SDL_HapticRumblePlay 1176 * \sa SDL_HapticRumbleStop 1177 */ 1178extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic); 1179 1180/** 1181 * \brief Initializes the haptic device for simple rumble playback. 1182 * 1183 * \param haptic Haptic device to initialize for simple rumble playback. 1184 * \return 0 on success or -1 on error. 1185 * 1186 * \sa SDL_HapticOpen 1187 * \sa SDL_HapticRumbleSupported 1188 * \sa SDL_HapticRumblePlay 1189 * \sa SDL_HapticRumbleStop 1190 */ 1191extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic); 1192 1193/** 1194 * \brief Runs simple rumble on a haptic device 1195 * 1196 * \param haptic Haptic device to play rumble effect on. 1197 * \param strength Strength of the rumble to play as a 0-1 float value. 1198 * \param length Length of the rumble to play in milliseconds. 1199 * \return 0 on success or -1 on error. 1200 * 1201 * \sa SDL_HapticRumbleSupported 1202 * \sa SDL_HapticRumbleInit 1203 * \sa SDL_HapticRumbleStop 1204 */ 1205extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length ); 1206 1207/** 1208 * \brief Stops the simple rumble on a haptic device. 1209 * 1210 * \param haptic Haptic to stop the rumble on. 1211 * \return 0 on success or -1 on error. 1212 * 1213 * \sa SDL_HapticRumbleSupported 1214 * \sa SDL_HapticRumbleInit 1215 * \sa SDL_HapticRumblePlay 1216 */ 1217extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic); 1218 1219/* Ends C function definitions when using C++ */ 1220#ifdef __cplusplus 1221} 1222#endif 1223#include "close_code.h" 1224 1225#endif /* SDL_haptic_h_ */ 1226 1227/* vi: set ts=4 sw=4 expandtab: */ 1228[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.