sdl3_sys/generated/haptic.rs
1//! The SDL haptic subsystem manages haptic (force feedback) devices.
2//!
3//! The basic usage is as follows:
4//!
5//! - Initialize the subsystem ([`SDL_INIT_HAPTIC`]).
6//! - Open a haptic device.
7//! - [`SDL_OpenHaptic()`] to open from index.
8//! - [`SDL_OpenHapticFromJoystick()`] to open from an existing joystick.
9//! - Create an effect ([`SDL_HapticEffect`]).
10//! - Upload the effect with [`SDL_CreateHapticEffect()`].
11//! - Run the effect with [`SDL_RunHapticEffect()`].
12//! - (optional) Free the effect with [`SDL_DestroyHapticEffect()`].
13//! - Close the haptic device with [`SDL_CloseHaptic()`].
14//!
15//! Simple rumble example:
16//!
17//! ```c
18//! SDL_Haptic *haptic = NULL;
19//!
20//! // Open the device
21//! SDL_HapticID *haptics = SDL_GetHaptics(NULL);
22//! if (haptics) {
23//! haptic = SDL_OpenHaptic(haptics[0]);
24//! SDL_free(haptics);
25//! }
26//! if (haptic == NULL)
27//! return;
28//!
29//! // Initialize simple rumble
30//! if (!SDL_InitHapticRumble(haptic))
31//! return;
32//!
33//! // Play effect at 50% strength for 2 seconds
34//! if (!SDL_PlayHapticRumble(haptic, 0.5, 2000))
35//! return;
36//! SDL_Delay(2000);
37//!
38//! // Clean up
39//! SDL_CloseHaptic(haptic);
40//! ```
41//!
42//! Complete example:
43//!
44//! ```c
45//! bool test_haptic(SDL_Joystick *joystick)
46//! {
47//! SDL_Haptic *haptic;
48//! SDL_HapticEffect effect;
49//! SDL_HapticEffectID effect_id;
50//!
51//! // Open the device
52//! haptic = SDL_OpenHapticFromJoystick(joystick);
53//! if (haptic == NULL) return false; // Most likely joystick isn't haptic
54//!
55//! // See if it can do sine waves
56//! if ((SDL_GetHapticFeatures(haptic) & SDL_HAPTIC_SINE)==0) {
57//! SDL_CloseHaptic(haptic); // No sine effect
58//! return false;
59//! }
60//!
61//! // Create the effect
62//! SDL_memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default
63//! effect.type = SDL_HAPTIC_SINE;
64//! effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates
65//! effect.periodic.direction.dir[0] = 18000; // Force comes from south
66//! effect.periodic.period = 1000; // 1000 ms
67//! effect.periodic.magnitude = 20000; // 20000/32767 strength
68//! effect.periodic.length = 5000; // 5 seconds long
69//! effect.periodic.attack_length = 1000; // Takes 1 second to get max strength
70//! effect.periodic.fade_length = 1000; // Takes 1 second to fade away
71//!
72//! // Upload the effect
73//! effect_id = SDL_CreateHapticEffect(haptic, &effect);
74//!
75//! // Test the effect
76//! SDL_RunHapticEffect(haptic, effect_id, 1);
77//! SDL_Delay(5000); // Wait for the effect to finish
78//!
79//! // We destroy the effect, although closing the device also does this
80//! SDL_DestroyHapticEffect(haptic, effect_id);
81//!
82//! // Close the device
83//! SDL_CloseHaptic(haptic);
84//!
85//! return true; // Success
86//! }
87//! ```
88//!
89//! Note that the SDL haptic subsystem is not thread-safe.
90
91use super::stdinc::*;
92
93use super::error::*;
94
95use super::joystick::*;
96
97/// Used to play a device an infinite number of times.
98///
99/// ## Availability
100/// This macro is available since SDL 3.2.0.
101///
102/// ## See also
103/// - [`SDL_RunHapticEffect`]
104pub const SDL_HAPTIC_INFINITY: ::core::primitive::u32 = 4294967295_u32;
105
106/// * Type of haptic effect.
107///
108/// ## Known values (`sdl3-sys`)
109/// | Associated constant | Global constant | Description |
110/// | ------------------- | --------------- | ----------- |
111/// | [`CONSTANT`](SDL_HapticEffectType::CONSTANT) | [`SDL_HAPTIC_CONSTANT`] | Constant effect supported. Constant haptic effect. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticCondition`] |
112/// | [`SINE`](SDL_HapticEffectType::SINE) | [`SDL_HAPTIC_SINE`] | Sine wave effect supported. Periodic haptic effect that simulates sine waves. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticPeriodic`] |
113/// | [`SQUARE`](SDL_HapticEffectType::SQUARE) | [`SDL_HAPTIC_SQUARE`] | Square wave effect supported. Periodic haptic effect that simulates square waves. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticPeriodic`] |
114/// | [`TRIANGLE`](SDL_HapticEffectType::TRIANGLE) | [`SDL_HAPTIC_TRIANGLE`] | Triangle wave effect supported. Periodic haptic effect that simulates triangular waves. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticPeriodic`] |
115/// | [`SAWTOOTHUP`](SDL_HapticEffectType::SAWTOOTHUP) | [`SDL_HAPTIC_SAWTOOTHUP`] | Sawtoothup wave effect supported. Periodic haptic effect that simulates saw tooth up waves. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticPeriodic`] |
116/// | [`SAWTOOTHDOWN`](SDL_HapticEffectType::SAWTOOTHDOWN) | [`SDL_HAPTIC_SAWTOOTHDOWN`] | Sawtoothdown wave effect supported. Periodic haptic effect that simulates saw tooth down waves. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticPeriodic`] |
117/// | [`RAMP`](SDL_HapticEffectType::RAMP) | [`SDL_HAPTIC_RAMP`] | Ramp effect supported. Ramp haptic effect. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticRamp`] |
118/// | [`SPRING`](SDL_HapticEffectType::SPRING) | [`SDL_HAPTIC_SPRING`] | Spring effect supported - uses axes position. Condition haptic effect that simulates a spring. Effect is based on the axes position. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticCondition`] |
119/// | [`DAMPER`](SDL_HapticEffectType::DAMPER) | [`SDL_HAPTIC_DAMPER`] | Damper effect supported - uses axes velocity. Condition haptic effect that simulates dampening. Effect is based on the axes velocity. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticCondition`] |
120/// | [`INERTIA`](SDL_HapticEffectType::INERTIA) | [`SDL_HAPTIC_INERTIA`] | Inertia effect supported - uses axes acceleration. Condition haptic effect that simulates inertia. Effect is based on the axes acceleration. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticCondition`] |
121/// | [`FRICTION`](SDL_HapticEffectType::FRICTION) | [`SDL_HAPTIC_FRICTION`] | Friction effect supported - uses axes movement. Condition haptic effect that simulates friction. Effect is based on the axes movement. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticCondition`] |
122/// | [`LEFTRIGHT`](SDL_HapticEffectType::LEFTRIGHT) | [`SDL_HAPTIC_LEFTRIGHT`] | Left/Right effect supported. Haptic effect for direct control over high/low frequency motors. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticLeftRight`] |
123/// | [`RESERVED1`](SDL_HapticEffectType::RESERVED1) | [`SDL_HAPTIC_RESERVED1`] | Reserved for future use. \since This macro is available since SDL 3.2.0. |
124/// | [`RESERVED2`](SDL_HapticEffectType::RESERVED2) | [`SDL_HAPTIC_RESERVED2`] | Reserved for future use. \since This macro is available since SDL 3.2.0. |
125/// | [`RESERVED3`](SDL_HapticEffectType::RESERVED3) | [`SDL_HAPTIC_RESERVED3`] | Reserved for future use. \since This macro is available since SDL 3.2.0. |
126/// | [`CUSTOM`](SDL_HapticEffectType::CUSTOM) | [`SDL_HAPTIC_CUSTOM`] | Custom effect is supported. User defined custom haptic effect. \since This macro is available since SDL 3.2.0. |
127/// | [`GAIN`](SDL_HapticEffectType::GAIN) | [`SDL_HAPTIC_GAIN`] | Device can set global gain. Device supports setting the global gain. \since This macro is available since SDL 3.2.0. \sa [`SDL_SetHapticGain`] |
128/// | [`AUTOCENTER`](SDL_HapticEffectType::AUTOCENTER) | [`SDL_HAPTIC_AUTOCENTER`] | Device can set autocenter. Device supports setting autocenter. \since This macro is available since SDL 3.2.0. \sa [`SDL_SetHapticAutocenter`] |
129/// | [`STATUS`](SDL_HapticEffectType::STATUS) | [`SDL_HAPTIC_STATUS`] | Device can be queried for effect status. Device supports querying effect status. \since This macro is available since SDL 3.2.0. \sa [`SDL_GetHapticEffectStatus`] |
130/// | [`PAUSE`](SDL_HapticEffectType::PAUSE) | [`SDL_HAPTIC_PAUSE`] | Device can be paused. Devices supports being paused. \since This macro is available since SDL 3.2.0. \sa [`SDL_PauseHaptic`] \sa [`SDL_ResumeHaptic`] |
131#[repr(transparent)]
132#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
133pub struct SDL_HapticEffectType(pub Uint16);
134
135impl ::core::cmp::PartialEq<Uint16> for SDL_HapticEffectType {
136 #[inline(always)]
137 fn eq(&self, other: &Uint16) -> bool {
138 &self.0 == other
139 }
140}
141
142impl ::core::cmp::PartialEq<SDL_HapticEffectType> for Uint16 {
143 #[inline(always)]
144 fn eq(&self, other: &SDL_HapticEffectType) -> bool {
145 self == &other.0
146 }
147}
148
149impl From<SDL_HapticEffectType> for Uint16 {
150 #[inline(always)]
151 fn from(value: SDL_HapticEffectType) -> Self {
152 value.0
153 }
154}
155
156#[cfg(feature = "debug-impls")]
157impl ::core::fmt::Debug for SDL_HapticEffectType {
158 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
159 let mut first = true;
160 let all_bits = 0;
161 write!(f, "SDL_HapticEffectType(")?;
162 let all_bits = all_bits | Self::CONSTANT.0;
163 if (Self::CONSTANT != 0 || self.0 == 0) && *self & Self::CONSTANT == Self::CONSTANT {
164 if !first {
165 write!(f, " | ")?;
166 }
167 first = false;
168 write!(f, "CONSTANT")?;
169 }
170 let all_bits = all_bits | Self::SINE.0;
171 if (Self::SINE != 0 || self.0 == 0) && *self & Self::SINE == Self::SINE {
172 if !first {
173 write!(f, " | ")?;
174 }
175 first = false;
176 write!(f, "SINE")?;
177 }
178 let all_bits = all_bits | Self::SQUARE.0;
179 if (Self::SQUARE != 0 || self.0 == 0) && *self & Self::SQUARE == Self::SQUARE {
180 if !first {
181 write!(f, " | ")?;
182 }
183 first = false;
184 write!(f, "SQUARE")?;
185 }
186 let all_bits = all_bits | Self::TRIANGLE.0;
187 if (Self::TRIANGLE != 0 || self.0 == 0) && *self & Self::TRIANGLE == Self::TRIANGLE {
188 if !first {
189 write!(f, " | ")?;
190 }
191 first = false;
192 write!(f, "TRIANGLE")?;
193 }
194 let all_bits = all_bits | Self::SAWTOOTHUP.0;
195 if (Self::SAWTOOTHUP != 0 || self.0 == 0) && *self & Self::SAWTOOTHUP == Self::SAWTOOTHUP {
196 if !first {
197 write!(f, " | ")?;
198 }
199 first = false;
200 write!(f, "SAWTOOTHUP")?;
201 }
202 let all_bits = all_bits | Self::SAWTOOTHDOWN.0;
203 if (Self::SAWTOOTHDOWN != 0 || self.0 == 0)
204 && *self & Self::SAWTOOTHDOWN == Self::SAWTOOTHDOWN
205 {
206 if !first {
207 write!(f, " | ")?;
208 }
209 first = false;
210 write!(f, "SAWTOOTHDOWN")?;
211 }
212 let all_bits = all_bits | Self::RAMP.0;
213 if (Self::RAMP != 0 || self.0 == 0) && *self & Self::RAMP == Self::RAMP {
214 if !first {
215 write!(f, " | ")?;
216 }
217 first = false;
218 write!(f, "RAMP")?;
219 }
220 let all_bits = all_bits | Self::SPRING.0;
221 if (Self::SPRING != 0 || self.0 == 0) && *self & Self::SPRING == Self::SPRING {
222 if !first {
223 write!(f, " | ")?;
224 }
225 first = false;
226 write!(f, "SPRING")?;
227 }
228 let all_bits = all_bits | Self::DAMPER.0;
229 if (Self::DAMPER != 0 || self.0 == 0) && *self & Self::DAMPER == Self::DAMPER {
230 if !first {
231 write!(f, " | ")?;
232 }
233 first = false;
234 write!(f, "DAMPER")?;
235 }
236 let all_bits = all_bits | Self::INERTIA.0;
237 if (Self::INERTIA != 0 || self.0 == 0) && *self & Self::INERTIA == Self::INERTIA {
238 if !first {
239 write!(f, " | ")?;
240 }
241 first = false;
242 write!(f, "INERTIA")?;
243 }
244 let all_bits = all_bits | Self::FRICTION.0;
245 if (Self::FRICTION != 0 || self.0 == 0) && *self & Self::FRICTION == Self::FRICTION {
246 if !first {
247 write!(f, " | ")?;
248 }
249 first = false;
250 write!(f, "FRICTION")?;
251 }
252 let all_bits = all_bits | Self::LEFTRIGHT.0;
253 if (Self::LEFTRIGHT != 0 || self.0 == 0) && *self & Self::LEFTRIGHT == Self::LEFTRIGHT {
254 if !first {
255 write!(f, " | ")?;
256 }
257 first = false;
258 write!(f, "LEFTRIGHT")?;
259 }
260 let all_bits = all_bits | Self::RESERVED1.0;
261 if (Self::RESERVED1 != 0 || self.0 == 0) && *self & Self::RESERVED1 == Self::RESERVED1 {
262 if !first {
263 write!(f, " | ")?;
264 }
265 first = false;
266 write!(f, "RESERVED1")?;
267 }
268 let all_bits = all_bits | Self::RESERVED2.0;
269 if (Self::RESERVED2 != 0 || self.0 == 0) && *self & Self::RESERVED2 == Self::RESERVED2 {
270 if !first {
271 write!(f, " | ")?;
272 }
273 first = false;
274 write!(f, "RESERVED2")?;
275 }
276 let all_bits = all_bits | Self::RESERVED3.0;
277 if (Self::RESERVED3 != 0 || self.0 == 0) && *self & Self::RESERVED3 == Self::RESERVED3 {
278 if !first {
279 write!(f, " | ")?;
280 }
281 first = false;
282 write!(f, "RESERVED3")?;
283 }
284 let all_bits = all_bits | Self::CUSTOM.0;
285 if (Self::CUSTOM != 0 || self.0 == 0) && *self & Self::CUSTOM == Self::CUSTOM {
286 if !first {
287 write!(f, " | ")?;
288 }
289 first = false;
290 write!(f, "CUSTOM")?;
291 }
292 let all_bits = all_bits | Self::GAIN.0;
293 if (Self::GAIN != 0 || self.0 == 0) && *self & Self::GAIN == Self::GAIN {
294 if !first {
295 write!(f, " | ")?;
296 }
297 first = false;
298 write!(f, "GAIN")?;
299 }
300 let all_bits = all_bits | Self::AUTOCENTER.0;
301 if (Self::AUTOCENTER != 0 || self.0 == 0) && *self & Self::AUTOCENTER == Self::AUTOCENTER {
302 if !first {
303 write!(f, " | ")?;
304 }
305 first = false;
306 write!(f, "AUTOCENTER")?;
307 }
308 let all_bits = all_bits | Self::STATUS.0;
309 if (Self::STATUS != 0 || self.0 == 0) && *self & Self::STATUS == Self::STATUS {
310 if !first {
311 write!(f, " | ")?;
312 }
313 first = false;
314 write!(f, "STATUS")?;
315 }
316 let all_bits = all_bits | Self::PAUSE.0;
317 if (Self::PAUSE != 0 || self.0 == 0) && *self & Self::PAUSE == Self::PAUSE {
318 if !first {
319 write!(f, " | ")?;
320 }
321 first = false;
322 write!(f, "PAUSE")?;
323 }
324
325 if self.0 & !all_bits != 0 {
326 if !first {
327 write!(f, " | ")?;
328 }
329 write!(f, "{:#x}", self.0)?;
330 } else if first {
331 write!(f, "0")?;
332 }
333 write!(f, ")")
334 }
335}
336
337impl ::core::ops::BitAnd for SDL_HapticEffectType {
338 type Output = Self;
339
340 #[inline(always)]
341 fn bitand(self, rhs: Self) -> Self::Output {
342 Self(self.0 & rhs.0)
343 }
344}
345
346impl ::core::ops::BitAndAssign for SDL_HapticEffectType {
347 #[inline(always)]
348 fn bitand_assign(&mut self, rhs: Self) {
349 self.0 &= rhs.0;
350 }
351}
352
353impl ::core::ops::BitOr for SDL_HapticEffectType {
354 type Output = Self;
355
356 #[inline(always)]
357 fn bitor(self, rhs: Self) -> Self::Output {
358 Self(self.0 | rhs.0)
359 }
360}
361
362impl ::core::ops::BitOrAssign for SDL_HapticEffectType {
363 #[inline(always)]
364 fn bitor_assign(&mut self, rhs: Self) {
365 self.0 |= rhs.0;
366 }
367}
368
369impl ::core::ops::BitXor for SDL_HapticEffectType {
370 type Output = Self;
371
372 #[inline(always)]
373 fn bitxor(self, rhs: Self) -> Self::Output {
374 Self(self.0 ^ rhs.0)
375 }
376}
377
378impl ::core::ops::BitXorAssign for SDL_HapticEffectType {
379 #[inline(always)]
380 fn bitxor_assign(&mut self, rhs: Self) {
381 self.0 ^= rhs.0;
382 }
383}
384
385impl ::core::ops::Not for SDL_HapticEffectType {
386 type Output = Self;
387
388 #[inline(always)]
389 fn not(self) -> Self::Output {
390 Self(!self.0)
391 }
392}
393
394impl SDL_HapticEffectType {
395 /// Constant effect supported.
396 ///
397 /// Constant haptic effect.
398 ///
399 /// ## Availability
400 /// This macro is available since SDL 3.2.0.
401 ///
402 /// ## See also
403 /// - [`SDL_HapticCondition`]
404 pub const CONSTANT: Self = Self((1_u32 as Uint16));
405 /// Sine wave effect supported.
406 ///
407 /// Periodic haptic effect that simulates sine waves.
408 ///
409 /// ## Availability
410 /// This macro is available since SDL 3.2.0.
411 ///
412 /// ## See also
413 /// - [`SDL_HapticPeriodic`]
414 pub const SINE: Self = Self((2_u32 as Uint16));
415 /// Square wave effect supported.
416 ///
417 /// Periodic haptic effect that simulates square waves.
418 ///
419 /// ## Availability
420 /// This macro is available since SDL 3.2.0.
421 ///
422 /// ## See also
423 /// - [`SDL_HapticPeriodic`]
424 pub const SQUARE: Self = Self((4_u32 as Uint16));
425 /// Triangle wave effect supported.
426 ///
427 /// Periodic haptic effect that simulates triangular waves.
428 ///
429 /// ## Availability
430 /// This macro is available since SDL 3.2.0.
431 ///
432 /// ## See also
433 /// - [`SDL_HapticPeriodic`]
434 pub const TRIANGLE: Self = Self((8_u32 as Uint16));
435 /// Sawtoothup wave effect supported.
436 ///
437 /// Periodic haptic effect that simulates saw tooth up waves.
438 ///
439 /// ## Availability
440 /// This macro is available since SDL 3.2.0.
441 ///
442 /// ## See also
443 /// - [`SDL_HapticPeriodic`]
444 pub const SAWTOOTHUP: Self = Self((16_u32 as Uint16));
445 /// Sawtoothdown wave effect supported.
446 ///
447 /// Periodic haptic effect that simulates saw tooth down waves.
448 ///
449 /// ## Availability
450 /// This macro is available since SDL 3.2.0.
451 ///
452 /// ## See also
453 /// - [`SDL_HapticPeriodic`]
454 pub const SAWTOOTHDOWN: Self = Self((32_u32 as Uint16));
455 /// Ramp effect supported.
456 ///
457 /// Ramp haptic effect.
458 ///
459 /// ## Availability
460 /// This macro is available since SDL 3.2.0.
461 ///
462 /// ## See also
463 /// - [`SDL_HapticRamp`]
464 pub const RAMP: Self = Self((64_u32 as Uint16));
465 /// Spring effect supported - uses axes position.
466 ///
467 /// Condition haptic effect that simulates a spring. Effect is based on the
468 /// axes position.
469 ///
470 /// ## Availability
471 /// This macro is available since SDL 3.2.0.
472 ///
473 /// ## See also
474 /// - [`SDL_HapticCondition`]
475 pub const SPRING: Self = Self((128_u32 as Uint16));
476 /// Damper effect supported - uses axes velocity.
477 ///
478 /// Condition haptic effect that simulates dampening. Effect is based on the
479 /// axes velocity.
480 ///
481 /// ## Availability
482 /// This macro is available since SDL 3.2.0.
483 ///
484 /// ## See also
485 /// - [`SDL_HapticCondition`]
486 pub const DAMPER: Self = Self((256_u32 as Uint16));
487 /// Inertia effect supported - uses axes acceleration.
488 ///
489 /// Condition haptic effect that simulates inertia. Effect is based on the axes
490 /// acceleration.
491 ///
492 /// ## Availability
493 /// This macro is available since SDL 3.2.0.
494 ///
495 /// ## See also
496 /// - [`SDL_HapticCondition`]
497 pub const INERTIA: Self = Self((512_u32 as Uint16));
498 /// Friction effect supported - uses axes movement.
499 ///
500 /// Condition haptic effect that simulates friction. Effect is based on the
501 /// axes movement.
502 ///
503 /// ## Availability
504 /// This macro is available since SDL 3.2.0.
505 ///
506 /// ## See also
507 /// - [`SDL_HapticCondition`]
508 pub const FRICTION: Self = Self((1024_u32 as Uint16));
509 /// Left/Right effect supported.
510 ///
511 /// Haptic effect for direct control over high/low frequency motors.
512 ///
513 /// ## Availability
514 /// This macro is available since SDL 3.2.0.
515 ///
516 /// ## See also
517 /// - [`SDL_HapticLeftRight`]
518 pub const LEFTRIGHT: Self = Self((2048_u32 as Uint16));
519 /// Reserved for future use.
520 ///
521 /// ## Availability
522 /// This macro is available since SDL 3.2.0.
523 pub const RESERVED1: Self = Self((4096_u32 as Uint16));
524 /// Reserved for future use.
525 ///
526 /// ## Availability
527 /// This macro is available since SDL 3.2.0.
528 pub const RESERVED2: Self = Self((8192_u32 as Uint16));
529 /// Reserved for future use.
530 ///
531 /// ## Availability
532 /// This macro is available since SDL 3.2.0.
533 pub const RESERVED3: Self = Self((16384_u32 as Uint16));
534 /// Custom effect is supported.
535 ///
536 /// User defined custom haptic effect.
537 ///
538 /// ## Availability
539 /// This macro is available since SDL 3.2.0.
540 pub const CUSTOM: Self = Self((32768_u32 as Uint16));
541 /// Device can set global gain.
542 ///
543 /// Device supports setting the global gain.
544 ///
545 /// ## Availability
546 /// This macro is available since SDL 3.2.0.
547 ///
548 /// ## See also
549 /// - [`SDL_SetHapticGain`]
550 pub const GAIN: Self = Self((65536_u32 as Uint16));
551 /// Device can set autocenter.
552 ///
553 /// Device supports setting autocenter.
554 ///
555 /// ## Availability
556 /// This macro is available since SDL 3.2.0.
557 ///
558 /// ## See also
559 /// - [`SDL_SetHapticAutocenter`]
560 pub const AUTOCENTER: Self = Self((131072_u32 as Uint16));
561 /// Device can be queried for effect status.
562 ///
563 /// Device supports querying effect status.
564 ///
565 /// ## Availability
566 /// This macro is available since SDL 3.2.0.
567 ///
568 /// ## See also
569 /// - [`SDL_GetHapticEffectStatus`]
570 pub const STATUS: Self = Self((262144_u32 as Uint16));
571 /// Device can be paused.
572 ///
573 /// Devices supports being paused.
574 ///
575 /// ## Availability
576 /// This macro is available since SDL 3.2.0.
577 ///
578 /// ## See also
579 /// - [`SDL_PauseHaptic`]
580 /// - [`SDL_ResumeHaptic`]
581 pub const PAUSE: Self = Self((524288_u32 as Uint16));
582}
583
584/// Constant effect supported.
585///
586/// Constant haptic effect.
587///
588/// ## Availability
589/// This macro is available since SDL 3.2.0.
590///
591/// ## See also
592/// - [`SDL_HapticCondition`]
593pub const SDL_HAPTIC_CONSTANT: SDL_HapticEffectType = SDL_HapticEffectType::CONSTANT;
594/// Sine wave effect supported.
595///
596/// Periodic haptic effect that simulates sine waves.
597///
598/// ## Availability
599/// This macro is available since SDL 3.2.0.
600///
601/// ## See also
602/// - [`SDL_HapticPeriodic`]
603pub const SDL_HAPTIC_SINE: SDL_HapticEffectType = SDL_HapticEffectType::SINE;
604/// Square wave effect supported.
605///
606/// Periodic haptic effect that simulates square waves.
607///
608/// ## Availability
609/// This macro is available since SDL 3.2.0.
610///
611/// ## See also
612/// - [`SDL_HapticPeriodic`]
613pub const SDL_HAPTIC_SQUARE: SDL_HapticEffectType = SDL_HapticEffectType::SQUARE;
614/// Triangle wave effect supported.
615///
616/// Periodic haptic effect that simulates triangular waves.
617///
618/// ## Availability
619/// This macro is available since SDL 3.2.0.
620///
621/// ## See also
622/// - [`SDL_HapticPeriodic`]
623pub const SDL_HAPTIC_TRIANGLE: SDL_HapticEffectType = SDL_HapticEffectType::TRIANGLE;
624/// Sawtoothup wave effect supported.
625///
626/// Periodic haptic effect that simulates saw tooth up waves.
627///
628/// ## Availability
629/// This macro is available since SDL 3.2.0.
630///
631/// ## See also
632/// - [`SDL_HapticPeriodic`]
633pub const SDL_HAPTIC_SAWTOOTHUP: SDL_HapticEffectType = SDL_HapticEffectType::SAWTOOTHUP;
634/// Sawtoothdown wave effect supported.
635///
636/// Periodic haptic effect that simulates saw tooth down waves.
637///
638/// ## Availability
639/// This macro is available since SDL 3.2.0.
640///
641/// ## See also
642/// - [`SDL_HapticPeriodic`]
643pub const SDL_HAPTIC_SAWTOOTHDOWN: SDL_HapticEffectType = SDL_HapticEffectType::SAWTOOTHDOWN;
644/// Ramp effect supported.
645///
646/// Ramp haptic effect.
647///
648/// ## Availability
649/// This macro is available since SDL 3.2.0.
650///
651/// ## See also
652/// - [`SDL_HapticRamp`]
653pub const SDL_HAPTIC_RAMP: SDL_HapticEffectType = SDL_HapticEffectType::RAMP;
654/// Spring effect supported - uses axes position.
655///
656/// Condition haptic effect that simulates a spring. Effect is based on the
657/// axes position.
658///
659/// ## Availability
660/// This macro is available since SDL 3.2.0.
661///
662/// ## See also
663/// - [`SDL_HapticCondition`]
664pub const SDL_HAPTIC_SPRING: SDL_HapticEffectType = SDL_HapticEffectType::SPRING;
665/// Damper effect supported - uses axes velocity.
666///
667/// Condition haptic effect that simulates dampening. Effect is based on the
668/// axes velocity.
669///
670/// ## Availability
671/// This macro is available since SDL 3.2.0.
672///
673/// ## See also
674/// - [`SDL_HapticCondition`]
675pub const SDL_HAPTIC_DAMPER: SDL_HapticEffectType = SDL_HapticEffectType::DAMPER;
676/// Inertia effect supported - uses axes acceleration.
677///
678/// Condition haptic effect that simulates inertia. Effect is based on the axes
679/// acceleration.
680///
681/// ## Availability
682/// This macro is available since SDL 3.2.0.
683///
684/// ## See also
685/// - [`SDL_HapticCondition`]
686pub const SDL_HAPTIC_INERTIA: SDL_HapticEffectType = SDL_HapticEffectType::INERTIA;
687/// Friction effect supported - uses axes movement.
688///
689/// Condition haptic effect that simulates friction. Effect is based on the
690/// axes movement.
691///
692/// ## Availability
693/// This macro is available since SDL 3.2.0.
694///
695/// ## See also
696/// - [`SDL_HapticCondition`]
697pub const SDL_HAPTIC_FRICTION: SDL_HapticEffectType = SDL_HapticEffectType::FRICTION;
698/// Left/Right effect supported.
699///
700/// Haptic effect for direct control over high/low frequency motors.
701///
702/// ## Availability
703/// This macro is available since SDL 3.2.0.
704///
705/// ## See also
706/// - [`SDL_HapticLeftRight`]
707pub const SDL_HAPTIC_LEFTRIGHT: SDL_HapticEffectType = SDL_HapticEffectType::LEFTRIGHT;
708/// Reserved for future use.
709///
710/// ## Availability
711/// This macro is available since SDL 3.2.0.
712pub const SDL_HAPTIC_RESERVED1: SDL_HapticEffectType = SDL_HapticEffectType::RESERVED1;
713/// Reserved for future use.
714///
715/// ## Availability
716/// This macro is available since SDL 3.2.0.
717pub const SDL_HAPTIC_RESERVED2: SDL_HapticEffectType = SDL_HapticEffectType::RESERVED2;
718/// Reserved for future use.
719///
720/// ## Availability
721/// This macro is available since SDL 3.2.0.
722pub const SDL_HAPTIC_RESERVED3: SDL_HapticEffectType = SDL_HapticEffectType::RESERVED3;
723/// Custom effect is supported.
724///
725/// User defined custom haptic effect.
726///
727/// ## Availability
728/// This macro is available since SDL 3.2.0.
729pub const SDL_HAPTIC_CUSTOM: SDL_HapticEffectType = SDL_HapticEffectType::CUSTOM;
730/// Device can set global gain.
731///
732/// Device supports setting the global gain.
733///
734/// ## Availability
735/// This macro is available since SDL 3.2.0.
736///
737/// ## See also
738/// - [`SDL_SetHapticGain`]
739pub const SDL_HAPTIC_GAIN: SDL_HapticEffectType = SDL_HapticEffectType::GAIN;
740/// Device can set autocenter.
741///
742/// Device supports setting autocenter.
743///
744/// ## Availability
745/// This macro is available since SDL 3.2.0.
746///
747/// ## See also
748/// - [`SDL_SetHapticAutocenter`]
749pub const SDL_HAPTIC_AUTOCENTER: SDL_HapticEffectType = SDL_HapticEffectType::AUTOCENTER;
750/// Device can be queried for effect status.
751///
752/// Device supports querying effect status.
753///
754/// ## Availability
755/// This macro is available since SDL 3.2.0.
756///
757/// ## See also
758/// - [`SDL_GetHapticEffectStatus`]
759pub const SDL_HAPTIC_STATUS: SDL_HapticEffectType = SDL_HapticEffectType::STATUS;
760/// Device can be paused.
761///
762/// Devices supports being paused.
763///
764/// ## Availability
765/// This macro is available since SDL 3.2.0.
766///
767/// ## See also
768/// - [`SDL_PauseHaptic`]
769/// - [`SDL_ResumeHaptic`]
770pub const SDL_HAPTIC_PAUSE: SDL_HapticEffectType = SDL_HapticEffectType::PAUSE;
771
772impl SDL_HapticEffectType {
773 /// Initialize a `SDL_HapticEffectType` from a raw value.
774 #[inline(always)]
775 pub const fn new(value: Uint16) -> Self {
776 Self(value)
777 }
778}
779
780impl SDL_HapticEffectType {
781 /// Get a copy of the inner raw value.
782 #[inline(always)]
783 pub const fn value(&self) -> Uint16 {
784 self.0
785 }
786}
787
788#[cfg(feature = "metadata")]
789impl sdl3_sys::metadata::GroupMetadata for SDL_HapticEffectType {
790 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
791 &crate::metadata::haptic::METADATA_SDL_HapticEffectType;
792}
793
794/// * Type of coordinates used for haptic direction.
795///
796/// ## Known values (`sdl3-sys`)
797/// | Associated constant | Global constant | Description |
798/// | ------------------- | --------------- | ----------- |
799/// | [`POLAR`](SDL_HapticDirectionType::POLAR) | [`SDL_HAPTIC_POLAR`] | Uses polar coordinates for the direction. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticDirection`] |
800/// | [`CARTESIAN`](SDL_HapticDirectionType::CARTESIAN) | [`SDL_HAPTIC_CARTESIAN`] | Uses cartesian coordinates for the direction. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticDirection`] |
801/// | [`SPHERICAL`](SDL_HapticDirectionType::SPHERICAL) | [`SDL_HAPTIC_SPHERICAL`] | Uses spherical coordinates for the direction. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticDirection`] |
802/// | [`STEERING_AXIS`](SDL_HapticDirectionType::STEERING_AXIS) | [`SDL_HAPTIC_STEERING_AXIS`] | Use this value to play an effect on the steering wheel axis. This provides better compatibility across platforms and devices as SDL will guess the correct axis. \since This macro is available since SDL 3.2.0. \sa [`SDL_HapticDirection`] |
803#[repr(transparent)]
804#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
805pub struct SDL_HapticDirectionType(pub Uint8);
806
807impl ::core::cmp::PartialEq<Uint8> for SDL_HapticDirectionType {
808 #[inline(always)]
809 fn eq(&self, other: &Uint8) -> bool {
810 &self.0 == other
811 }
812}
813
814impl ::core::cmp::PartialEq<SDL_HapticDirectionType> for Uint8 {
815 #[inline(always)]
816 fn eq(&self, other: &SDL_HapticDirectionType) -> bool {
817 self == &other.0
818 }
819}
820
821impl From<SDL_HapticDirectionType> for Uint8 {
822 #[inline(always)]
823 fn from(value: SDL_HapticDirectionType) -> Self {
824 value.0
825 }
826}
827
828#[cfg(feature = "debug-impls")]
829impl ::core::fmt::Debug for SDL_HapticDirectionType {
830 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
831 #[allow(unreachable_patterns)]
832 f.write_str(match *self {
833 Self::POLAR => "SDL_HAPTIC_POLAR",
834 Self::CARTESIAN => "SDL_HAPTIC_CARTESIAN",
835 Self::SPHERICAL => "SDL_HAPTIC_SPHERICAL",
836 Self::STEERING_AXIS => "SDL_HAPTIC_STEERING_AXIS",
837
838 _ => return write!(f, "SDL_HapticDirectionType({})", self.0),
839 })
840 }
841}
842
843impl SDL_HapticDirectionType {
844 /// Uses polar coordinates for the direction.
845 ///
846 /// ## Availability
847 /// This macro is available since SDL 3.2.0.
848 ///
849 /// ## See also
850 /// - [`SDL_HapticDirection`]
851 pub const POLAR: Self = Self((0 as Uint8));
852 /// Uses cartesian coordinates for the direction.
853 ///
854 /// ## Availability
855 /// This macro is available since SDL 3.2.0.
856 ///
857 /// ## See also
858 /// - [`SDL_HapticDirection`]
859 pub const CARTESIAN: Self = Self((1 as Uint8));
860 /// Uses spherical coordinates for the direction.
861 ///
862 /// ## Availability
863 /// This macro is available since SDL 3.2.0.
864 ///
865 /// ## See also
866 /// - [`SDL_HapticDirection`]
867 pub const SPHERICAL: Self = Self((2 as Uint8));
868 /// Use this value to play an effect on the steering wheel axis.
869 ///
870 /// This provides better compatibility across platforms and devices as SDL will
871 /// guess the correct axis.
872 ///
873 /// ## Availability
874 /// This macro is available since SDL 3.2.0.
875 ///
876 /// ## See also
877 /// - [`SDL_HapticDirection`]
878 pub const STEERING_AXIS: Self = Self((3 as Uint8));
879}
880
881/// Uses polar coordinates for the direction.
882///
883/// ## Availability
884/// This macro is available since SDL 3.2.0.
885///
886/// ## See also
887/// - [`SDL_HapticDirection`]
888pub const SDL_HAPTIC_POLAR: SDL_HapticDirectionType = SDL_HapticDirectionType::POLAR;
889/// Uses cartesian coordinates for the direction.
890///
891/// ## Availability
892/// This macro is available since SDL 3.2.0.
893///
894/// ## See also
895/// - [`SDL_HapticDirection`]
896pub const SDL_HAPTIC_CARTESIAN: SDL_HapticDirectionType = SDL_HapticDirectionType::CARTESIAN;
897/// Uses spherical coordinates for the direction.
898///
899/// ## Availability
900/// This macro is available since SDL 3.2.0.
901///
902/// ## See also
903/// - [`SDL_HapticDirection`]
904pub const SDL_HAPTIC_SPHERICAL: SDL_HapticDirectionType = SDL_HapticDirectionType::SPHERICAL;
905/// Use this value to play an effect on the steering wheel axis.
906///
907/// This provides better compatibility across platforms and devices as SDL will
908/// guess the correct axis.
909///
910/// ## Availability
911/// This macro is available since SDL 3.2.0.
912///
913/// ## See also
914/// - [`SDL_HapticDirection`]
915pub const SDL_HAPTIC_STEERING_AXIS: SDL_HapticDirectionType =
916 SDL_HapticDirectionType::STEERING_AXIS;
917
918impl SDL_HapticDirectionType {
919 /// Initialize a `SDL_HapticDirectionType` from a raw value.
920 #[inline(always)]
921 pub const fn new(value: Uint8) -> Self {
922 Self(value)
923 }
924}
925
926impl SDL_HapticDirectionType {
927 /// Get a copy of the inner raw value.
928 #[inline(always)]
929 pub const fn value(&self) -> Uint8 {
930 self.0
931 }
932}
933
934#[cfg(feature = "metadata")]
935impl sdl3_sys::metadata::GroupMetadata for SDL_HapticDirectionType {
936 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
937 &crate::metadata::haptic::METADATA_SDL_HapticDirectionType;
938}
939
940/// ID for haptic effects.
941///
942/// This is -1 if the ID is invalid.
943///
944/// ## See also
945/// - [`SDL_CreateHapticEffect`]
946#[repr(transparent)]
947#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
948#[cfg_attr(feature = "debug-impls", derive(Debug))]
949pub struct SDL_HapticEffectID(pub ::core::ffi::c_int);
950
951impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_HapticEffectID {
952 #[inline(always)]
953 fn eq(&self, other: &::core::ffi::c_int) -> bool {
954 &self.0 == other
955 }
956}
957
958impl ::core::cmp::PartialEq<SDL_HapticEffectID> for ::core::ffi::c_int {
959 #[inline(always)]
960 fn eq(&self, other: &SDL_HapticEffectID) -> bool {
961 self == &other.0
962 }
963}
964
965impl From<SDL_HapticEffectID> for ::core::ffi::c_int {
966 #[inline(always)]
967 fn from(value: SDL_HapticEffectID) -> Self {
968 value.0
969 }
970}
971
972#[cfg(feature = "display-impls")]
973impl ::core::fmt::Display for SDL_HapticEffectID {
974 #[inline(always)]
975 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
976 <::core::ffi::c_int as ::core::fmt::Display>::fmt(&self.0, f)
977 }
978}
979
980impl SDL_HapticEffectID {
981 /// Initialize a `SDL_HapticEffectID` from a raw value.
982 #[inline(always)]
983 pub const fn new(value: ::core::ffi::c_int) -> Self {
984 Self(value)
985 }
986}
987
988impl SDL_HapticEffectID {
989 /// Get a copy of the inner raw value.
990 #[inline(always)]
991 pub const fn value(&self) -> ::core::ffi::c_int {
992 self.0
993 }
994}
995
996#[cfg(feature = "metadata")]
997impl sdl3_sys::metadata::GroupMetadata for SDL_HapticEffectID {
998 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
999 &crate::metadata::haptic::METADATA_SDL_HapticEffectID;
1000}
1001
1002/// Structure that represents a haptic direction.
1003///
1004/// This is the direction where the force comes from, instead of the direction
1005/// in which the force is exerted.
1006///
1007/// Directions can be specified by:
1008///
1009/// - [`SDL_HAPTIC_POLAR`] : Specified by polar coordinates.
1010/// - [`SDL_HAPTIC_CARTESIAN`] : Specified by cartesian coordinates.
1011/// - [`SDL_HAPTIC_SPHERICAL`] : Specified by spherical coordinates.
1012///
1013/// Cardinal directions of the haptic device are relative to the positioning of
1014/// the device. North is considered to be away from the user.
1015///
1016/// The following diagram represents the cardinal directions:
1017///
1018/// ```text
1019/// .--.
1020/// |__| .-------.
1021/// |=.| |.-----.|
1022/// |--| || ||
1023/// | | |'-----'|
1024/// |__|~')_____('
1025/// [ COMPUTER ]
1026///
1027///
1028/// North (0,-1)
1029/// ^
1030/// |
1031/// |
1032/// (-1,0) West <----[ HAPTIC ]----> East (1,0)
1033/// |
1034/// |
1035/// v
1036/// South (0,1)
1037///
1038///
1039/// [ USER ]
1040/// \|||/
1041/// (o o)
1042/// ---ooO-(_)-Ooo---
1043/// ```
1044///
1045/// If type is [`SDL_HAPTIC_POLAR`], direction is encoded by hundredths of a degree
1046/// starting north and turning clockwise. [`SDL_HAPTIC_POLAR`] only uses the first
1047/// `dir` parameter. The cardinal directions would be:
1048///
1049/// - North: 0 (0 degrees)
1050/// - East: 9000 (90 degrees)
1051/// - South: 18000 (180 degrees)
1052/// - West: 27000 (270 degrees)
1053///
1054/// If type is [`SDL_HAPTIC_CARTESIAN`], direction is encoded by three positions (X
1055/// axis, Y axis and Z axis (with 3 axes)). [`SDL_HAPTIC_CARTESIAN`] uses the first
1056/// three `dir` parameters. The cardinal directions would be:
1057///
1058/// - North: 0,-1, 0
1059/// - East: 1, 0, 0
1060/// - South: 0, 1, 0
1061/// - West: -1, 0, 0
1062///
1063/// The Z axis represents the height of the effect if supported, otherwise it's
1064/// unused. In cartesian encoding (1, 2) would be the same as (2, 4), you can
1065/// use any multiple you want, only the direction matters.
1066///
1067/// If type is [`SDL_HAPTIC_SPHERICAL`], direction is encoded by two rotations. The
1068/// first two `dir` parameters are used. The `dir` parameters are as follows
1069/// (all values are in hundredths of degrees):
1070///
1071/// - Degrees from (1, 0) rotated towards (0, 1).
1072/// - Degrees towards (0, 0, 1) (device needs at least 3 axes).
1073///
1074/// Example of force coming from the south with all encodings (force coming
1075/// from the south means the user will have to pull the stick to counteract):
1076///
1077/// ```c
1078/// SDL_HapticDirection direction;
1079///
1080/// // Cartesian directions
1081/// direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.
1082/// direction.dir[0] = 0; // X position
1083/// direction.dir[1] = 1; // Y position
1084/// // Assuming the device has 2 axes, we don't need to specify third parameter.
1085///
1086/// // Polar directions
1087/// direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
1088/// direction.dir[0] = 18000; // Polar only uses first parameter
1089///
1090/// // Spherical coordinates
1091/// direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding
1092/// direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
1093/// ```
1094///
1095/// ## Availability
1096/// This struct is available since SDL 3.2.0.
1097///
1098/// ## See also
1099/// - [`SDL_HAPTIC_POLAR`]
1100/// - [`SDL_HAPTIC_CARTESIAN`]
1101/// - [`SDL_HAPTIC_SPHERICAL`]
1102/// - [`SDL_HAPTIC_STEERING_AXIS`]
1103/// - [`SDL_HapticEffect`]
1104/// - [`SDL_GetNumHapticAxes`]
1105#[repr(C)]
1106#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1107#[cfg_attr(feature = "debug-impls", derive(Debug))]
1108pub struct SDL_HapticDirection {
1109 /// The type of encoding.
1110 pub r#type: SDL_HapticDirectionType,
1111 /// The encoded direction.
1112 pub dir: [Sint32; 3],
1113}
1114
1115/// A structure containing a template for a Constant effect.
1116///
1117/// This struct is exclusively for the [`SDL_HAPTIC_CONSTANT`] effect.
1118///
1119/// A constant effect applies a constant force in the specified direction to
1120/// the joystick.
1121///
1122/// ## Availability
1123/// This struct is available since SDL 3.2.0.
1124///
1125/// ## See also
1126/// - [`SDL_HAPTIC_CONSTANT`]
1127/// - [`SDL_HapticEffect`]
1128#[repr(C)]
1129#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1130#[cfg_attr(feature = "debug-impls", derive(Debug))]
1131pub struct SDL_HapticConstant {
1132 /// [`SDL_HAPTIC_CONSTANT`]
1133 pub r#type: SDL_HapticEffectType,
1134 /// Direction of the effect.
1135 pub direction: SDL_HapticDirection,
1136 /// Duration of the effect.
1137 pub length: Uint32,
1138 /// Delay before starting the effect.
1139 pub delay: Uint16,
1140 /// Button that triggers the effect.
1141 pub button: Uint16,
1142 /// How soon it can be triggered again after button.
1143 pub interval: Uint16,
1144 /// Strength of the constant effect.
1145 pub level: Sint16,
1146 /// Duration of the attack.
1147 pub attack_length: Uint16,
1148 /// Level at the start of the attack.
1149 pub attack_level: Uint16,
1150 /// Duration of the fade.
1151 pub fade_length: Uint16,
1152 /// Level at the end of the fade.
1153 pub fade_level: Uint16,
1154}
1155
1156/// A structure containing a template for a Periodic effect.
1157///
1158/// The struct handles the following effects:
1159///
1160/// - [`SDL_HAPTIC_SINE`]
1161/// - [`SDL_HAPTIC_SQUARE`]
1162/// - [`SDL_HAPTIC_TRIANGLE`]
1163/// - [`SDL_HAPTIC_SAWTOOTHUP`]
1164/// - [`SDL_HAPTIC_SAWTOOTHDOWN`]
1165///
1166/// A periodic effect consists in a wave-shaped effect that repeats itself over
1167/// time. The type determines the shape of the wave and the parameters
1168/// determine the dimensions of the wave.
1169///
1170/// Phase is given by hundredth of a degree meaning that giving the phase a
1171/// value of 9000 will displace it 25% of its period. Here are sample values:
1172///
1173/// - 0: No phase displacement.
1174/// - 9000: Displaced 25% of its period.
1175/// - 18000: Displaced 50% of its period.
1176/// - 27000: Displaced 75% of its period.
1177/// - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.
1178///
1179/// Examples:
1180///
1181/// ```text
1182/// SDL_HAPTIC_SINE
1183/// __ __ __ __
1184/// / \ / \ / \ /
1185/// / \__/ \__/ \__/
1186///
1187/// SDL_HAPTIC_SQUARE
1188/// __ __ __ __ __
1189/// | | | | | | | | | |
1190/// | |__| |__| |__| |__| |
1191///
1192/// SDL_HAPTIC_TRIANGLE
1193/// /\ /\ /\ /\ /\
1194/// / \ / \ / \ / \ /
1195/// / \/ \/ \/ \/
1196///
1197/// SDL_HAPTIC_SAWTOOTHUP
1198/// /| /| /| /| /| /| /|
1199/// / | / | / | / | / | / | / |
1200/// / |/ |/ |/ |/ |/ |/ |
1201///
1202/// SDL_HAPTIC_SAWTOOTHDOWN
1203/// \ |\ |\ |\ |\ |\ |\ |
1204/// \ | \ | \ | \ | \ | \ | \ |
1205/// \| \| \| \| \| \| \|
1206/// ```
1207///
1208/// ## Availability
1209/// This struct is available since SDL 3.2.0.
1210///
1211/// ## See also
1212/// - [`SDL_HAPTIC_SINE`]
1213/// - [`SDL_HAPTIC_SQUARE`]
1214/// - [`SDL_HAPTIC_TRIANGLE`]
1215/// - [`SDL_HAPTIC_SAWTOOTHUP`]
1216/// - [`SDL_HAPTIC_SAWTOOTHDOWN`]
1217/// - [`SDL_HapticEffect`]
1218#[repr(C)]
1219#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1220#[cfg_attr(feature = "debug-impls", derive(Debug))]
1221pub struct SDL_HapticPeriodic {
1222 /// [`SDL_HAPTIC_SINE`], [`SDL_HAPTIC_SQUARE`]
1223 /// [`SDL_HAPTIC_TRIANGLE`], [`SDL_HAPTIC_SAWTOOTHUP`] or
1224 /// [`SDL_HAPTIC_SAWTOOTHDOWN`]
1225 pub r#type: SDL_HapticEffectType,
1226 /// Direction of the effect.
1227 pub direction: SDL_HapticDirection,
1228 /// Duration of the effect.
1229 pub length: Uint32,
1230 /// Delay before starting the effect.
1231 pub delay: Uint16,
1232 /// Button that triggers the effect.
1233 pub button: Uint16,
1234 /// How soon it can be triggered again after button.
1235 pub interval: Uint16,
1236 /// Period of the wave.
1237 pub period: Uint16,
1238 /// Peak value; if negative, equivalent to 180 degrees extra phase shift.
1239 pub magnitude: Sint16,
1240 /// Mean value of the wave.
1241 pub offset: Sint16,
1242 /// Positive phase shift given by hundredth of a degree.
1243 pub phase: Uint16,
1244 /// Duration of the attack.
1245 pub attack_length: Uint16,
1246 /// Level at the start of the attack.
1247 pub attack_level: Uint16,
1248 /// Duration of the fade.
1249 pub fade_length: Uint16,
1250 /// Level at the end of the fade.
1251 pub fade_level: Uint16,
1252}
1253
1254/// A structure containing a template for a Condition effect.
1255///
1256/// The struct handles the following effects:
1257///
1258/// - [`SDL_HAPTIC_SPRING`]\: Effect based on axes position.
1259/// - [`SDL_HAPTIC_DAMPER`]\: Effect based on axes velocity.
1260/// - [`SDL_HAPTIC_INERTIA`]\: Effect based on axes acceleration.
1261/// - [`SDL_HAPTIC_FRICTION`]\: Effect based on axes movement.
1262///
1263/// Direction is handled by condition internals instead of a direction member.
1264/// The condition effect specific members have three parameters. The first
1265/// refers to the X axis, the second refers to the Y axis and the third refers
1266/// to the Z axis. The right terms refer to the positive side of the axis and
1267/// the left terms refer to the negative side of the axis. Please refer to the
1268/// [`SDL_HapticDirection`] diagram for which side is positive and which is
1269/// negative.
1270///
1271/// ## Availability
1272/// This struct is available since SDL 3.2.0.
1273///
1274/// ## See also
1275/// - [`SDL_HapticDirection`]
1276/// - [`SDL_HAPTIC_SPRING`]
1277/// - [`SDL_HAPTIC_DAMPER`]
1278/// - [`SDL_HAPTIC_INERTIA`]
1279/// - [`SDL_HAPTIC_FRICTION`]
1280/// - [`SDL_HapticEffect`]
1281#[repr(C)]
1282#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1283#[cfg_attr(feature = "debug-impls", derive(Debug))]
1284pub struct SDL_HapticCondition {
1285 /// [`SDL_HAPTIC_SPRING`], [`SDL_HAPTIC_DAMPER`],
1286 /// [`SDL_HAPTIC_INERTIA`] or [`SDL_HAPTIC_FRICTION`]
1287 pub r#type: SDL_HapticEffectType,
1288 /// Direction of the effect.
1289 pub direction: SDL_HapticDirection,
1290 /// Duration of the effect.
1291 pub length: Uint32,
1292 /// Delay before starting the effect.
1293 pub delay: Uint16,
1294 /// Button that triggers the effect.
1295 pub button: Uint16,
1296 /// How soon it can be triggered again after button.
1297 pub interval: Uint16,
1298 /// Level when joystick is to the positive side; max 0xFFFF.
1299 pub right_sat: [Uint16; 3],
1300 /// Level when joystick is to the negative side; max 0xFFFF.
1301 pub left_sat: [Uint16; 3],
1302 /// How fast to increase the force towards the positive side.
1303 pub right_coeff: [Sint16; 3],
1304 /// How fast to increase the force towards the negative side.
1305 pub left_coeff: [Sint16; 3],
1306 /// Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered.
1307 pub deadband: [Uint16; 3],
1308 /// Position of the dead zone.
1309 pub center: [Sint16; 3],
1310}
1311
1312/// A structure containing a template for a Ramp effect.
1313///
1314/// This struct is exclusively for the [`SDL_HAPTIC_RAMP`] effect.
1315///
1316/// The ramp effect starts at start strength and ends at end strength. It
1317/// augments in linear fashion. If you use attack and fade with a ramp the
1318/// effects get added to the ramp effect making the effect become quadratic
1319/// instead of linear.
1320///
1321/// ## Availability
1322/// This struct is available since SDL 3.2.0.
1323///
1324/// ## See also
1325/// - [`SDL_HAPTIC_RAMP`]
1326/// - [`SDL_HapticEffect`]
1327#[repr(C)]
1328#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1329#[cfg_attr(feature = "debug-impls", derive(Debug))]
1330pub struct SDL_HapticRamp {
1331 /// [`SDL_HAPTIC_RAMP`]
1332 pub r#type: SDL_HapticEffectType,
1333 /// Direction of the effect.
1334 pub direction: SDL_HapticDirection,
1335 /// Duration of the effect.
1336 pub length: Uint32,
1337 /// Delay before starting the effect.
1338 pub delay: Uint16,
1339 /// Button that triggers the effect.
1340 pub button: Uint16,
1341 /// How soon it can be triggered again after button.
1342 pub interval: Uint16,
1343 /// Beginning strength level.
1344 pub start: Sint16,
1345 /// Ending strength level.
1346 pub end: Sint16,
1347 /// Duration of the attack.
1348 pub attack_length: Uint16,
1349 /// Level at the start of the attack.
1350 pub attack_level: Uint16,
1351 /// Duration of the fade.
1352 pub fade_length: Uint16,
1353 /// Level at the end of the fade.
1354 pub fade_level: Uint16,
1355}
1356
1357/// A structure containing a template for a Left/Right effect.
1358///
1359/// This struct is exclusively for the [`SDL_HAPTIC_LEFTRIGHT`] effect.
1360///
1361/// The Left/Right effect is used to explicitly control the large and small
1362/// motors, commonly found in modern game controllers. The small (right) motor
1363/// is high frequency, and the large (left) motor is low frequency.
1364///
1365/// ## Availability
1366/// This struct is available since SDL 3.2.0.
1367///
1368/// ## See also
1369/// - [`SDL_HAPTIC_LEFTRIGHT`]
1370/// - [`SDL_HapticEffect`]
1371#[repr(C)]
1372#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1373#[cfg_attr(feature = "debug-impls", derive(Debug))]
1374pub struct SDL_HapticLeftRight {
1375 /// [`SDL_HAPTIC_LEFTRIGHT`]
1376 pub r#type: SDL_HapticEffectType,
1377 /// Duration of the effect in milliseconds.
1378 pub length: Uint32,
1379 /// Control of the large controller motor.
1380 pub large_magnitude: Uint16,
1381 /// Control of the small controller motor.
1382 pub small_magnitude: Uint16,
1383}
1384
1385/// A structure containing a template for the [`SDL_HAPTIC_CUSTOM`] effect.
1386///
1387/// This struct is exclusively for the [`SDL_HAPTIC_CUSTOM`] effect.
1388///
1389/// A custom force feedback effect is much like a periodic effect, where the
1390/// application can define its exact shape. You will have to allocate the data
1391/// yourself. Data should consist of channels * samples Uint16 samples.
1392///
1393/// If channels is one, the effect is rotated using the defined direction.
1394/// Otherwise it uses the samples in data for the different axes.
1395///
1396/// ## Availability
1397/// This struct is available since SDL 3.2.0.
1398///
1399/// ## See also
1400/// - [`SDL_HAPTIC_CUSTOM`]
1401/// - [`SDL_HapticEffect`]
1402#[repr(C)]
1403#[derive(Clone, Copy)]
1404#[cfg_attr(feature = "debug-impls", derive(Debug))]
1405pub struct SDL_HapticCustom {
1406 /// [`SDL_HAPTIC_CUSTOM`]
1407 pub r#type: SDL_HapticEffectType,
1408 /// Direction of the effect.
1409 pub direction: SDL_HapticDirection,
1410 /// Duration of the effect.
1411 pub length: Uint32,
1412 /// Delay before starting the effect.
1413 pub delay: Uint16,
1414 /// Button that triggers the effect.
1415 pub button: Uint16,
1416 /// How soon it can be triggered again after button.
1417 pub interval: Uint16,
1418 /// Axes to use, minimum of one.
1419 pub channels: Uint8,
1420 /// Sample periods.
1421 pub period: Uint16,
1422 /// Amount of samples.
1423 pub samples: Uint16,
1424 /// Should contain channels*samples items.
1425 pub data: *mut Uint16,
1426 /// Duration of the attack.
1427 pub attack_length: Uint16,
1428 /// Level at the start of the attack.
1429 pub attack_level: Uint16,
1430 /// Duration of the fade.
1431 pub fade_length: Uint16,
1432 /// Level at the end of the fade.
1433 pub fade_level: Uint16,
1434}
1435
1436impl ::core::default::Default for SDL_HapticCustom {
1437 /// Initialize all fields to zero
1438 #[inline(always)]
1439 fn default() -> Self {
1440 unsafe { ::core::mem::MaybeUninit::<Self>::zeroed().assume_init() }
1441 }
1442}
1443
1444/// The generic template for any haptic effect.
1445///
1446/// All values max at 32767 (0x7FFF). Signed values also can be negative. Time
1447/// values unless specified otherwise are in milliseconds.
1448///
1449/// You can also pass [`SDL_HAPTIC_INFINITY`] to length instead of a 0-32767 value.
1450/// Neither delay, interval, attack_length nor fade_length support
1451/// [`SDL_HAPTIC_INFINITY`]. Fade will also not be used since effect never ends.
1452///
1453/// Additionally, the [`SDL_HAPTIC_RAMP`] effect does not support a duration of
1454/// [`SDL_HAPTIC_INFINITY`].
1455///
1456/// Button triggers may not be supported on all devices, it is advised to not
1457/// use them if possible. Buttons start at index 1 instead of index 0 like the
1458/// joystick.
1459///
1460/// If both attack_length and fade_level are 0, the envelope is not used,
1461/// otherwise both values are used.
1462///
1463/// Common parts:
1464///
1465/// ```c
1466/// // Replay - All effects have this
1467/// Uint32 length; // Duration of effect (ms).
1468/// Uint16 delay; // Delay before starting effect.
1469///
1470/// // Trigger - All effects have this
1471/// Uint16 button; // Button that triggers effect.
1472/// Uint16 interval; // How soon before effect can be triggered again.
1473///
1474/// // Envelope - All effects except condition effects have this
1475/// Uint16 attack_length; // Duration of the attack (ms).
1476/// Uint16 attack_level; // Level at the start of the attack.
1477/// Uint16 fade_length; // Duration of the fade out (ms).
1478/// Uint16 fade_level; // Level at the end of the fade.
1479/// ```
1480///
1481/// Here we have an example of a constant effect evolution in time:
1482///
1483/// ```text
1484/// Strength
1485/// ^
1486/// |
1487/// | effect level --> _________________
1488/// | / \
1489/// | / \
1490/// | / \
1491/// | / \
1492/// | attack_level --> | \
1493/// | | | <--- fade_level
1494/// |
1495/// +--------------------------------------------------> Time
1496/// [--] [---]
1497/// attack_length fade_length
1498///
1499/// [------------------][-----------------------]
1500/// delay length
1501/// ```
1502///
1503/// Note either the attack_level or the fade_level may be above the actual
1504/// effect level.
1505///
1506/// ## Availability
1507/// This struct is available since SDL 3.2.0.
1508///
1509/// ## See also
1510/// - [`SDL_HapticConstant`]
1511/// - [`SDL_HapticPeriodic`]
1512/// - [`SDL_HapticCondition`]
1513/// - [`SDL_HapticRamp`]
1514/// - [`SDL_HapticLeftRight`]
1515/// - [`SDL_HapticCustom`]
1516#[repr(C)]
1517#[derive(Clone, Copy)]
1518pub union SDL_HapticEffect {
1519 /// Effect type.
1520 pub r#type: SDL_HapticEffectType,
1521 /// Constant effect.
1522 pub constant: SDL_HapticConstant,
1523 /// Periodic effect.
1524 pub periodic: SDL_HapticPeriodic,
1525 /// Condition effect.
1526 pub condition: SDL_HapticCondition,
1527 /// Ramp effect.
1528 pub ramp: SDL_HapticRamp,
1529 /// Left/Right effect.
1530 pub leftright: SDL_HapticLeftRight,
1531 /// Custom effect.
1532 pub custom: SDL_HapticCustom,
1533}
1534
1535impl ::core::default::Default for SDL_HapticEffect {
1536 /// Initialize all fields to zero
1537 #[inline(always)]
1538 fn default() -> Self {
1539 unsafe { ::core::mem::MaybeUninit::<Self>::zeroed().assume_init() }
1540 }
1541}
1542
1543/// This is a unique ID for a haptic device for the time it is connected to the
1544/// system, and is never reused for the lifetime of the application.
1545///
1546/// If the haptic device is disconnected and reconnected, it will get a new ID.
1547///
1548/// The value 0 is an invalid ID.
1549///
1550/// ## Availability
1551/// This datatype is available since SDL 3.2.0.
1552#[repr(transparent)]
1553#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
1554#[cfg_attr(feature = "debug-impls", derive(Debug))]
1555pub struct SDL_HapticID(pub Uint32);
1556
1557impl ::core::cmp::PartialEq<Uint32> for SDL_HapticID {
1558 #[inline(always)]
1559 fn eq(&self, other: &Uint32) -> bool {
1560 &self.0 == other
1561 }
1562}
1563
1564impl ::core::cmp::PartialEq<SDL_HapticID> for Uint32 {
1565 #[inline(always)]
1566 fn eq(&self, other: &SDL_HapticID) -> bool {
1567 self == &other.0
1568 }
1569}
1570
1571impl From<SDL_HapticID> for Uint32 {
1572 #[inline(always)]
1573 fn from(value: SDL_HapticID) -> Self {
1574 value.0
1575 }
1576}
1577
1578#[cfg(feature = "display-impls")]
1579impl ::core::fmt::Display for SDL_HapticID {
1580 #[inline(always)]
1581 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1582 <Uint32 as ::core::fmt::Display>::fmt(&self.0, f)
1583 }
1584}
1585
1586impl SDL_HapticID {
1587 /// Initialize a `SDL_HapticID` from a raw value.
1588 #[inline(always)]
1589 pub const fn new(value: Uint32) -> Self {
1590 Self(value)
1591 }
1592}
1593
1594impl SDL_HapticID {
1595 /// Get a copy of the inner raw value.
1596 #[inline(always)]
1597 pub const fn value(&self) -> Uint32 {
1598 self.0
1599 }
1600}
1601
1602#[cfg(feature = "metadata")]
1603impl sdl3_sys::metadata::GroupMetadata for SDL_HapticID {
1604 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
1605 &crate::metadata::haptic::METADATA_SDL_HapticID;
1606}
1607
1608unsafe extern "C" {
1609 /// Get a list of currently connected haptic devices.
1610 ///
1611 /// ## Parameters
1612 /// - `count`: a pointer filled in with the number of haptic devices
1613 /// returned, may be NULL.
1614 ///
1615 /// ## Return value
1616 /// Returns a 0 terminated array of haptic device instance IDs or NULL on
1617 /// failure; call [`SDL_GetError()`] for more information. This should be
1618 /// freed with [`SDL_free()`] when it is no longer needed.
1619 ///
1620 /// ## Availability
1621 /// This function is available since SDL 3.2.0.
1622 ///
1623 /// ## See also
1624 /// - [`SDL_OpenHaptic`]
1625 pub fn SDL_GetHaptics(count: *mut ::core::ffi::c_int) -> *mut SDL_HapticID;
1626}
1627
1628unsafe extern "C" {
1629 /// Get the implementation dependent name of a haptic device.
1630 ///
1631 /// This can be called before any haptic devices are opened.
1632 ///
1633 /// ## Parameters
1634 /// - `instance_id`: the haptic device instance ID.
1635 ///
1636 /// ## Return value
1637 /// Returns the name of the selected haptic device. If no name can be found,
1638 /// this function returns NULL; call [`SDL_GetError()`] for more
1639 /// information.
1640 ///
1641 /// ## Availability
1642 /// This function is available since SDL 3.2.0.
1643 ///
1644 /// ## See also
1645 /// - [`SDL_GetHapticName`]
1646 /// - [`SDL_OpenHaptic`]
1647 pub fn SDL_GetHapticNameForID(instance_id: SDL_HapticID) -> *const ::core::ffi::c_char;
1648}
1649
1650unsafe extern "C" {
1651 /// Open a haptic device for use.
1652 ///
1653 /// The index passed as an argument refers to the N'th haptic device on this
1654 /// system.
1655 ///
1656 /// When opening a haptic device, its gain will be set to maximum and
1657 /// autocenter will be disabled. To modify these values use [`SDL_SetHapticGain()`]
1658 /// and [`SDL_SetHapticAutocenter()`].
1659 ///
1660 /// ## Parameters
1661 /// - `instance_id`: the haptic device instance ID.
1662 ///
1663 /// ## Return value
1664 /// Returns the device identifier or NULL on failure; call [`SDL_GetError()`] for
1665 /// more information.
1666 ///
1667 /// ## Availability
1668 /// This function is available since SDL 3.2.0.
1669 ///
1670 /// ## See also
1671 /// - [`SDL_CloseHaptic`]
1672 /// - [`SDL_GetHaptics`]
1673 /// - [`SDL_OpenHapticFromJoystick`]
1674 /// - [`SDL_OpenHapticFromMouse`]
1675 /// - [`SDL_SetHapticAutocenter`]
1676 /// - [`SDL_SetHapticGain`]
1677 pub fn SDL_OpenHaptic(instance_id: SDL_HapticID) -> *mut SDL_Haptic;
1678}
1679
1680unsafe extern "C" {
1681 /// Get the [`SDL_Haptic`] associated with an instance ID, if it has been opened.
1682 ///
1683 /// ## Parameters
1684 /// - `instance_id`: the instance ID to get the [`SDL_Haptic`] for.
1685 ///
1686 /// ## Return value
1687 /// Returns an [`SDL_Haptic`] on success or NULL on failure or if it hasn't been
1688 /// opened yet; call [`SDL_GetError()`] for more information.
1689 ///
1690 /// ## Availability
1691 /// This function is available since SDL 3.2.0.
1692 pub fn SDL_GetHapticFromID(instance_id: SDL_HapticID) -> *mut SDL_Haptic;
1693}
1694
1695unsafe extern "C" {
1696 /// Get the instance ID of an opened haptic device.
1697 ///
1698 /// ## Parameters
1699 /// - `haptic`: the [`SDL_Haptic`] device to query.
1700 ///
1701 /// ## Return value
1702 /// Returns the instance ID of the specified haptic device on success or 0 on
1703 /// failure; call [`SDL_GetError()`] for more information.
1704 ///
1705 /// ## Availability
1706 /// This function is available since SDL 3.2.0.
1707 pub fn SDL_GetHapticID(haptic: *mut SDL_Haptic) -> SDL_HapticID;
1708}
1709
1710unsafe extern "C" {
1711 /// Get the implementation dependent name of a haptic device.
1712 ///
1713 /// ## Parameters
1714 /// - `haptic`: the [`SDL_Haptic`] obtained from [`SDL_OpenJoystick()`].
1715 ///
1716 /// ## Return value
1717 /// Returns the name of the selected haptic device. If no name can be found,
1718 /// this function returns NULL; call [`SDL_GetError()`] for more
1719 /// information.
1720 ///
1721 /// ## Availability
1722 /// This function is available since SDL 3.2.0.
1723 ///
1724 /// ## See also
1725 /// - [`SDL_GetHapticNameForID`]
1726 pub fn SDL_GetHapticName(haptic: *mut SDL_Haptic) -> *const ::core::ffi::c_char;
1727}
1728
1729unsafe extern "C" {
1730 /// Query whether or not the current mouse has haptic capabilities.
1731 ///
1732 /// ## Return value
1733 /// Returns true if the mouse is haptic or false if it isn't.
1734 ///
1735 /// ## Availability
1736 /// This function is available since SDL 3.2.0.
1737 ///
1738 /// ## See also
1739 /// - [`SDL_OpenHapticFromMouse`]
1740 pub fn SDL_IsMouseHaptic() -> ::core::primitive::bool;
1741}
1742
1743unsafe extern "C" {
1744 /// Try to open a haptic device from the current mouse.
1745 ///
1746 /// ## Return value
1747 /// Returns the haptic device identifier or NULL on failure; call
1748 /// [`SDL_GetError()`] for more information.
1749 ///
1750 /// ## Availability
1751 /// This function is available since SDL 3.2.0.
1752 ///
1753 /// ## See also
1754 /// - [`SDL_CloseHaptic`]
1755 /// - [`SDL_IsMouseHaptic`]
1756 pub fn SDL_OpenHapticFromMouse() -> *mut SDL_Haptic;
1757}
1758
1759unsafe extern "C" {
1760 /// Query if a joystick has haptic features.
1761 ///
1762 /// ## Parameters
1763 /// - `joystick`: the [`SDL_Joystick`] to test for haptic capabilities.
1764 ///
1765 /// ## Return value
1766 /// Returns true if the joystick is haptic or false if it isn't.
1767 ///
1768 /// ## Availability
1769 /// This function is available since SDL 3.2.0.
1770 ///
1771 /// ## See also
1772 /// - [`SDL_OpenHapticFromJoystick`]
1773 pub fn SDL_IsJoystickHaptic(joystick: *mut SDL_Joystick) -> ::core::primitive::bool;
1774}
1775
1776unsafe extern "C" {
1777 /// Open a haptic device for use from a joystick device.
1778 ///
1779 /// You must still close the haptic device separately. It will not be closed
1780 /// with the joystick.
1781 ///
1782 /// When opened from a joystick you should first close the haptic device before
1783 /// closing the joystick device. If not, on some implementations the haptic
1784 /// device will also get unallocated and you'll be unable to use force feedback
1785 /// on that device.
1786 ///
1787 /// ## Parameters
1788 /// - `joystick`: the [`SDL_Joystick`] to create a haptic device from.
1789 ///
1790 /// ## Return value
1791 /// Returns a valid haptic device identifier on success or NULL on failure;
1792 /// call [`SDL_GetError()`] for more information.
1793 ///
1794 /// ## Availability
1795 /// This function is available since SDL 3.2.0.
1796 ///
1797 /// ## See also
1798 /// - [`SDL_CloseHaptic`]
1799 /// - [`SDL_IsJoystickHaptic`]
1800 pub fn SDL_OpenHapticFromJoystick(joystick: *mut SDL_Joystick) -> *mut SDL_Haptic;
1801}
1802
1803unsafe extern "C" {
1804 /// Close a haptic device previously opened with [`SDL_OpenHaptic()`].
1805 ///
1806 /// ## Parameters
1807 /// - `haptic`: the [`SDL_Haptic`] device to close.
1808 ///
1809 /// ## Availability
1810 /// This function is available since SDL 3.2.0.
1811 ///
1812 /// ## See also
1813 /// - [`SDL_OpenHaptic`]
1814 pub fn SDL_CloseHaptic(haptic: *mut SDL_Haptic);
1815}
1816
1817unsafe extern "C" {
1818 /// Get the number of effects a haptic device can store.
1819 ///
1820 /// On some platforms this isn't fully supported, and therefore is an
1821 /// approximation. Always check to see if your created effect was actually
1822 /// created and do not rely solely on [`SDL_GetMaxHapticEffects()`].
1823 ///
1824 /// ## Parameters
1825 /// - `haptic`: the [`SDL_Haptic`] device to query.
1826 ///
1827 /// ## Return value
1828 /// Returns the number of effects the haptic device can store or a negative
1829 /// error code on failure; call [`SDL_GetError()`] for more information.
1830 ///
1831 /// ## Availability
1832 /// This function is available since SDL 3.2.0.
1833 ///
1834 /// ## See also
1835 /// - [`SDL_GetMaxHapticEffectsPlaying`]
1836 /// - [`SDL_GetHapticFeatures`]
1837 pub fn SDL_GetMaxHapticEffects(haptic: *mut SDL_Haptic) -> ::core::ffi::c_int;
1838}
1839
1840unsafe extern "C" {
1841 /// Get the number of effects a haptic device can play at the same time.
1842 ///
1843 /// This is not supported on all platforms, but will always return a value.
1844 ///
1845 /// ## Parameters
1846 /// - `haptic`: the [`SDL_Haptic`] device to query maximum playing effects.
1847 ///
1848 /// ## Return value
1849 /// Returns the number of effects the haptic device can play at the same time
1850 /// or -1 on failure; call [`SDL_GetError()`] for more information.
1851 ///
1852 /// ## Availability
1853 /// This function is available since SDL 3.2.0.
1854 ///
1855 /// ## See also
1856 /// - [`SDL_GetMaxHapticEffects`]
1857 /// - [`SDL_GetHapticFeatures`]
1858 pub fn SDL_GetMaxHapticEffectsPlaying(haptic: *mut SDL_Haptic) -> ::core::ffi::c_int;
1859}
1860
1861unsafe extern "C" {
1862 /// Get the haptic device's supported features in bitwise manner.
1863 ///
1864 /// ## Parameters
1865 /// - `haptic`: the [`SDL_Haptic`] device to query.
1866 ///
1867 /// ## Return value
1868 /// Returns a list of supported haptic features in bitwise manner (OR'd), or 0
1869 /// on failure; call [`SDL_GetError()`] for more information.
1870 ///
1871 /// ## Availability
1872 /// This function is available since SDL 3.2.0.
1873 ///
1874 /// ## See also
1875 /// - [`SDL_HapticEffectSupported`]
1876 /// - [`SDL_GetMaxHapticEffects`]
1877 pub fn SDL_GetHapticFeatures(haptic: *mut SDL_Haptic) -> Uint32;
1878}
1879
1880unsafe extern "C" {
1881 /// Get the number of haptic axes the device has.
1882 ///
1883 /// The number of haptic axes might be useful if working with the
1884 /// [`SDL_HapticDirection`] effect.
1885 ///
1886 /// ## Parameters
1887 /// - `haptic`: the [`SDL_Haptic`] device to query.
1888 ///
1889 /// ## Return value
1890 /// Returns the number of axes on success or -1 on failure; call
1891 /// [`SDL_GetError()`] for more information.
1892 ///
1893 /// ## Availability
1894 /// This function is available since SDL 3.2.0.
1895 pub fn SDL_GetNumHapticAxes(haptic: *mut SDL_Haptic) -> ::core::ffi::c_int;
1896}
1897
1898unsafe extern "C" {
1899 /// Check to see if an effect is supported by a haptic device.
1900 ///
1901 /// ## Parameters
1902 /// - `haptic`: the [`SDL_Haptic`] device to query.
1903 /// - `effect`: the desired effect to query.
1904 ///
1905 /// ## Return value
1906 /// Returns true if the effect is supported or false if it isn't.
1907 ///
1908 /// ## Availability
1909 /// This function is available since SDL 3.2.0.
1910 ///
1911 /// ## See also
1912 /// - [`SDL_CreateHapticEffect`]
1913 /// - [`SDL_GetHapticFeatures`]
1914 pub fn SDL_HapticEffectSupported(
1915 haptic: *mut SDL_Haptic,
1916 effect: *const SDL_HapticEffect,
1917 ) -> ::core::primitive::bool;
1918}
1919
1920unsafe extern "C" {
1921 /// Create a new haptic effect on a specified device.
1922 ///
1923 /// ## Parameters
1924 /// - `haptic`: an [`SDL_Haptic`] device to create the effect on.
1925 /// - `effect`: an [`SDL_HapticEffect`] structure containing the properties of
1926 /// the effect to create.
1927 ///
1928 /// ## Return value
1929 /// Returns the ID of the effect on success or -1 on failure; call
1930 /// [`SDL_GetError()`] for more information.
1931 ///
1932 /// ## Availability
1933 /// This function is available since SDL 3.2.0.
1934 ///
1935 /// ## See also
1936 /// - [`SDL_DestroyHapticEffect`]
1937 /// - [`SDL_RunHapticEffect`]
1938 /// - [`SDL_UpdateHapticEffect`]
1939 pub fn SDL_CreateHapticEffect(
1940 haptic: *mut SDL_Haptic,
1941 effect: *const SDL_HapticEffect,
1942 ) -> SDL_HapticEffectID;
1943}
1944
1945unsafe extern "C" {
1946 /// Update the properties of an effect.
1947 ///
1948 /// Can be used dynamically, although behavior when dynamically changing
1949 /// direction may be strange. Specifically the effect may re-upload itself and
1950 /// start playing from the start. You also cannot change the type either when
1951 /// running [`SDL_UpdateHapticEffect()`].
1952 ///
1953 /// ## Parameters
1954 /// - `haptic`: the [`SDL_Haptic`] device that has the effect.
1955 /// - `effect`: the identifier of the effect to update.
1956 /// - `data`: an [`SDL_HapticEffect`] structure containing the new effect
1957 /// properties to use.
1958 ///
1959 /// ## Return value
1960 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1961 /// information.
1962 ///
1963 /// ## Availability
1964 /// This function is available since SDL 3.2.0.
1965 ///
1966 /// ## See also
1967 /// - [`SDL_CreateHapticEffect`]
1968 /// - [`SDL_RunHapticEffect`]
1969 pub fn SDL_UpdateHapticEffect(
1970 haptic: *mut SDL_Haptic,
1971 effect: SDL_HapticEffectID,
1972 data: *const SDL_HapticEffect,
1973 ) -> ::core::primitive::bool;
1974}
1975
1976unsafe extern "C" {
1977 /// Run the haptic effect on its associated haptic device.
1978 ///
1979 /// To repeat the effect over and over indefinitely, set `iterations` to
1980 /// [`SDL_HAPTIC_INFINITY`]. (Repeats the envelope - attack and fade.) To make
1981 /// one instance of the effect last indefinitely (so the effect does not fade),
1982 /// set the effect's `length` in its structure/union to [`SDL_HAPTIC_INFINITY`]
1983 /// instead.
1984 ///
1985 /// ## Parameters
1986 /// - `haptic`: the [`SDL_Haptic`] device to run the effect on.
1987 /// - `effect`: the ID of the haptic effect to run.
1988 /// - `iterations`: the number of iterations to run the effect; use
1989 /// [`SDL_HAPTIC_INFINITY`] to repeat forever.
1990 ///
1991 /// ## Return value
1992 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1993 /// information.
1994 ///
1995 /// ## Availability
1996 /// This function is available since SDL 3.2.0.
1997 ///
1998 /// ## See also
1999 /// - [`SDL_GetHapticEffectStatus`]
2000 /// - [`SDL_StopHapticEffect`]
2001 /// - [`SDL_StopHapticEffects`]
2002 pub fn SDL_RunHapticEffect(
2003 haptic: *mut SDL_Haptic,
2004 effect: SDL_HapticEffectID,
2005 iterations: Uint32,
2006 ) -> ::core::primitive::bool;
2007}
2008
2009unsafe extern "C" {
2010 /// Stop the haptic effect on its associated haptic device.
2011 ///
2012 /// ## Parameters
2013 /// - `haptic`: the [`SDL_Haptic`] device to stop the effect on.
2014 /// - `effect`: the ID of the haptic effect to stop.
2015 ///
2016 /// ## Return value
2017 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2018 /// information.
2019 ///
2020 /// ## Availability
2021 /// This function is available since SDL 3.2.0.
2022 ///
2023 /// ## See also
2024 /// - [`SDL_RunHapticEffect`]
2025 /// - [`SDL_StopHapticEffects`]
2026 pub fn SDL_StopHapticEffect(
2027 haptic: *mut SDL_Haptic,
2028 effect: SDL_HapticEffectID,
2029 ) -> ::core::primitive::bool;
2030}
2031
2032unsafe extern "C" {
2033 /// Destroy a haptic effect on the device.
2034 ///
2035 /// This will stop the effect if it's running. Effects are automatically
2036 /// destroyed when the device is closed.
2037 ///
2038 /// ## Parameters
2039 /// - `haptic`: the [`SDL_Haptic`] device to destroy the effect on.
2040 /// - `effect`: the ID of the haptic effect to destroy.
2041 ///
2042 /// ## Availability
2043 /// This function is available since SDL 3.2.0.
2044 ///
2045 /// ## See also
2046 /// - [`SDL_CreateHapticEffect`]
2047 pub fn SDL_DestroyHapticEffect(haptic: *mut SDL_Haptic, effect: SDL_HapticEffectID);
2048}
2049
2050unsafe extern "C" {
2051 /// Get the status of the current effect on the specified haptic device.
2052 ///
2053 /// Device must support the [`SDL_HAPTIC_STATUS`] feature.
2054 ///
2055 /// ## Parameters
2056 /// - `haptic`: the [`SDL_Haptic`] device to query for the effect status on.
2057 /// - `effect`: the ID of the haptic effect to query its status.
2058 ///
2059 /// ## Return value
2060 /// Returns true if it is playing, false if it isn't playing or haptic status
2061 /// isn't supported.
2062 ///
2063 /// ## Availability
2064 /// This function is available since SDL 3.2.0.
2065 ///
2066 /// ## See also
2067 /// - [`SDL_GetHapticFeatures`]
2068 pub fn SDL_GetHapticEffectStatus(
2069 haptic: *mut SDL_Haptic,
2070 effect: SDL_HapticEffectID,
2071 ) -> ::core::primitive::bool;
2072}
2073
2074unsafe extern "C" {
2075 /// Set the global gain of the specified haptic device.
2076 ///
2077 /// Device must support the [`SDL_HAPTIC_GAIN`] feature.
2078 ///
2079 /// The user may specify the maximum gain by setting the environment variable
2080 /// `SDL_HAPTIC_GAIN_MAX` which should be between 0 and 100. All calls to
2081 /// [`SDL_SetHapticGain()`] will scale linearly using `SDL_HAPTIC_GAIN_MAX` as the
2082 /// maximum.
2083 ///
2084 /// ## Parameters
2085 /// - `haptic`: the [`SDL_Haptic`] device to set the gain on.
2086 /// - `gain`: value to set the gain to, should be between 0 and 100 (0 -
2087 /// 100).
2088 ///
2089 /// ## Return value
2090 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2091 /// information.
2092 ///
2093 /// ## Availability
2094 /// This function is available since SDL 3.2.0.
2095 ///
2096 /// ## See also
2097 /// - [`SDL_GetHapticFeatures`]
2098 pub fn SDL_SetHapticGain(
2099 haptic: *mut SDL_Haptic,
2100 gain: ::core::ffi::c_int,
2101 ) -> ::core::primitive::bool;
2102}
2103
2104unsafe extern "C" {
2105 /// Set the global autocenter of the device.
2106 ///
2107 /// Autocenter should be between 0 and 100. Setting it to 0 will disable
2108 /// autocentering.
2109 ///
2110 /// Device must support the [`SDL_HAPTIC_AUTOCENTER`] feature.
2111 ///
2112 /// ## Parameters
2113 /// - `haptic`: the [`SDL_Haptic`] device to set autocentering on.
2114 /// - `autocenter`: value to set autocenter to (0-100).
2115 ///
2116 /// ## Return value
2117 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2118 /// information.
2119 ///
2120 /// ## Availability
2121 /// This function is available since SDL 3.2.0.
2122 ///
2123 /// ## See also
2124 /// - [`SDL_GetHapticFeatures`]
2125 pub fn SDL_SetHapticAutocenter(
2126 haptic: *mut SDL_Haptic,
2127 autocenter: ::core::ffi::c_int,
2128 ) -> ::core::primitive::bool;
2129}
2130
2131unsafe extern "C" {
2132 /// Pause a haptic device.
2133 ///
2134 /// Device must support the [`SDL_HAPTIC_PAUSE`] feature. Call [`SDL_ResumeHaptic()`]
2135 /// to resume playback.
2136 ///
2137 /// Do not modify the effects nor add new ones while the device is paused. That
2138 /// can cause all sorts of weird errors.
2139 ///
2140 /// ## Parameters
2141 /// - `haptic`: the [`SDL_Haptic`] device to pause.
2142 ///
2143 /// ## Return value
2144 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2145 /// information.
2146 ///
2147 /// ## Availability
2148 /// This function is available since SDL 3.2.0.
2149 ///
2150 /// ## See also
2151 /// - [`SDL_ResumeHaptic`]
2152 pub fn SDL_PauseHaptic(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2153}
2154
2155unsafe extern "C" {
2156 /// Resume a haptic device.
2157 ///
2158 /// Call to unpause after [`SDL_PauseHaptic()`].
2159 ///
2160 /// ## Parameters
2161 /// - `haptic`: the [`SDL_Haptic`] device to unpause.
2162 ///
2163 /// ## Return value
2164 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2165 /// information.
2166 ///
2167 /// ## Availability
2168 /// This function is available since SDL 3.2.0.
2169 ///
2170 /// ## See also
2171 /// - [`SDL_PauseHaptic`]
2172 pub fn SDL_ResumeHaptic(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2173}
2174
2175unsafe extern "C" {
2176 /// Stop all the currently playing effects on a haptic device.
2177 ///
2178 /// ## Parameters
2179 /// - `haptic`: the [`SDL_Haptic`] device to stop.
2180 ///
2181 /// ## Return value
2182 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2183 /// information.
2184 ///
2185 /// ## Availability
2186 /// This function is available since SDL 3.2.0.
2187 ///
2188 /// ## See also
2189 /// - [`SDL_RunHapticEffect`]
2190 /// - [`SDL_StopHapticEffect`]
2191 pub fn SDL_StopHapticEffects(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2192}
2193
2194unsafe extern "C" {
2195 /// Check whether rumble is supported on a haptic device.
2196 ///
2197 /// ## Parameters
2198 /// - `haptic`: haptic device to check for rumble support.
2199 ///
2200 /// ## Return value
2201 /// Returns true if the effect is supported or false if it isn't.
2202 ///
2203 /// ## Availability
2204 /// This function is available since SDL 3.2.0.
2205 ///
2206 /// ## See also
2207 /// - [`SDL_InitHapticRumble`]
2208 pub fn SDL_HapticRumbleSupported(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2209}
2210
2211unsafe extern "C" {
2212 /// Initialize a haptic device for simple rumble playback.
2213 ///
2214 /// ## Parameters
2215 /// - `haptic`: the haptic device to initialize for simple rumble playback.
2216 ///
2217 /// ## Return value
2218 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2219 /// information.
2220 ///
2221 /// ## Availability
2222 /// This function is available since SDL 3.2.0.
2223 ///
2224 /// ## See also
2225 /// - [`SDL_PlayHapticRumble`]
2226 /// - [`SDL_StopHapticRumble`]
2227 /// - [`SDL_HapticRumbleSupported`]
2228 pub fn SDL_InitHapticRumble(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2229}
2230
2231unsafe extern "C" {
2232 /// Run a simple rumble effect on a haptic device.
2233 ///
2234 /// ## Parameters
2235 /// - `haptic`: the haptic device to play the rumble effect on.
2236 /// - `strength`: strength of the rumble to play as a 0-1 float value.
2237 /// - `length`: length of the rumble to play in milliseconds.
2238 ///
2239 /// ## Return value
2240 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2241 /// information.
2242 ///
2243 /// ## Availability
2244 /// This function is available since SDL 3.2.0.
2245 ///
2246 /// ## See also
2247 /// - [`SDL_InitHapticRumble`]
2248 /// - [`SDL_StopHapticRumble`]
2249 pub fn SDL_PlayHapticRumble(
2250 haptic: *mut SDL_Haptic,
2251 strength: ::core::ffi::c_float,
2252 length: Uint32,
2253 ) -> ::core::primitive::bool;
2254}
2255
2256unsafe extern "C" {
2257 /// Stop the simple rumble on a haptic device.
2258 ///
2259 /// ## Parameters
2260 /// - `haptic`: the haptic device to stop the rumble effect on.
2261 ///
2262 /// ## Return value
2263 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2264 /// information.
2265 ///
2266 /// ## Availability
2267 /// This function is available since SDL 3.2.0.
2268 ///
2269 /// ## See also
2270 /// - [`SDL_PlayHapticRumble`]
2271 pub fn SDL_StopHapticRumble(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2272}
2273
2274/// The haptic structure used to identify an SDL haptic.
2275///
2276/// ## Availability
2277/// This struct is available since SDL 3.2.0.
2278///
2279/// ## See also
2280/// - [`SDL_OpenHaptic`]
2281/// - [`SDL_OpenHapticFromJoystick`]
2282/// - [`SDL_CloseHaptic`]
2283#[repr(C)]
2284pub struct SDL_Haptic {
2285 _opaque: [::core::primitive::u8; 0],
2286}
2287
2288#[cfg(doc)]
2289use crate::everything::*;