SDL 3.0
SDL_haptic.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
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 * # CategoryHaptic
24 *
25 * The SDL haptic subsystem manages haptic (force feedback) devices.
26 *
27 * The basic usage is as follows:
28 *
29 * - Initialize the subsystem (SDL_INIT_HAPTIC).
30 * - Open a haptic device.
31 * - SDL_OpenHaptic() to open from index.
32 * - SDL_OpenHapticFromJoystick() to open from an existing joystick.
33 * - Create an effect (SDL_HapticEffect).
34 * - Upload the effect with SDL_CreateHapticEffect().
35 * - Run the effect with SDL_RunHapticEffect().
36 * - (optional) Free the effect with SDL_DestroyHapticEffect().
37 * - Close the haptic device with SDL_CloseHaptic().
38 *
39 * Simple rumble example:
40 *
41 * ```c
42 * SDL_Haptic *haptic = NULL;
43 *
44 * // Open the device
45 * SDL_HapticID *haptics = SDL_GetHaptics(NULL);
46 * if (haptics) {
47 * haptic = SDL_OpenHaptic(haptics[0]);
48 * SDL_free(haptics);
49 * }
50 * if (haptic == NULL)
51 * return;
52 *
53 * // Initialize simple rumble
54 * if (!SDL_InitHapticRumble(haptic))
55 * return;
56 *
57 * // Play effect at 50% strength for 2 seconds
58 * if (!SDL_PlayHapticRumble(haptic, 0.5, 2000))
59 * return;
60 * SDL_Delay(2000);
61 *
62 * // Clean up
63 * SDL_CloseHaptic(haptic);
64 * ```
65 *
66 * Complete example:
67 *
68 * ```c
69 * bool test_haptic(SDL_Joystick *joystick)
70 * {
71 * SDL_Haptic *haptic;
72 * SDL_HapticEffect effect;
73 * int effect_id;
74 *
75 * // Open the device
76 * haptic = SDL_OpenHapticFromJoystick(joystick);
77 * if (haptic == NULL) return false; // Most likely joystick isn't haptic
78 *
79 * // See if it can do sine waves
80 * if ((SDL_GetHapticFeatures(haptic) & SDL_HAPTIC_SINE)==0) {
81 * SDL_CloseHaptic(haptic); // No sine effect
82 * return false;
83 * }
84 *
85 * // Create the effect
86 * SDL_memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default
87 * effect.type = SDL_HAPTIC_SINE;
88 * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates
89 * effect.periodic.direction.dir[0] = 18000; // Force comes from south
90 * effect.periodic.period = 1000; // 1000 ms
91 * effect.periodic.magnitude = 20000; // 20000/32767 strength
92 * effect.periodic.length = 5000; // 5 seconds long
93 * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength
94 * effect.periodic.fade_length = 1000; // Takes 1 second to fade away
95 *
96 * // Upload the effect
97 * effect_id = SDL_CreateHapticEffect(haptic, &effect);
98 *
99 * // Test the effect
100 * SDL_RunHapticEffect(haptic, effect_id, 1);
101 * SDL_Delay(5000); // Wait for the effect to finish
102 *
103 * // We destroy the effect, although closing the device also does this
104 * SDL_DestroyHapticEffect(haptic, effect_id);
105 *
106 * // Close the device
107 * SDL_CloseHaptic(haptic);
108 *
109 * return true; // Success
110 * }
111 * ```
112 *
113 * Note that the SDL haptic subsystem is not thread-safe.
114 */
115
116
117#ifndef SDL_haptic_h_
118#define SDL_haptic_h_
119
120#include <SDL3/SDL_stdinc.h>
121#include <SDL3/SDL_error.h>
122#include <SDL3/SDL_joystick.h>
123
124#include <SDL3/SDL_begin_code.h>
125/* Set up for C function definitions, even when using C++ */
126#ifdef __cplusplus
127extern "C" {
128#endif /* __cplusplus */
129
130/* FIXME:
131 *
132 * At the moment the magnitude variables are mixed between signed/unsigned, and
133 * it is also not made clear that ALL of those variables expect a max of 0x7FFF.
134 *
135 * Some platforms may have higher precision than that (Linux FF, Windows XInput)
136 * so we should fix the inconsistency in favor of higher possible precision,
137 * adjusting for platforms that use different scales.
138 * -flibit
139 */
140
141/**
142 * The haptic structure used to identify an SDL haptic.
143 *
144 * \since This struct is available since SDL 3.0.0.
145 *
146 * \sa SDL_OpenHaptic
147 * \sa SDL_OpenHapticFromJoystick
148 * \sa SDL_CloseHaptic
149 */
150typedef struct SDL_Haptic SDL_Haptic;
151
152
153/**
154 * \name Haptic features
155 *
156 * Different haptic features a device can have.
157 */
158/* @{ */
159
160/**
161 * \name Haptic effects
162 */
163/* @{ */
164
165/**
166 * Constant effect supported.
167 *
168 * Constant haptic effect.
169 *
170 * \since This macro is available since SDL 3.0.0.
171 *
172 * \sa SDL_HapticCondition
173 */
174#define SDL_HAPTIC_CONSTANT (1u<<0)
175
176/**
177 * Sine wave effect supported.
178 *
179 * Periodic haptic effect that simulates sine waves.
180 *
181 * \since This macro is available since SDL 3.0.0.
182 *
183 * \sa SDL_HapticPeriodic
184 */
185#define SDL_HAPTIC_SINE (1u<<1)
186
187/**
188 * Square wave effect supported.
189 *
190 * Periodic haptic effect that simulates square waves.
191 *
192 * \since This macro is available since SDL 3.0.0.
193 *
194 * \sa SDL_HapticPeriodic
195 */
196#define SDL_HAPTIC_SQUARE (1u<<2)
197
198/**
199 * Triangle wave effect supported.
200 *
201 * Periodic haptic effect that simulates triangular waves.
202 *
203 * \since This macro is available since SDL 3.0.0.
204 *
205 * \sa SDL_HapticPeriodic
206 */
207#define SDL_HAPTIC_TRIANGLE (1u<<3)
208
209/**
210 * Sawtoothup wave effect supported.
211 *
212 * Periodic haptic effect that simulates saw tooth up waves.
213 *
214 * \since This macro is available since SDL 3.0.0.
215 *
216 * \sa SDL_HapticPeriodic
217 */
218#define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
219
220/**
221 * Sawtoothdown wave effect supported.
222 *
223 * Periodic haptic effect that simulates saw tooth down waves.
224 *
225 * \since This macro is available since SDL 3.0.0.
226 *
227 * \sa SDL_HapticPeriodic
228 */
229#define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
230
231/**
232 * Ramp effect supported.
233 *
234 * Ramp haptic effect.
235 *
236 * \since This macro is available since SDL 3.0.0.
237 *
238 * \sa SDL_HapticRamp
239 */
240#define SDL_HAPTIC_RAMP (1u<<6)
241
242/**
243 * Spring effect supported - uses axes position.
244 *
245 * Condition haptic effect that simulates a spring. Effect is based on the
246 * axes position.
247 *
248 * \since This macro is available since SDL 3.0.0.
249 *
250 * \sa SDL_HapticCondition
251 */
252#define SDL_HAPTIC_SPRING (1u<<7)
253
254/**
255 * Damper effect supported - uses axes velocity.
256 *
257 * Condition haptic effect that simulates dampening. Effect is based on the
258 * axes velocity.
259 *
260 * \since This macro is available since SDL 3.0.0.
261 *
262 * \sa SDL_HapticCondition
263 */
264#define SDL_HAPTIC_DAMPER (1u<<8)
265
266/**
267 * Inertia effect supported - uses axes acceleration.
268 *
269 * Condition haptic effect that simulates inertia. Effect is based on the axes
270 * acceleration.
271 *
272 * \since This macro is available since SDL 3.0.0.
273 *
274 * \sa SDL_HapticCondition
275 */
276#define SDL_HAPTIC_INERTIA (1u<<9)
277
278/**
279 * Friction effect supported - uses axes movement.
280 *
281 * Condition haptic effect that simulates friction. Effect is based on the
282 * axes movement.
283 *
284 * \since This macro is available since SDL 3.0.0.
285 *
286 * \sa SDL_HapticCondition
287 */
288#define SDL_HAPTIC_FRICTION (1u<<10)
289
290/**
291 * Left/Right effect supported.
292 *
293 * Haptic effect for direct control over high/low frequency motors.
294 *
295 * \since This macro is available since SDL 3.0.0.
296 *
297 * \sa SDL_HapticLeftRight
298 */
299#define SDL_HAPTIC_LEFTRIGHT (1u<<11)
300
301/**
302 * Reserved for future use
303 *
304 * \since This macro is available since SDL 3.0.0.
305 */
306#define SDL_HAPTIC_RESERVED1 (1u<<12)
307#define SDL_HAPTIC_RESERVED2 (1u<<13)
308#define SDL_HAPTIC_RESERVED3 (1u<<14)
309
310/**
311 * Custom effect is supported.
312 *
313 * User defined custom haptic effect.
314 *
315 * \since This macro is available since SDL 3.0.0.
316 */
317#define SDL_HAPTIC_CUSTOM (1u<<15)
318
319/* @} *//* Haptic effects */
320
321/* These last few are features the device has, not effects */
322
323/**
324 * Device can set global gain.
325 *
326 * Device supports setting the global gain.
327 *
328 * \since This macro is available since SDL 3.0.0.
329 *
330 * \sa SDL_SetHapticGain
331 */
332#define SDL_HAPTIC_GAIN (1u<<16)
333
334/**
335 * Device can set autocenter.
336 *
337 * Device supports setting autocenter.
338 *
339 * \since This macro is available since SDL 3.0.0.
340 *
341 * \sa SDL_SetHapticAutocenter
342 */
343#define SDL_HAPTIC_AUTOCENTER (1u<<17)
344
345/**
346 * Device can be queried for effect status.
347 *
348 * Device supports querying effect status.
349 *
350 * \since This macro is available since SDL 3.0.0.
351 *
352 * \sa SDL_GetHapticEffectStatus
353 */
354#define SDL_HAPTIC_STATUS (1u<<18)
355
356/**
357 * Device can be paused.
358 *
359 * Devices supports being paused.
360 *
361 * \since This macro is available since SDL 3.0.0.
362 *
363 * \sa SDL_PauseHaptic
364 * \sa SDL_ResumeHaptic
365 */
366#define SDL_HAPTIC_PAUSE (1u<<19)
367
368
369/**
370 * \name Direction encodings
371 */
372/* @{ */
373
374/**
375 * Uses polar coordinates for the direction.
376 *
377 * \since This macro is available since SDL 3.0.0.
378 *
379 * \sa SDL_HapticDirection
380 */
381#define SDL_HAPTIC_POLAR 0
382
383/**
384 * Uses cartesian coordinates for the direction.
385 *
386 * \since This macro is available since SDL 3.0.0.
387 *
388 * \sa SDL_HapticDirection
389 */
390#define SDL_HAPTIC_CARTESIAN 1
391
392/**
393 * Uses spherical coordinates for the direction.
394 *
395 * \since This macro is available since SDL 3.0.0.
396 *
397 * \sa SDL_HapticDirection
398 */
399#define SDL_HAPTIC_SPHERICAL 2
400
401/**
402 * Use this value to play an effect on the steering wheel axis.
403 *
404 * This provides better compatibility across platforms and devices as SDL will
405 * guess the correct axis.
406 *
407 * \since This macro is available since SDL 3.0.0.
408 *
409 * \sa SDL_HapticDirection
410 */
411#define SDL_HAPTIC_STEERING_AXIS 3
412
413/* @} *//* Direction encodings */
414
415/* @} *//* Haptic features */
416
417/*
418 * Misc defines.
419 */
420
421/**
422 * Used to play a device an infinite number of times.
423 *
424 * \since This macro is available since SDL 3.0.0.
425 *
426 * \sa SDL_RunHapticEffect
427 */
428#define SDL_HAPTIC_INFINITY 4294967295U
429
430
431/**
432 * Structure that represents a haptic direction.
433 *
434 * This is the direction where the force comes from, instead of the direction
435 * in which the force is exerted.
436 *
437 * Directions can be specified by:
438 *
439 * - SDL_HAPTIC_POLAR : Specified by polar coordinates.
440 * - SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates.
441 * - SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates.
442 *
443 * Cardinal directions of the haptic device are relative to the positioning of
444 * the device. North is considered to be away from the user.
445 *
446 * The following diagram represents the cardinal directions:
447 *
448 * ```
449 * .--.
450 * |__| .-------.
451 * |=.| |.-----.|
452 * |--| || ||
453 * | | |'-----'|
454 * |__|~')_____('
455 * [ COMPUTER ]
456 *
457 *
458 * North (0,-1)
459 * ^
460 * |
461 * |
462 * (-1,0) West <----[ HAPTIC ]----> East (1,0)
463 * |
464 * |
465 * v
466 * South (0,1)
467 *
468 *
469 * [ USER ]
470 * \|||/
471 * (o o)
472 * ---ooO-(_)-Ooo---
473 * ```
474 *
475 * If type is SDL_HAPTIC_POLAR, direction is encoded by hundredths of a degree
476 * starting north and turning clockwise. SDL_HAPTIC_POLAR only uses the first
477 * `dir` parameter. The cardinal directions would be:
478 *
479 * - North: 0 (0 degrees)
480 * - East: 9000 (90 degrees)
481 * - South: 18000 (180 degrees)
482 * - West: 27000 (270 degrees)
483 *
484 * If type is SDL_HAPTIC_CARTESIAN, direction is encoded by three positions (X
485 * axis, Y axis and Z axis (with 3 axes)). SDL_HAPTIC_CARTESIAN uses the first
486 * three `dir` parameters. The cardinal directions would be:
487 *
488 * - North: 0,-1, 0
489 * - East: 1, 0, 0
490 * - South: 0, 1, 0
491 * - West: -1, 0, 0
492 *
493 * The Z axis represents the height of the effect if supported, otherwise it's
494 * unused. In cartesian encoding (1, 2) would be the same as (2, 4), you can
495 * use any multiple you want, only the direction matters.
496 *
497 * If type is SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations. The
498 * first two `dir` parameters are used. The `dir` parameters are as follows
499 * (all values are in hundredths of degrees):
500 *
501 * - Degrees from (1, 0) rotated towards (0, 1).
502 * - Degrees towards (0, 0, 1) (device needs at least 3 axes).
503 *
504 * Example of force coming from the south with all encodings (force coming
505 * from the south means the user will have to pull the stick to counteract):
506 *
507 * ```c
508 * SDL_HapticDirection direction;
509 *
510 * // Cartesian directions
511 * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.
512 * direction.dir[0] = 0; // X position
513 * direction.dir[1] = 1; // Y position
514 * // Assuming the device has 2 axes, we don't need to specify third parameter.
515 *
516 * // Polar directions
517 * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
518 * direction.dir[0] = 18000; // Polar only uses first parameter
519 *
520 * // Spherical coordinates
521 * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding
522 * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
523 * ```
524 *
525 * \since This struct is available since SDL 3.0.0.
526 *
527 * \sa SDL_HAPTIC_POLAR
528 * \sa SDL_HAPTIC_CARTESIAN
529 * \sa SDL_HAPTIC_SPHERICAL
530 * \sa SDL_HAPTIC_STEERING_AXIS
531 * \sa SDL_HapticEffect
532 * \sa SDL_GetNumHapticAxes
533 */
535{
536 Uint8 type; /**< The type of encoding. */
537 Sint32 dir[3]; /**< The encoded direction. */
539
540
541/**
542 * A structure containing a template for a Constant effect.
543 *
544 * This struct is exclusively for the SDL_HAPTIC_CONSTANT effect.
545 *
546 * A constant effect applies a constant force in the specified direction to
547 * the joystick.
548 *
549 * \since This struct is available since SDL 3.0.0.
550 *
551 * \sa SDL_HAPTIC_CONSTANT
552 * \sa SDL_HapticEffect
553 */
554typedef struct SDL_HapticConstant
555{
556 /* Header */
557 Uint16 type; /**< SDL_HAPTIC_CONSTANT */
558 SDL_HapticDirection direction; /**< Direction of the effect. */
559
560 /* Replay */
561 Uint32 length; /**< Duration of the effect. */
562 Uint16 delay; /**< Delay before starting the effect. */
563
564 /* Trigger */
565 Uint16 button; /**< Button that triggers the effect. */
566 Uint16 interval; /**< How soon it can be triggered again after button. */
567
568 /* Constant */
569 Sint16 level; /**< Strength of the constant effect. */
570
571 /* Envelope */
572 Uint16 attack_length; /**< Duration of the attack. */
573 Uint16 attack_level; /**< Level at the start of the attack. */
574 Uint16 fade_length; /**< Duration of the fade. */
575 Uint16 fade_level; /**< Level at the end of the fade. */
577
578/**
579 * A structure containing a template for a Periodic effect.
580 *
581 * The struct handles the following effects:
582 *
583 * - SDL_HAPTIC_SINE
584 * - SDL_HAPTIC_SQUARE
585 * - SDL_HAPTIC_TRIANGLE
586 * - SDL_HAPTIC_SAWTOOTHUP
587 * - SDL_HAPTIC_SAWTOOTHDOWN
588 *
589 * A periodic effect consists in a wave-shaped effect that repeats itself over
590 * time. The type determines the shape of the wave and the parameters
591 * determine the dimensions of the wave.
592 *
593 * Phase is given by hundredth of a degree meaning that giving the phase a
594 * value of 9000 will displace it 25% of its period. Here are sample values:
595 *
596 * - 0: No phase displacement.
597 * - 9000: Displaced 25% of its period.
598 * - 18000: Displaced 50% of its period.
599 * - 27000: Displaced 75% of its period.
600 * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.
601 *
602 * Examples:
603 *
604 * ```
605 * SDL_HAPTIC_SINE
606 * __ __ __ __
607 * / \ / \ / \ /
608 * / \__/ \__/ \__/
609 *
610 * SDL_HAPTIC_SQUARE
611 * __ __ __ __ __
612 * | | | | | | | | | |
613 * | |__| |__| |__| |__| |
614 *
615 * SDL_HAPTIC_TRIANGLE
616 * /\ /\ /\ /\ /\
617 * / \ / \ / \ / \ /
618 * / \/ \/ \/ \/
619 *
620 * SDL_HAPTIC_SAWTOOTHUP
621 * /| /| /| /| /| /| /|
622 * / | / | / | / | / | / | / |
623 * / |/ |/ |/ |/ |/ |/ |
624 *
625 * SDL_HAPTIC_SAWTOOTHDOWN
626 * \ |\ |\ |\ |\ |\ |\ |
627 * \ | \ | \ | \ | \ | \ | \ |
628 * \| \| \| \| \| \| \|
629 * ```
630 *
631 * \since This struct is available since SDL 3.0.0.
632 *
633 * \sa SDL_HAPTIC_SINE
634 * \sa SDL_HAPTIC_SQUARE
635 * \sa SDL_HAPTIC_TRIANGLE
636 * \sa SDL_HAPTIC_SAWTOOTHUP
637 * \sa SDL_HAPTIC_SAWTOOTHDOWN
638 * \sa SDL_HapticEffect
639 */
640typedef struct SDL_HapticPeriodic
641{
642 /* Header */
643 Uint16 type; /**< SDL_HAPTIC_SINE, SDL_HAPTIC_SQUARE
644 SDL_HAPTIC_TRIANGLE, SDL_HAPTIC_SAWTOOTHUP or
645 SDL_HAPTIC_SAWTOOTHDOWN */
646 SDL_HapticDirection direction; /**< Direction of the effect. */
647
648 /* Replay */
649 Uint32 length; /**< Duration of the effect. */
650 Uint16 delay; /**< Delay before starting the effect. */
651
652 /* Trigger */
653 Uint16 button; /**< Button that triggers the effect. */
654 Uint16 interval; /**< How soon it can be triggered again after button. */
655
656 /* Periodic */
657 Uint16 period; /**< Period of the wave. */
658 Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
659 Sint16 offset; /**< Mean value of the wave. */
660 Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */
661
662 /* Envelope */
663 Uint16 attack_length; /**< Duration of the attack. */
664 Uint16 attack_level; /**< Level at the start of the attack. */
665 Uint16 fade_length; /**< Duration of the fade. */
666 Uint16 fade_level; /**< Level at the end of the fade. */
668
669/**
670 * A structure containing a template for a Condition effect.
671 *
672 * The struct handles the following effects:
673 *
674 * - SDL_HAPTIC_SPRING: Effect based on axes position.
675 * - SDL_HAPTIC_DAMPER: Effect based on axes velocity.
676 * - SDL_HAPTIC_INERTIA: Effect based on axes acceleration.
677 * - SDL_HAPTIC_FRICTION: Effect based on axes movement.
678 *
679 * Direction is handled by condition internals instead of a direction member.
680 * The condition effect specific members have three parameters. The first
681 * refers to the X axis, the second refers to the Y axis and the third refers
682 * to the Z axis. The right terms refer to the positive side of the axis and
683 * the left terms refer to the negative side of the axis. Please refer to the
684 * SDL_HapticDirection diagram for which side is positive and which is
685 * negative.
686 *
687 * \since This struct is available since SDL 3.0.0.
688 *
689 * \sa SDL_HapticDirection
690 * \sa SDL_HAPTIC_SPRING
691 * \sa SDL_HAPTIC_DAMPER
692 * \sa SDL_HAPTIC_INERTIA
693 * \sa SDL_HAPTIC_FRICTION
694 * \sa SDL_HapticEffect
695 */
697{
698 /* Header */
699 Uint16 type; /**< SDL_HAPTIC_SPRING, SDL_HAPTIC_DAMPER,
700 SDL_HAPTIC_INERTIA or SDL_HAPTIC_FRICTION */
701 SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */
702
703 /* Replay */
704 Uint32 length; /**< Duration of the effect. */
705 Uint16 delay; /**< Delay before starting the effect. */
706
707 /* Trigger */
708 Uint16 button; /**< Button that triggers the effect. */
709 Uint16 interval; /**< How soon it can be triggered again after button. */
710
711 /* Condition */
712 Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */
713 Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */
714 Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */
715 Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */
716 Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */
717 Sint16 center[3]; /**< Position of the dead zone. */
719
720/**
721 * A structure containing a template for a Ramp effect.
722 *
723 * This struct is exclusively for the SDL_HAPTIC_RAMP effect.
724 *
725 * The ramp effect starts at start strength and ends at end strength. It
726 * augments in linear fashion. If you use attack and fade with a ramp the
727 * effects get added to the ramp effect making the effect become quadratic
728 * instead of linear.
729 *
730 * \since This struct is available since SDL 3.0.0.
731 *
732 * \sa SDL_HAPTIC_RAMP
733 * \sa SDL_HapticEffect
734 */
735typedef struct SDL_HapticRamp
736{
737 /* Header */
738 Uint16 type; /**< SDL_HAPTIC_RAMP */
739 SDL_HapticDirection direction; /**< Direction of the effect. */
740
741 /* Replay */
742 Uint32 length; /**< Duration of the effect. */
743 Uint16 delay; /**< Delay before starting the effect. */
744
745 /* Trigger */
746 Uint16 button; /**< Button that triggers the effect. */
747 Uint16 interval; /**< How soon it can be triggered again after button. */
748
749 /* Ramp */
750 Sint16 start; /**< Beginning strength level. */
751 Sint16 end; /**< Ending strength level. */
752
753 /* Envelope */
754 Uint16 attack_length; /**< Duration of the attack. */
755 Uint16 attack_level; /**< Level at the start of the attack. */
756 Uint16 fade_length; /**< Duration of the fade. */
757 Uint16 fade_level; /**< Level at the end of the fade. */
759
760/**
761 * A structure containing a template for a Left/Right effect.
762 *
763 * This struct is exclusively for the SDL_HAPTIC_LEFTRIGHT effect.
764 *
765 * The Left/Right effect is used to explicitly control the large and small
766 * motors, commonly found in modern game controllers. The small (right) motor
767 * is high frequency, and the large (left) motor is low frequency.
768 *
769 * \since This struct is available since SDL 3.0.0.
770 *
771 * \sa SDL_HAPTIC_LEFTRIGHT
772 * \sa SDL_HapticEffect
773 */
775{
776 /* Header */
777 Uint16 type; /**< SDL_HAPTIC_LEFTRIGHT */
778
779 /* Replay */
780 Uint32 length; /**< Duration of the effect in milliseconds. */
781
782 /* Rumble */
783 Uint16 large_magnitude; /**< Control of the large controller motor. */
784 Uint16 small_magnitude; /**< Control of the small controller motor. */
786
787/**
788 * A structure containing a template for the SDL_HAPTIC_CUSTOM effect.
789 *
790 * This struct is exclusively for the SDL_HAPTIC_CUSTOM effect.
791 *
792 * A custom force feedback effect is much like a periodic effect, where the
793 * application can define its exact shape. You will have to allocate the data
794 * yourself. Data should consist of channels * samples Uint16 samples.
795 *
796 * If channels is one, the effect is rotated using the defined direction.
797 * Otherwise it uses the samples in data for the different axes.
798 *
799 * \since This struct is available since SDL 3.0.0.
800 *
801 * \sa SDL_HAPTIC_CUSTOM
802 * \sa SDL_HapticEffect
803 */
804typedef struct SDL_HapticCustom
805{
806 /* Header */
807 Uint16 type; /**< SDL_HAPTIC_CUSTOM */
808 SDL_HapticDirection direction; /**< Direction of the effect. */
809
810 /* Replay */
811 Uint32 length; /**< Duration of the effect. */
812 Uint16 delay; /**< Delay before starting the effect. */
813
814 /* Trigger */
815 Uint16 button; /**< Button that triggers the effect. */
816 Uint16 interval; /**< How soon it can be triggered again after button. */
817
818 /* Custom */
819 Uint8 channels; /**< Axes to use, minimum of one. */
820 Uint16 period; /**< Sample periods. */
821 Uint16 samples; /**< Amount of samples. */
822 Uint16 *data; /**< Should contain channels*samples items. */
823
824 /* Envelope */
825 Uint16 attack_length; /**< Duration of the attack. */
826 Uint16 attack_level; /**< Level at the start of the attack. */
827 Uint16 fade_length; /**< Duration of the fade. */
828 Uint16 fade_level; /**< Level at the end of the fade. */
830
831/**
832 * The generic template for any haptic effect.
833 *
834 * All values max at 32767 (0x7FFF). Signed values also can be negative. Time
835 * values unless specified otherwise are in milliseconds.
836 *
837 * You can also pass SDL_HAPTIC_INFINITY to length instead of a 0-32767 value.
838 * Neither delay, interval, attack_length nor fade_length support
839 * SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends.
840 *
841 * Additionally, the SDL_HAPTIC_RAMP effect does not support a duration of
842 * SDL_HAPTIC_INFINITY.
843 *
844 * Button triggers may not be supported on all devices, it is advised to not
845 * use them if possible. Buttons start at index 1 instead of index 0 like the
846 * joystick.
847 *
848 * If both attack_length and fade_level are 0, the envelope is not used,
849 * otherwise both values are used.
850 *
851 * Common parts:
852 *
853 * ```c
854 * // Replay - All effects have this
855 * Uint32 length; // Duration of effect (ms).
856 * Uint16 delay; // Delay before starting effect.
857 *
858 * // Trigger - All effects have this
859 * Uint16 button; // Button that triggers effect.
860 * Uint16 interval; // How soon before effect can be triggered again.
861 *
862 * // Envelope - All effects except condition effects have this
863 * Uint16 attack_length; // Duration of the attack (ms).
864 * Uint16 attack_level; // Level at the start of the attack.
865 * Uint16 fade_length; // Duration of the fade out (ms).
866 * Uint16 fade_level; // Level at the end of the fade.
867 * ```
868 *
869 * Here we have an example of a constant effect evolution in time:
870 *
871 * ```
872 * Strength
873 * ^
874 * |
875 * | effect level --> _________________
876 * | / \
877 * | / \
878 * | / \
879 * | / \
880 * | attack_level --> | \
881 * | | | <--- fade_level
882 * |
883 * +--------------------------------------------------> Time
884 * [--] [---]
885 * attack_length fade_length
886 *
887 * [------------------][-----------------------]
888 * delay length
889 * ```
890 *
891 * Note either the attack_level or the fade_level may be above the actual
892 * effect level.
893 *
894 * \since This struct is available since SDL 3.0.0.
895 *
896 * \sa SDL_HapticConstant
897 * \sa SDL_HapticPeriodic
898 * \sa SDL_HapticCondition
899 * \sa SDL_HapticRamp
900 * \sa SDL_HapticLeftRight
901 * \sa SDL_HapticCustom
902 */
903typedef union SDL_HapticEffect
904{
905 /* Common for all force feedback effects */
906 Uint16 type; /**< Effect type. */
907 SDL_HapticConstant constant; /**< Constant effect. */
908 SDL_HapticPeriodic periodic; /**< Periodic effect. */
909 SDL_HapticCondition condition; /**< Condition effect. */
910 SDL_HapticRamp ramp; /**< Ramp effect. */
911 SDL_HapticLeftRight leftright; /**< Left/Right effect. */
912 SDL_HapticCustom custom; /**< Custom effect. */
914
915/**
916 * This is a unique ID for a haptic device for the time it is connected to the
917 * system, and is never reused for the lifetime of the application.
918 *
919 * If the haptic device is disconnected and reconnected, it will get a new ID.
920 *
921 * The value 0 is an invalid ID.
922 *
923 * \since This datatype is available since SDL 3.0.0.
924 */
926
927
928/* Function prototypes */
929
930/**
931 * Get a list of currently connected haptic devices.
932 *
933 * \param count a pointer filled in with the number of haptic devices
934 * returned, may be NULL.
935 * \returns a 0 terminated array of haptic device instance IDs or NULL on
936 * failure; call SDL_GetError() for more information. This should be
937 * freed with SDL_free() when it is no longer needed.
938 *
939 * \since This function is available since SDL 3.0.0.
940 *
941 * \sa SDL_OpenHaptic
942 */
943extern SDL_DECLSPEC SDL_HapticID * SDLCALL SDL_GetHaptics(int *count);
944
945/**
946 * Get the implementation dependent name of a haptic device.
947 *
948 * This can be called before any haptic devices are opened.
949 *
950 * \param instance_id the haptic device instance ID.
951 * \returns the name of the selected haptic device. If no name can be found,
952 * this function returns NULL; call SDL_GetError() for more
953 * information.
954 *
955 * \since This function is available since SDL 3.0.0.
956 *
957 * \sa SDL_GetHapticName
958 * \sa SDL_OpenHaptic
959 */
960extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticNameForID(SDL_HapticID instance_id);
961
962/**
963 * Open a haptic device for use.
964 *
965 * The index passed as an argument refers to the N'th haptic device on this
966 * system.
967 *
968 * When opening a haptic device, its gain will be set to maximum and
969 * autocenter will be disabled. To modify these values use SDL_SetHapticGain()
970 * and SDL_SetHapticAutocenter().
971 *
972 * \param instance_id the haptic device instance ID.
973 * \returns the device identifier or NULL on failure; call SDL_GetError() for
974 * more information.
975 *
976 * \since This function is available since SDL 3.0.0.
977 *
978 * \sa SDL_CloseHaptic
979 * \sa SDL_GetHaptics
980 * \sa SDL_OpenHapticFromJoystick
981 * \sa SDL_OpenHapticFromMouse
982 * \sa SDL_SetHapticAutocenter
983 * \sa SDL_SetHapticGain
984 */
985extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHaptic(SDL_HapticID instance_id);
986
987
988/**
989 * Get the SDL_Haptic associated with an instance ID, if it has been opened.
990 *
991 * \param instance_id the instance ID to get the SDL_Haptic for.
992 * \returns an SDL_Haptic on success or NULL on failure or if it hasn't been
993 * opened yet; call SDL_GetError() for more information.
994 *
995 * \since This function is available since SDL 3.0.0.
996 */
997extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_GetHapticFromID(SDL_HapticID instance_id);
998
999/**
1000 * Get the instance ID of an opened haptic device.
1001 *
1002 * \param haptic the SDL_Haptic device to query.
1003 * \returns the instance ID of the specified haptic device on success or 0 on
1004 * failure; call SDL_GetError() for more information.
1005 *
1006 * \since This function is available since SDL 3.0.0.
1007 */
1008extern SDL_DECLSPEC SDL_HapticID SDLCALL SDL_GetHapticID(SDL_Haptic *haptic);
1009
1010/**
1011 * Get the implementation dependent name of a haptic device.
1012 *
1013 * \param haptic the SDL_Haptic obtained from SDL_OpenJoystick().
1014 * \returns the name of the selected haptic device. If no name can be found,
1015 * this function returns NULL; call SDL_GetError() for more
1016 * information.
1017 *
1018 * \since This function is available since SDL 3.0.0.
1019 *
1020 * \sa SDL_GetHapticNameForID
1021 */
1022extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticName(SDL_Haptic *haptic);
1023
1024/**
1025 * Query whether or not the current mouse has haptic capabilities.
1026 *
1027 * \returns true if the mouse is haptic or false if it isn't.
1028 *
1029 * \since This function is available since SDL 3.0.0.
1030 *
1031 * \sa SDL_OpenHapticFromMouse
1032 */
1033extern SDL_DECLSPEC bool SDLCALL SDL_IsMouseHaptic(void);
1034
1035/**
1036 * Try to open a haptic device from the current mouse.
1037 *
1038 * \returns the haptic device identifier or NULL on failure; call
1039 * SDL_GetError() for more information.
1040 *
1041 * \since This function is available since SDL 3.0.0.
1042 *
1043 * \sa SDL_CloseHaptic
1044 * \sa SDL_IsMouseHaptic
1045 */
1046extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHapticFromMouse(void);
1047
1048/**
1049 * Query if a joystick has haptic features.
1050 *
1051 * \param joystick the SDL_Joystick to test for haptic capabilities.
1052 * \returns true if the joystick is haptic or false if it isn't.
1053 *
1054 * \since This function is available since SDL 3.0.0.
1055 *
1056 * \sa SDL_OpenHapticFromJoystick
1057 */
1058extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickHaptic(SDL_Joystick *joystick);
1059
1060/**
1061 * Open a haptic device for use from a joystick device.
1062 *
1063 * You must still close the haptic device separately. It will not be closed
1064 * with the joystick.
1065 *
1066 * When opened from a joystick you should first close the haptic device before
1067 * closing the joystick device. If not, on some implementations the haptic
1068 * device will also get unallocated and you'll be unable to use force feedback
1069 * on that device.
1070 *
1071 * \param joystick the SDL_Joystick to create a haptic device from.
1072 * \returns a valid haptic device identifier on success or NULL on failure;
1073 * call SDL_GetError() for more information.
1074 *
1075 * \since This function is available since SDL 3.0.0.
1076 *
1077 * \sa SDL_CloseHaptic
1078 * \sa SDL_IsJoystickHaptic
1079 */
1080extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHapticFromJoystick(SDL_Joystick *joystick);
1081
1082/**
1083 * Close a haptic device previously opened with SDL_OpenHaptic().
1084 *
1085 * \param haptic the SDL_Haptic device to close.
1086 *
1087 * \since This function is available since SDL 3.0.0.
1088 *
1089 * \sa SDL_OpenHaptic
1090 */
1091extern SDL_DECLSPEC void SDLCALL SDL_CloseHaptic(SDL_Haptic *haptic);
1092
1093/**
1094 * Get the number of effects a haptic device can store.
1095 *
1096 * On some platforms this isn't fully supported, and therefore is an
1097 * approximation. Always check to see if your created effect was actually
1098 * created and do not rely solely on SDL_GetMaxHapticEffects().
1099 *
1100 * \param haptic the SDL_Haptic device to query.
1101 * \returns the number of effects the haptic device can store or a negative
1102 * error code on failure; call SDL_GetError() for more information.
1103 *
1104 * \since This function is available since SDL 3.0.0.
1105 *
1106 * \sa SDL_GetMaxHapticEffectsPlaying
1107 * \sa SDL_GetHapticFeatures
1108 */
1109extern SDL_DECLSPEC int SDLCALL SDL_GetMaxHapticEffects(SDL_Haptic *haptic);
1110
1111/**
1112 * Get the number of effects a haptic device can play at the same time.
1113 *
1114 * This is not supported on all platforms, but will always return a value.
1115 *
1116 * \param haptic the SDL_Haptic device to query maximum playing effects.
1117 * \returns the number of effects the haptic device can play at the same time
1118 * or -1 on failure; call SDL_GetError() for more information.
1119 *
1120 * \since This function is available since SDL 3.0.0.
1121 *
1122 * \sa SDL_GetMaxHapticEffects
1123 * \sa SDL_GetHapticFeatures
1124 */
1125extern SDL_DECLSPEC int SDLCALL SDL_GetMaxHapticEffectsPlaying(SDL_Haptic *haptic);
1126
1127/**
1128 * Get the haptic device's supported features in bitwise manner.
1129 *
1130 * \param haptic the SDL_Haptic device to query.
1131 * \returns a list of supported haptic features in bitwise manner (OR'd), or 0
1132 * on failure; call SDL_GetError() for more information.
1133 *
1134 * \since This function is available since SDL 3.0.0.
1135 *
1136 * \sa SDL_HapticEffectSupported
1137 * \sa SDL_GetMaxHapticEffects
1138 */
1139extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetHapticFeatures(SDL_Haptic *haptic);
1140
1141/**
1142 * Get the number of haptic axes the device has.
1143 *
1144 * The number of haptic axes might be useful if working with the
1145 * SDL_HapticDirection effect.
1146 *
1147 * \param haptic the SDL_Haptic device to query.
1148 * \returns the number of axes on success or -1 on failure; call
1149 * SDL_GetError() for more information.
1150 *
1151 * \since This function is available since SDL 3.0.0.
1152 */
1153extern SDL_DECLSPEC int SDLCALL SDL_GetNumHapticAxes(SDL_Haptic *haptic);
1154
1155/**
1156 * Check to see if an effect is supported by a haptic device.
1157 *
1158 * \param haptic the SDL_Haptic device to query.
1159 * \param effect the desired effect to query.
1160 * \returns true if the effect is supported or false if it isn't.
1161 *
1162 * \since This function is available since SDL 3.0.0.
1163 *
1164 * \sa SDL_CreateHapticEffect
1165 * \sa SDL_GetHapticFeatures
1166 */
1167extern SDL_DECLSPEC bool SDLCALL SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effect);
1168
1169/**
1170 * Create a new haptic effect on a specified device.
1171 *
1172 * \param haptic an SDL_Haptic device to create the effect on.
1173 * \param effect an SDL_HapticEffect structure containing the properties of
1174 * the effect to create.
1175 * \returns the ID of the effect on success or -1 on failure; call
1176 * SDL_GetError() for more information.
1177 *
1178 * \since This function is available since SDL 3.0.0.
1179 *
1180 * \sa SDL_DestroyHapticEffect
1181 * \sa SDL_RunHapticEffect
1182 * \sa SDL_UpdateHapticEffect
1183 */
1184extern SDL_DECLSPEC int SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect);
1185
1186/**
1187 * Update the properties of an effect.
1188 *
1189 * Can be used dynamically, although behavior when dynamically changing
1190 * direction may be strange. Specifically the effect may re-upload itself and
1191 * start playing from the start. You also cannot change the type either when
1192 * running SDL_UpdateHapticEffect().
1193 *
1194 * \param haptic the SDL_Haptic device that has the effect.
1195 * \param effect the identifier of the effect to update.
1196 * \param data an SDL_HapticEffect structure containing the new effect
1197 * properties to use.
1198 * \returns true on success or false on failure; call SDL_GetError() for more
1199 * information.
1200 *
1201 * \since This function is available since SDL 3.0.0.
1202 *
1203 * \sa SDL_CreateHapticEffect
1204 * \sa SDL_RunHapticEffect
1205 */
1206extern SDL_DECLSPEC bool SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data);
1207
1208/**
1209 * Run the haptic effect on its associated haptic device.
1210 *
1211 * To repeat the effect over and over indefinitely, set `iterations` to
1212 * `SDL_HAPTIC_INFINITY`. (Repeats the envelope - attack and fade.) To make
1213 * one instance of the effect last indefinitely (so the effect does not fade),
1214 * set the effect's `length` in its structure/union to `SDL_HAPTIC_INFINITY`
1215 * instead.
1216 *
1217 * \param haptic the SDL_Haptic device to run the effect on.
1218 * \param effect the ID of the haptic effect to run.
1219 * \param iterations the number of iterations to run the effect; use
1220 * `SDL_HAPTIC_INFINITY` to repeat forever.
1221 * \returns true on success or false on failure; call SDL_GetError() for more
1222 * information.
1223 *
1224 * \since This function is available since SDL 3.0.0.
1225 *
1226 * \sa SDL_GetHapticEffectStatus
1227 * \sa SDL_StopHapticEffect
1228 * \sa SDL_StopHapticEffects
1229 */
1230extern SDL_DECLSPEC bool SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations);
1231
1232/**
1233 * Stop the haptic effect on its associated haptic device.
1234 *
1235 * \param haptic the SDL_Haptic device to stop the effect on.
1236 * \param effect the ID of the haptic effect to stop.
1237 * \returns true on success or false on failure; call SDL_GetError() for more
1238 * information.
1239 *
1240 * \since This function is available since SDL 3.0.0.
1241 *
1242 * \sa SDL_RunHapticEffect
1243 * \sa SDL_StopHapticEffects
1244 */
1245extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, int effect);
1246
1247/**
1248 * Destroy a haptic effect on the device.
1249 *
1250 * This will stop the effect if it's running. Effects are automatically
1251 * destroyed when the device is closed.
1252 *
1253 * \param haptic the SDL_Haptic device to destroy the effect on.
1254 * \param effect the ID of the haptic effect to destroy.
1255 *
1256 * \since This function is available since SDL 3.0.0.
1257 *
1258 * \sa SDL_CreateHapticEffect
1259 */
1260extern SDL_DECLSPEC void SDLCALL SDL_DestroyHapticEffect(SDL_Haptic *haptic, int effect);
1261
1262/**
1263 * Get the status of the current effect on the specified haptic device.
1264 *
1265 * Device must support the SDL_HAPTIC_STATUS feature.
1266 *
1267 * \param haptic the SDL_Haptic device to query for the effect status on.
1268 * \param effect the ID of the haptic effect to query its status.
1269 * \returns true if it is playing, false if it isn't playing or haptic status
1270 * isn't supported.
1271 *
1272 * \since This function is available since SDL 3.0.0.
1273 *
1274 * \sa SDL_GetHapticFeatures
1275 */
1276extern SDL_DECLSPEC bool SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect);
1277
1278/**
1279 * Set the global gain of the specified haptic device.
1280 *
1281 * Device must support the SDL_HAPTIC_GAIN feature.
1282 *
1283 * The user may specify the maximum gain by setting the environment variable
1284 * `SDL_HAPTIC_GAIN_MAX` which should be between 0 and 100. All calls to
1285 * SDL_SetHapticGain() will scale linearly using `SDL_HAPTIC_GAIN_MAX` as the
1286 * maximum.
1287 *
1288 * \param haptic the SDL_Haptic device to set the gain on.
1289 * \param gain value to set the gain to, should be between 0 and 100 (0 -
1290 * 100).
1291 * \returns true on success or false on failure; call SDL_GetError() for more
1292 * information.
1293 *
1294 * \since This function is available since SDL 3.0.0.
1295 *
1296 * \sa SDL_GetHapticFeatures
1297 */
1298extern SDL_DECLSPEC bool SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int gain);
1299
1300/**
1301 * Set the global autocenter of the device.
1302 *
1303 * Autocenter should be between 0 and 100. Setting it to 0 will disable
1304 * autocentering.
1305 *
1306 * Device must support the SDL_HAPTIC_AUTOCENTER feature.
1307 *
1308 * \param haptic the SDL_Haptic device to set autocentering on.
1309 * \param autocenter value to set autocenter to (0-100).
1310 * \returns true on success or false on failure; call SDL_GetError() for more
1311 * information.
1312 *
1313 * \since This function is available since SDL 3.0.0.
1314 *
1315 * \sa SDL_GetHapticFeatures
1316 */
1317extern SDL_DECLSPEC bool SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter);
1318
1319/**
1320 * Pause a haptic device.
1321 *
1322 * Device must support the `SDL_HAPTIC_PAUSE` feature. Call SDL_ResumeHaptic()
1323 * to resume playback.
1324 *
1325 * Do not modify the effects nor add new ones while the device is paused. That
1326 * can cause all sorts of weird errors.
1327 *
1328 * \param haptic the SDL_Haptic device to pause.
1329 * \returns true on success or false on failure; call SDL_GetError() for more
1330 * information.
1331 *
1332 * \since This function is available since SDL 3.0.0.
1333 *
1334 * \sa SDL_ResumeHaptic
1335 */
1336extern SDL_DECLSPEC bool SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic);
1337
1338/**
1339 * Resume a haptic device.
1340 *
1341 * Call to unpause after SDL_PauseHaptic().
1342 *
1343 * \param haptic the SDL_Haptic device to unpause.
1344 * \returns true on success or false on failure; call SDL_GetError() for more
1345 * information.
1346 *
1347 * \since This function is available since SDL 3.0.0.
1348 *
1349 * \sa SDL_PauseHaptic
1350 */
1351extern SDL_DECLSPEC bool SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic);
1352
1353/**
1354 * Stop all the currently playing effects on a haptic device.
1355 *
1356 * \param haptic the SDL_Haptic device to stop.
1357 * \returns true on success or false on failure; call SDL_GetError() for more
1358 * information.
1359 *
1360 * \since This function is available since SDL 3.0.0.
1361 *
1362 * \sa SDL_RunHapticEffect
1363 * \sa SDL_StopHapticEffects
1364 */
1365extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffects(SDL_Haptic *haptic);
1366
1367/**
1368 * Check whether rumble is supported on a haptic device.
1369 *
1370 * \param haptic haptic device to check for rumble support.
1371 * \returns true if the effect is supported or false if it isn't.
1372 *
1373 * \since This function is available since SDL 3.0.0.
1374 *
1375 * \sa SDL_InitHapticRumble
1376 */
1377extern SDL_DECLSPEC bool SDLCALL SDL_HapticRumbleSupported(SDL_Haptic *haptic);
1378
1379/**
1380 * Initialize a haptic device for simple rumble playback.
1381 *
1382 * \param haptic the haptic device to initialize for simple rumble playback.
1383 * \returns true on success or false on failure; call SDL_GetError() for more
1384 * information.
1385 *
1386 * \since This function is available since SDL 3.0.0.
1387 *
1388 * \sa SDL_PlayHapticRumble
1389 * \sa SDL_StopHapticRumble
1390 * \sa SDL_HapticRumbleSupported
1391 */
1392extern SDL_DECLSPEC bool SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic);
1393
1394/**
1395 * Run a simple rumble effect on a haptic device.
1396 *
1397 * \param haptic the haptic device to play the rumble effect on.
1398 * \param strength strength of the rumble to play as a 0-1 float value.
1399 * \param length length of the rumble to play in milliseconds.
1400 * \returns true on success or false on failure; call SDL_GetError() for more
1401 * information.
1402 *
1403 * \since This function is available since SDL 3.0.0.
1404 *
1405 * \sa SDL_InitHapticRumble
1406 * \sa SDL_StopHapticRumble
1407 */
1408extern SDL_DECLSPEC bool SDLCALL SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length);
1409
1410/**
1411 * Stop the simple rumble on a haptic device.
1412 *
1413 * \param haptic the haptic device to stop the rumble effect on.
1414 * \returns true on success or false on failure; call SDL_GetError() for more
1415 * information.
1416 *
1417 * \since This function is available since SDL 3.0.0.
1418 *
1419 * \sa SDL_PlayHapticRumble
1420 */
1421extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticRumble(SDL_Haptic *haptic);
1422
1423/* Ends C function definitions when using C++ */
1424#ifdef __cplusplus
1425}
1426#endif
1427#include <SDL3/SDL_close_code.h>
1428
1429#endif /* SDL_haptic_h_ */
bool SDL_StopHapticEffects(SDL_Haptic *haptic)
bool SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data)
int SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect)
int SDL_GetMaxHapticEffects(SDL_Haptic *haptic)
bool SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length)
SDL_Haptic * SDL_OpenHaptic(SDL_HapticID instance_id)
int SDL_GetMaxHapticEffectsPlaying(SDL_Haptic *haptic)
bool SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations)
bool SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter)
bool SDL_ResumeHaptic(SDL_Haptic *haptic)
SDL_Haptic * SDL_OpenHapticFromJoystick(SDL_Joystick *joystick)
bool SDL_IsJoystickHaptic(SDL_Joystick *joystick)
bool SDL_SetHapticGain(SDL_Haptic *haptic, int gain)
const char * SDL_GetHapticNameForID(SDL_HapticID instance_id)
bool SDL_InitHapticRumble(SDL_Haptic *haptic)
bool SDL_StopHapticRumble(SDL_Haptic *haptic)
Uint32 SDL_HapticID
Definition SDL_haptic.h:925
bool SDL_IsMouseHaptic(void)
bool SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effect)
bool SDL_PauseHaptic(SDL_Haptic *haptic)
struct SDL_Haptic SDL_Haptic
Definition SDL_haptic.h:150
bool SDL_HapticRumbleSupported(SDL_Haptic *haptic)
int SDL_GetNumHapticAxes(SDL_Haptic *haptic)
const char * SDL_GetHapticName(SDL_Haptic *haptic)
SDL_Haptic * SDL_GetHapticFromID(SDL_HapticID instance_id)
void SDL_CloseHaptic(SDL_Haptic *haptic)
SDL_HapticID * SDL_GetHaptics(int *count)
bool SDL_StopHapticEffect(SDL_Haptic *haptic, int effect)
SDL_HapticID SDL_GetHapticID(SDL_Haptic *haptic)
Uint32 SDL_GetHapticFeatures(SDL_Haptic *haptic)
SDL_Haptic * SDL_OpenHapticFromMouse(void)
void SDL_DestroyHapticEffect(SDL_Haptic *haptic, int effect)
bool SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect)
struct SDL_Joystick SDL_Joystick
uint8_t Uint8
Definition SDL_stdinc.h:320
uint16_t Uint16
Definition SDL_stdinc.h:338
int32_t Sint32
Definition SDL_stdinc.h:347
int16_t Sint16
Definition SDL_stdinc.h:329
uint32_t Uint32
Definition SDL_stdinc.h:356
Sint16 right_coeff[3]
Definition SDL_haptic.h:714
SDL_HapticDirection direction
Definition SDL_haptic.h:701
SDL_HapticDirection direction
Definition SDL_haptic.h:558
SDL_HapticDirection direction
Definition SDL_haptic.h:808
SDL_HapticDirection direction
Definition SDL_haptic.h:646
Uint16 fade_level
Definition SDL_haptic.h:757
SDL_HapticDirection direction
Definition SDL_haptic.h:739
Uint16 attack_level
Definition SDL_haptic.h:755
Uint16 fade_length
Definition SDL_haptic.h:756
Uint16 attack_length
Definition SDL_haptic.h:754
SDL_HapticCustom custom
Definition SDL_haptic.h:912
SDL_HapticRamp ramp
Definition SDL_haptic.h:910
SDL_HapticLeftRight leftright
Definition SDL_haptic.h:911
SDL_HapticPeriodic periodic
Definition SDL_haptic.h:908
SDL_HapticCondition condition
Definition SDL_haptic.h:909
SDL_HapticConstant constant
Definition SDL_haptic.h:907