src/joystick/darwin/SDL_sysjoystick_c.h
author Ryan C. Gordon <icculus@icculus.org>
Sat, 22 Feb 2014 21:15:34 -0500
changeset 8242 f6a2b1a6932b
parent 8230 1c185bacf915
child 9433 bd062398b648
permissions -rw-r--r--
Mac joystick: ignore duplicate HID elements.

The DualShock 4 has all elements listed twice: once in the top-level list of
elements, and once in an "Application Collection" element at the top-level.

Each element has a proper cookie with a unique value, so now we descend into
each element collections, but before we add an element to the device's list,
we make sure we don't already have one with that cookie, probably from
another collection or a buggy device.
slouken@2713
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 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
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@2713
    22
slouken@2713
    23
#ifndef SDL_JOYSTICK_IOKIT_H
slouken@2713
    24
slouken@2713
    25
#include <IOKit/hid/IOHIDLib.h>
slouken@2713
    26
slouken@2713
    27
struct recElement
slouken@2713
    28
{
icculus@8230
    29
    IOHIDElementRef elementRef;
icculus@8242
    30
    IOHIDElementCookie cookie;
icculus@8230
    31
    uint32_t usagePage, usage;      /* HID usage */
icculus@8230
    32
    SInt32 min;                   /* reported min value possible */
icculus@8230
    33
    SInt32 max;                   /* reported max value possible */
slouken@2713
    34
slouken@2713
    35
    /* runtime variables used for auto-calibration */
icculus@8230
    36
    SInt32 minReport;             /* min returned value */
icculus@8230
    37
    SInt32 maxReport;             /* max returned value */
slouken@2713
    38
slouken@2713
    39
    struct recElement *pNext;   /* next element in list */
slouken@2713
    40
};
slouken@2713
    41
typedef struct recElement recElement;
slouken@2713
    42
slouken@2713
    43
struct joystick_hwdata
slouken@2713
    44
{
icculus@8230
    45
    IOHIDDeviceRef deviceRef;   /* HIDManager device handle */
slouken@2713
    46
    io_service_t ffservice;     /* Interface for force feedback, 0 = no ff */
slouken@7191
    47
slouken@2713
    48
    char product[256];          /* name of product */
icculus@8230
    49
    uint32_t usage;                 /* usage page from IOUSBHID Parser.h which defines general usage */
icculus@8230
    50
    uint32_t usagePage;             /* usage within above page from IOUSBHID Parser.h which defines specific usage */
slouken@2713
    51
icculus@8230
    52
    int axes;                  /* number of axis (calculated, not reported by device) */
icculus@8230
    53
    int buttons;               /* number of buttons (calculated, not reported by device) */
icculus@8230
    54
    int hats;                  /* number of hat switches (calculated, not reported by device) */
icculus@8230
    55
    int elements;              /* number of total elements (should be total of above) (calculated, not reported by device) */
slouken@2713
    56
slouken@2713
    57
    recElement *firstAxis;
slouken@2713
    58
    recElement *firstButton;
slouken@2713
    59
    recElement *firstHat;
slouken@2713
    60
slouken@2713
    61
    int removed;
slouken@2713
    62
    int uncentered;
slouken@7191
    63
slouken@7191
    64
    int instance_id;
slouken@7191
    65
    SDL_JoystickGUID guid;
slouken@7191
    66
    Uint8 send_open_event;      /* 1 if we need to send an Added event for this device */
slouken@2713
    67
slouken@2713
    68
    struct joystick_hwdata *pNext;      /* next device */
slouken@2713
    69
};
slouken@2713
    70
typedef struct joystick_hwdata recDevice;
slouken@2713
    71
slouken@2713
    72
slouken@2713
    73
#endif /* SDL_JOYSTICK_IOKIT_H */