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 * \file SDL_haptic.h
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#ifndef SDL_haptic_h_
117#define SDL_haptic_h_
118
119#include <SDL3/SDL_stdinc.h>
120#include <SDL3/SDL_error.h>
121#include <SDL3/SDL_joystick.h>
122
123#include <SDL3/SDL_begin_code.h>
124/* Set up for C function definitions, even when using C++ */
125#ifdef __cplusplus
126extern "C" {
127#endif /* __cplusplus */
128
129/* FIXME: For SDL 2.1, adjust all the magnitude variables to be Uint16 (0xFFFF).
130 *
131 * At the moment the magnitude variables are mixed between signed/unsigned, and
132 * it is also not made clear that ALL of those variables expect a max of 0x7FFF.
133 *
134 * Some platforms may have higher precision than that (Linux FF, Windows XInput)
135 * so we should fix the inconsistency in favor of higher possible precision,
136 * adjusting for platforms that use different scales.
137 * -flibit
138 */
139
140/**
141 * \typedef SDL_Haptic
142 *
143 * The haptic structure used to identify an SDL haptic.
144 *
145 * \sa SDL_OpenHaptic
146 * \sa SDL_OpenHapticFromJoystick
147 * \sa SDL_CloseHaptic
148 */
149struct SDL_Haptic;
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 (1<<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 ID value starts at 1 and increments from there. The value 0 is an
922 * invalid ID.
923 *
924 * \since This datatype is available since SDL 3.0.0.
925 */
927
928
929/* Function prototypes */
930
931/**
932 * Get a list of currently connected haptic devices.
933 *
934 * \param count a pointer filled in with the number of haptic devices returned
935 * \returns a 0 terminated array of haptic device instance IDs which should be
936 * freed with SDL_free(), or NULL on error; call SDL_GetError() for
937 * more details.
938 *
939 * \since This function is available since SDL 3.0.0.
940 *
941 * \sa SDL_OpenHaptic
942 */
943extern 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 DECLSPEC const char *SDLCALL SDL_GetHapticInstanceName(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 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 DECLSPEC SDL_Haptic *SDLCALL SDL_GetHapticFromInstanceID(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 DECLSPEC SDL_HapticID SDLCALL SDL_GetHapticInstanceID(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_GetHapticInstanceName
1021 */
1022extern 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 SDL_TRUE if the mouse is haptic or SDL_FALSE if it isn't.
1028 *
1029 * \since This function is available since SDL 3.0.0.
1030 *
1031 * \sa SDL_OpenHapticFromMouse
1032 */
1033extern DECLSPEC SDL_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 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 SDL_TRUE if the joystick is haptic or SDL_FALSE if it isn't.
1053 *
1054 * \since This function is available since SDL 3.0.0.
1055 *
1056 * \sa SDL_OpenHapticFromJoystick
1057 */
1058extern DECLSPEC SDL_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 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 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 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 a negative error code on failure; call SDL_GetError() for more
1119 * information.
1120 *
1121 * \since This function is available since SDL 3.0.0.
1122 *
1123 * \sa SDL_GetMaxHapticEffects
1124 * \sa SDL_GetHapticFeatures
1125 */
1126extern DECLSPEC int SDLCALL SDL_GetMaxHapticEffectsPlaying(SDL_Haptic *haptic);
1127
1128/**
1129 * Get the haptic device's supported features in bitwise manner.
1130 *
1131 * \param haptic the SDL_Haptic device to query
1132 * \returns a list of supported haptic features in bitwise manner (OR'd), or 0
1133 * on failure; call SDL_GetError() for more information.
1134 *
1135 * \since This function is available since SDL 3.0.0.
1136 *
1137 * \sa SDL_HapticEffectSupported
1138 * \sa SDL_GetMaxHapticEffects
1139 */
1140extern DECLSPEC Uint32 SDLCALL SDL_GetHapticFeatures(SDL_Haptic *haptic);
1141
1142/**
1143 * Get the number of haptic axes the device has.
1144 *
1145 * The number of haptic axes might be useful if working with the
1146 * SDL_HapticDirection effect.
1147 *
1148 * \param haptic the SDL_Haptic device to query
1149 * \returns the number of axes on success or a negative error code on failure;
1150 * call SDL_GetError() for more information.
1151 *
1152 * \since This function is available since SDL 3.0.0.
1153 */
1154extern DECLSPEC int SDLCALL SDL_GetNumHapticAxes(SDL_Haptic *haptic);
1155
1156/**
1157 * Check to see if an effect is supported by a haptic device.
1158 *
1159 * \param haptic the SDL_Haptic device to query
1160 * \param effect the desired effect to query
1161 * \returns SDL_TRUE if the effect is supported or SDL_FALSE if it isn't.
1162 *
1163 * \since This function is available since SDL 3.0.0.
1164 *
1165 * \sa SDL_CreateHapticEffect
1166 * \sa SDL_GetHapticFeatures
1167 */
1168extern DECLSPEC SDL_bool SDLCALL SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effect);
1169
1170/**
1171 * Create a new haptic effect on a specified device.
1172 *
1173 * \param haptic an SDL_Haptic device to create the effect on
1174 * \param effect an SDL_HapticEffect structure containing the properties of
1175 * the effect to create
1176 * \returns the ID of the effect on success or a negative error code on
1177 * failure; call SDL_GetError() for more information.
1178 *
1179 * \since This function is available since SDL 3.0.0.
1180 *
1181 * \sa SDL_DestroyHapticEffect
1182 * \sa SDL_RunHapticEffect
1183 * \sa SDL_UpdateHapticEffect
1184 */
1185extern DECLSPEC int SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect);
1186
1187/**
1188 * Update the properties of an effect.
1189 *
1190 * Can be used dynamically, although behavior when dynamically changing
1191 * direction may be strange. Specifically the effect may re-upload itself and
1192 * start playing from the start. You also cannot change the type either when
1193 * running SDL_UpdateHapticEffect().
1194 *
1195 * \param haptic the SDL_Haptic device that has the effect
1196 * \param effect the identifier of the effect to update
1197 * \param data an SDL_HapticEffect structure containing the new effect
1198 * properties to use
1199 * \returns 0 on success or a negative error code on failure; call
1200 * SDL_GetError() for more information.
1201 *
1202 * \since This function is available since SDL 3.0.0.
1203 *
1204 * \sa SDL_CreateHapticEffect
1205 * \sa SDL_RunHapticEffect
1206 */
1207extern DECLSPEC int SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data);
1208
1209/**
1210 * Run the haptic effect on its associated haptic device.
1211 *
1212 * To repeat the effect over and over indefinitely, set `iterations` to
1213 * `SDL_HAPTIC_INFINITY`. (Repeats the envelope - attack and fade.) To make
1214 * one instance of the effect last indefinitely (so the effect does not fade),
1215 * set the effect's `length` in its structure/union to `SDL_HAPTIC_INFINITY`
1216 * instead.
1217 *
1218 * \param haptic the SDL_Haptic device to run the effect on
1219 * \param effect the ID of the haptic effect to run
1220 * \param iterations the number of iterations to run the effect; use
1221 * `SDL_HAPTIC_INFINITY` to repeat forever
1222 * \returns 0 on success or a negative error code on failure; call
1223 * SDL_GetError() for more information.
1224 *
1225 * \since This function is available since SDL 3.0.0.
1226 *
1227 * \sa SDL_GetHapticEffectStatus
1228 * \sa SDL_StopHapticEffect
1229 * \sa SDL_StopHapticEffects
1230 */
1231extern DECLSPEC int SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations);
1232
1233/**
1234 * Stop the haptic effect on its associated haptic device.
1235 *
1236 * \param haptic the SDL_Haptic device to stop the effect on
1237 * \param effect the ID of the haptic effect to stop
1238 * \returns 0 on success or a negative error code on failure; call
1239 * SDL_GetError() for more information.
1240 *
1241 * \since This function is available since SDL 3.0.0.
1242 *
1243 * \sa SDL_RunHapticEffect
1244 * \sa SDL_StopHapticEffects
1245 */
1246extern DECLSPEC int SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, int effect);
1247
1248/**
1249 * Destroy a haptic effect on the device.
1250 *
1251 * This will stop the effect if it's running. Effects are automatically
1252 * destroyed when the device is closed.
1253 *
1254 * \param haptic the SDL_Haptic device to destroy the effect on
1255 * \param effect the ID of the haptic effect to destroy
1256 *
1257 * \since This function is available since SDL 3.0.0.
1258 *
1259 * \sa SDL_CreateHapticEffect
1260 */
1261extern DECLSPEC void SDLCALL SDL_DestroyHapticEffect(SDL_Haptic *haptic, int effect);
1262
1263/**
1264 * Get the status of the current effect on the specified haptic device.
1265 *
1266 * Device must support the SDL_HAPTIC_STATUS feature.
1267 *
1268 * \param haptic the SDL_Haptic device to query for the effect status on
1269 * \param effect the ID of the haptic effect to query its status
1270 * \returns 0 if it isn't playing, 1 if it is playing, or a negative error
1271 * code on failure; call SDL_GetError() for more information.
1272 *
1273 * \since This function is available since SDL 3.0.0.
1274 */
1275extern DECLSPEC int SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect);
1276
1277/**
1278 * Set the global gain of the specified haptic device.
1279 *
1280 * Device must support the SDL_HAPTIC_GAIN feature.
1281 *
1282 * The user may specify the maximum gain by setting the environment variable
1283 * `SDL_HAPTIC_GAIN_MAX` which should be between 0 and 100. All calls to
1284 * SDL_SetHapticGain() will scale linearly using `SDL_HAPTIC_GAIN_MAX` as the
1285 * maximum.
1286 *
1287 * \param haptic the SDL_Haptic device to set the gain on
1288 * \param gain value to set the gain to, should be between 0 and 100 (0 - 100)
1289 * \returns 0 on success or a negative error code on failure; call
1290 * SDL_GetError() for more information.
1291 *
1292 * \since This function is available since SDL 3.0.0.
1293 *
1294 * \sa SDL_GetHapticFeatures
1295 */
1296extern DECLSPEC int SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int gain);
1297
1298/**
1299 * Set the global autocenter of the device.
1300 *
1301 * Autocenter should be between 0 and 100. Setting it to 0 will disable
1302 * autocentering.
1303 *
1304 * Device must support the SDL_HAPTIC_AUTOCENTER feature.
1305 *
1306 * \param haptic the SDL_Haptic device to set autocentering on
1307 * \param autocenter value to set autocenter to (0-100)
1308 * \returns 0 on success or a negative error code on failure; call
1309 * SDL_GetError() for more information.
1310 *
1311 * \since This function is available since SDL 3.0.0.
1312 *
1313 * \sa SDL_GetHapticFeatures
1314 */
1315extern DECLSPEC int SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter);
1316
1317/**
1318 * Pause a haptic device.
1319 *
1320 * Device must support the `SDL_HAPTIC_PAUSE` feature. Call SDL_ResumeHaptic()
1321 * to resume playback.
1322 *
1323 * Do not modify the effects nor add new ones while the device is paused. That
1324 * can cause all sorts of weird errors.
1325 *
1326 * \param haptic the SDL_Haptic device to pause
1327 * \returns 0 on success or a negative error code on failure; call
1328 * SDL_GetError() for more information.
1329 *
1330 * \since This function is available since SDL 3.0.0.
1331 *
1332 * \sa SDL_ResumeHaptic
1333 */
1334extern DECLSPEC int SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic);
1335
1336/**
1337 * Resume a haptic device.
1338 *
1339 * Call to unpause after SDL_PauseHaptic().
1340 *
1341 * \param haptic the SDL_Haptic device to unpause
1342 * \returns 0 on success or a negative error code on failure; call
1343 * SDL_GetError() for more information.
1344 *
1345 * \since This function is available since SDL 3.0.0.
1346 *
1347 * \sa SDL_PauseHaptic
1348 */
1349extern DECLSPEC int SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic);
1350
1351/**
1352 * Stop all the currently playing effects on a haptic device.
1353 *
1354 * \param haptic the SDL_Haptic device to stop
1355 * \returns 0 on success or a negative error code on failure; call
1356 * SDL_GetError() for more information.
1357 *
1358 * \since This function is available since SDL 3.0.0.
1359 *
1360 * \sa SDL_RunHapticEffect
1361 * \sa SDL_StopHapticEffects
1362 */
1363extern DECLSPEC int SDLCALL SDL_StopHapticEffects(SDL_Haptic *haptic);
1364
1365/**
1366 * Check whether rumble is supported on a haptic device.
1367 *
1368 * \param haptic haptic device to check for rumble support
1369 * \returns SDL_TRUE if the effect is supported or SDL_FALSE if it isn't.
1370 *
1371 * \since This function is available since SDL 3.0.0.
1372 *
1373 * \sa SDL_InitHapticRumble
1374 */
1375extern DECLSPEC SDL_bool SDLCALL SDL_HapticRumbleSupported(SDL_Haptic *haptic);
1376
1377/**
1378 * Initialize a haptic device for simple rumble playback.
1379 *
1380 * \param haptic the haptic device to initialize for simple rumble playback
1381 * \returns 0 on success or a negative error code on failure; call
1382 * SDL_GetError() for more information.
1383 *
1384 * \since This function is available since SDL 3.0.0.
1385 *
1386 * \sa SDL_PlayHapticRumble
1387 * \sa SDL_StopHapticRumble
1388 * \sa SDL_HapticRumbleSupported
1389 */
1390extern DECLSPEC int SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic);
1391
1392/**
1393 * Run a simple rumble effect on a haptic device.
1394 *
1395 * \param haptic the haptic device to play the rumble effect on
1396 * \param strength strength of the rumble to play as a 0-1 float value
1397 * \param length length of the rumble to play in milliseconds
1398 * \returns 0 on success or a negative error code on failure; call
1399 * SDL_GetError() for more information.
1400 *
1401 * \since This function is available since SDL 3.0.0.
1402 *
1403 * \sa SDL_InitHapticRumble
1404 * \sa SDL_StopHapticRumble
1405 */
1406extern DECLSPEC int SDLCALL SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length);
1407
1408/**
1409 * Stop the simple rumble on a haptic device.
1410 *
1411 * \param haptic the haptic device to stop the rumble effect on
1412 * \returns 0 on success or a negative error code on failure; call
1413 * SDL_GetError() for more information.
1414 *
1415 * \since This function is available since SDL 3.0.0.
1416 *
1417 * \sa SDL_PlayHapticRumble
1418 */
1419extern DECLSPEC int SDLCALL SDL_StopHapticRumble(SDL_Haptic *haptic);
1420
1421/* Ends C function definitions when using C++ */
1422#ifdef __cplusplus
1423}
1424#endif
1425#include <SDL3/SDL_close_code.h>
1426
1427#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)
SDL_Haptic * SDL_GetHapticFromInstanceID(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)
SDL_HapticID SDL_GetHapticInstanceID(SDL_Haptic *haptic)
struct SDL_Haptic SDL_Haptic
Definition SDL_haptic.h:150
int SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length)
Uint32 SDL_HapticID
Definition SDL_haptic.h:926
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)
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)
const char * SDL_GetHapticInstanceName(SDL_HapticID instance_id)
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)
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:188
uint16_t Uint16
Definition SDL_stdinc.h:206
int32_t Sint32
Definition SDL_stdinc.h:215
int SDL_bool
Definition SDL_stdinc.h:170
int16_t Sint16
Definition SDL_stdinc.h:197
uint32_t Uint32
Definition SDL_stdinc.h:224
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