include/SDL_joystick.h
author Sam Lantinga <slouken@libsdl.org>
Tue, 31 Jan 2017 12:23:29 -0800
changeset 10868 a06c32b64184
parent 10865 179bcbe6c911
child 10870 b158d18e06d0
permissions -rw-r--r--
Added support for the HOTAS Warthog throttle
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
slouken@0
    21
slouken@1895
    22
/**
slouken@3407
    23
 *  \file SDL_joystick.h
slouken@7191
    24
 *
slouken@3407
    25
 *  Include file for SDL joystick event handling
slouken@6690
    26
 *
philipp@10213
    27
 * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks(), with the exact joystick
slouken@6690
    28
 *   behind a device_index changing as joysticks are plugged and unplugged.
slouken@6690
    29
 *
slouken@6690
    30
 * The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted
slouken@6690
    31
 *   then it will get a new instance_id, instance_id's are monotonically increasing identifiers of a joystick plugged in.
slouken@6690
    32
 *
slouken@7191
    33
 * The term JoystickGUID is a stable 128-bit identifier for a joystick device that does not change over time, it identifies class of
slouken@6690
    34
 *   the device (a X360 wired controller for example). This identifier is platform dependent.
slouken@6690
    35
 *
slouken@6690
    36
 *
slouken@1895
    37
 */
slouken@0
    38
slouken@10638
    39
#ifndef SDL_joystick_h_
slouken@10638
    40
#define SDL_joystick_h_
slouken@0
    41
slouken@1356
    42
#include "SDL_stdinc.h"
slouken@1358
    43
#include "SDL_error.h"
slouken@0
    44
slouken@0
    45
#include "begin_code.h"
slouken@0
    46
/* Set up for C function definitions, even when using C++ */
slouken@0
    47
#ifdef __cplusplus
slouken@0
    48
