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
772#[cfg(feature = "metadata")]
773impl sdl3_sys::metadata::GroupMetadata for SDL_HapticEffectType {
774 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
775 &crate::metadata::haptic::METADATA_SDL_HapticEffectType;
776}
777
778/// * Type of coordinates used for haptic direction.
779///
780/// ## Known values (`sdl3-sys`)
781/// | Associated constant | Global constant | Description |
782/// | ------------------- | --------------- | ----------- |
783/// | [`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`] |
784/// | [`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`] |
785/// | [`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`] |
786/// | [`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`] |
787#[repr(transparent)]
788#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
789pub struct SDL_HapticDirectionType(pub Uint8);
790
791impl ::core::cmp::PartialEq<Uint8> for SDL_HapticDirectionType {
792 #[inline(always)]
793 fn eq(&self, other: &Uint8) -> bool {
794 &self.0 == other
795 }
796}
797
798impl ::core::cmp::PartialEq<SDL_HapticDirectionType> for Uint8 {
799 #[inline(always)]
800 fn eq(&self, other: &SDL_HapticDirectionType) -> bool {
801 self == &other.0
802 }
803}
804
805impl From<SDL_HapticDirectionType> for Uint8 {
806 #[inline(always)]
807 fn from(value: SDL_HapticDirectionType) -> Self {
808 value.0
809 }
810}
811
812#[cfg(feature = "debug-impls")]
813impl ::core::fmt::Debug for SDL_HapticDirectionType {
814 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
815 #[allow(unreachable_patterns)]
816 f.write_str(match *self {
817 Self::POLAR => "SDL_HAPTIC_POLAR",
818 Self::CARTESIAN => "SDL_HAPTIC_CARTESIAN",
819 Self::SPHERICAL => "SDL_HAPTIC_SPHERICAL",
820 Self::STEERING_AXIS => "SDL_HAPTIC_STEERING_AXIS",
821
822 _ => return write!(f, "SDL_HapticDirectionType({})", self.0),
823 })
824 }
825}
826
827impl SDL_HapticDirectionType {
828 /// Uses polar coordinates for the direction.
829 ///
830 /// ## Availability
831 /// This macro is available since SDL 3.2.0.
832 ///
833 /// ## See also
834 /// - [`SDL_HapticDirection`]
835 pub const POLAR: Self = Self((0 as Uint8));
836 /// Uses cartesian coordinates for the direction.
837 ///
838 /// ## Availability
839 /// This macro is available since SDL 3.2.0.
840 ///
841 /// ## See also
842 /// - [`SDL_HapticDirection`]
843 pub const CARTESIAN: Self = Self((1 as Uint8));
844 /// Uses spherical 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 SPHERICAL: Self = Self((2 as Uint8));
852 /// Use this value to play an effect on the steering wheel axis.
853 ///
854 /// This provides better compatibility across platforms and devices as SDL will
855 /// guess the correct axis.
856 ///
857 /// ## Availability
858 /// This macro is available since SDL 3.2.0.
859 ///
860 /// ## See also
861 /// - [`SDL_HapticDirection`]
862 pub const STEERING_AXIS: Self = Self((3 as Uint8));
863}
864
865/// Uses polar coordinates for the direction.
866///
867/// ## Availability
868/// This macro is available since SDL 3.2.0.
869///
870/// ## See also
871/// - [`SDL_HapticDirection`]
872pub const SDL_HAPTIC_POLAR: SDL_HapticDirectionType = SDL_HapticDirectionType::POLAR;
873/// Uses cartesian coordinates for the direction.
874///
875/// ## Availability
876/// This macro is available since SDL 3.2.0.
877///
878/// ## See also
879/// - [`SDL_HapticDirection`]
880pub const SDL_HAPTIC_CARTESIAN: SDL_HapticDirectionType = SDL_HapticDirectionType::CARTESIAN;
881/// Uses spherical 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_SPHERICAL: SDL_HapticDirectionType = SDL_HapticDirectionType::SPHERICAL;
889/// Use this value to play an effect on the steering wheel axis.
890///
891/// This provides better compatibility across platforms and devices as SDL will
892/// guess the correct axis.
893///
894/// ## Availability
895/// This macro is available since SDL 3.2.0.
896///
897/// ## See also
898/// - [`SDL_HapticDirection`]
899pub const SDL_HAPTIC_STEERING_AXIS: SDL_HapticDirectionType =
900 SDL_HapticDirectionType::STEERING_AXIS;
901
902#[cfg(feature = "metadata")]
903impl sdl3_sys::metadata::GroupMetadata for SDL_HapticDirectionType {
904 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
905 &crate::metadata::haptic::METADATA_SDL_HapticDirectionType;
906}
907
908/// ID for haptic effects.
909///
910/// This is -1 if the ID is invalid.
911///
912/// ## See also
913/// - [`SDL_CreateHapticEffect`]
914#[repr(transparent)]
915#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
916#[cfg_attr(feature = "debug-impls", derive(Debug))]
917pub struct SDL_HapticEffectID(pub ::core::ffi::c_int);
918
919impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_HapticEffectID {
920 #[inline(always)]
921 fn eq(&self, other: &::core::ffi::c_int) -> bool {
922 &self.0 == other
923 }
924}
925
926impl ::core::cmp::PartialEq<SDL_HapticEffectID> for ::core::ffi::c_int {
927 #[inline(always)]
928 fn eq(&self, other: &SDL_HapticEffectID) -> bool {
929 self == &other.0
930 }
931}
932
933impl From<SDL_HapticEffectID> for ::core::ffi::c_int {
934 #[inline(always)]
935 fn from(value: SDL_HapticEffectID) -> Self {
936 value.0
937 }
938}
939
940#[cfg(feature = "metadata")]
941impl sdl3_sys::metadata::GroupMetadata for SDL_HapticEffectID {
942 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
943 &crate::metadata::haptic::METADATA_SDL_HapticEffectID;
944}
945
946/// Structure that represents a haptic direction.
947///
948/// This is the direction where the force comes from, instead of the direction
949/// in which the force is exerted.
950///
951/// Directions can be specified by:
952///
953/// - [`SDL_HAPTIC_POLAR`] : Specified by polar coordinates.
954/// - [`SDL_HAPTIC_CARTESIAN`] : Specified by cartesian coordinates.
955/// - [`SDL_HAPTIC_SPHERICAL`] : Specified by spherical coordinates.
956///
957/// Cardinal directions of the haptic device are relative to the positioning of
958/// the device. North is considered to be away from the user.
959///
960/// The following diagram represents the cardinal directions:
961///
962/// ```text
963/// .--.
964/// |__| .-------.
965/// |=.| |.-----.|
966/// |--| || ||
967/// | | |'-----'|
968/// |__|~')_____('
969/// [ COMPUTER ]
970///
971///
972/// North (0,-1)
973/// ^
974/// |
975/// |
976/// (-1,0) West <----[ HAPTIC ]----> East (1,0)
977/// |
978/// |
979/// v
980/// South (0,1)
981///
982///
983/// [ USER ]
984/// \|||/
985/// (o o)
986/// ---ooO-(_)-Ooo---
987/// ```
988///
989/// If type is [`SDL_HAPTIC_POLAR`], direction is encoded by hundredths of a degree
990/// starting north and turning clockwise. [`SDL_HAPTIC_POLAR`] only uses the first
991/// `dir` parameter. The cardinal directions would be:
992///
993/// - North: 0 (0 degrees)
994/// - East: 9000 (90 degrees)
995/// - South: 18000 (180 degrees)
996/// - West: 27000 (270 degrees)
997///
998/// If type is [`SDL_HAPTIC_CARTESIAN`], direction is encoded by three positions (X
999/// axis, Y axis and Z axis (with 3 axes)). [`SDL_HAPTIC_CARTESIAN`] uses the first
1000/// three `dir` parameters. The cardinal directions would be:
1001///
1002/// - North: 0,-1, 0
1003/// - East: 1, 0, 0
1004/// - South: 0, 1, 0
1005/// - West: -1, 0, 0
1006///
1007/// The Z axis represents the height of the effect if supported, otherwise it's
1008/// unused. In cartesian encoding (1, 2) would be the same as (2, 4), you can
1009/// use any multiple you want, only the direction matters.
1010///
1011/// If type is [`SDL_HAPTIC_SPHERICAL`], direction is encoded by two rotations. The
1012/// first two `dir` parameters are used. The `dir` parameters are as follows
1013/// (all values are in hundredths of degrees):
1014///
1015/// - Degrees from (1, 0) rotated towards (0, 1).
1016/// - Degrees towards (0, 0, 1) (device needs at least 3 axes).
1017///
1018/// Example of force coming from the south with all encodings (force coming
1019/// from the south means the user will have to pull the stick to counteract):
1020///
1021/// ```c
1022/// SDL_HapticDirection direction;
1023///
1024/// // Cartesian directions
1025/// direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.
1026/// direction.dir[0] = 0; // X position
1027/// direction.dir[1] = 1; // Y position
1028/// // Assuming the device has 2 axes, we don't need to specify third parameter.
1029///
1030/// // Polar directions
1031/// direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
1032/// direction.dir[0] = 18000; // Polar only uses first parameter
1033///
1034/// // Spherical coordinates
1035/// direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding
1036/// direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
1037/// ```
1038///
1039/// ## Availability
1040/// This struct is available since SDL 3.2.0.
1041///
1042/// ## See also
1043/// - [`SDL_HAPTIC_POLAR`]
1044/// - [`SDL_HAPTIC_CARTESIAN`]
1045/// - [`SDL_HAPTIC_SPHERICAL`]
1046/// - [`SDL_HAPTIC_STEERING_AXIS`]
1047/// - [`SDL_HapticEffect`]
1048/// - [`SDL_GetNumHapticAxes`]
1049#[repr(C)]
1050#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1051#[cfg_attr(feature = "debug-impls", derive(Debug))]
1052pub struct SDL_HapticDirection {
1053 /// The type of encoding.
1054 pub r#type: SDL_HapticDirectionType,
1055 /// The encoded direction.
1056 pub dir: [Sint32; 3],
1057}
1058
1059/// A structure containing a template for a Constant effect.
1060///
1061/// This struct is exclusively for the [`SDL_HAPTIC_CONSTANT`] effect.
1062///
1063/// A constant effect applies a constant force in the specified direction to
1064/// the joystick.
1065///
1066/// ## Availability
1067/// This struct is available since SDL 3.2.0.
1068///
1069/// ## See also
1070/// - [`SDL_HAPTIC_CONSTANT`]
1071/// - [`SDL_HapticEffect`]
1072#[repr(C)]
1073#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1074#[cfg_attr(feature = "debug-impls", derive(Debug))]
1075pub struct SDL_HapticConstant {
1076 /// [`SDL_HAPTIC_CONSTANT`]
1077 pub r#type: SDL_HapticEffectType,
1078 /// Direction of the effect.
1079 pub direction: SDL_HapticDirection,
1080 /// Duration of the effect.
1081 pub length: Uint32,
1082 /// Delay before starting the effect.
1083 pub delay: Uint16,
1084 /// Button that triggers the effect.
1085 pub button: Uint16,
1086 /// How soon it can be triggered again after button.
1087 pub interval: Uint16,
1088 /// Strength of the constant effect.
1089 pub level: Sint16,
1090 /// Duration of the attack.
1091 pub attack_length: Uint16,
1092 /// Level at the start of the attack.
1093 pub attack_level: Uint16,
1094 /// Duration of the fade.
1095 pub fade_length: Uint16,
1096 /// Level at the end of the fade.
1097 pub fade_level: Uint16,
1098}
1099
1100/// A structure containing a template for a Periodic effect.
1101///
1102/// The struct handles the following effects:
1103///
1104/// - [`SDL_HAPTIC_SINE`]
1105/// - [`SDL_HAPTIC_SQUARE`]
1106/// - [`SDL_HAPTIC_TRIANGLE`]
1107/// - [`SDL_HAPTIC_SAWTOOTHUP`]
1108/// - [`SDL_HAPTIC_SAWTOOTHDOWN`]
1109///
1110/// A periodic effect consists in a wave-shaped effect that repeats itself over
1111/// time. The type determines the shape of the wave and the parameters
1112/// determine the dimensions of the wave.
1113///
1114/// Phase is given by hundredth of a degree meaning that giving the phase a
1115/// value of 9000 will displace it 25% of its period. Here are sample values:
1116///
1117/// - 0: No phase displacement.
1118/// - 9000: Displaced 25% of its period.
1119/// - 18000: Displaced 50% of its period.
1120/// - 27000: Displaced 75% of its period.
1121/// - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.
1122///
1123/// Examples:
1124///
1125/// ```text
1126/// SDL_HAPTIC_SINE
1127/// __ __ __ __
1128/// / \ / \ / \ /
1129/// / \__/ \__/ \__/
1130///
1131/// SDL_HAPTIC_SQUARE
1132/// __ __ __ __ __
1133/// | | | | | | | | | |
1134/// | |__| |__| |__| |__| |
1135///
1136/// SDL_HAPTIC_TRIANGLE
1137/// /\ /\ /\ /\ /\
1138/// / \ / \ / \ / \ /
1139/// / \/ \/ \/ \/
1140///
1141/// SDL_HAPTIC_SAWTOOTHUP
1142/// /| /| /| /| /| /| /|
1143/// / | / | / | / | / | / | / |
1144/// / |/ |/ |/ |/ |/ |/ |
1145///
1146/// SDL_HAPTIC_SAWTOOTHDOWN
1147/// \ |\ |\ |\ |\ |\ |\ |
1148/// \ | \ | \ | \ | \ | \ | \ |
1149/// \| \| \| \| \| \| \|
1150/// ```
1151///
1152/// ## Availability
1153/// This struct is available since SDL 3.2.0.
1154///
1155/// ## See also
1156/// - [`SDL_HAPTIC_SINE`]
1157/// - [`SDL_HAPTIC_SQUARE`]
1158/// - [`SDL_HAPTIC_TRIANGLE`]
1159/// - [`SDL_HAPTIC_SAWTOOTHUP`]
1160/// - [`SDL_HAPTIC_SAWTOOTHDOWN`]
1161/// - [`SDL_HapticEffect`]
1162#[repr(C)]
1163#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1164#[cfg_attr(feature = "debug-impls", derive(Debug))]
1165pub struct SDL_HapticPeriodic {
1166 /// [`SDL_HAPTIC_SINE`], [`SDL_HAPTIC_SQUARE`]
1167 /// [`SDL_HAPTIC_TRIANGLE`], [`SDL_HAPTIC_SAWTOOTHUP`] or
1168 /// [`SDL_HAPTIC_SAWTOOTHDOWN`]
1169 pub r#type: SDL_HapticEffectType,
1170 /// Direction of the effect.
1171 pub direction: SDL_HapticDirection,
1172 /// Duration of the effect.
1173 pub length: Uint32,
1174 /// Delay before starting the effect.
1175 pub delay: Uint16,
1176 /// Button that triggers the effect.
1177 pub button: Uint16,
1178 /// How soon it can be triggered again after button.
1179 pub interval: Uint16,
1180 /// Period of the wave.
1181 pub period: Uint16,
1182 /// Peak value; if negative, equivalent to 180 degrees extra phase shift.
1183 pub magnitude: Sint16,
1184 /// Mean value of the wave.
1185 pub offset: Sint16,
1186 /// Positive phase shift given by hundredth of a degree.
1187 pub phase: Uint16,
1188 /// Duration of the attack.
1189 pub attack_length: Uint16,
1190 /// Level at the start of the attack.
1191 pub attack_level: Uint16,
1192 /// Duration of the fade.
1193 pub fade_length: Uint16,
1194 /// Level at the end of the fade.
1195 pub fade_level: Uint16,
1196}
1197
1198/// A structure containing a template for a Condition effect.
1199///
1200/// The struct handles the following effects:
1201///
1202/// - [`SDL_HAPTIC_SPRING`]\: Effect based on axes position.
1203/// - [`SDL_HAPTIC_DAMPER`]\: Effect based on axes velocity.
1204/// - [`SDL_HAPTIC_INERTIA`]\: Effect based on axes acceleration.
1205/// - [`SDL_HAPTIC_FRICTION`]\: Effect based on axes movement.
1206///
1207/// Direction is handled by condition internals instead of a direction member.
1208/// The condition effect specific members have three parameters. The first
1209/// refers to the X axis, the second refers to the Y axis and the third refers
1210/// to the Z axis. The right terms refer to the positive side of the axis and
1211/// the left terms refer to the negative side of the axis. Please refer to the
1212/// [`SDL_HapticDirection`] diagram for which side is positive and which is
1213/// negative.
1214///
1215/// ## Availability
1216/// This struct is available since SDL 3.2.0.
1217///
1218/// ## See also
1219/// - [`SDL_HapticDirection`]
1220/// - [`SDL_HAPTIC_SPRING`]
1221/// - [`SDL_HAPTIC_DAMPER`]
1222/// - [`SDL_HAPTIC_INERTIA`]
1223/// - [`SDL_HAPTIC_FRICTION`]
1224/// - [`SDL_HapticEffect`]
1225#[repr(C)]
1226#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1227#[cfg_attr(feature = "debug-impls", derive(Debug))]
1228pub struct SDL_HapticCondition {
1229 /// [`SDL_HAPTIC_SPRING`], [`SDL_HAPTIC_DAMPER`],
1230 /// [`SDL_HAPTIC_INERTIA`] or [`SDL_HAPTIC_FRICTION`]
1231 pub r#type: SDL_HapticEffectType,
1232 /// Direction of the effect.
1233 pub direction: SDL_HapticDirection,
1234 /// Duration of the effect.
1235 pub length: Uint32,
1236 /// Delay before starting the effect.
1237 pub delay: Uint16,
1238 /// Button that triggers the effect.
1239 pub button: Uint16,
1240 /// How soon it can be triggered again after button.
1241 pub interval: Uint16,
1242 /// Level when joystick is to the positive side; max 0xFFFF.
1243 pub right_sat: [Uint16; 3],
1244 /// Level when joystick is to the negative side; max 0xFFFF.
1245 pub left_sat: [Uint16; 3],
1246 /// How fast to increase the force towards the positive side.
1247 pub right_coeff: [Sint16; 3],
1248 /// How fast to increase the force towards the negative side.
1249 pub left_coeff: [Sint16; 3],
1250 /// Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered.
1251 pub deadband: [Uint16; 3],
1252 /// Position of the dead zone.
1253 pub center: [Sint16; 3],
1254}
1255
1256/// A structure containing a template for a Ramp effect.
1257///
1258/// This struct is exclusively for the [`SDL_HAPTIC_RAMP`] effect.
1259///
1260/// The ramp effect starts at start strength and ends at end strength. It
1261/// augments in linear fashion. If you use attack and fade with a ramp the
1262/// effects get added to the ramp effect making the effect become quadratic
1263/// instead of linear.
1264///
1265/// ## Availability
1266/// This struct is available since SDL 3.2.0.
1267///
1268/// ## See also
1269/// - [`SDL_HAPTIC_RAMP`]
1270/// - [`SDL_HapticEffect`]
1271#[repr(C)]
1272#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1273#[cfg_attr(feature = "debug-impls", derive(Debug))]
1274pub struct SDL_HapticRamp {
1275 /// [`SDL_HAPTIC_RAMP`]
1276 pub r#type: SDL_HapticEffectType,
1277 /// Direction of the effect.
1278 pub direction: SDL_HapticDirection,
1279 /// Duration of the effect.
1280 pub length: Uint32,
1281 /// Delay before starting the effect.
1282 pub delay: Uint16,
1283 /// Button that triggers the effect.
1284 pub button: Uint16,
1285 /// How soon it can be triggered again after button.
1286 pub interval: Uint16,
1287 /// Beginning strength level.
1288 pub start: Sint16,
1289 /// Ending strength level.
1290 pub end: Sint16,
1291 /// Duration of the attack.
1292 pub attack_length: Uint16,
1293 /// Level at the start of the attack.
1294 pub attack_level: Uint16,
1295 /// Duration of the fade.
1296 pub fade_length: Uint16,
1297 /// Level at the end of the fade.
1298 pub fade_level: Uint16,
1299}
1300
1301/// A structure containing a template for a Left/Right effect.
1302///
1303/// This struct is exclusively for the [`SDL_HAPTIC_LEFTRIGHT`] effect.
1304///
1305/// The Left/Right effect is used to explicitly control the large and small
1306/// motors, commonly found in modern game controllers. The small (right) motor
1307/// is high frequency, and the large (left) motor is low frequency.
1308///
1309/// ## Availability
1310/// This struct is available since SDL 3.2.0.
1311///
1312/// ## See also
1313/// - [`SDL_HAPTIC_LEFTRIGHT`]
1314/// - [`SDL_HapticEffect`]
1315#[repr(C)]
1316#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
1317#[cfg_attr(feature = "debug-impls", derive(Debug))]
1318pub struct SDL_HapticLeftRight {
1319 /// [`SDL_HAPTIC_LEFTRIGHT`]
1320 pub r#type: SDL_HapticEffectType,
1321 /// Duration of the effect in milliseconds.
1322 pub length: Uint32,
1323 /// Control of the large controller motor.
1324 pub large_magnitude: Uint16,
1325 /// Control of the small controller motor.
1326 pub small_magnitude: Uint16,
1327}
1328
1329/// A structure containing a template for the [`SDL_HAPTIC_CUSTOM`] effect.
1330///
1331/// This struct is exclusively for the [`SDL_HAPTIC_CUSTOM`] effect.
1332///
1333/// A custom force feedback effect is much like a periodic effect, where the
1334/// application can define its exact shape. You will have to allocate the data
1335/// yourself. Data should consist of channels * samples Uint16 samples.
1336///
1337/// If channels is one, the effect is rotated using the defined direction.
1338/// Otherwise it uses the samples in data for the different axes.
1339///
1340/// ## Availability
1341/// This struct is available since SDL 3.2.0.
1342///
1343/// ## See also
1344/// - [`SDL_HAPTIC_CUSTOM`]
1345/// - [`SDL_HapticEffect`]
1346#[repr(C)]
1347#[derive(Clone, Copy)]
1348#[cfg_attr(feature = "debug-impls", derive(Debug))]
1349pub struct SDL_HapticCustom {
1350 /// [`SDL_HAPTIC_CUSTOM`]
1351 pub r#type: SDL_HapticEffectType,
1352 /// Direction of the effect.
1353 pub direction: SDL_HapticDirection,
1354 /// Duration of the effect.
1355 pub length: Uint32,
1356 /// Delay before starting the effect.
1357 pub delay: Uint16,
1358 /// Button that triggers the effect.
1359 pub button: Uint16,
1360 /// How soon it can be triggered again after button.
1361 pub interval: Uint16,
1362 /// Axes to use, minimum of one.
1363 pub channels: Uint8,
1364 /// Sample periods.
1365 pub period: Uint16,
1366 /// Amount of samples.
1367 pub samples: Uint16,
1368 /// Should contain channels*samples items.
1369 pub data: *mut Uint16,
1370 /// Duration of the attack.
1371 pub attack_length: Uint16,
1372 /// Level at the start of the attack.
1373 pub attack_level: Uint16,
1374 /// Duration of the fade.
1375 pub fade_length: Uint16,
1376 /// Level at the end of the fade.
1377 pub fade_level: Uint16,
1378}
1379
1380impl ::core::default::Default for SDL_HapticCustom {
1381 /// Initialize all fields to zero
1382 #[inline(always)]
1383 fn default() -> Self {
1384 unsafe { ::core::mem::MaybeUninit::<Self>::zeroed().assume_init() }
1385 }
1386}
1387
1388/// The generic template for any haptic effect.
1389///
1390/// All values max at 32767 (0x7FFF). Signed values also can be negative. Time
1391/// values unless specified otherwise are in milliseconds.
1392///
1393/// You can also pass [`SDL_HAPTIC_INFINITY`] to length instead of a 0-32767 value.
1394/// Neither delay, interval, attack_length nor fade_length support
1395/// [`SDL_HAPTIC_INFINITY`]. Fade will also not be used since effect never ends.
1396///
1397/// Additionally, the [`SDL_HAPTIC_RAMP`] effect does not support a duration of
1398/// [`SDL_HAPTIC_INFINITY`].
1399///
1400/// Button triggers may not be supported on all devices, it is advised to not
1401/// use them if possible. Buttons start at index 1 instead of index 0 like the
1402/// joystick.
1403///
1404/// If both attack_length and fade_level are 0, the envelope is not used,
1405/// otherwise both values are used.
1406///
1407/// Common parts:
1408///
1409/// ```c
1410/// // Replay - All effects have this
1411/// Uint32 length; // Duration of effect (ms).
1412/// Uint16 delay; // Delay before starting effect.
1413///
1414/// // Trigger - All effects have this
1415/// Uint16 button; // Button that triggers effect.
1416/// Uint16 interval; // How soon before effect can be triggered again.
1417///
1418/// // Envelope - All effects except condition effects have this
1419/// Uint16 attack_length; // Duration of the attack (ms).
1420/// Uint16 attack_level; // Level at the start of the attack.
1421/// Uint16 fade_length; // Duration of the fade out (ms).
1422/// Uint16 fade_level; // Level at the end of the fade.
1423/// ```
1424///
1425/// Here we have an example of a constant effect evolution in time:
1426///
1427/// ```text
1428/// Strength
1429/// ^
1430/// |
1431/// | effect level --> _________________
1432/// | / \
1433/// | / \
1434/// | / \
1435/// | / \
1436/// | attack_level --> | \
1437/// | | | <--- fade_level
1438/// |
1439/// +--------------------------------------------------> Time
1440/// [--] [---]
1441/// attack_length fade_length
1442///
1443/// [------------------][-----------------------]
1444/// delay length
1445/// ```
1446///
1447/// Note either the attack_level or the fade_level may be above the actual
1448/// effect level.
1449///
1450/// ## Availability
1451/// This struct is available since SDL 3.2.0.
1452///
1453/// ## See also
1454/// - [`SDL_HapticConstant`]
1455/// - [`SDL_HapticPeriodic`]
1456/// - [`SDL_HapticCondition`]
1457/// - [`SDL_HapticRamp`]
1458/// - [`SDL_HapticLeftRight`]
1459/// - [`SDL_HapticCustom`]
1460#[repr(C)]
1461#[derive(Clone, Copy)]
1462pub union SDL_HapticEffect {
1463 /// Effect type.
1464 pub r#type: SDL_HapticEffectType,
1465 /// Constant effect.
1466 pub constant: SDL_HapticConstant,
1467 /// Periodic effect.
1468 pub periodic: SDL_HapticPeriodic,
1469 /// Condition effect.
1470 pub condition: SDL_HapticCondition,
1471 /// Ramp effect.
1472 pub ramp: SDL_HapticRamp,
1473 /// Left/Right effect.
1474 pub leftright: SDL_HapticLeftRight,
1475 /// Custom effect.
1476 pub custom: SDL_HapticCustom,
1477}
1478
1479impl ::core::default::Default for SDL_HapticEffect {
1480 /// Initialize all fields to zero
1481 #[inline(always)]
1482 fn default() -> Self {
1483 unsafe { ::core::mem::MaybeUninit::<Self>::zeroed().assume_init() }
1484 }
1485}
1486
1487/// This is a unique ID for a haptic device for the time it is connected to the
1488/// system, and is never reused for the lifetime of the application.
1489///
1490/// If the haptic device is disconnected and reconnected, it will get a new ID.
1491///
1492/// The value 0 is an invalid ID.
1493///
1494/// ## Availability
1495/// This datatype is available since SDL 3.2.0.
1496#[repr(transparent)]
1497#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
1498#[cfg_attr(feature = "debug-impls", derive(Debug))]
1499pub struct SDL_HapticID(pub Uint32);
1500
1501impl ::core::cmp::PartialEq<Uint32> for SDL_HapticID {
1502 #[inline(always)]
1503 fn eq(&self, other: &Uint32) -> bool {
1504 &self.0 == other
1505 }
1506}
1507
1508impl ::core::cmp::PartialEq<SDL_HapticID> for Uint32 {
1509 #[inline(always)]
1510 fn eq(&self, other: &SDL_HapticID) -> bool {
1511 self == &other.0
1512 }
1513}
1514
1515impl From<SDL_HapticID> for Uint32 {
1516 #[inline(always)]
1517 fn from(value: SDL_HapticID) -> Self {
1518 value.0
1519 }
1520}
1521
1522#[cfg(feature = "metadata")]
1523impl sdl3_sys::metadata::GroupMetadata for SDL_HapticID {
1524 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
1525 &crate::metadata::haptic::METADATA_SDL_HapticID;
1526}
1527
1528unsafe extern "C" {
1529 /// Get a list of currently connected haptic devices.
1530 ///
1531 /// ## Parameters
1532 /// - `count`: a pointer filled in with the number of haptic devices
1533 /// returned, may be NULL.
1534 ///
1535 /// ## Return value
1536 /// Returns a 0 terminated array of haptic device instance IDs or NULL on
1537 /// failure; call [`SDL_GetError()`] for more information. This should be
1538 /// freed with [`SDL_free()`] when it is no longer needed.
1539 ///
1540 /// ## Availability
1541 /// This function is available since SDL 3.2.0.
1542 ///
1543 /// ## See also
1544 /// - [`SDL_OpenHaptic`]
1545 pub fn SDL_GetHaptics(count: *mut ::core::ffi::c_int) -> *mut SDL_HapticID;
1546}
1547
1548unsafe extern "C" {
1549 /// Get the implementation dependent name of a haptic device.
1550 ///
1551 /// This can be called before any haptic devices are opened.
1552 ///
1553 /// ## Parameters
1554 /// - `instance_id`: the haptic device instance ID.
1555 ///
1556 /// ## Return value
1557 /// Returns the name of the selected haptic device. If no name can be found,
1558 /// this function returns NULL; call [`SDL_GetError()`] for more
1559 /// information.
1560 ///
1561 /// ## Availability
1562 /// This function is available since SDL 3.2.0.
1563 ///
1564 /// ## See also
1565 /// - [`SDL_GetHapticName`]
1566 /// - [`SDL_OpenHaptic`]
1567 pub fn SDL_GetHapticNameForID(instance_id: SDL_HapticID) -> *const ::core::ffi::c_char;
1568}
1569
1570unsafe extern "C" {
1571 /// Open a haptic device for use.
1572 ///
1573 /// The index passed as an argument refers to the N'th haptic device on this
1574 /// system.
1575 ///
1576 /// When opening a haptic device, its gain will be set to maximum and
1577 /// autocenter will be disabled. To modify these values use [`SDL_SetHapticGain()`]
1578 /// and [`SDL_SetHapticAutocenter()`].
1579 ///
1580 /// ## Parameters
1581 /// - `instance_id`: the haptic device instance ID.
1582 ///
1583 /// ## Return value
1584 /// Returns the device identifier or NULL on failure; call [`SDL_GetError()`] for
1585 /// more information.
1586 ///
1587 /// ## Availability
1588 /// This function is available since SDL 3.2.0.
1589 ///
1590 /// ## See also
1591 /// - [`SDL_CloseHaptic`]
1592 /// - [`SDL_GetHaptics`]
1593 /// - [`SDL_OpenHapticFromJoystick`]
1594 /// - [`SDL_OpenHapticFromMouse`]
1595 /// - [`SDL_SetHapticAutocenter`]
1596 /// - [`SDL_SetHapticGain`]
1597 pub fn SDL_OpenHaptic(instance_id: SDL_HapticID) -> *mut SDL_Haptic;
1598}
1599
1600unsafe extern "C" {
1601 /// Get the [`SDL_Haptic`] associated with an instance ID, if it has been opened.
1602 ///
1603 /// ## Parameters
1604 /// - `instance_id`: the instance ID to get the [`SDL_Haptic`] for.
1605 ///
1606 /// ## Return value
1607 /// Returns an [`SDL_Haptic`] on success or NULL on failure or if it hasn't been
1608 /// opened yet; call [`SDL_GetError()`] for more information.
1609 ///
1610 /// ## Availability
1611 /// This function is available since SDL 3.2.0.
1612 pub fn SDL_GetHapticFromID(instance_id: SDL_HapticID) -> *mut SDL_Haptic;
1613}
1614
1615unsafe extern "C" {
1616 /// Get the instance ID of an opened haptic device.
1617 ///
1618 /// ## Parameters
1619 /// - `haptic`: the [`SDL_Haptic`] device to query.
1620 ///
1621 /// ## Return value
1622 /// Returns the instance ID of the specified haptic device on success or 0 on
1623 /// failure; call [`SDL_GetError()`] for more information.
1624 ///
1625 /// ## Availability
1626 /// This function is available since SDL 3.2.0.
1627 pub fn SDL_GetHapticID(haptic: *mut SDL_Haptic) -> SDL_HapticID;
1628}
1629
1630unsafe extern "C" {
1631 /// Get the implementation dependent name of a haptic device.
1632 ///
1633 /// ## Parameters
1634 /// - `haptic`: the [`SDL_Haptic`] obtained from [`SDL_OpenJoystick()`].
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_GetHapticNameForID`]
1646 pub fn SDL_GetHapticName(haptic: *mut SDL_Haptic) -> *const ::core::ffi::c_char;
1647}
1648
1649unsafe extern "C" {
1650 /// Query whether or not the current mouse has haptic capabilities.
1651 ///
1652 /// ## Return value
1653 /// Returns true if the mouse is haptic or false if it isn't.
1654 ///
1655 /// ## Availability
1656 /// This function is available since SDL 3.2.0.
1657 ///
1658 /// ## See also
1659 /// - [`SDL_OpenHapticFromMouse`]
1660 pub fn SDL_IsMouseHaptic() -> ::core::primitive::bool;
1661}
1662
1663unsafe extern "C" {
1664 /// Try to open a haptic device from the current mouse.
1665 ///
1666 /// ## Return value
1667 /// Returns the haptic device identifier or NULL on failure; call
1668 /// [`SDL_GetError()`] for more information.
1669 ///
1670 /// ## Availability
1671 /// This function is available since SDL 3.2.0.
1672 ///
1673 /// ## See also
1674 /// - [`SDL_CloseHaptic`]
1675 /// - [`SDL_IsMouseHaptic`]
1676 pub fn SDL_OpenHapticFromMouse() -> *mut SDL_Haptic;
1677}
1678
1679unsafe extern "C" {
1680 /// Query if a joystick has haptic features.
1681 ///
1682 /// ## Parameters
1683 /// - `joystick`: the [`SDL_Joystick`] to test for haptic capabilities.
1684 ///
1685 /// ## Return value
1686 /// Returns true if the joystick is haptic or false if it isn't.
1687 ///
1688 /// ## Availability
1689 /// This function is available since SDL 3.2.0.
1690 ///
1691 /// ## See also
1692 /// - [`SDL_OpenHapticFromJoystick`]
1693 pub fn SDL_IsJoystickHaptic(joystick: *mut SDL_Joystick) -> ::core::primitive::bool;
1694}
1695
1696unsafe extern "C" {
1697 /// Open a haptic device for use from a joystick device.
1698 ///
1699 /// You must still close the haptic device separately. It will not be closed
1700 /// with the joystick.
1701 ///
1702 /// When opened from a joystick you should first close the haptic device before
1703 /// closing the joystick device. If not, on some implementations the haptic
1704 /// device will also get unallocated and you'll be unable to use force feedback
1705 /// on that device.
1706 ///
1707 /// ## Parameters
1708 /// - `joystick`: the [`SDL_Joystick`] to create a haptic device from.
1709 ///
1710 /// ## Return value
1711 /// Returns a valid haptic device identifier on success or NULL on failure;
1712 /// call [`SDL_GetError()`] for more information.
1713 ///
1714 /// ## Availability
1715 /// This function is available since SDL 3.2.0.
1716 ///
1717 /// ## See also
1718 /// - [`SDL_CloseHaptic`]
1719 /// - [`SDL_IsJoystickHaptic`]
1720 pub fn SDL_OpenHapticFromJoystick(joystick: *mut SDL_Joystick) -> *mut SDL_Haptic;
1721}
1722
1723unsafe extern "C" {
1724 /// Close a haptic device previously opened with [`SDL_OpenHaptic()`].
1725 ///
1726 /// ## Parameters
1727 /// - `haptic`: the [`SDL_Haptic`] device to close.
1728 ///
1729 /// ## Availability
1730 /// This function is available since SDL 3.2.0.
1731 ///
1732 /// ## See also
1733 /// - [`SDL_OpenHaptic`]
1734 pub fn SDL_CloseHaptic(haptic: *mut SDL_Haptic);
1735}
1736
1737unsafe extern "C" {
1738 /// Get the number of effects a haptic device can store.
1739 ///
1740 /// On some platforms this isn't fully supported, and therefore is an
1741 /// approximation. Always check to see if your created effect was actually
1742 /// created and do not rely solely on [`SDL_GetMaxHapticEffects()`].
1743 ///
1744 /// ## Parameters
1745 /// - `haptic`: the [`SDL_Haptic`] device to query.
1746 ///
1747 /// ## Return value
1748 /// Returns the number of effects the haptic device can store or a negative
1749 /// error code on failure; call [`SDL_GetError()`] for more information.
1750 ///
1751 /// ## Availability
1752 /// This function is available since SDL 3.2.0.
1753 ///
1754 /// ## See also
1755 /// - [`SDL_GetMaxHapticEffectsPlaying`]
1756 /// - [`SDL_GetHapticFeatures`]
1757 pub fn SDL_GetMaxHapticEffects(haptic: *mut SDL_Haptic) -> ::core::ffi::c_int;
1758}
1759
1760unsafe extern "C" {
1761 /// Get the number of effects a haptic device can play at the same time.
1762 ///
1763 /// This is not supported on all platforms, but will always return a value.
1764 ///
1765 /// ## Parameters
1766 /// - `haptic`: the [`SDL_Haptic`] device to query maximum playing effects.
1767 ///
1768 /// ## Return value
1769 /// Returns the number of effects the haptic device can play at the same time
1770 /// or -1 on failure; call [`SDL_GetError()`] for more information.
1771 ///
1772 /// ## Availability
1773 /// This function is available since SDL 3.2.0.
1774 ///
1775 /// ## See also
1776 /// - [`SDL_GetMaxHapticEffects`]
1777 /// - [`SDL_GetHapticFeatures`]
1778 pub fn SDL_GetMaxHapticEffectsPlaying(haptic: *mut SDL_Haptic) -> ::core::ffi::c_int;
1779}
1780
1781unsafe extern "C" {
1782 /// Get the haptic device's supported features in bitwise manner.
1783 ///
1784 /// ## Parameters
1785 /// - `haptic`: the [`SDL_Haptic`] device to query.
1786 ///
1787 /// ## Return value
1788 /// Returns a list of supported haptic features in bitwise manner (OR'd), or 0
1789 /// on failure; call [`SDL_GetError()`] for more information.
1790 ///
1791 /// ## Availability
1792 /// This function is available since SDL 3.2.0.
1793 ///
1794 /// ## See also
1795 /// - [`SDL_HapticEffectSupported`]
1796 /// - [`SDL_GetMaxHapticEffects`]
1797 pub fn SDL_GetHapticFeatures(haptic: *mut SDL_Haptic) -> Uint32;
1798}
1799
1800unsafe extern "C" {
1801 /// Get the number of haptic axes the device has.
1802 ///
1803 /// The number of haptic axes might be useful if working with the
1804 /// [`SDL_HapticDirection`] effect.
1805 ///
1806 /// ## Parameters
1807 /// - `haptic`: the [`SDL_Haptic`] device to query.
1808 ///
1809 /// ## Return value
1810 /// Returns the number of axes on success or -1 on failure; call
1811 /// [`SDL_GetError()`] for more information.
1812 ///
1813 /// ## Availability
1814 /// This function is available since SDL 3.2.0.
1815 pub fn SDL_GetNumHapticAxes(haptic: *mut SDL_Haptic) -> ::core::ffi::c_int;
1816}
1817
1818unsafe extern "C" {
1819 /// Check to see if an effect is supported by a haptic device.
1820 ///
1821 /// ## Parameters
1822 /// - `haptic`: the [`SDL_Haptic`] device to query.
1823 /// - `effect`: the desired effect to query.
1824 ///
1825 /// ## Return value
1826 /// Returns true if the effect is supported or false if it isn't.
1827 ///
1828 /// ## Availability
1829 /// This function is available since SDL 3.2.0.
1830 ///
1831 /// ## See also
1832 /// - [`SDL_CreateHapticEffect`]
1833 /// - [`SDL_GetHapticFeatures`]
1834 pub fn SDL_HapticEffectSupported(
1835 haptic: *mut SDL_Haptic,
1836 effect: *const SDL_HapticEffect,
1837 ) -> ::core::primitive::bool;
1838}
1839
1840unsafe extern "C" {
1841 /// Create a new haptic effect on a specified device.
1842 ///
1843 /// ## Parameters
1844 /// - `haptic`: an [`SDL_Haptic`] device to create the effect on.
1845 /// - `effect`: an [`SDL_HapticEffect`] structure containing the properties of
1846 /// the effect to create.
1847 ///
1848 /// ## Return value
1849 /// Returns the ID of the effect on success or -1 on failure; call
1850 /// [`SDL_GetError()`] for more information.
1851 ///
1852 /// ## Availability
1853 /// This function is available since SDL 3.2.0.
1854 ///
1855 /// ## See also
1856 /// - [`SDL_DestroyHapticEffect`]
1857 /// - [`SDL_RunHapticEffect`]
1858 /// - [`SDL_UpdateHapticEffect`]
1859 pub fn SDL_CreateHapticEffect(
1860 haptic: *mut SDL_Haptic,
1861 effect: *const SDL_HapticEffect,
1862 ) -> SDL_HapticEffectID;
1863}
1864
1865unsafe extern "C" {
1866 /// Update the properties of an effect.
1867 ///
1868 /// Can be used dynamically, although behavior when dynamically changing
1869 /// direction may be strange. Specifically the effect may re-upload itself and
1870 /// start playing from the start. You also cannot change the type either when
1871 /// running [`SDL_UpdateHapticEffect()`].
1872 ///
1873 /// ## Parameters
1874 /// - `haptic`: the [`SDL_Haptic`] device that has the effect.
1875 /// - `effect`: the identifier of the effect to update.
1876 /// - `data`: an [`SDL_HapticEffect`] structure containing the new effect
1877 /// properties to use.
1878 ///
1879 /// ## Return value
1880 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1881 /// information.
1882 ///
1883 /// ## Availability
1884 /// This function is available since SDL 3.2.0.
1885 ///
1886 /// ## See also
1887 /// - [`SDL_CreateHapticEffect`]
1888 /// - [`SDL_RunHapticEffect`]
1889 pub fn SDL_UpdateHapticEffect(
1890 haptic: *mut SDL_Haptic,
1891 effect: SDL_HapticEffectID,
1892 data: *const SDL_HapticEffect,
1893 ) -> ::core::primitive::bool;
1894}
1895
1896unsafe extern "C" {
1897 /// Run the haptic effect on its associated haptic device.
1898 ///
1899 /// To repeat the effect over and over indefinitely, set `iterations` to
1900 /// [`SDL_HAPTIC_INFINITY`]. (Repeats the envelope - attack and fade.) To make
1901 /// one instance of the effect last indefinitely (so the effect does not fade),
1902 /// set the effect's `length` in its structure/union to [`SDL_HAPTIC_INFINITY`]
1903 /// instead.
1904 ///
1905 /// ## Parameters
1906 /// - `haptic`: the [`SDL_Haptic`] device to run the effect on.
1907 /// - `effect`: the ID of the haptic effect to run.
1908 /// - `iterations`: the number of iterations to run the effect; use
1909 /// [`SDL_HAPTIC_INFINITY`] to repeat forever.
1910 ///
1911 /// ## Return value
1912 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1913 /// information.
1914 ///
1915 /// ## Availability
1916 /// This function is available since SDL 3.2.0.
1917 ///
1918 /// ## See also
1919 /// - [`SDL_GetHapticEffectStatus`]
1920 /// - [`SDL_StopHapticEffect`]
1921 /// - [`SDL_StopHapticEffects`]
1922 pub fn SDL_RunHapticEffect(
1923 haptic: *mut SDL_Haptic,
1924 effect: SDL_HapticEffectID,
1925 iterations: Uint32,
1926 ) -> ::core::primitive::bool;
1927}
1928
1929unsafe extern "C" {
1930 /// Stop the haptic effect on its associated haptic device.
1931 ///
1932 /// ## Parameters
1933 /// - `haptic`: the [`SDL_Haptic`] device to stop the effect on.
1934 /// - `effect`: the ID of the haptic effect to stop.
1935 ///
1936 /// ## Return value
1937 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1938 /// information.
1939 ///
1940 /// ## Availability
1941 /// This function is available since SDL 3.2.0.
1942 ///
1943 /// ## See also
1944 /// - [`SDL_RunHapticEffect`]
1945 /// - [`SDL_StopHapticEffects`]
1946 pub fn SDL_StopHapticEffect(
1947 haptic: *mut SDL_Haptic,
1948 effect: SDL_HapticEffectID,
1949 ) -> ::core::primitive::bool;
1950}
1951
1952unsafe extern "C" {
1953 /// Destroy a haptic effect on the device.
1954 ///
1955 /// This will stop the effect if it's running. Effects are automatically
1956 /// destroyed when the device is closed.
1957 ///
1958 /// ## Parameters
1959 /// - `haptic`: the [`SDL_Haptic`] device to destroy the effect on.
1960 /// - `effect`: the ID of the haptic effect to destroy.
1961 ///
1962 /// ## Availability
1963 /// This function is available since SDL 3.2.0.
1964 ///
1965 /// ## See also
1966 /// - [`SDL_CreateHapticEffect`]
1967 pub fn SDL_DestroyHapticEffect(haptic: *mut SDL_Haptic, effect: SDL_HapticEffectID);
1968}
1969
1970unsafe extern "C" {
1971 /// Get the status of the current effect on the specified haptic device.
1972 ///
1973 /// Device must support the [`SDL_HAPTIC_STATUS`] feature.
1974 ///
1975 /// ## Parameters
1976 /// - `haptic`: the [`SDL_Haptic`] device to query for the effect status on.
1977 /// - `effect`: the ID of the haptic effect to query its status.
1978 ///
1979 /// ## Return value
1980 /// Returns true if it is playing, false if it isn't playing or haptic status
1981 /// isn't supported.
1982 ///
1983 /// ## Availability
1984 /// This function is available since SDL 3.2.0.
1985 ///
1986 /// ## See also
1987 /// - [`SDL_GetHapticFeatures`]
1988 pub fn SDL_GetHapticEffectStatus(
1989 haptic: *mut SDL_Haptic,
1990 effect: SDL_HapticEffectID,
1991 ) -> ::core::primitive::bool;
1992}
1993
1994unsafe extern "C" {
1995 /// Set the global gain of the specified haptic device.
1996 ///
1997 /// Device must support the [`SDL_HAPTIC_GAIN`] feature.
1998 ///
1999 /// The user may specify the maximum gain by setting the environment variable
2000 /// `SDL_HAPTIC_GAIN_MAX` which should be between 0 and 100. All calls to
2001 /// [`SDL_SetHapticGain()`] will scale linearly using `SDL_HAPTIC_GAIN_MAX` as the
2002 /// maximum.
2003 ///
2004 /// ## Parameters
2005 /// - `haptic`: the [`SDL_Haptic`] device to set the gain on.
2006 /// - `gain`: value to set the gain to, should be between 0 and 100 (0 -
2007 /// 100).
2008 ///
2009 /// ## Return value
2010 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2011 /// information.
2012 ///
2013 /// ## Availability
2014 /// This function is available since SDL 3.2.0.
2015 ///
2016 /// ## See also
2017 /// - [`SDL_GetHapticFeatures`]
2018 pub fn SDL_SetHapticGain(
2019 haptic: *mut SDL_Haptic,
2020 gain: ::core::ffi::c_int,
2021 ) -> ::core::primitive::bool;
2022}
2023
2024unsafe extern "C" {
2025 /// Set the global autocenter of the device.
2026 ///
2027 /// Autocenter should be between 0 and 100. Setting it to 0 will disable
2028 /// autocentering.
2029 ///
2030 /// Device must support the [`SDL_HAPTIC_AUTOCENTER`] feature.
2031 ///
2032 /// ## Parameters
2033 /// - `haptic`: the [`SDL_Haptic`] device to set autocentering on.
2034 /// - `autocenter`: value to set autocenter to (0-100).
2035 ///
2036 /// ## Return value
2037 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2038 /// information.
2039 ///
2040 /// ## Availability
2041 /// This function is available since SDL 3.2.0.
2042 ///
2043 /// ## See also
2044 /// - [`SDL_GetHapticFeatures`]
2045 pub fn SDL_SetHapticAutocenter(
2046 haptic: *mut SDL_Haptic,
2047 autocenter: ::core::ffi::c_int,
2048 ) -> ::core::primitive::bool;
2049}
2050
2051unsafe extern "C" {
2052 /// Pause a haptic device.
2053 ///
2054 /// Device must support the [`SDL_HAPTIC_PAUSE`] feature. Call [`SDL_ResumeHaptic()`]
2055 /// to resume playback.
2056 ///
2057 /// Do not modify the effects nor add new ones while the device is paused. That
2058 /// can cause all sorts of weird errors.
2059 ///
2060 /// ## Parameters
2061 /// - `haptic`: the [`SDL_Haptic`] device to pause.
2062 ///
2063 /// ## Return value
2064 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2065 /// information.
2066 ///
2067 /// ## Availability
2068 /// This function is available since SDL 3.2.0.
2069 ///
2070 /// ## See also
2071 /// - [`SDL_ResumeHaptic`]
2072 pub fn SDL_PauseHaptic(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2073}
2074
2075unsafe extern "C" {
2076 /// Resume a haptic device.
2077 ///
2078 /// Call to unpause after [`SDL_PauseHaptic()`].
2079 ///
2080 /// ## Parameters
2081 /// - `haptic`: the [`SDL_Haptic`] device to unpause.
2082 ///
2083 /// ## Return value
2084 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2085 /// information.
2086 ///
2087 /// ## Availability
2088 /// This function is available since SDL 3.2.0.
2089 ///
2090 /// ## See also
2091 /// - [`SDL_PauseHaptic`]
2092 pub fn SDL_ResumeHaptic(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2093}
2094
2095unsafe extern "C" {
2096 /// Stop all the currently playing effects on a haptic device.
2097 ///
2098 /// ## Parameters
2099 /// - `haptic`: the [`SDL_Haptic`] device to stop.
2100 ///
2101 /// ## Return value
2102 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2103 /// information.
2104 ///
2105 /// ## Availability
2106 /// This function is available since SDL 3.2.0.
2107 ///
2108 /// ## See also
2109 /// - [`SDL_RunHapticEffect`]
2110 /// - [`SDL_StopHapticEffects`]
2111 pub fn SDL_StopHapticEffects(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2112}
2113
2114unsafe extern "C" {
2115 /// Check whether rumble is supported on a haptic device.
2116 ///
2117 /// ## Parameters
2118 /// - `haptic`: haptic device to check for rumble support.
2119 ///
2120 /// ## Return value
2121 /// Returns true if the effect is supported or false if it isn't.
2122 ///
2123 /// ## Availability
2124 /// This function is available since SDL 3.2.0.
2125 ///
2126 /// ## See also
2127 /// - [`SDL_InitHapticRumble`]
2128 pub fn SDL_HapticRumbleSupported(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2129}
2130
2131unsafe extern "C" {
2132 /// Initialize a haptic device for simple rumble playback.
2133 ///
2134 /// ## Parameters
2135 /// - `haptic`: the haptic device to initialize for simple rumble playback.
2136 ///
2137 /// ## Return value
2138 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2139 /// information.
2140 ///
2141 /// ## Availability
2142 /// This function is available since SDL 3.2.0.
2143 ///
2144 /// ## See also
2145 /// - [`SDL_PlayHapticRumble`]
2146 /// - [`SDL_StopHapticRumble`]
2147 /// - [`SDL_HapticRumbleSupported`]
2148 pub fn SDL_InitHapticRumble(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2149}
2150
2151unsafe extern "C" {
2152 /// Run a simple rumble effect on a haptic device.
2153 ///
2154 /// ## Parameters
2155 /// - `haptic`: the haptic device to play the rumble effect on.
2156 /// - `strength`: strength of the rumble to play as a 0-1 float value.
2157 /// - `length`: length of the rumble to play in milliseconds.
2158 ///
2159 /// ## Return value
2160 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2161 /// information.
2162 ///
2163 /// ## Availability
2164 /// This function is available since SDL 3.2.0.
2165 ///
2166 /// ## See also
2167 /// - [`SDL_InitHapticRumble`]
2168 /// - [`SDL_StopHapticRumble`]
2169 pub fn SDL_PlayHapticRumble(
2170 haptic: *mut SDL_Haptic,
2171 strength: ::core::ffi::c_float,
2172 length: Uint32,
2173 ) -> ::core::primitive::bool;
2174}
2175
2176unsafe extern "C" {
2177 /// Stop the simple rumble on a haptic device.
2178 ///
2179 /// ## Parameters
2180 /// - `haptic`: the haptic device to stop the rumble effect on.
2181 ///
2182 /// ## Return value
2183 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2184 /// information.
2185 ///
2186 /// ## Availability
2187 /// This function is available since SDL 3.2.0.
2188 ///
2189 /// ## See also
2190 /// - [`SDL_PlayHapticRumble`]
2191 pub fn SDL_StopHapticRumble(haptic: *mut SDL_Haptic) -> ::core::primitive::bool;
2192}
2193
2194/// The haptic structure used to identify an SDL haptic.
2195///
2196/// ## Availability
2197/// This struct is available since SDL 3.2.0.
2198///
2199/// ## See also
2200/// - [`SDL_OpenHaptic`]
2201/// - [`SDL_OpenHapticFromJoystick`]
2202/// - [`SDL_CloseHaptic`]
2203#[repr(C)]
2204pub struct SDL_Haptic {
2205 _opaque: [::core::primitive::u8; 0],
2206}
2207
2208#[cfg(doc)]
2209use crate::everything::*;