src/joystick/darwin/SDL_sysjoystick_c.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 26 Nov 2012 16:37:54 -0800
changeset 6690 9548c8a58103
parent 6138 4c64952a58fb
child 6745 de3683865c14
permissions -rw-r--r--
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
slouken@2713
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6138
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@2713
     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@2713
     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@2713
    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@2713
    20
*/
slouken@2713
    21
#include "SDL_config.h"
slouken@2713
    22
slouken@2713
    23
#ifndef SDL_JOYSTICK_IOKIT_H
slouken@2713
    24
slouken@2713
    25
slouken@2713
    26
#include <IOKit/hid/IOHIDLib.h>
slouken@2713
    27
#include <IOKit/hid/IOHIDKeys.h>
slouken@6690
    28
#include <IOKit/IOKitLib.h>
slouken@2713
    29
slouken@2713
    30
slouken@2713
    31
struct recElement
slouken@2713
    32
{
slouken@2713
    33
    IOHIDElementCookie cookie;  /* unique value which identifies element, will NOT change */
slouken@2776
    34
    long usagePage, usage;      /* HID usage */
slouken@2713
    35
    long min;                   /* reported min value possible */
slouken@2713
    36
    long max;                   /* reported max value possible */
slouken@2713
    37
#if 0
slouken@2713
    38
    /* TODO: maybe should handle the following stuff somehow? */
slouken@2713
    39
slouken@2713
    40
    long scaledMin;             /* reported scaled min value possible */
slouken@2713
    41
    long scaledMax;             /* reported scaled max value possible */
slouken@2713
    42
    long size;                  /* size in bits of data return from element */
slouken@2713
    43
    Boolean relative;           /* are reports relative to last report (deltas) */
slouken@2713
    44
    Boolean wrapping;           /* does element wrap around (one value higher than max is min) */
slouken@2713
    45
    Boolean nonLinear;          /* are the values reported non-linear relative to element movement */
slouken@2713
    46
    Boolean preferredState;     /* does element have a preferred state (such as a button) */
slouken@2713
    47
    Boolean nullState;          /* does element have null state */
slouken@2713
    48
#endif                          /* 0 */
slouken@2713
    49
slouken@2713
    50
    /* runtime variables used for auto-calibration */
slouken@2713
    51
    long minReport;             /* min returned value */
slouken@2713
    52
    long maxReport;             /* max returned value */
slouken@2713
    53
slouken@2713
    54
    struct recElement *pNext;   /* next element in list */
slouken@2713
    55
};
slouken@2713
    56
typedef struct recElement recElement;
slouken@2713
    57
slouken@2713
    58
struct joystick_hwdata
slouken@2713
    59
{
slouken@2713
    60
    io_service_t ffservice;     /* Interface for force feedback, 0 = no ff */
slouken@2713
    61
    IOHIDDeviceInterface **interface;   /* interface to device, NULL = no interface */
slouken@6690
    62
	IONotificationPortRef notificationPort; /* port to be notified on joystick removal */
slouken@6690
    63
	io_iterator_t portIterator; /* iterator for removal callback */
slouken@6690
    64
	
slouken@2713
    65
    char product[256];          /* name of product */
slouken@2713
    66
    long usage;                 /* usage page from IOUSBHID Parser.h which defines general usage */
slouken@2713
    67
    long usagePage;             /* usage within above page from IOUSBHID Parser.h which defines specific usage */
slouken@2713
    68
slouken@2713
    69
    long axes;                  /* number of axis (calculated, not reported by device) */
slouken@2713
    70
    long buttons;               /* number of buttons (calculated, not reported by device) */
slouken@2713
    71
    long hats;                  /* number of hat switches (calculated, not reported by device) */
slouken@2713
    72
    long elements;              /* number of total elements (shouldbe total of above) (calculated, not reported by device) */
slouken@2713
    73
slouken@2713
    74
    recElement *firstAxis;
slouken@2713
    75
    recElement *firstButton;
slouken@2713
    76
    recElement *firstHat;
slouken@2713
    77
slouken@2713
    78
    int removed;
slouken@2713
    79
    int uncentered;
slouken@6690
    80
	
slouken@6690
    81
	int instance_id;
slouken@6690
    82
	JoystickGUID guid;
slouken@6690
    83
	Uint8 send_open_event;		/* 1 if we need to send an Added event for this device */
slouken@2713
    84
slouken@2713
    85
    struct joystick_hwdata *pNext;      /* next device */
slouken@2713
    86
};
slouken@2713
    87
typedef struct joystick_hwdata recDevice;
slouken@2713
    88
slouken@2713
    89
slouken@2713
    90
#endif /* SDL_JOYSTICK_IOKIT_H */