extern "C" {
slouken@0
    49
#endif
slouken@0
    50
slouken@3407
    51
/**
slouken@3407
    52
 *  \file SDL_joystick.h
slouken@3407
    53
 *
slouken@3407
    54
 *  In order to use these functions, SDL_Init() must have been called
slouken@3407
    55
 *  with the ::SDL_INIT_JOYSTICK flag.  This causes SDL to scan the system
slouken@3407
    56
 *  for joysticks, and load appropriate drivers.
slouken@7341
    57
 *
slouken@7341
    58
 *  If you would like to receive joystick updates while the application
slouken@7341
    59
 *  is in the background, you should set the following hint before calling
slouken@7341
    60
 *  SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
slouken@3407
    61
 */
slouken@0
    62
slouken@10636
    63
/**
slouken@10636
    64
 * The joystick structure used to identify an SDL joystick
slouken@10636
    65
 */
slouken@0
    66
struct _SDL_Joystick;
slouken@0
    67
typedef struct _SDL_Joystick SDL_Joystick;
slouken@0
    68
slouken@6707
    69
/* A structure that encodes the stable unique id for a joystick device */
slouken@6707
    70
typedef struct {
slouken@7191
    71
    Uint8 data[16];
slouken@6738
    72
} SDL_JoystickGUID;
slouken@6707
    73
slouken@6974
    74
typedef Sint32 SDL_JoystickID;
slouken@6707
    75
slouken@9884
    76
typedef enum
slouken@9884
    77
{
slouken@10855
    78
    SDL_JOYSTICK_TYPE_UNKNOWN,
slouken@10855
    79
    SDL_JOYSTICK_TYPE_GAMECONTROLLER,
slouken@10855
    80
    SDL_JOYSTICK_TYPE_WHEEL,
slouken@10855
    81
    SDL_JOYSTICK_TYPE_ARCADE_STICK,
slouken@10855
    82
    SDL_JOYSTICK_TYPE_FLIGHT_STICK,
slouken@10855
    83
    SDL_JOYSTICK_TYPE_DANCE_PAD,
slouken@10855
    84
    SDL_JOYSTICK_TYPE_GUITAR,
slouken@10855
    85
    SDL_JOYSTICK_TYPE_DRUM_KIT,
slouken@10868
    86
    SDL_JOYSTICK_TYPE_ARCADE_PAD,
slouken@10868
    87
	SDL_JOYSTICK_TYPE_THROTTLE,
slouken@10855
    88
} SDL_JoystickType;
slouken@10855
    89
slouken@10855
    90
typedef enum
slouken@10855
    91
{
slouken@9884
    92
    SDL_JOYSTICK_POWER_UNKNOWN = -1,
slouken@9884
    93
    SDL_JOYSTICK_POWER_EMPTY,
slouken@9884
    94
    SDL_JOYSTICK_POWER_LOW,
slouken@9884
    95
    SDL_JOYSTICK_POWER_MEDIUM,
slouken@9884
    96
    SDL_JOYSTICK_POWER_FULL,
slouken@9884
    97
    SDL_JOYSTICK_POWER_WIRED,
slouken@9884
    98
    SDL_JOYSTICK_POWER_MAX
slouken@9884
    99
} SDL_JoystickPowerLevel;
slouken@6707
   100
slouken@0
   101
/* Function prototypes */
slouken@3407
   102
/**
slouken@6690
   103
 *  Count the number of joysticks attached to the system right now
slouken@0
   104
 */
slouken@337
   105
extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
slouken@0
   106
slouken@3407
   107
/**
slouken@3407
   108
 *  Get the implementation dependent name of a joystick.
slouken@3407
   109
 *  This can be called before any joysticks are opened.
slouken@3407
   110
 *  If no name can be found, this function returns NULL.
slouken@0
   111
 */
slouken@6690
   112
extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
slouken@0
   113
slouken@3407
   114
/**
slouken@10595
   115
 *  Return the GUID for the joystick at this index
slouken@10595
   116
 *  This can be called before any joysticks are opened.
slouken@10595
   117
 */
slouken@10595
   118
extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
slouken@10595
   119
slouken@10595
   120
/**
slouken@10595
   121
 *  Get the USB vendor ID of a joystick, if available.
slouken@10595
   122
 *  This can be called before any joysticks are opened.
slouken@10595
   123
 *  If the vendor ID isn't available this function returns 0.
slouken@10595
   124
 */
slouken@10595
   125
extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceVendor(int device_index);
slouken@10595
   126
slouken@10595
   127
/**
slouken@10595
   128
 *  Get the USB product ID of a joystick, if available.
slouken@10595
   129
 *  This can be called before any joysticks are opened.
slouken@10595
   130
 *  If the product ID isn't available this function returns 0.
slouken@10595
   131
 */
slouken@10595
   132
extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProduct(int device_index);
slouken@10595
   133
slouken@10595
   134
/**
slouken@10595
   135
 *  Get the product version of a joystick, if available.
slouken@10595
   136
 *  This can be called before any joysticks are opened.
slouken@10595
   137
 *  If the product version isn't available this function returns 0.
slouken@10595
   138
 */
slouken@10595
   139
extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProductVersion(int device_index);
slouken@10595
   140
slouken@10595
   141
/**
slouken@10855
   142
 *  Get the type of a joystick, if available.
slouken@10855
   143
 *  This can be called before any joysticks are opened.
slouken@10855
   144
 */
slouken@10855
   145
extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetDeviceType(int device_index);
slouken@10855
   146
slouken@10855
   147
/**
slouken@7191
   148
 *  Open a joystick for use.
philipp@9227
   149
 *  The index passed as an argument refers to the N'th joystick on the system.
philipp@9569
   150
 *  This index is not the value which will identify this joystick in future
philipp@9569
   151
 *  joystick events.  The joystick's instance id (::SDL_JoystickID) will be used
philipp@9569
   152
 *  there instead.
slouken@7191
   153
 *
slouken@3407
   154
 *  \return A joystick identifier, or NULL if an error occurred.
slouken@0
   155
 */
slouken@1895
   156
extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
slouken@0
   157
slouken@3407
   158
/**
icculus@9916
   159
 * Return the SDL_Joystick associated with an instance id.
icculus@9916
   160
 */
icculus@9916
   161
extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID joyid);
icculus@9916
   162
icculus@9916
   163
/**
slouken@6690
   164
 *  Return the name for this currently opened joystick.
slouken@6690
   165
 *  If no name can be found, this function returns NULL.
slouken@0
   166
 */
slouken@6690
   167
extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
slouken@7191
   168
slouken@6690
   169
/**
slouken@6690
   170
 *  Return the GUID for this opened joystick
slouken@6690
   171
 */
slouken@6738
   172
extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
slouken@6690
   173
slouken@6690
   174
/**
slouken@10595
   175
 *  Get the USB vendor ID of an opened joystick, if available.
slouken@10595
   176
 *  If the vendor ID isn't available this function returns 0.
slouken@10595
   177
 */
