src/joystick/SDL_sysjoystick.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 12 Nov 2017 10:59:05 -0800
changeset 11701 d131f3193794
parent 11663 0d96acbd34f0
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Fixed Android build error on older SDK
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
*/
icculus@8093
    21
#include "../SDL_internal.h"
slouken@0
    22
slouken@10638
    23
#ifndef SDL_sysjoystick_h_
slouken@10638
    24
#define SDL_sysjoystick_h_
slouken@8972
    25
slouken@0
    26
/* This is the system specific header for the SDL joystick API */
slouken@0
    27
slouken@0
    28
#include "SDL_joystick.h"
slouken@6690
    29
#include "SDL_joystick_c.h"
slouken@0
    30
slouken@0
    31
/* The SDL joystick structure */
slouken@10713
    32
typedef struct _SDL_JoystickAxisInfo
slouken@10713
    33
{
slouken@10752
    34
    Sint16 initial_value;       /* Initial axis state */
slouken@10752
    35
    Sint16 value;               /* Current axis state */
slouken@10745
    36
    Sint16 zero;                /* Zero point on the axis (-32768 for triggers) */
slouken@10745
    37
    SDL_bool has_initial_value; /* Whether we've seen a value on the axis yet */
slouken@10745
    38
    SDL_bool sent_initial_value; /* Whether we've sent the initial axis value */
slouken@10713
    39
} SDL_JoystickAxisInfo;
slouken@10713
    40
slouken@1895
    41
struct _SDL_Joystick
slouken@1895
    42
{
slouken@6949
    43
    SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
slouken@6949
    44
    char *name;                 /* Joystick name - system dependent */
slouken@0
    45
slouken@1895
    46
    int naxes;                  /* Number of axis controls on the joystick */
slouken@10713
    47
    SDL_JoystickAxisInfo *axes;
slouken@0
    48
slouken@1895
    49
    int nhats;                  /* Number of hats on the joystick */
slouken@1895
    50
    Uint8 *hats;                /* Current hat states */
slouken@0
    51
slouken@1895
    52
    int nballs;                 /* Number of trackballs on the joystick */
slouken@6949
    53
    struct balldelta {
slouken@1895
    54
        int dx;
slouken@1895
    55
        int dy;
slouken@1895
    56
    } *balls;                   /* Current ball motion deltas */
slouken@1895
    57
slouken@1895
    58
    int nbuttons;               /* Number of buttons on the joystick */
slouken@1895
    59
    Uint8 *buttons;             /* Current button states */
slouken@1895
    60
slouken@1895
    61
    struct joystick_hwdata *hwdata;     /* Driver dependent information */
slouken@1895
    62
slouken@1895
    63
    int ref_count;              /* Reference count for multiple opens */
slouken@6949
    64
slouken@10855
    65
    SDL_bool is_game_controller;
icculus@9433
    66
    SDL_bool force_recentering; /* SDL_TRUE if this device needs to have its state reset to 0 */
slouken@9884
    67
    SDL_JoystickPowerLevel epowerlevel; /* power level of this joystick, SDL_JOYSTICK_POWER_UNKNOWN if not supported */
slouken@6949
    68
    struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */
slouken@0
    69
};
slouken@0
    70
slouken@10966
    71
/* Macro to combine a USB vendor ID and product ID into a single Uint32 value */
slouken@10966
    72
#define MAKE_VIDPID(VID, PID)   (((Uint32)(VID))<<16|(PID))
slouken@10966
    73
slouken@0
    74
/* Function to scan the system for joysticks.
slouken@0
    75
 * Joystick 0 should be the system default joystick.
slouken@0
    76
 * This function should return the number of available joysticks, or -1
slouken@0
    77
 * on an unrecoverable fatal error.
slouken@0
    78
 */
slouken@0
    79
extern int SDL_SYS_JoystickInit(void);
slouken@0
    80
slouken@6707
    81
/* Function to return the number of joystick devices plugged in right now */
slouken@10609
    82
extern int SDL_SYS_NumJoysticks(void);
slouken@6707
    83
slouken@6707
    84
/* Function to cause any queued joystick insertions to be processed */
slouken@10609
    85
extern void SDL_SYS_JoystickDetect(void);
slouken@6707
    86
slouken@0
    87
/* Function to get the device-dependent name of a joystick */
slouken@6707
    88
extern const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index);
slouken@6690
    89
slouken@6690
    90
/* Function to get the current instance id of the joystick located at device_index */
slouken@6707
    91
extern SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index);
slouken@0
    92
slouken@0
    93
/* Function to open a joystick for use.
philipp@9380
    94
   The joystick to open is specified by the device index.
slouken@0
    95
   This should fill the nbuttons and naxes fields of the joystick structure.
slouken@0
    96
   It returns 0, or -1 if there is an error.
slouken@0
    97
 */
slouken@6707
    98
extern int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index);
slouken@6707
    99
slouken@6707
   100
/* Function to query if the joystick is currently attached
philipp@9380
   101
 * It returns SDL_TRUE if attached, SDL_FALSE otherwise.
slouken@6707
   102
 */
slouken@6707
   103
extern SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick * joystick);
slouken@0
   104
slouken@0
   105
/* Function to update the state of a joystick - called as a device poll.
slouken@0
   106
 * This function shouldn't update the joystick structure directly,
slouken@0
   107
 * but instead should call SDL_PrivateJoystick*() to deliver events
slouken@0
   108
 * and update joystick device state.
slouken@0
   109
 */
slouken@1895
   110
extern void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick);
slouken@0
   111
slouken@0
   112
/* Function to close a joystick after use */
slouken@1895
   113
extern void SDL_SYS_JoystickClose(SDL_Joystick * joystick);
slouken@0
   114
slouken@0
   115
/* Function to perform any system-specific joystick related cleanup */
slouken@0
   116
extern void SDL_SYS_JoystickQuit(void);
slouken@1978
   117
slouken@6707
   118
/* Function to return the stable GUID for a plugged in device */
slouken@6738
   119
extern SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index);
slouken@6690
   120
slouken@6707
   121
/* Function to return the stable GUID for a opened joystick */
slouken@6738
   122
extern SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);
slouken@6690
   123
slouken@8985
   124
#if SDL_JOYSTICK_XINPUT
slouken@8920
   125
/* Function returns SDL_TRUE if this device is an XInput gamepad */
slouken@8972
   126
extern SDL_bool SDL_SYS_IsXInputGamepad_DeviceIndex(int device_index);
slouken@8985
   127
#endif
slouken@8972
   128
slouken@11663
   129
#if defined(__ANDROID__)
slouken@11663
   130
/* Function returns SDL_TRUE if this device is a DPAD (maybe a TV remote) */
slouken@11663
   131
extern SDL_bool SDL_SYS_IsDPAD_DeviceIndex(int device_index);
slouken@11663
   132
#endif
slouken@11663
   133
slouken@10638
   134
#endif /* SDL_sysjoystick_h_ */
slouken@6707
   135
slouken@1895
   136
/* vi: set ts=4 sw=4 expandtab: */