My Project
SDL_haptic.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
107 #ifndef SDL_haptic_h_
108 #define SDL_haptic_h_
109 
110 #include "SDL_stdinc.h"
111 #include "SDL_error.h"
112 #include "SDL_joystick.h"
113 
114 #include "begin_code.h"
115 /* Set up for C function definitions, even when using C++ */
116 #ifdef __cplusplus
117 extern "C" {
118 #endif /* __cplusplus */
119 
129 struct _SDL_Haptic;
130 typedef struct _SDL_Haptic SDL_Haptic;
131 
132 
138 /* @{ */
139 
143 /* @{ */
144 
152 #define SDL_HAPTIC_CONSTANT (1u<<0)
153 
161 #define SDL_HAPTIC_SINE (1u<<1)
162 
172 #define SDL_HAPTIC_LEFTRIGHT (1u<<2)
173 
174 /* !!! FIXME: put this back when we have more bits in 2.1 */
175 /* #define SDL_HAPTIC_SQUARE (1<<2) */
176 
184 #define SDL_HAPTIC_TRIANGLE (1u<<3)
185 
193 #define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
194 
202 #define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
203 
211 #define SDL_HAPTIC_RAMP (1u<<6)
212 
221 #define SDL_HAPTIC_SPRING (1u<<7)
222 
231 #define SDL_HAPTIC_DAMPER (1u<<8)
232 
241 #define SDL_HAPTIC_INERTIA (1u<<9)
242 
251 #define SDL_HAPTIC_FRICTION (1u<<10)
252 
258 #define SDL_HAPTIC_CUSTOM (1u<<11)
259 
260 /* @} *//* Haptic effects */
261 
262 /* These last few are features the device has, not effects */
263 
271 #define SDL_HAPTIC_GAIN (1u<<12)
272 
280 #define SDL_HAPTIC_AUTOCENTER (1u<<13)
281 
289 #define SDL_HAPTIC_STATUS (1u<<14)
290 
299 #define SDL_HAPTIC_PAUSE (1u<<15)
300 
301 
305 /* @{ */
306 
312 #define SDL_HAPTIC_POLAR 0
313 
319 #define SDL_HAPTIC_CARTESIAN 1
320 
326 #define SDL_HAPTIC_SPHERICAL 2
327 
328 /* @} *//* Direction encodings */
329 
330 /* @} *//* Haptic features */
331 
332 /*
333  * Misc defines.
334  */
335 
341 #define SDL_HAPTIC_INFINITY 4294967295U
342 
343 
439 typedef struct SDL_HapticDirection
440 {
441  Uint8 type;
442  Sint32 dir[3];
444 
445 
457 typedef struct SDL_HapticConstant
458 {
459  /* Header */
460  Uint16 type;
463  /* Replay */
464  Uint32 length;
465  Uint16 delay;
467  /* Trigger */
468  Uint16 button;
469  Uint16 interval;
471  /* Constant */
472  Sint16 level;
474  /* Envelope */
475  Uint16 attack_length;
476  Uint16 attack_level;
477  Uint16 fade_length;
478  Uint16 fade_level;
480 
538 typedef struct SDL_HapticPeriodic
539 {
540  /* Header */
541  Uint16 type;
546  /* Replay */
547  Uint32 length;
548  Uint16 delay;
550  /* Trigger */
551  Uint16 button;
552  Uint16 interval;
554  /* Periodic */
555  Uint16 period;
556  Sint16 magnitude;
557  Sint16 offset;
558  Uint16 phase;
560  /* Envelope */
561  Uint16 attack_length;
562  Uint16 attack_level;
563  Uint16 fade_length;
564  Uint16 fade_level;
566 
591 typedef struct SDL_HapticCondition
592 {
593  /* Header */
594  Uint16 type;
598  /* Replay */
599  Uint32 length;
600  Uint16 delay;
602  /* Trigger */
603  Uint16 button;
604  Uint16 interval;
606  /* Condition */
607  Uint16 right_sat[3];
608  Uint16 left_sat[3];
609  Sint16 right_coeff[3];
610  Sint16 left_coeff[3];
611  Uint16 deadband[3];
612  Sint16 center[3];
614 
628 typedef struct SDL_HapticRamp
629 {
630  /* Header */
631  Uint16 type;
634  /* Replay */
635  Uint32 length;
636  Uint16 delay;
638  /* Trigger */
639  Uint16 button;
640  Uint16 interval;
642  /* Ramp */
643  Sint16 start;
644  Sint16 end;
646  /* Envelope */
647  Uint16 attack_length;
648  Uint16 attack_level;
649  Uint16 fade_length;
650  Uint16 fade_level;
652 
665 typedef struct SDL_HapticLeftRight
666 {
667  /* Header */
668  Uint16 type;
670  /* Replay */
671  Uint32 length;
673  /* Rumble */
677 
693 typedef struct SDL_HapticCustom
694 {
695  /* Header */
696  Uint16 type;
699  /* Replay */
700  Uint32 length;
701  Uint16 delay;
703  /* Trigger */
704  Uint16 button;
705  Uint16 interval;
707  /* Custom */
708  Uint8 channels;
709  Uint16 period;
710  Uint16 samples;
711  Uint16 *data;
713  /* Envelope */
714  Uint16 attack_length;
715  Uint16 attack_level;
716  Uint16 fade_length;
717  Uint16 fade_level;
719 
789 typedef union SDL_HapticEffect
790 {
791  /* Common for all force feedback effects */
792  Uint16 type;
800 
801 
802 /* Function prototypes */
808 extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
809 
821 extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
822 
845 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index);
846 
856 extern DECLSPEC int SDLCALL SDL_HapticOpened(int device_index);
857 
867 extern DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic * haptic);
868 
876 extern DECLSPEC int SDLCALL SDL_MouseIsHaptic(void);
877 
886 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void);
887 
897 extern DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick * joystick);
898 
916 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick *
917  joystick);
918 
924 extern DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic * haptic);
925 
940 extern DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic * haptic);
941 
956 extern DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic);
957 
974 extern DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic * haptic);
975 
976 
982 extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);
983 
994 extern DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic * haptic,
996  effect);
997 
1009 extern DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic * haptic,
1010  SDL_HapticEffect * effect);
1011 
1029 extern DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic * haptic,
1030  int effect,
1031  SDL_HapticEffect * data);
1032 
1051 extern DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic * haptic,
1052  int effect,
1053  Uint32 iterations);
1054 
1065 extern DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic * haptic,
1066  int effect);
1067 
1079 extern DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic * haptic,
1080  int effect);
1081 
1094 extern DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic * haptic,
1095  int effect);
1096 
1113 extern DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
1114 
1129 extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic,
1130  int autocenter);
1131 
1146 extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic);
1147 
1158 extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);
1159 
1166 extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic);
1167 
1178 extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic);
1179 
1191 extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic);
1192 
1205 extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length );
1206 
1217 extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic);
1218 
1219 /* Ends C function definitions when using C++ */
1220 #ifdef __cplusplus
1221 }
1222 #endif
1223 #include "close_code.h"
1224 
1225 #endif /* SDL_haptic_h_ */
1226 
1227 /* vi: set ts=4 sw=4 expandtab: */
DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void)
Tries to open a haptic device from the current mouse.
DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index)
Opens a haptic device for use.
DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic *haptic)
Closes a haptic device previously opened with SDL_HapticOpen().
SDL_HapticCustom custom
Definition: SDL_haptic.h:798
Uint16 interval
Definition: SDL_haptic.h:705
A structure containing a template for the SDL_HAPTIC_CUSTOM effect.
Definition: SDL_haptic.h:693
Sint16 level
Definition: SDL_haptic.h:472
Uint16 samples
Definition: SDL_haptic.h:710
Uint16 fade_level
Definition: SDL_haptic.h:650
struct SDL_HapticRamp SDL_HapticRamp
A structure containing a template for a Ramp effect.
DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic *haptic)
Gets the index of a haptic device.
Uint16 attack_length
Definition: SDL_haptic.h:561
Uint16 large_magnitude
Definition: SDL_haptic.h:674
struct _SDL_Haptic SDL_Haptic
The haptic structure used to identify an SDL haptic.
Definition: SDL_haptic.h:130
struct SDL_HapticPeriodic SDL_HapticPeriodic
A structure containing a template for a Periodic effect.
Uint16 fade_level
Definition: SDL_haptic.h:478
DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic *haptic)
Stops all the currently playing effects on a haptic device.
DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic *haptic, int effect)
Stops the haptic effect on its associated haptic device.
Uint8 type
Definition: SDL_haptic.h:441
Uint16 button
Definition: SDL_haptic.h:639
Sint32 dir[3]
Definition: SDL_haptic.h:442
Uint16 attack_level
Definition: SDL_haptic.h:562
Uint16 period
Definition: SDL_haptic.h:709
Uint16 small_magnitude
Definition: SDL_haptic.h:675
Uint16 fade_length
Definition: SDL_haptic.h:563
Uint16 attack_length
Definition: SDL_haptic.h:714
Uint16 attack_level
Definition: SDL_haptic.h:476
Uint16 delay
Definition: SDL_haptic.h:636
Uint16 delay
Definition: SDL_haptic.h:548
SDL_HapticConstant constant
Definition: SDL_haptic.h:793
Uint16 button
Definition: SDL_haptic.h:551
Uint16 type
Definition: SDL_haptic.h:460
SDL_HapticDirection direction
Definition: SDL_haptic.h:596
Uint16 button
Definition: SDL_haptic.h:468
DECLSPEC int SDLCALL SDL_HapticOpened(int device_index)
Checks if the haptic device at index has been opened.
Uint16 * data
Definition: SDL_haptic.h:711
Uint16 period
Definition: SDL_haptic.h:555
Uint32 length
Definition: SDL_haptic.h:464
DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic *haptic, int effect, SDL_HapticEffect *data)
Updates the properties of an effect.
A structure containing a template for a Constant effect.
Definition: SDL_haptic.h:457
DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic *haptic)
Initializes the haptic device for simple rumble playback.
Uint16 button
Definition: SDL_haptic.h:704
Uint8 channels
Definition: SDL_haptic.h:708
Uint16 fade_length
Definition: SDL_haptic.h:716
DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic *haptic)
Returns the number of effects a haptic device can play at the same time.
struct SDL_HapticLeftRight SDL_HapticLeftRight
A structure containing a template for a Left/Right effect.
SDL_HapticDirection direction
Definition: SDL_haptic.h:697
DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic *haptic, SDL_HapticEffect *effect)
Creates a new haptic effect on the device.
SDL_HapticDirection direction
Definition: SDL_haptic.h:632
DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic *haptic, float strength, Uint32 length)
Runs simple rumble on a haptic device.
Uint32 length
Definition: SDL_haptic.h:700
Uint16 button
Definition: SDL_haptic.h:603
SDL_HapticDirection direction
Definition: SDL_haptic.h:461
DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
Gets the status of the current effect on the haptic device.
Uint32 length
Definition: SDL_haptic.h:547
Uint16 delay
Definition: SDL_haptic.h:600
DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
Opens a haptic device for use from a joystick device.
SDL_HapticCondition condition
Definition: SDL_haptic.h:795
Uint16 type
Definition: SDL_haptic.h:541
Sint16 end
Definition: SDL_haptic.h:644
DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic *haptic, int effect)
Destroys a haptic effect on the device.
Uint16 fade_length
Definition: SDL_haptic.h:649
Uint16 type
Definition: SDL_haptic.h:631
Uint16 interval
Definition: SDL_haptic.h:469
A structure containing a template for a Periodic effect.
Definition: SDL_haptic.h:538
DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic *haptic, SDL_HapticEffect *effect)
Checks to see if effect is supported by haptic.
Uint16 type
Definition: SDL_haptic.h:668
Sint16 magnitude
Definition: SDL_haptic.h:556
Uint32 length
Definition: SDL_haptic.h:671
Uint16 fade_length
Definition: SDL_haptic.h:477
Uint16 fade_level
Definition: SDL_haptic.h:717
SDL_HapticDirection direction
Definition: SDL_haptic.h:544
DECLSPEC int SDLCALL SDL_MouseIsHaptic(void)
Gets whether or not the current mouse has haptic capabilities.
DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic *haptic, int effect, Uint32 iterations)
Runs the haptic effect on its associated haptic device.
Uint16 interval
Definition: SDL_haptic.h:640
The generic template for any haptic effect.
Definition: SDL_haptic.h:789
Sint16 offset
Definition: SDL_haptic.h:557
DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
Sets the global autocenter of the device.
A structure containing a template for a Condition effect.
Definition: SDL_haptic.h:591
DECLSPEC const char *SDLCALL SDL_HapticName(int device_index)
Get the implementation dependent name of a haptic device.
DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic *haptic)
Gets the haptic device&#39;s supported features in bitwise manner.
struct SDL_HapticCondition SDL_HapticCondition
A structure containing a template for a Condition effect.
SDL_HapticLeftRight leftright
Definition: SDL_haptic.h:797
DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick *joystick)
Checks to see if a joystick has haptic features.
Uint16 delay
Definition: SDL_haptic.h:701
struct SDL_HapticConstant SDL_HapticConstant
A structure containing a template for a Constant effect.
Uint16 delay
Definition: SDL_haptic.h:465
Structure that represents a haptic direction.
Definition: SDL_haptic.h:439
DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic *haptic)
Checks to see if rumble is supported on a haptic device.
struct SDL_HapticCustom SDL_HapticCustom
A structure containing a template for the SDL_HAPTIC_CUSTOM effect.
SDL_HapticRamp ramp
Definition: SDL_haptic.h:796
Uint16 type
Definition: SDL_haptic.h:792
DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic *haptic, int gain)
Sets the global gain of the device.
A structure containing a template for a Ramp effect.
Definition: SDL_haptic.h:628
Uint16 fade_level
Definition: SDL_haptic.h:564
Uint16 attack_level
Definition: SDL_haptic.h:648
DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic *haptic)
Unpauses a haptic device.
SDL_HapticPeriodic periodic
Definition: SDL_haptic.h:794
Uint16 attack_length
Definition: SDL_haptic.h:647
DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic *haptic)
Stops the simple rumble on a haptic device.
Uint32 length
Definition: SDL_haptic.h:635
DECLSPEC int SDLCALL SDL_NumHaptics(void)
Count the number of haptic devices attached to the system.
Uint16 type
Definition: SDL_haptic.h:594
Sint16 start
Definition: SDL_haptic.h:643
Uint16 interval
Definition: SDL_haptic.h:604
DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic *haptic)
Returns the number of effects a haptic device can store.
struct SDL_HapticDirection SDL_HapticDirection
Structure that represents a haptic direction.
Uint16 type
Definition: SDL_haptic.h:696
Uint16 attack_length
Definition: SDL_haptic.h:475
Uint32 length
Definition: SDL_haptic.h:599
DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic *haptic)
Gets the number of haptic axes the device has.
Uint16 attack_level
Definition: SDL_haptic.h:715
Uint16 phase
Definition: SDL_haptic.h:558
DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic *haptic)
Pauses a haptic device.
A structure containing a template for a Left/Right effect.
Definition: SDL_haptic.h:665
union SDL_HapticEffect SDL_HapticEffect
The generic template for any haptic effect.
Uint16 interval
Definition: SDL_haptic.h:552