slouken@10595
   178
extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetVendor(SDL_Joystick * joystick);
slouken@10595
   179
slouken@10595
   180
/**
slouken@10595
   181
 *  Get the USB product ID of an opened joystick, if available.
slouken@10595
   182
 *  If the product ID isn't available this function returns 0.
slouken@10595
   183
 */
slouken@10595
   184
extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProduct(SDL_Joystick * joystick);
slouken@10595
   185
slouken@10595
   186
/**
slouken@10595
   187
 *  Get the product version of an opened joystick, if available.
slouken@10595
   188
 *  If the product version isn't available this function returns 0.
slouken@10595
   189
 */
slouken@10595
   190
extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick * joystick);
slouken@10595
   191
slouken@10595
   192
/**
slouken@10855
   193
 *  Get the type of an opened joystick.
slouken@10855
   194
 */
slouken@10855
   195
extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick * joystick);
slouken@10855
   196
slouken@10855
   197
/**
icculus@6746
   198
 *  Return a string representation for this guid. pszGUID must point to at least 33 bytes
icculus@6746
   199
 *  (32 for the string plus a NULL terminator).
slouken@6690
   200
 */
icculus@8028
   201
extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
slouken@6690
   202
slouken@6690
   203
/**
slouken@10595
   204
 *  Convert a string into a joystick guid
slouken@6690
   205
 */
slouken@6738
   206
extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
slouken@6690
   207
slouken@6707
   208
/**
slouken@6707
   209
 *  Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
slouken@6707
   210
 */
slouken@6707
   211
extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
slouken@6690
   212
slouken@6690
   213
/**
slouken@6974
   214
 *  Get the instance ID of an opened joystick or -1 if the joystick is invalid.
slouken@0
   215
 */
slouken@6690
   216
extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
slouken@0
   217
slouken@3407
   218
/**
slouken@3407
   219
 *  Get the number of general axis controls on a joystick.
slouken@0
   220
 */
slouken@1895
   221
extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
slouken@0
   222
slouken@3407
   223
/**
slouken@3407
   224
 *  Get the number of trackballs on a joystick.
slouken@7191
   225
 *
slouken@3407
   226
 *  Joystick trackballs have only relative motion events associated
slouken@3407
   227
 *  with them and their state cannot be polled.
slouken@0
   228
 */
slouken@1895
   229
extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
slouken@0
   230
slouken@3407
   231
/**
slouken@3407
   232
 *  Get the number of POV hats on a joystick.
slouken@0
   233
 */
slouken@1895
   234
extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
slouken@0
   235
slouken@3407
   236
/**
slouken@3407
   237
 *  Get the number of buttons on a joystick.
slouken@0
   238
 */
slouken@1895
   239
extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
slouken@0
   240
slouken@3407
   241
/**
slouken@3407
   242
 *  Update the current state of the open joysticks.
slouken@7191
   243
 *
slouken@3407
   244
 *  This is called automatically by the event loop if any joystick
slouken@3407
   245
 *  events are enabled.
slouken@0
   246
 */
slouken@337
   247
extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
slouken@0
   248
slouken@3407
   249
/**
slouken@3407
   250
 *  Enable/disable joystick event polling.
slouken@7191
   251
 *
slouken@3407
   252
 *  If joystick events are disabled, you must call SDL_JoystickUpdate()
slouken@3407
   253
 *  yourself and check the state of the joystick when you want joystick
slouken@3407
   254
 *  information.
slouken@7191
   255
 *
slouken@3407
   256
 *  The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
slouken@0
   257
 */
slouken@337
   258
extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
slouken@0
   259
slouken@10724
   260
#define SDL_JOYSTICK_AXIS_MAX   32767
slouken@10724
   261
#define SDL_JOYSTICK_AXIS_MIN   -32768
slouken@3407
   262
/**
slouken@3407
   263
 *  Get the current state of an axis control on a joystick.
slouken@7191
   264
 *
slouken@3407
   265
 *  The state is a value ranging from -32768 to 32767.
slouken@7191
   266
 *
slouken@3407
   267
 *  The axis indices start at index 0.
slouken@0
   268
 */
slouken@1895
   269
extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
slouken@1895
   270
                                                   int axis);
slouken@0
   271
slouken@3407
   272
