My Project
Loading...
Searching...
No Matches
SDL_joystick.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2023 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
41#ifndef SDL_joystick_h_
42#define SDL_joystick_h_
43
44#include "SDL_stdinc.h"
45#include "SDL_error.h"
46#include "SDL_guid.h"
47
48#include "begin_code.h"
49/* Set up for C function definitions, even when using C++ */
50#ifdef __cplusplus
51extern "C" {
52#endif
53
69struct _SDL_Joystick;
70typedef struct _SDL_Joystick SDL_Joystick;
71
72/* A structure that encodes the stable unique id for a joystick device */
74
82typedef Sint32 SDL_JoystickID;
83
84typedef enum
85{
86 SDL_JOYSTICK_TYPE_UNKNOWN,
87 SDL_JOYSTICK_TYPE_GAMECONTROLLER,
88 SDL_JOYSTICK_TYPE_WHEEL,
89 SDL_JOYSTICK_TYPE_ARCADE_STICK,
90 SDL_JOYSTICK_TYPE_FLIGHT_STICK,
91 SDL_JOYSTICK_TYPE_DANCE_PAD,
92 SDL_JOYSTICK_TYPE_GUITAR,
93 SDL_JOYSTICK_TYPE_DRUM_KIT,
94 SDL_JOYSTICK_TYPE_ARCADE_PAD,
95 SDL_JOYSTICK_TYPE_THROTTLE
96} SDL_JoystickType;
97
98typedef enum
99{
100 SDL_JOYSTICK_POWER_UNKNOWN = -1,
101 SDL_JOYSTICK_POWER_EMPTY, /* <= 5% */
102 SDL_JOYSTICK_POWER_LOW, /* <= 20% */
103 SDL_JOYSTICK_POWER_MEDIUM, /* <= 70% */
104 SDL_JOYSTICK_POWER_FULL, /* <= 100% */
105 SDL_JOYSTICK_POWER_WIRED,
106 SDL_JOYSTICK_POWER_MAX
107} SDL_JoystickPowerLevel;
108
109/* Set max recognized G-force from accelerometer
110 See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
111 */
112#define SDL_IPHONE_MAX_GFORCE 5.0
113
114
115/* Function prototypes */
116
134extern DECLSPEC void SDLCALL SDL_LockJoysticks(void);
135
136
149extern DECLSPEC void SDLCALL SDL_UnlockJoysticks(void);
150
163extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
164
180extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
181
197extern DECLSPEC const char *SDLCALL SDL_JoystickPathForIndex(int device_index);
198
205extern DECLSPEC int SDLCALL SDL_JoystickGetDevicePlayerIndex(int device_index);
206
223extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
224
238extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceVendor(int device_index);
239
253extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProduct(int device_index);
254
268extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProductVersion(int device_index);
269
282extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetDeviceType(int device_index);
283
297extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickGetDeviceInstanceID(int device_index);
298
319extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
320
330extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID instance_id);
331
341extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromPlayerIndex(int player_index);
342
350extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtual(SDL_JoystickType type,
351 int naxes,
352 int nbuttons,
353 int nhats);
354
364{
365 Uint16 version;
366 Uint16 type;
367 Uint16 naxes;
368 Uint16 nbuttons;
369 Uint16 nhats;
370 Uint16 vendor_id;
371 Uint16 product_id;
372 Uint16 padding;
373 Uint32 button_mask;
375 Uint32 axis_mask;
377 const char *name;
379 void *userdata;
380 void (SDLCALL *Update)(void *userdata);
381 void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index);
382 int (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
383 int (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble);
384 int (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue);
385 int (SDLCALL *SendEffect)(void *userdata, const void *data, int size);
388
392#define SDL_VIRTUAL_JOYSTICK_DESC_VERSION 1
393
401extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtualEx(const SDL_VirtualJoystickDesc *desc);
402
412extern DECLSPEC int SDLCALL SDL_JoystickDetachVirtual(int device_index);
413
422extern DECLSPEC SDL_bool SDLCALL SDL_JoystickIsVirtual(int device_index);
423
444extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
445
462extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualButton(SDL_Joystick *joystick, int button, Uint8 value);
463
480extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
481
494extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick *joystick);
495
507extern DECLSPEC const char *SDLCALL SDL_JoystickPath(SDL_Joystick *joystick);
508
520extern DECLSPEC int SDLCALL SDL_JoystickGetPlayerIndex(SDL_Joystick *joystick);
521
531extern DECLSPEC void SDLCALL SDL_JoystickSetPlayerIndex(SDL_Joystick *joystick, int player_index);
532
548extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick *joystick);
549
560extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetVendor(SDL_Joystick *joystick);
561
572extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProduct(SDL_Joystick *joystick);
573
584extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick *joystick);
585
597extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetFirmwareVersion(SDL_Joystick *joystick);
598
610extern DECLSPEC const char * SDLCALL SDL_JoystickGetSerial(SDL_Joystick *joystick);
611
620extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick *joystick);
621
637extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
638
653extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
654
672extern DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);
673
686extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick *joystick);
687
699extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick *joystick);
700
718extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick);
719
736extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick);
737
750extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick);
751
764extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick);
765
776extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
777
801extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
802
803#define SDL_JOYSTICK_AXIS_MAX 32767
804#define SDL_JOYSTICK_AXIS_MIN -32768
805
828extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick,
829 int axis);
830
845extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick *joystick,
846 int axis, Sint16 *state);
847
851/* @{ */
852#define SDL_HAT_CENTERED 0x00
853#define SDL_HAT_UP 0x01
854#define SDL_HAT_RIGHT 0x02
855#define SDL_HAT_DOWN 0x04
856#define SDL_HAT_LEFT 0x08
857#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
858#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
859#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
860#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
861/* @} */
862
886extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick,
887 int hat);
888
908extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick,
909 int ball, int *dx, int *dy);
910
923extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick,
924 int button);
925
944extern DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
945
969extern DECLSPEC int SDLCALL SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
970
982extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick *joystick);
983
994extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumble(SDL_Joystick *joystick);
995
1006extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick);
1007
1022extern DECLSPEC int SDLCALL SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
1023
1034extern DECLSPEC int SDLCALL SDL_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size);
1035
1045extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick);
1046
1056extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick *joystick);
1057
1058/* Ends C function definitions when using C++ */
1059#ifdef __cplusplus
1060}
1061#endif
1062#include "close_code.h"
1063
1064#endif /* SDL_joystick_h_ */
1065
1066/* vi: set ts=4 sw=4 expandtab: */
DECLSPEC int SDLCALL SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
DECLSPEC Uint16 SDLCALL SDL_JoystickGetProduct(SDL_Joystick *joystick)
DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProductVersion(int device_index)
DECLSPEC Uint16 SDLCALL SDL_JoystickGetVendor(SDL_Joystick *joystick)
DECLSPEC int SDLCALL SDL_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID instance_id)
DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick *joystick)
DECLSPEC int SDLCALL SDL_JoystickGetPlayerIndex(SDL_Joystick *joystick)
DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick, int hat)
DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick *joystick)
DECLSPEC const char *SDLCALL SDL_JoystickPath(SDL_Joystick *joystick)
DECLSPEC int SDLCALL SDL_NumJoysticks(void)
DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetDeviceType(int device_index)
DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state)
Sint32 SDL_JoystickID
Definition: SDL_joystick.h:82
DECLSPEC void SDLCALL SDL_JoystickUpdate(void)
DECLSPEC int SDLCALL SDL_JoystickSetVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value)
DECLSPEC int SDLCALL SDL_JoystickAttachVirtualEx(const SDL_VirtualJoystickDesc *desc)
DECLSPEC void SDLCALL SDL_LockJoysticks(void)
DECLSPEC Uint16 SDLCALL SDL_JoystickGetFirmwareVersion(SDL_Joystick *joystick)
DECLSPEC int SDLCALL SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
DECLSPEC int SDLCALL SDL_JoystickEventState(int state)
DECLSPEC void SDLCALL SDL_JoystickSetPlayerIndex(SDL_Joystick *joystick, int player_index)
DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProduct(int device_index)
DECLSPEC int SDLCALL SDL_JoystickSetVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value)
DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index)
DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickGetDeviceInstanceID(int device_index)
DECLSPEC const char *SDLCALL SDL_JoystickPathForIndex(int device_index)
DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick *joystick)
DECLSPEC SDL_bool SDLCALL SDL_JoystickIsVirtual(int device_index)
DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick)
DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick *joystick)
DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index)
DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID)
DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick)
DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick)
DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick)
DECLSPEC int SDLCALL SDL_JoystickSetVirtualButton(SDL_Joystick *joystick, int button, Uint8 value)
DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick, int button)
DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick)
DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick *joystick)
DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromPlayerIndex(int player_index)
DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16)
DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis)
DECLSPEC int SDLCALL SDL_JoystickAttachVirtual(SDL_JoystickType type, int naxes, int nbuttons, int nhats)
DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy)
DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick *joystick)
DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick *joystick)
DECLSPEC int SDLCALL SDL_JoystickGetDevicePlayerIndex(int device_index)
DECLSPEC void SDLCALL SDL_UnlockJoysticks(void)
DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick)
DECLSPEC int SDLCALL SDL_JoystickDetachVirtual(int device_index)
DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID)
DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumble(SDL_Joystick *joystick)
DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceVendor(int device_index)
DECLSPEC const char *SDLCALL SDL_JoystickGetSerial(SDL_Joystick *joystick)
DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index)
DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick *joystick)
Definition: SDL_guid.h:55
Definition: SDL_joystick.h:364
Uint16 vendor_id
Definition: SDL_joystick.h:370
Uint16 padding
Definition: SDL_joystick.h:372
Uint32 button_mask
Definition: SDL_joystick.h:373
Uint32 axis_mask
Definition: SDL_joystick.h:375
Uint16 nbuttons
Definition: SDL_joystick.h:368
Uint8 Uint8 Uint8 blue
Definition: SDL_joystick.h:384
Uint16 Uint16 high_frequency_rumble
Definition: SDL_joystick.h:382
Uint16 nhats
Definition: SDL_joystick.h:369
Uint16 type
Definition: SDL_joystick.h:366
const char * name
Definition: SDL_joystick.h:377
const void int size
Definition: SDL_joystick.h:385
void(SDLCALL *Update)(void *userdata)
int player_index
Definition: SDL_joystick.h:381
Uint16 naxes
Definition: SDL_joystick.h:367
Uint16 product_id
Definition: SDL_joystick.h:371
Uint16 Uint16 right_rumble
Definition: SDL_joystick.h:383
Uint16 version
Definition: SDL_joystick.h:365
void * userdata
Definition: SDL_joystick.h:379