sdl

FORK: Simple Directmedia Layer
git clone https://git.neptards.moe/neptards/sdl.git
Log | Files | Refs

SDL_hidapijoystick_c.h (5194B)


      1 /*
      2   Simple DirectMedia Layer
      3   Copyright (C) 1997-2020 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 #include "../../SDL_internal.h"
     22 
     23 #ifndef SDL_JOYSTICK_HIDAPI_H
     24 #define SDL_JOYSTICK_HIDAPI_H
     25 
     26 #include "SDL_atomic.h"
     27 #include "SDL_mutex.h"
     28 #include "SDL_joystick.h"
     29 #include "SDL_gamecontroller.h"
     30 #include "../../hidapi/hidapi/hidapi.h"
     31 #include "../usb_ids.h"
     32 
     33 /* This is the full set of HIDAPI drivers available */
     34 #define SDL_JOYSTICK_HIDAPI_PS4
     35 #define SDL_JOYSTICK_HIDAPI_PS5
     36 #define SDL_JOYSTICK_HIDAPI_SWITCH
     37 #define SDL_JOYSTICK_HIDAPI_XBOX360
     38 #define SDL_JOYSTICK_HIDAPI_XBOXONE
     39 #define SDL_JOYSTICK_HIDAPI_GAMECUBE
     40 
     41 #if defined(__IPHONEOS__) || defined(__TVOS__) || defined(__ANDROID__)
     42 /* Very basic Steam Controller support on mobile devices */
     43 #define SDL_JOYSTICK_HIDAPI_STEAM
     44 #endif
     45 
     46 /* The maximum size of a USB packet for HID devices */
     47 #define USB_PACKET_LENGTH   64
     48 
     49 /* Forward declaration */
     50 struct _SDL_HIDAPI_DeviceDriver;
     51 
     52 typedef struct _SDL_HIDAPI_Device
     53 {
     54     char *name;
     55     char *path;
     56     Uint16 vendor_id;
     57     Uint16 product_id;
     58     Uint16 version;
     59     char *serial;
     60     SDL_JoystickGUID guid;
     61     int interface_number;   /* Available on Windows and Linux */
     62     int interface_class;
     63     int interface_subclass;
     64     int interface_protocol;
     65     Uint16 usage_page;      /* Available on Windows and Mac OS X */
     66     Uint16 usage;           /* Available on Windows and Mac OS X */
     67 
     68     struct _SDL_HIDAPI_DeviceDriver *driver;
     69     void *context;
     70     SDL_mutex *dev_lock;
     71     hid_device *dev;
     72     SDL_atomic_t rumble_pending;
     73     int num_joysticks;
     74     SDL_JoystickID *joysticks;
     75 
     76     /* Used during scanning for device changes */
     77     SDL_bool seen;
     78 
     79     /* Used to flag that the device is being updated */
     80     SDL_bool updating;
     81 
     82     struct _SDL_HIDAPI_Device *next;
     83 } SDL_HIDAPI_Device;
     84 
     85 typedef struct _SDL_HIDAPI_DeviceDriver
     86 {
     87     const char *hint;
     88     SDL_bool enabled;
     89     SDL_bool (*IsSupportedDevice)(const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol);
     90     const char *(*GetDeviceName)(Uint16 vendor_id, Uint16 product_id);
     91     SDL_bool (*InitDevice)(SDL_HIDAPI_Device *device);
     92     int (*GetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id);
     93     void (*SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index);
     94     SDL_bool (*UpdateDevice)(SDL_HIDAPI_Device *device);
     95     SDL_bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
     96     int (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
     97     int (*RumbleJoystickTriggers)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);
     98     SDL_bool (*HasJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
     99     int (*SetJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
    100     int (*SetJoystickSensorsEnabled)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled);
    101     void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
    102     void (*FreeDevice)(SDL_HIDAPI_Device *device);
    103 
    104 } SDL_HIDAPI_DeviceDriver;
    105 
    106 
    107 /* HIDAPI device support */
    108 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
    109 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5;
    110 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
    111 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
    112 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
    113 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W;
    114 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
    115 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
    116 
    117 /* Return true if a HID device is present and supported as a joystick */
    118 extern SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
    119 
    120 extern void HIDAPI_UpdateDevices(void);
    121 extern SDL_bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID);
    122 extern void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID);
    123 
    124 extern void HIDAPI_DumpPacket(const char *prefix, Uint8 *data, int size);
    125 
    126 #endif /* SDL_JOYSTICK_HIDAPI_H */
    127 
    128 /* vi: set ts=4 sw=4 expandtab: */