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