/**
slouken@10752
   273
 *  Get the initial state of an axis control on a joystick.
slouken@10752
   274
 *
slouken@10752
   275
 *  The state is a value ranging from -32768 to 32767.
slouken@10752
   276
 *
slouken@10752
   277
 *  The axis indices start at index 0.
slouken@10752
   278
 *
slouken@10752
   279
 *  \return SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
slouken@10752
   280
 */
slouken@10752
   281
extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick * joystick,
slouken@10752
   282
                                                   int axis, Sint16 *state);
slouken@10752
   283
slouken@10752
   284
/**
slouken@3407
   285
 *  \name Hat positions
slouken@0
   286
 */
gabomdq@7678
   287
/* @{ */
slouken@7191
   288
#define SDL_HAT_CENTERED    0x00
philipp@9806
   289
#define SDL_HAT_UP          0x01
slouken@7191
   290
#define SDL_HAT_RIGHT       0x02
slouken@7191
   291
#define SDL_HAT_DOWN        0x04
slouken@7191
   292
#define SDL_HAT_LEFT        0x08
slouken@7191
   293
#define SDL_HAT_RIGHTUP     (SDL_HAT_RIGHT|SDL_HAT_UP)
slouken@7191
   294
#define SDL_HAT_RIGHTDOWN   (SDL_HAT_RIGHT|SDL_HAT_DOWN)
slouken@7191
   295
#define SDL_HAT_LEFTUP      (SDL_HAT_LEFT|SDL_HAT_UP)
slouken@7191
   296
#define SDL_HAT_LEFTDOWN    (SDL_HAT_LEFT|SDL_HAT_DOWN)
gabomdq@7678
   297
/* @} */
slouken@3407
   298
slouken@3407
   299
/**
slouken@3407
   300
 *  Get the current state of a POV hat on a joystick.
slouken@3407
   301
 *
slouken@3407
   302
 *  The hat indices start at index 0.
slouken@7191
   303
 *
slouken@3407
   304
 *  \return The return value is one of the following positions:
slouken@3407
   305
 *           - ::SDL_HAT_CENTERED
slouken@3407
   306
 *           - ::SDL_HAT_UP
slouken@3407
   307
 *           - ::SDL_HAT_RIGHT
slouken@3407
   308
 *           - ::SDL_HAT_DOWN
slouken@3407
   309
 *           - ::SDL_HAT_LEFT
slouken@3407
   310
 *           - ::SDL_HAT_RIGHTUP
slouken@3407
   311
 *           - ::SDL_HAT_RIGHTDOWN
slouken@3407
   312
 *           - ::SDL_HAT_LEFTUP
slouken@3407
   313
 *           - ::SDL_HAT_LEFTDOWN
slouken@0
   314
 */
slouken@1895
   315
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
slouken@1895
   316
                                                 int hat);
slouken@0
   317
slouken@3407
   318
/**
slouken@3407
   319
 *  Get the ball axis change since the last poll.
slouken@7191
   320
 *
slouken@3407
   321
 *  \return 0, or -1 if you passed it invalid parameters.
slouken@7191
   322
 *
slouken@3407
   323
 *  The ball indices start at index 0.
slouken@0
   324
 */
slouken@1895
   325
extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
slouken@1895
   326
                                                int ball, int *dx, int *dy);
slouken@0
   327
slouken@3407
   328
/**
slouken@3407
   329
 *  Get the current state of a button on a joystick.
slouken@7191
   330
 *
slouken@3407
   331
 *  The button indices start at index 0.
slouken@0
   332
 */
slouken@1895
   333
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
slouken@1895
   334
                                                    int button);
slouken@0
   335
slouken@3407
   336
/**
slouken@3407
   337
 *  Close a joystick previously opened with SDL_JoystickOpen().
slouken@0
   338
 */
slouken@1895
   339
extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
slouken@0
   340
slouken@9884
   341
/**
icculus@9917
   342
 *  Return the battery level of this joystick
icculus@9917
   343
 */
slouken@9884
   344
extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick);
slouken@9884
   345
slouken@0
   346
/* Ends C function definitions when using C++ */
slouken@0
   347
#ifdef __cplusplus
slouken@0
   348
}
slouken@0
   349
#endif
slouken@0
   350
#include "close_code.h"
slouken@0
   351
slouken@10638
   352
#endif /* SDL_joystick_h_ */
slouken@1895
   353
slouken@1895
   354
/* vi: set ts=4 sw=4 expandtab: */