src/joystick/SDL_sysjoystick.h
author Sam Lantinga
Mon, 26 Nov 2012 16:37:54 -0800
changeset 6690 9548c8a58103
parent 6138 4c64952a58fb
child 6693 3c98e4ec2180
permissions -rw-r--r--
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6138
     3
  Copyright (C) 1997-2012 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@1402
    21
#include "SDL_config.h"
slouken@0
    22
slouken@0
    23
/* This is the system specific header for the SDL joystick API */
slouken@0
    24
slouken@0
    25
#include "SDL_joystick.h"
slouken@6690
    26
#include "SDL_joystick_c.h"
slouken@0
    27
slouken@0
    28
/* The SDL joystick structure */
slouken@1895
    29
struct _SDL_Joystick
slouken@1895
    30
{
slouken@6690
    31
    int instance_id;                /* Device instance, monotonically increasing from 0 */
slouken@6690
    32
    char *name;          		 /* Joystick name - system dependent */
slouken@0
    33
slouken@1895
    34
    int naxes;                  /* Number of axis controls on the joystick */
slouken@1895
    35
    Sint16 *axes;               /* Current axis states */
slouken@1895
    36
slouken@1895
    37
    int nhats;                  /* Number of hats on the joystick */
slouken@1895
    38
    Uint8 *hats;                /* Current hat states */
slouken@0
    39
slouken@1895
    40
    int nballs;                 /* Number of trackballs on the joystick */
slouken@1895
    41
    struct balldelta
slouken@1895
    42
    {
slouken@1895
    43
        int dx;
slouken@1895
    44
        int dy;
slouken@1895
    45
    } *balls;                   /* Current ball motion deltas */
slouken@0
    46
slouken@1895
    47
    int nbuttons;               /* Number of buttons on the joystick */
slouken@1895
    48
    Uint8 *buttons;             /* Current button states */
slouken@1895
    49
slouken@1895
    50
    struct joystick_hwdata *hwdata;     /* Driver dependent information */
slouken@1895
    51
slouken@1895
    52
    int ref_count;              /* Reference count for multiple opens */
slouken@6690
    53
	
slouken@6690
    54
	Uint8 closed;				/* 1 if this device is no longer valid */
slouken@6690
    55
	Uint8 uncentered;			/* 1 if this device needs to have its state reset to 0 */
slouken@6690
    56
	struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */
slouken@0
    57
};
slouken@0
    58
slouken@0
    59
/* Function to scan the system for joysticks.
slouken@0
    60
 * Joystick 0 should be the system default joystick.
slouken@0
    61
 * This function should return the number of available joysticks, or -1
slouken@0
    62
 * on an unrecoverable fatal error.
slouken@0
    63
 */
slouken@0
    64
extern int SDL_SYS_JoystickInit(void);
slouken@0
    65
slouken@0
    66
/* Function to get the device-dependent name of a joystick */
slouken@6690
    67
extern const char *SDL_SYS_JoystickNameForIndex(int index);
slouken@6690
    68
slouken@6690
    69
/* Function to get the current instance id of the joystick located at device_index */
slouken@6690
    70
extern SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex( int device_index );
slouken@0
    71
slouken@0
    72
/* Function to open a joystick for use.
slouken@0
    73
   The joystick to open is specified by the index field of the joystick.
slouken@0
    74
   This should fill the nbuttons and naxes fields of the joystick structure.
slouken@0
    75
   It returns 0, or -1 if there is an error.
slouken@0
    76
 */
slouken@6690
    77
extern int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index );
slouken@0
    78
slouken@0
    79
/* Function to update the state of a joystick - called as a device poll.
slouken@0
    80
 * This function shouldn't update the joystick structure directly,
slouken@0
    81
 * but instead should call SDL_PrivateJoystick*() to deliver events
slouken@0
    82
 * and update joystick device state.
slouken@0
    83
 */
slouken@1895
    84
extern void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick);
slouken@0
    85
slouken@0
    86
/* Function to close a joystick after use */
slouken@1895
    87
extern void SDL_SYS_JoystickClose(SDL_Joystick * joystick);
slouken@0
    88
slouken@0
    89
/* Function to perform any system-specific joystick related cleanup */
slouken@0
    90
extern void SDL_SYS_JoystickQuit(void);
slouken@1978
    91
slouken@6690
    92
/* Function to query if the joystick is currently attached
slouken@6690
    93
 *   It returns 1 if attached, 0 otherwise.
slouken@6690
    94
 */
slouken@6690
    95
extern int SDL_SYS_JoystickAttached(SDL_Joystick * joystick);
slouken@6690
    96
slouken@6690
    97
/* Function to return the number of joystick devices plugged in right now*/
slouken@6690
    98
extern int SDL_SYS_NumJoysticks();
slouken@6690
    99
slouken@6690
   100
/* Function to cause any queued joystick insertions to be processed
slouken@6690
   101
 */
slouken@6690
   102
extern void SDL_SYS_JoystickDetect();
slouken@6690
   103
slouken@6690
   104
/* Function to determine if the joystick loop needs to run right now
slouken@6690
   105
 */
slouken@6690
   106
extern int SDL_SYS_JoystickNeedsPolling();
slouken@6690
   107
slouken@6690
   108
/* Function to return the stable GUID for a plugged in device
slouken@6690
   109
 */
slouken@6690
   110
extern JoystickGUID SDL_SYS_PrivateJoystickGetDeviceID( int device_index );
slouken@6690
   111
slouken@6690
   112
/* Function to return the stable GUID for a opened joystick
slouken@6690
   113
 */
slouken@6690
   114
extern JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick);
slouken@6690
   115
slouken@6690
   116
#ifdef __WIN32__
slouken@6690
   117
/* Function to get the current instance id of the joystick located at device_index */
slouken@6690
   118
extern int SDL_SYS_IsXInputDeviceIndex( int device_index );
slouken@6690
   119
#endif
slouken@1895
   120
/* vi: set ts=4 sw=4 expandtab: */