2018-08-09 16:00:17 -07:00
/*
Simple DirectMedia Layer
2026-01-01 09:39:50 -08:00
Copyright ( C ) 1997 - 2026 Sam Lantinga < slouken @ libsdl . org >
2018-08-09 16:00:17 -07:00
This software is provided ' as - is ' , without any express or implied
warranty . In no event will the authors be held liable for any damages
arising from the use of this software .
Permission is granted to anyone to use this software for any purpose ,
including commercial applications , and to alter it and redistribute it
freely , subject to the following restrictions :
1. The origin of this software must not be misrepresented ; you must not
claim that you wrote the original software . If you use this software
in a product , an acknowledgment in the product documentation would be
appreciated but is not required .
2. Altered source versions must be plainly marked as such , and must not be
misrepresented as being the original software .
3. This notice may not be removed or altered from any source distribution .
*/
2018-08-09 16:04:45 -07:00
/* This driver supports the Nintendo Switch Pro controller.
Code and logic contributed by Valve Corporation under the SDL zlib license .
*/
2022-11-29 18:34:15 -08:00
# include "SDL_internal.h"
2018-08-09 16:00:17 -07:00
# ifdef SDL_JOYSTICK_HIDAPI
2020-02-07 11:44:57 -08:00
# include "../../SDL_hints_c.h"
2018-08-09 16:00:17 -07:00
# include "../SDL_sysjoystick.h"
# include "SDL_hidapijoystick_c.h"
2020-02-07 11:44:57 -08:00
# include "SDL_hidapi_rumble.h"
2022-09-01 20:27:34 -07:00
# include "SDL_hidapi_nintendo.h"
2018-08-09 16:00:17 -07:00
# ifdef SDL_JOYSTICK_HIDAPI_SWITCH
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Define this if you want to log all packets from the controller
2025-07-15 17:41:32 -07:00
#if 0
# define DEBUG_SWITCH_PROTOCOL
# endif
2020-11-06 11:30:52 -08:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Define this to get log output for rumble logic
// #define DEBUG_RUMBLE
2020-04-17 15:08:48 -07:00
2021-01-14 23:49:37 -08:00
/* The initialization sequence doesn't appear to work correctly on Windows unless
the reads and writes are on the same thread .
. . . and now I can ' t reproduce this , so I ' m leaving it in , but disabled for now .
*/
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// #define SWITCH_SYNCHRONOUS_WRITES
2021-01-14 23:49:37 -08:00
2021-01-14 23:49:33 -08:00
/* How often you can write rumble commands to the controller.
If you send commands more frequently than this , you can turn off the controller
in Bluetooth mode , or the motors can miss the command in USB mode .
2020-04-17 15:08:48 -07:00
*/
2022-11-30 12:51:59 -08:00
# define RUMBLE_WRITE_FREQUENCY_MS 30
2020-04-17 15:08:48 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// How often you have to refresh a long duration rumble to keep the motors running
2021-01-14 23:49:33 -08:00
# define RUMBLE_REFRESH_FREQUENCY_MS 50
2020-04-17 15:08:48 -07:00
2022-11-30 12:51:59 -08:00
# define SWITCH_GYRO_SCALE 14.2842f
# define SWITCH_ACCEL_SCALE 4096.f
2021-01-11 15:36:40 +08:00
2022-11-30 12:51:59 -08:00
# define SWITCH_GYRO_SCALE_MULT 936.0f
# define SWITCH_ACCEL_SCALE_MULT 4.0f
2022-04-27 00:57:17 +08:00
2023-12-27 11:28:27 -08:00
enum
{
SDL_GAMEPAD_BUTTON_SWITCH_SHARE = 11 ,
SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1 ,
SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1 ,
SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2 ,
SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2 ,
SDL_GAMEPAD_NUM_SWITCH_BUTTONS ,
} ;
2022-11-30 12:51:59 -08:00
typedef enum
{
k_eSwitchInputReportIDs_SubcommandReply = 0x21 ,
k_eSwitchInputReportIDs_FullControllerState = 0x30 ,
2023-06-26 10:54:52 -06:00
k_eSwitchInputReportIDs_FullControllerAndMcuState = 0x31 ,
2018-08-09 16:00:17 -07:00
k_eSwitchInputReportIDs_SimpleControllerState = 0x3F ,
2022-11-30 12:51:59 -08:00
k_eSwitchInputReportIDs_CommandAck = 0x81 ,
2018-08-09 16:00:17 -07:00
} ESwitchInputReportIDs ;
2022-11-30 12:51:59 -08:00
typedef enum
{
2018-08-09 16:00:17 -07:00
k_eSwitchOutputReportIDs_RumbleAndSubcommand = 0x01 ,
2022-11-30 12:51:59 -08:00
k_eSwitchOutputReportIDs_Rumble = 0x10 ,
k_eSwitchOutputReportIDs_Proprietary = 0x80 ,
2018-08-09 16:00:17 -07:00
} ESwitchOutputReportIDs ;
2022-11-30 12:51:59 -08:00
typedef enum
{
2018-08-09 16:00:17 -07:00
k_eSwitchSubcommandIDs_BluetoothManualPair = 0x01 ,
2022-11-30 12:51:59 -08:00
k_eSwitchSubcommandIDs_RequestDeviceInfo = 0x02 ,
k_eSwitchSubcommandIDs_SetInputReportMode = 0x03 ,
k_eSwitchSubcommandIDs_SetHCIState = 0x06 ,
k_eSwitchSubcommandIDs_SPIFlashRead = 0x10 ,
k_eSwitchSubcommandIDs_SetPlayerLights = 0x30 ,
k_eSwitchSubcommandIDs_SetHomeLight = 0x38 ,
k_eSwitchSubcommandIDs_EnableIMU = 0x40 ,
k_eSwitchSubcommandIDs_SetIMUSensitivity = 0x41 ,
k_eSwitchSubcommandIDs_EnableVibration = 0x48 ,
2018-08-09 16:00:17 -07:00
} ESwitchSubcommandIDs ;
2022-11-30 12:51:59 -08:00
typedef enum
{
k_eSwitchProprietaryCommandIDs_Status = 0x01 ,
2018-08-09 16:00:17 -07:00
k_eSwitchProprietaryCommandIDs_Handshake = 0x02 ,
k_eSwitchProprietaryCommandIDs_HighSpeed = 0x03 ,
2022-11-30 12:51:59 -08:00
k_eSwitchProprietaryCommandIDs_ForceUSB = 0x04 ,
k_eSwitchProprietaryCommandIDs_ClearUSB = 0x05 ,
k_eSwitchProprietaryCommandIDs_ResetMCU = 0x06 ,
2018-08-09 16:00:17 -07:00
} ESwitchProprietaryCommandIDs ;
# define k_unSwitchOutputPacketDataLength 49
# define k_unSwitchMaxOutputPacketLength 64
# define k_unSwitchBluetoothPacketLength k_unSwitchOutputPacketDataLength
# define k_unSwitchUSBPacketLength k_unSwitchMaxOutputPacketLength
2023-01-09 17:42:17 -06:00
# define k_unSPIStickFactoryCalibrationStartOffset 0x603D
# define k_unSPIStickFactoryCalibrationEndOffset 0x604E
# define k_unSPIStickFactoryCalibrationLength (k_unSPIStickFactoryCalibrationEndOffset - k_unSPIStickFactoryCalibrationStartOffset + 1)
# define k_unSPIStickUserCalibrationStartOffset 0x8010
# define k_unSPIStickUserCalibrationEndOffset 0x8025
# define k_unSPIStickUserCalibrationLength (k_unSPIStickUserCalibrationEndOffset - k_unSPIStickUserCalibrationStartOffset + 1)
2018-08-09 16:00:17 -07:00
2022-11-30 12:51:59 -08:00
# define k_unSPIIMUScaleStartOffset 0x6020
# define k_unSPIIMUScaleEndOffset 0x6037
# define k_unSPIIMUScaleLength (k_unSPIIMUScaleEndOffset - k_unSPIIMUScaleStartOffset + 1)
2022-04-27 00:57:17 +08:00
2022-11-30 12:51:59 -08:00
# define k_unSPIIMUUserScaleStartOffset 0x8026
# define k_unSPIIMUUserScaleEndOffset 0x8039
# define k_unSPIIMUUserScaleLength (k_unSPIIMUUserScaleEndOffset - k_unSPIIMUUserScaleStartOffset + 1)
2022-04-27 00:57:17 +08:00
2018-08-09 16:00:17 -07:00
# pragma pack(1)
2019-10-17 16:59:05 -07:00
typedef struct
{
Uint8 rgucButtons [ 2 ] ;
Uint8 ucStickHat ;
Uint8 rgucJoystickLeft [ 2 ] ;
Uint8 rgucJoystickRight [ 2 ] ;
} SwitchInputOnlyControllerStatePacket_t ;
2018-08-09 16:00:17 -07:00
typedef struct
{
Uint8 rgucButtons [ 2 ] ;
Uint8 ucStickHat ;
Sint16 sJoystickLeft [ 2 ] ;
Sint16 sJoystickRight [ 2 ] ;
} SwitchSimpleStatePacket_t ;
typedef struct
{
Uint8 ucCounter ;
Uint8 ucBatteryAndConnection ;
Uint8 rgucButtons [ 3 ] ;
Uint8 rgucJoystickLeft [ 3 ] ;
Uint8 rgucJoystickRight [ 3 ] ;
Uint8 ucVibrationCode ;
} SwitchControllerStatePacket_t ;
typedef struct
{
2025-11-05 17:08:22 -08:00
Sint16 sAccelX ;
Sint16 sAccelY ;
Sint16 sAccelZ ;
2018-08-09 16:00:17 -07:00
2025-11-05 17:08:22 -08:00
Sint16 sGyroX ;
Sint16 sGyroY ;
Sint16 sGyroZ ;
} SwitchControllerIMUState_t ;
typedef struct
{
SwitchControllerStatePacket_t controllerState ;
SwitchControllerIMUState_t imuState [ 3 ] ;
2018-08-09 16:00:17 -07:00
} SwitchStatePacket_t ;
typedef struct
{
Uint32 unAddress ;
Uint8 ucLength ;
} SwitchSPIOpData_t ;
typedef struct
{
SwitchControllerStatePacket_t m_controllerState ;
Uint8 ucSubcommandAck ;
Uint8 ucSubcommandID ;
2022-11-30 12:51:59 -08:00
# define k_unSubcommandDataBytes 35
union
{
2019-10-17 16:59:05 -07:00
Uint8 rgucSubcommandData [ k_unSubcommandDataBytes ] ;
2018-08-09 16:00:17 -07:00
2022-11-30 12:51:59 -08:00
struct
{
2018-08-09 16:00:17 -07:00
SwitchSPIOpData_t opData ;
2019-10-17 16:59:05 -07:00
Uint8 rgucReadData [ k_unSubcommandDataBytes - sizeof ( SwitchSPIOpData_t ) ] ;
2018-08-09 16:00:17 -07:00
} spiReadData ;
2022-11-30 12:51:59 -08:00
struct
{
2018-08-09 16:00:17 -07:00
Uint8 rgucFirmwareVersion [ 2 ] ;
Uint8 ucDeviceType ;
Uint8 ucFiller1 ;
Uint8 rgucMACAddress [ 6 ] ;
Uint8 ucFiller2 ;
Uint8 ucColorLocation ;
} deviceInfo ;
2023-01-09 17:42:17 -06:00
struct
{
SwitchSPIOpData_t opData ;
Uint8 rgucLeftCalibration [ 9 ] ;
Uint8 rgucRightCalibration [ 9 ] ;
} stickFactoryCalibration ;
struct
{
SwitchSPIOpData_t opData ;
Uint8 rgucLeftMagic [ 2 ] ;
Uint8 rgucLeftCalibration [ 9 ] ;
Uint8 rgucRightMagic [ 2 ] ;
Uint8 rgucRightCalibration [ 9 ] ;
} stickUserCalibration ;
2018-08-09 16:00:17 -07:00
} ;
} SwitchSubcommandInputPacket_t ;
2021-01-14 23:49:41 -08:00
typedef struct
{
2022-08-31 13:24:23 -07:00
Uint8 ucPacketType ;
Uint8 ucCommandID ;
Uint8 ucFiller ;
2021-01-14 23:49:41 -08:00
2022-08-31 13:24:23 -07:00
Uint8 ucDeviceType ;
Uint8 rgucMACAddress [ 6 ] ;
2021-01-14 23:49:41 -08:00
} SwitchProprietaryStatusPacket_t ;
2018-08-09 16:00:17 -07:00
typedef struct
{
Uint8 rgucData [ 4 ] ;
} SwitchRumbleData_t ;
typedef struct
{
Uint8 ucPacketType ;
Uint8 ucPacketNumber ;
SwitchRumbleData_t rumbleData [ 2 ] ;
} SwitchCommonOutputPacket_t ;
typedef struct
{
SwitchCommonOutputPacket_t commonData ;
Uint8 ucSubcommandID ;
2019-10-17 16:59:05 -07:00
Uint8 rgucSubcommandData [ k_unSwitchOutputPacketDataLength - sizeof ( SwitchCommonOutputPacket_t ) - 1 ] ;
2018-08-09 16:00:17 -07:00
} SwitchSubcommandOutputPacket_t ;
typedef struct
{
Uint8 ucPacketType ;
Uint8 ucProprietaryID ;
2019-10-17 16:59:05 -07:00
Uint8 rgucProprietaryData [ k_unSwitchOutputPacketDataLength - 1 - 1 ] ;
2018-08-09 16:00:17 -07:00
} SwitchProprietaryOutputPacket_t ;
# pragma pack()
2025-01-02 14:27:38 -08:00
/* Enhanced report hint mode:
* " 0 " : enhanced features are never used
* " 1 " : enhanced features are always used
* " auto " : enhanced features are advertised to the application , but SDL doesn ' t touch the controller state unless the application explicitly requests it .
*/
typedef enum
{
SWITCH_ENHANCED_REPORT_HINT_OFF ,
SWITCH_ENHANCED_REPORT_HINT_ON ,
SWITCH_ENHANCED_REPORT_HINT_AUTO
} HIDAPI_Switch_EnhancedReportHint ;
2022-11-30 12:51:59 -08:00
typedef struct
{
2020-02-07 11:44:57 -08:00
SDL_HIDAPI_Device * device ;
2022-09-22 18:22:17 -07:00
SDL_Joystick * joystick ;
2024-08-22 09:21:26 -07:00
bool m_bInputOnly ;
bool m_bUseButtonLabels ;
bool m_bPlayerLights ;
2022-11-30 12:51:59 -08:00
int m_nPlayerIndex ;
2024-08-22 09:21:26 -07:00
bool m_bSyncWrite ;
2022-11-30 12:51:59 -08:00
int m_nMaxWriteAttempts ;
2021-01-14 23:49:41 -08:00
ESwitchDeviceInfoControllerType m_eControllerType ;
2023-12-24 08:12:14 -08:00
Uint8 m_nInitialInputMode ;
Uint8 m_nCurrentInputMode ;
2021-01-14 23:49:41 -08:00
Uint8 m_rgucMACAddress [ 6 ] ;
2018-08-09 16:00:17 -07:00
Uint8 m_nCommandNumber ;
2025-01-02 14:27:38 -08:00
HIDAPI_Switch_EnhancedReportHint m_eEnhancedReportHint ;
bool m_bEnhancedMode ;
bool m_bEnhancedModeAvailable ;
2018-08-09 16:00:17 -07:00
SwitchCommonOutputPacket_t m_RumblePacket ;
Uint8 m_rgucReadBuffer [ k_unSwitchMaxOutputPacketLength ] ;
2024-08-22 09:21:26 -07:00
bool m_bRumbleActive ;
2022-12-02 01:17:17 -08:00
Uint64 m_ulRumbleSent ;
2024-08-22 09:21:26 -07:00
bool m_bRumblePending ;
bool m_bRumbleZeroPending ;
2021-07-26 10:18:18 -07:00
Uint32 m_unRumblePending ;
2025-01-02 14:27:38 -08:00
bool m_bSensorsSupported ;
2024-08-22 09:21:26 -07:00
bool m_bReportSensors ;
bool m_bHasSensorData ;
2022-12-02 01:17:17 -08:00
Uint64 m_ulLastInput ;
Uint64 m_ulLastIMUReset ;
Uint64 m_ulIMUSampleTimestampNS ;
2022-09-27 12:34:03 -07:00
Uint32 m_unIMUSamples ;
2022-12-02 01:17:17 -08:00
Uint64 m_ulIMUUpdateIntervalNS ;
Uint64 m_ulTimestampNS ;
2024-08-22 09:21:26 -07:00
bool m_bVerticalMode ;
2025-10-13 10:34:22 -07:00
SDL_PowerState m_ePowerState ;
int m_nPowerPercent ;
2019-10-17 16:59:05 -07:00
SwitchInputOnlyControllerStatePacket_t m_lastInputOnlyState ;
2018-08-09 16:00:17 -07:00
SwitchSimpleStatePacket_t m_lastSimpleState ;
SwitchStatePacket_t m_lastFullState ;
2022-11-30 12:51:59 -08:00
struct StickCalibrationData
{
struct
{
2018-08-09 16:00:17 -07:00
Sint16 sCenter ;
Sint16 sMin ;
Sint16 sMax ;
} axis [ 2 ] ;
} m_StickCalData [ 2 ] ;
2022-11-30 12:51:59 -08:00
struct StickExtents
{
struct
{
2018-08-09 16:00:17 -07:00
Sint16 sMin ;
Sint16 sMax ;
} axis [ 2 ] ;
2022-09-26 18:18:16 -07:00
} m_StickExtents [ 2 ] , m_SimpleStickExtents [ 2 ] ;
2022-04-27 00:57:17 +08:00
2022-11-30 12:51:59 -08:00
struct IMUScaleData
{
2022-04-27 00:57:17 +08:00
float fAccelScaleX ;
float fAccelScaleY ;
float fAccelScaleZ ;
float fGyroScaleX ;
float fGyroScaleY ;
float fGyroScaleZ ;
} m_IMUScaleData ;
2018-08-09 16:00:17 -07:00
} SDL_DriverSwitch_Context ;
static int ReadInput ( SDL_DriverSwitch_Context * ctx )
{
2024-07-06 05:29:12 -07:00
int result ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Make sure we don't try to read at the same time a write is happening
2024-09-16 23:21:31 -07:00
if ( SDL_GetAtomicInt ( & ctx - > device - > rumble_pending ) > 0 ) {
2020-02-07 11:44:57 -08:00
return 0 ;
}
2024-07-06 05:29:12 -07:00
result = SDL_hid_read_timeout ( ctx - > device - > dev , ctx - > m_rgucReadBuffer , sizeof ( ctx - > m_rgucReadBuffer ) , 0 ) ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// See if we can guess the initial input mode
2024-07-06 05:29:12 -07:00
if ( result > 0 & & ! ctx - > m_bInputOnly & & ! ctx - > m_nInitialInputMode ) {
switch ( ctx - > m_rgucReadBuffer [ 0 ] ) {
case k_eSwitchInputReportIDs_FullControllerState :
case k_eSwitchInputReportIDs_FullControllerAndMcuState :
case k_eSwitchInputReportIDs_SimpleControllerState :
ctx - > m_nInitialInputMode = ctx - > m_rgucReadBuffer [ 0 ] ;
break ;
default :
break ;
}
}
return result ;
2018-08-09 16:00:17 -07:00
}
2020-02-07 11:44:57 -08:00
static int WriteOutput ( SDL_DriverSwitch_Context * ctx , const Uint8 * data , int size )
2018-08-09 16:00:17 -07:00
{
2021-01-14 23:49:37 -08:00
# ifdef SWITCH_SYNCHRONOUS_WRITES
2021-11-07 22:58:44 -08:00
return SDL_hid_write ( ctx - > device - > dev , data , size ) ;
2021-01-14 23:49:37 -08:00
# else
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Use the rumble thread for general asynchronous writes
2024-08-22 17:33:49 -07:00
if ( ! SDL_HIDAPI_LockRumble ( ) ) {
2020-02-07 11:44:57 -08:00
return - 1 ;
}
return SDL_HIDAPI_SendRumbleAndUnlock ( ctx - > device , data , size ) ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
# endif // SWITCH_SYNCHRONOUS_WRITES
2018-08-09 16:00:17 -07:00
}
2025-11-05 17:34:22 -08:00
static SwitchSubcommandInputPacket_t * ReadSubcommandReply ( SDL_DriverSwitch_Context * ctx , ESwitchSubcommandIDs expectedID , const Uint8 * pBuf , Uint8 ucLen )
2018-08-09 16:00:17 -07:00
{
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Average response time for messages is ~30ms
2022-12-02 01:17:17 -08:00
Uint64 endTicks = SDL_GetTicks ( ) + 100 ;
2018-08-09 16:00:17 -07:00
int nRead = 0 ;
while ( ( nRead = ReadInput ( ctx ) ) ! = - 1 ) {
if ( nRead > 0 ) {
if ( ctx - > m_rgucReadBuffer [ 0 ] = = k_eSwitchInputReportIDs_SubcommandReply ) {
2019-10-17 16:59:05 -07:00
SwitchSubcommandInputPacket_t * reply = ( SwitchSubcommandInputPacket_t * ) & ctx - > m_rgucReadBuffer [ 1 ] ;
2025-11-05 17:34:22 -08:00
if ( reply - > ucSubcommandID ! = expectedID | | ! ( reply - > ucSubcommandAck & 0x80 ) ) {
continue ;
2018-08-09 16:00:17 -07:00
}
2025-11-05 17:34:22 -08:00
if ( reply - > ucSubcommandID = = k_eSwitchSubcommandIDs_SPIFlashRead ) {
SDL_assert ( ucLen = = sizeof ( reply - > spiReadData . opData ) ) ;
if ( SDL_memcmp ( & reply - > spiReadData . opData , pBuf , ucLen ) ! = 0 ) {
// This was a reply for another SPI read command
continue ;
}
}
return reply ;
2018-08-09 16:00:17 -07:00
}
} else {
SDL_Delay ( 1 ) ;
}
2022-12-02 01:17:17 -08:00
if ( SDL_GetTicks ( ) > = endTicks ) {
2018-08-09 16:00:17 -07:00
break ;
}
}
return NULL ;
}
2024-08-22 09:21:26 -07:00
static bool ReadProprietaryReply ( SDL_DriverSwitch_Context * ctx , ESwitchProprietaryCommandIDs expectedID )
2018-08-09 16:00:17 -07:00
{
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Average response time for messages is ~30ms
2022-12-02 01:17:17 -08:00
Uint64 endTicks = SDL_GetTicks ( ) + 100 ;
2018-08-09 16:00:17 -07:00
int nRead = 0 ;
while ( ( nRead = ReadInput ( ctx ) ) ! = - 1 ) {
if ( nRead > 0 ) {
2019-10-17 16:59:05 -07:00
if ( ctx - > m_rgucReadBuffer [ 0 ] = = k_eSwitchInputReportIDs_CommandAck & & ctx - > m_rgucReadBuffer [ 1 ] = = expectedID ) {
2024-08-22 09:21:26 -07:00
return true ;
2018-08-09 16:00:17 -07:00
}
} else {
SDL_Delay ( 1 ) ;
}
2022-12-02 01:17:17 -08:00
if ( SDL_GetTicks ( ) > = endTicks ) {
2018-08-09 16:00:17 -07:00
break ;
}
}
2024-08-22 09:21:26 -07:00
return false ;
2018-08-09 16:00:17 -07:00
}
2023-06-02 15:52:56 -07:00
static void ConstructSubcommand ( SDL_DriverSwitch_Context * ctx , ESwitchSubcommandIDs ucCommandID , const Uint8 * pBuf , Uint8 ucLen , SwitchSubcommandOutputPacket_t * outPacket )
2018-08-09 16:00:17 -07:00
{
2026-01-23 19:42:06 +01:00
SDL_zerop ( outPacket ) ;
2018-08-09 16:00:17 -07:00
outPacket - > commonData . ucPacketType = k_eSwitchOutputReportIDs_RumbleAndSubcommand ;
outPacket - > commonData . ucPacketNumber = ctx - > m_nCommandNumber ;
2021-11-13 17:56:28 +03:00
SDL_memcpy ( outPacket - > commonData . rumbleData , ctx - > m_RumblePacket . rumbleData , sizeof ( ctx - > m_RumblePacket . rumbleData ) ) ;
2018-08-09 16:00:17 -07:00
outPacket - > ucSubcommandID = ucCommandID ;
2022-08-02 15:00:55 +02:00
if ( pBuf ) {
SDL_memcpy ( outPacket - > rgucSubcommandData , pBuf , ucLen ) ;
}
2018-08-09 16:00:17 -07:00
ctx - > m_nCommandNumber = ( ctx - > m_nCommandNumber + 1 ) & 0xF ;
}
2024-08-22 09:21:26 -07:00
static bool WritePacket ( SDL_DriverSwitch_Context * ctx , void * pBuf , Uint8 ucLen )
2018-08-09 16:00:17 -07:00
{
Uint8 rgucBuf [ k_unSwitchMaxOutputPacketLength ] ;
2022-09-26 14:20:34 -07:00
const size_t unWriteSize = ctx - > device - > is_bluetooth ? k_unSwitchBluetoothPacketLength : k_unSwitchUSBPacketLength ;
2018-08-09 16:00:17 -07:00
if ( ucLen > k_unSwitchOutputPacketDataLength ) {
2024-08-22 09:21:26 -07:00
return false ;
2018-08-09 16:00:17 -07:00
}
if ( ucLen < unWriteSize ) {
SDL_memcpy ( rgucBuf , pBuf , ucLen ) ;
2022-11-30 12:51:59 -08:00
SDL_memset ( rgucBuf + ucLen , 0 , unWriteSize - ucLen ) ;
2018-08-09 16:00:17 -07:00
pBuf = rgucBuf ;
ucLen = ( Uint8 ) unWriteSize ;
}
2022-08-04 00:40:38 -07:00
if ( ctx - > m_bSyncWrite ) {
2022-11-27 17:38:43 +01:00
return SDL_hid_write ( ctx - > device - > dev , ( Uint8 * ) pBuf , ucLen ) > = 0 ;
2022-08-04 00:40:38 -07:00
} else {
2022-11-27 17:38:43 +01:00
return WriteOutput ( ctx , ( Uint8 * ) pBuf , ucLen ) > = 0 ;
2022-07-28 21:39:32 -07:00
}
}
2024-08-22 09:21:26 -07:00
static bool WriteSubcommand ( SDL_DriverSwitch_Context * ctx , ESwitchSubcommandIDs ucCommandID , const Uint8 * pBuf , Uint8 ucLen , SwitchSubcommandInputPacket_t * * ppReply )
2018-08-09 16:00:17 -07:00
{
SwitchSubcommandInputPacket_t * reply = NULL ;
2022-08-04 00:40:38 -07:00
int nTries ;
2018-08-09 16:00:17 -07:00
2023-11-09 22:29:15 +01:00
for ( nTries = 1 ; ! reply & & nTries < = ctx - > m_nMaxWriteAttempts ; + + nTries ) {
2018-08-09 16:00:17 -07:00
SwitchSubcommandOutputPacket_t commandPacket ;
ConstructSubcommand ( ctx , ucCommandID , pBuf , ucLen , & commandPacket ) ;
if ( ! WritePacket ( ctx , & commandPacket , sizeof ( commandPacket ) ) ) {
continue ;
}
2025-11-05 17:34:22 -08:00
reply = ReadSubcommandReply ( ctx , ucCommandID , pBuf , ucLen ) ;
2018-08-09 16:00:17 -07:00
}
if ( ppReply ) {
* ppReply = reply ;
}
return reply ! = NULL ;
}
2024-08-22 09:21:26 -07:00
static bool WriteProprietary ( SDL_DriverSwitch_Context * ctx , ESwitchProprietaryCommandIDs ucCommand , Uint8 * pBuf , Uint8 ucLen , bool waitForReply )
2018-08-09 16:00:17 -07:00
{
2022-08-04 00:40:38 -07:00
int nTries ;
2018-08-09 16:00:17 -07:00
2022-08-04 00:40:38 -07:00
for ( nTries = 1 ; nTries < = ctx - > m_nMaxWriteAttempts ; + + nTries ) {
2018-08-09 16:00:17 -07:00
SwitchProprietaryOutputPacket_t packet ;
2023-11-09 22:29:15 +01:00
if ( ( ! pBuf & & ucLen > 0 ) | | ucLen > sizeof ( packet . rgucProprietaryData ) ) {
2024-08-22 09:21:26 -07:00
return false ;
2018-08-09 16:00:17 -07:00
}
2021-01-14 23:49:37 -08:00
SDL_zero ( packet ) ;
2018-08-09 16:00:17 -07:00
packet . ucPacketType = k_eSwitchOutputReportIDs_Proprietary ;
packet . ucProprietaryID = ucCommand ;
2020-02-07 11:49:56 -08:00
if ( pBuf ) {
SDL_memcpy ( packet . rgucProprietaryData , pBuf , ucLen ) ;
}
2018-08-09 16:00:17 -07:00
if ( ! WritePacket ( ctx , & packet , sizeof ( packet ) ) ) {
continue ;
}
if ( ! waitForReply | | ReadProprietaryReply ( ctx , ucCommand ) ) {
2025-01-22 12:59:57 -08:00
// SDL_Log("Succeeded%s after %d tries", ctx->m_bSyncWrite ? " (sync)" : "", nTries);
2024-08-22 09:21:26 -07:00
return true ;
2018-08-09 16:00:17 -07:00
}
}
2025-01-22 12:59:57 -08:00
// SDL_Log("Failed%s after %d tries", ctx->m_bSyncWrite ? " (sync)" : "", nTries);
2024-08-22 09:21:26 -07:00
return false ;
2022-08-03 22:12:21 -07:00
}
2022-11-30 12:51:59 -08:00
static Uint8 EncodeRumbleHighAmplitude ( Uint16 amplitude )
{
2021-07-23 10:45:03 -05:00
/* More information about these values can be found here:
* https : //github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md
*/
2022-11-30 12:51:59 -08:00
Uint16 hfa [ 101 ] [ 2 ] = { { 0 , 0x0 } , { 514 , 0x2 } , { 775 , 0x4 } , { 921 , 0x6 } , { 1096 , 0x8 } , { 1303 , 0x0a } , { 1550 , 0x0c } , { 1843 , 0x0e } , { 2192 , 0x10 } , { 2606 , 0x12 } , { 3100 , 0x14 } , { 3686 , 0x16 } , { 4383 , 0x18 } , { 5213 , 0x1a } , { 6199 , 0x1c } , { 7372 , 0x1e } , { 7698 , 0x20 } , { 8039 , 0x22 } , { 8395 , 0x24 } , { 8767 , 0x26 } , { 9155 , 0x28 } , { 9560 , 0x2a } , { 9984 , 0x2c } , { 10426 , 0x2e } , { 10887 , 0x30 } , { 11369 , 0x32 } , { 11873 , 0x34 } , { 12398 , 0x36 } , { 12947 , 0x38 } , { 13520 , 0x3a } , { 14119 , 0x3c } , { 14744 , 0x3e } , { 15067 , 0x40 } , { 15397 , 0x42 } , { 15734 , 0x44 } , { 16079 , 0x46 } , { 16431 , 0x48 } , { 16790 , 0x4a } , { 17158 , 0x4c } , { 17534 , 0x4e } , { 17918 , 0x50 } , { 18310 , 0x52 } , { 18711 , 0x54 } , { 19121 , 0x56 } , { 19540 , 0x58 } , { 19967 , 0x5a } , { 20405 , 0x5c } , { 20851 , 0x5e } , { 21308 , 0x60 } , { 21775 , 0x62 } , { 22251 , 0x64 } , { 22739 , 0x66 } , { 23236 , 0x68 } , { 23745 , 0x6a } , { 24265 , 0x6c } , { 24797 , 0x6e } , { 25340 , 0x70 } , { 25894 , 0x72 } , { 26462 , 0x74 } , { 27041 , 0x76 } , { 27633 , 0x78 } , { 28238 , 0x7a } , { 28856 , 0x7c } , { 29488 , 0x7e } , { 30134 , 0x80 } , { 30794 , 0x82 } , { 31468 , 0x84 } , { 32157 , 0x86 } , { 32861 , 0x88 } , { 33581 , 0x8a } , { 34316 , 0x8c } , { 35068 , 0x8e } , { 35836 , 0x90 } , { 36620 , 0x92 } , { 37422 , 0x94 } , { 38242 , 0x96 } , { 39079 , 0x98 } , { 39935 , 0x9a } , { 40809 , 0x9c } , { 41703 , 0x9e } , { 42616 , 0xa0 } , { 43549 , 0xa2 } , { 44503 , 0xa4 } , { 45477 , 0xa6 } , { 46473 , 0xa8 } , { 47491 , 0xaa } , { 48531 , 0xac } , { 49593 , 0xae } , { 50679 , 0xb0 } , { 51789 , 0xb2 } , { 52923 , 0xb4 } , { 54082 , 0xb6 } , { 55266 , 0xb8 } , { 56476 , 0xba } , { 57713 , 0xbc } , { 58977 , 0xbe } , { 60268 , 0xc0 } , { 61588 , 0xc2 } , { 62936 , 0xc4 } , { 64315 , 0xc6 } , { 65535 , 0xc8 } } ;
2021-07-23 10:45:03 -05:00
int index = 0 ;
2022-11-30 12:51:59 -08:00
for ( ; index < 101 ; index + + ) {
2021-07-23 10:45:03 -05:00
if ( amplitude < = hfa [ index ] [ 0 ] ) {
return ( Uint8 ) hfa [ index ] [ 1 ] ;
}
}
return ( Uint8 ) hfa [ 100 ] [ 1 ] ;
}
2022-11-30 12:51:59 -08:00
static Uint16 EncodeRumbleLowAmplitude ( Uint16 amplitude )
{
2021-07-23 10:45:03 -05:00
/* More information about these values can be found here:
* https : //github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md
*/
2022-11-30 12:51:59 -08:00
Uint16 lfa [ 101 ] [ 2 ] = { { 0 , 0x0040 } , { 514 , 0x8040 } , { 775 , 0x0041 } , { 921 , 0x8041 } , { 1096 , 0x0042 } , { 1303 , 0x8042 } , { 1550 , 0x0043 } , { 1843 , 0x8043 } , { 2192 , 0x0044 } , { 2606 , 0x8044 } , { 3100 , 0x0045 } , { 3686 , 0x8045 } , { 4383 , 0x0046 } , { 5213 , 0x8046 } , { 6199 , 0x0047 } , { 7372 , 0x8047 } , { 7698 , 0x0048 } , { 8039 , 0x8048 } , { 8395 , 0x0049 } , { 8767 , 0x8049 } , { 9155 , 0x004a } , { 9560 , 0x804a } , { 9984 , 0x004b } , { 10426 , 0x804b } , { 10887 , 0x004c } , { 11369 , 0x804c } , { 11873 , 0x004d } , { 12398 , 0x804d } , { 12947 , 0x004e } , { 13520 , 0x804e } , { 14119 , 0x004f } , { 14744 , 0x804f } , { 15067 , 0x0050 } , { 15397 , 0x8050 } , { 15734 , 0x0051 } , { 16079 , 0x8051 } , { 16431 , 0x0052 } , { 16790 , 0x8052 } , { 17158 , 0x0053 } , { 17534 , 0x8053 } , { 17918 , 0x0054 } , { 18310 , 0x8054 } , { 18711 , 0x0055 } , { 19121 , 0x8055 } , { 19540 , 0x0056 } , { 19967 , 0x8056 } , { 20405 , 0x0057 } , { 20851 , 0x8057 } , { 21308 , 0x0058 } , { 21775 , 0x8058 } , { 22251 , 0x0059 } , { 22739 , 0x8059 } , { 23236 , 0x005a } , { 23745 , 0x805a } , { 24265 , 0x005b } , { 24797 , 0x805b } , { 25340 , 0x005c } , { 25894 , 0x805c } , { 26462 , 0x005d } , { 27041 , 0x805d } , { 27633 , 0x005e } , { 28238 , 0x805e } , { 28856 , 0x005f } , { 29488 , 0x805f } , { 30134 , 0x0060 } , { 30794 , 0x8060 } , { 31468 , 0x0061 } , { 32157 , 0x8061 } , { 32861 , 0x0062 } , { 33581 , 0x8062 } , { 34316 , 0x0063 } , { 35068 , 0x8063 } , { 35836 , 0x0064 } , { 36620 , 0x8064 } , { 37422 , 0x0065 } , { 38242 , 0x8065 } , { 39079 , 0x0066 } , { 39935 , 0x8066 } , { 40809 , 0x0067 } , { 41703 , 0x8067 } , { 42616 , 0x0068 } , { 43549 , 0x8068 } , { 44503 , 0x0069 } , { 45477 , 0x8069 } , { 46473 , 0x006a } , { 47491 , 0x806a } , { 48531 , 0x006b } , { 49593 , 0x806b } , { 50679 , 0x006c } , { 51789 , 0x806c } , { 52923 , 0x006d } , { 54082 , 0x806d } , { 55266 , 0x006e } , { 56476 , 0x806e } , { 57713 , 0x006f } , { 58977 , 0x806f } , { 60268 , 0x0070 } , { 61588 , 0x8070 } , { 62936 , 0x0071 } , { 64315 , 0x8071 } , { 65535 , 0x0072 } } ;
2021-07-23 10:45:03 -05:00
int index = 0 ;
for ( ; index < 101 ; index + + ) {
if ( amplitude < = lfa [ index ] [ 0 ] ) {
return lfa [ index ] [ 1 ] ;
}
}
return lfa [ 100 ] [ 1 ] ;
}
2025-11-20 09:24:07 -08:00
static void SetNeutralRumble ( SDL_HIDAPI_Device * device , SwitchRumbleData_t * pRumble )
2018-08-09 16:00:17 -07:00
{
2025-11-20 09:24:07 -08:00
bool bStandardNeutralValue ;
if ( device - > vendor_id = = USB_VENDOR_NINTENDO & &
device - > product_id = = USB_PRODUCT_NINTENDO_N64_CONTROLLER ) {
// The 8BitDo 64 Bluetooth Controller rumbles at startup with the standard neutral value,
// so we'll use a 0 amplitude value instead.
bStandardNeutralValue = false ;
} else {
// The KingKong2 PRO Controller doesn't initialize correctly with a 0 amplitude value
// over Bluetooth, so we'll use the standard value in all other cases.
bStandardNeutralValue = true ;
}
if ( bStandardNeutralValue ) {
pRumble - > rgucData [ 0 ] = 0x00 ;
pRumble - > rgucData [ 1 ] = 0x01 ;
pRumble - > rgucData [ 2 ] = 0x40 ;
pRumble - > rgucData [ 3 ] = 0x40 ;
} else {
pRumble - > rgucData [ 0 ] = 0x00 ;
pRumble - > rgucData [ 1 ] = 0x00 ;
pRumble - > rgucData [ 2 ] = 0x01 ;
pRumble - > rgucData [ 3 ] = 0x40 ;
}
2018-08-09 16:00:17 -07:00
}
2025-11-20 09:24:07 -08:00
static void EncodeRumble ( SDL_HIDAPI_Device * device , SwitchRumbleData_t * pRumble , Uint16 usHighFreq , Uint8 ucHighFreqAmp , Uint8 ucLowFreq , Uint16 usLowFreqAmp )
2018-08-09 16:00:17 -07:00
{
if ( ucHighFreqAmp > 0 | | usLowFreqAmp > 0 ) {
// High-band frequency and low-band amplitude are actually nine-bits each so they
// take a bit from the high-band amplitude and low-band frequency bytes respectively
pRumble - > rgucData [ 0 ] = usHighFreq & 0xFF ;
pRumble - > rgucData [ 1 ] = ucHighFreqAmp | ( ( usHighFreq > > 8 ) & 0x01 ) ;
2022-11-30 12:51:59 -08:00
pRumble - > rgucData [ 2 ] = ucLowFreq | ( ( usLowFreqAmp > > 8 ) & 0x80 ) ;
pRumble - > rgucData [ 3 ] = usLowFreqAmp & 0xFF ;
2018-08-09 16:00:17 -07:00
# ifdef DEBUG_RUMBLE
2025-01-22 12:59:57 -08:00
SDL_Log ( " Freq: %.2X %.2X %.2X, Amp: %.2X %.2X %.2X " ,
2022-11-30 12:51:59 -08:00
usHighFreq & 0xFF , ( ( usHighFreq > > 8 ) & 0x01 ) , ucLowFreq ,
ucHighFreqAmp , ( ( usLowFreqAmp > > 8 ) & 0x80 ) , usLowFreqAmp & 0xFF ) ;
2018-08-09 16:00:17 -07:00
# endif
} else {
2025-11-20 09:24:07 -08:00
SetNeutralRumble ( device , pRumble ) ;
2018-08-09 16:00:17 -07:00
}
}
2024-08-22 09:21:26 -07:00
static bool WriteRumble ( SDL_DriverSwitch_Context * ctx )
2018-08-09 16:00:17 -07:00
{
/* Write into m_RumblePacket rather than a temporary buffer to allow the current rumble state
* to be retained for subsequent rumble or subcommand packets sent to the controller
*/
ctx - > m_RumblePacket . ucPacketType = k_eSwitchOutputReportIDs_Rumble ;
ctx - > m_RumblePacket . ucPacketNumber = ctx - > m_nCommandNumber ;
ctx - > m_nCommandNumber = ( ctx - > m_nCommandNumber + 1 ) & 0xF ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Refresh the rumble state periodically
2022-12-02 01:17:17 -08:00
ctx - > m_ulRumbleSent = SDL_GetTicks ( ) ;
2020-02-07 11:44:57 -08:00
2018-08-09 16:00:17 -07:00
return WritePacket ( ctx , ( Uint8 * ) & ctx - > m_RumblePacket , sizeof ( ctx - > m_RumblePacket ) ) ;
}
2022-09-22 18:22:17 -07:00
static ESwitchDeviceInfoControllerType CalculateControllerType ( SDL_DriverSwitch_Context * ctx , ESwitchDeviceInfoControllerType eControllerType )
{
SDL_HIDAPI_Device * device = ctx - > device ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// The N64 controller reports as a Pro controller over USB
2022-09-22 18:22:17 -07:00
if ( eControllerType = = k_eSwitchDeviceInfoControllerType_ProController & &
device - > product_id = = USB_PRODUCT_NINTENDO_N64_CONTROLLER ) {
eControllerType = k_eSwitchDeviceInfoControllerType_N64 ;
}
if ( eControllerType = = k_eSwitchDeviceInfoControllerType_Unknown ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// This might be a Joy-Con that's missing from a charging grip slot
2022-09-22 18:22:17 -07:00
if ( device - > product_id = = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP ) {
if ( device - > interface_number = = 1 ) {
eControllerType = k_eSwitchDeviceInfoControllerType_JoyConLeft ;
} else {
eControllerType = k_eSwitchDeviceInfoControllerType_JoyConRight ;
}
}
}
return eControllerType ;
}
2024-08-22 09:21:26 -07:00
static bool BReadDeviceInfo ( SDL_DriverSwitch_Context * ctx )
2021-01-14 23:49:41 -08:00
{
SwitchSubcommandInputPacket_t * reply = NULL ;
2023-06-17 12:42:55 -07:00
if ( ctx - > device - > is_bluetooth ) {
if ( WriteSubcommand ( ctx , k_eSwitchSubcommandIDs_RequestDeviceInfo , NULL , 0 , & reply ) ) {
// Byte 2: Controller ID (1=LJC, 2=RJC, 3=Pro)
ctx - > m_eControllerType = CalculateControllerType ( ctx , ( ESwitchDeviceInfoControllerType ) reply - > deviceInfo . ucDeviceType ) ;
2021-01-14 23:49:41 -08:00
2023-06-17 12:42:55 -07:00
// Bytes 4-9: MAC address (big-endian)
SDL_memcpy ( ctx - > m_rgucMACAddress , reply - > deviceInfo . rgucMACAddress , sizeof ( ctx - > m_rgucMACAddress ) ) ;
2022-08-03 22:12:21 -07:00
2024-08-22 09:21:26 -07:00
return true ;
2022-11-27 17:38:43 +01:00
}
2023-06-17 12:42:55 -07:00
} else {
2024-08-22 09:21:26 -07:00
if ( WriteProprietary ( ctx , k_eSwitchProprietaryCommandIDs_Status , NULL , 0 , true ) ) {
2023-06-17 12:42:55 -07:00
SwitchProprietaryStatusPacket_t * status = ( SwitchProprietaryStatusPacket_t * ) & ctx - > m_rgucReadBuffer [ 0 ] ;
size_t i ;
2021-01-14 23:49:41 -08:00
2023-06-17 12:42:55 -07:00
ctx - > m_eControllerType = CalculateControllerType ( ctx , ( ESwitchDeviceInfoControllerType ) status - > ucDeviceType ) ;
2021-01-14 23:49:41 -08:00
2023-06-17 12:42:55 -07:00
for ( i = 0 ; i < sizeof ( ctx - > m_rgucMACAddress ) ; + + i ) {
ctx - > m_rgucMACAddress [ i ] = status - > rgucMACAddress [ sizeof ( ctx - > m_rgucMACAddress ) - i - 1 ] ;
}
2021-01-14 23:49:41 -08:00
2024-08-22 09:21:26 -07:00
return true ;
2023-06-17 12:42:55 -07:00
}
2021-01-14 23:49:41 -08:00
}
2024-08-22 09:21:26 -07:00
return false ;
2021-01-14 23:49:41 -08:00
}
2024-08-22 09:21:26 -07:00
static bool BTrySetupUSB ( SDL_DriverSwitch_Context * ctx )
2018-08-09 16:00:17 -07:00
{
/* We have to send a connection handshake to the controller when communicating over USB
* before we ' re able to send it other commands . Luckily this command is not supported
* over Bluetooth , so we can use the controller ' s lack of response as a way to
* determine if the connection is over USB or Bluetooth
*/
2024-08-22 09:21:26 -07:00
if ( ! WriteProprietary ( ctx , k_eSwitchProprietaryCommandIDs_Handshake , NULL , 0 , true ) ) {
return false ;
2018-08-09 16:00:17 -07:00
}
2024-08-22 09:21:26 -07:00
if ( ! WriteProprietary ( ctx , k_eSwitchProprietaryCommandIDs_HighSpeed , NULL , 0 , true ) ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// The 8BitDo M30 and SF30 Pro don't respond to this command, but otherwise work correctly
2024-08-22 09:21:26 -07:00
// return false;
2018-08-09 16:00:17 -07:00
}
2024-08-22 09:21:26 -07:00
if ( ! WriteProprietary ( ctx , k_eSwitchProprietaryCommandIDs_Handshake , NULL , 0 , true ) ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// This fails on the right Joy-Con when plugged into the charging grip
2024-08-22 09:21:26 -07:00
// return false;
2018-08-09 16:00:17 -07:00
}
2024-08-22 09:21:26 -07:00
if ( ! WriteProprietary ( ctx , k_eSwitchProprietaryCommandIDs_ForceUSB , NULL , 0 , false ) ) {
return false ;
2021-01-14 23:49:41 -08:00
}
2024-08-22 09:21:26 -07:00
return true ;
2018-08-09 16:00:17 -07:00
}
2024-08-22 09:21:26 -07:00
static bool SetVibrationEnabled ( SDL_DriverSwitch_Context * ctx , Uint8 enabled )
2018-08-09 16:00:17 -07:00
{
return WriteSubcommand ( ctx , k_eSwitchSubcommandIDs_EnableVibration , & enabled , sizeof ( enabled ) , NULL ) ;
}
2024-08-22 09:21:26 -07:00
static bool SetInputMode ( SDL_DriverSwitch_Context * ctx , Uint8 input_mode )
2018-08-09 16:00:17 -07:00
{
2024-06-12 22:28:47 -07:00
# ifdef FORCE_SIMPLE_REPORTS
input_mode = k_eSwitchInputReportIDs_SimpleControllerState ;
# endif
# ifdef FORCE_FULL_REPORTS
input_mode = k_eSwitchInputReportIDs_FullControllerState ;
# endif
2023-12-24 08:12:14 -08:00
if ( input_mode = = ctx - > m_nCurrentInputMode ) {
2024-08-22 09:21:26 -07:00
return true ;
2023-12-24 08:12:14 -08:00
} else {
ctx - > m_nCurrentInputMode = input_mode ;
return WriteSubcommand ( ctx , k_eSwitchSubcommandIDs_SetInputReportMode , & input_mode , sizeof ( input_mode ) , NULL ) ;
}
2018-08-09 16:00:17 -07:00
}
2024-08-22 09:21:26 -07:00
static bool SetHomeLED ( SDL_DriverSwitch_Context * ctx , Uint8 brightness )
2018-08-09 16:00:17 -07:00
{
Uint8 ucLedIntensity = 0 ;
Uint8 rgucBuffer [ 4 ] ;
if ( brightness > 0 ) {
if ( brightness < 65 ) {
ucLedIntensity = ( brightness + 5 ) / 10 ;
} else {
ucLedIntensity = ( Uint8 ) SDL_ceilf ( 0xF * SDL_powf ( ( float ) brightness / 100.f , 2.13f ) ) ;
}
}
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
rgucBuffer [ 0 ] = ( 0x0 < < 4 ) | 0x1 ; // 0 mini cycles (besides first), cycle duration 8ms
rgucBuffer [ 1 ] = ( ( ucLedIntensity & 0xF ) < < 4 ) | 0x0 ; // LED start intensity (0x0-0xF), 0 cycles (LED stays on at start intensity after first cycle)
rgucBuffer [ 2 ] = ( ( ucLedIntensity & 0xF ) < < 4 ) | 0x0 ; // First cycle LED intensity, 0x0 intensity for second cycle
rgucBuffer [ 3 ] = ( 0x0 < < 4 ) | 0x0 ; // 8ms fade transition to first cycle, 8ms first cycle LED duration
2018-08-09 16:00:17 -07:00
return WriteSubcommand ( ctx , k_eSwitchSubcommandIDs_SetHomeLight , rgucBuffer , sizeof ( rgucBuffer ) , NULL ) ;
}
2022-07-25 11:26:18 -07:00
static void SDLCALL SDL_HomeLEDHintChanged ( void * userdata , const char * name , const char * oldValue , const char * hint )
{
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) userdata ;
if ( hint & & * hint ) {
int value ;
if ( SDL_strchr ( hint , ' . ' ) ! = NULL ) {
value = ( int ) ( 100.0f * SDL_atof ( hint ) ) ;
2023-03-30 14:04:32 -07:00
if ( value > 255 ) {
value = 255 ;
}
2024-08-22 09:21:26 -07:00
} else if ( SDL_GetStringBoolean ( hint , true ) ) {
2022-07-25 11:26:18 -07:00
value = 100 ;
} else {
value = 0 ;
}
2023-03-30 14:04:32 -07:00
SetHomeLED ( ctx , ( Uint8 ) value ) ;
2022-07-25 11:26:18 -07:00
}
}
2022-08-06 10:34:19 -07:00
static void UpdateSlotLED ( SDL_DriverSwitch_Context * ctx )
2018-08-09 16:00:17 -07:00
{
2022-08-06 10:34:19 -07:00
if ( ! ctx - > m_bInputOnly ) {
2022-08-09 00:18:19 -07:00
Uint8 led_data = 0 ;
2026-02-07 02:40:54 -08:00
const Uint8 player_pattern [ ] = { 0x1 , 0x3 , 0x7 , 0xf , 0x9 , 0x5 , 0xd , 0x6 } ;
2022-11-30 12:51:59 -08:00
2022-08-09 00:18:19 -07:00
if ( ctx - > m_bPlayerLights & & ctx - > m_nPlayerIndex > = 0 ) {
2026-02-07 02:40:54 -08:00
led_data = player_pattern [ ctx - > m_nPlayerIndex % 8 ] ;
2022-08-09 00:18:19 -07:00
}
2022-08-06 10:34:19 -07:00
WriteSubcommand ( ctx , k_eSwitchSubcommandIDs_SetPlayerLights , & led_data , sizeof ( led_data ) , NULL ) ;
}
}
static void SDLCALL SDL_PlayerLEDHintChanged ( void * userdata , const char * name , const char * oldValue , const char * hint )
{
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) userdata ;
2024-08-22 09:21:26 -07:00
bool bPlayerLights = SDL_GetStringBoolean ( hint , true ) ;
2022-08-06 10:34:19 -07:00
if ( bPlayerLights ! = ctx - > m_bPlayerLights ) {
ctx - > m_bPlayerLights = bPlayerLights ;
UpdateSlotLED ( ctx ) ;
2024-01-27 14:37:30 -08:00
HIDAPI_UpdateDeviceProperties ( ctx - > device ) ;
2022-08-06 10:34:19 -07:00
}
2018-08-09 16:00:17 -07:00
}
2024-07-06 05:29:12 -07:00
static void GetInitialInputMode ( SDL_DriverSwitch_Context * ctx )
2023-12-24 08:12:14 -08:00
{
2024-07-06 05:29:12 -07:00
if ( ! ctx - > m_nInitialInputMode ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// This will set the initial input mode if it can
2024-07-06 05:29:12 -07:00
ReadInput ( ctx ) ;
2023-12-24 08:12:14 -08:00
}
}
2023-06-13 22:40:51 -07:00
static Uint8 GetDefaultInputMode ( SDL_DriverSwitch_Context * ctx )
{
Uint8 input_mode ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Determine the desired input mode
2023-12-24 08:12:14 -08:00
if ( ctx - > m_nInitialInputMode ) {
input_mode = ctx - > m_nInitialInputMode ;
2023-06-13 22:40:51 -07:00
} else {
2023-12-24 08:12:14 -08:00
if ( ctx - > device - > is_bluetooth ) {
input_mode = k_eSwitchInputReportIDs_SimpleControllerState ;
} else {
input_mode = k_eSwitchInputReportIDs_FullControllerState ;
}
2023-06-13 22:40:51 -07:00
}
2025-01-02 14:27:38 -08:00
switch ( ctx - > m_eEnhancedReportHint ) {
case SWITCH_ENHANCED_REPORT_HINT_OFF :
input_mode = k_eSwitchInputReportIDs_SimpleControllerState ;
break ;
case SWITCH_ENHANCED_REPORT_HINT_ON :
if ( input_mode = = k_eSwitchInputReportIDs_SimpleControllerState ) {
input_mode = k_eSwitchInputReportIDs_FullControllerState ;
}
break ;
case SWITCH_ENHANCED_REPORT_HINT_AUTO :
/* Joy-Con controllers switch their thumbsticks into D-pad mode in simple mode,
2024-06-12 23:36:16 -07:00
* so let ' s enable full controller state for them .
*/
2025-01-02 14:27:38 -08:00
if ( ctx - > device - > vendor_id = = USB_VENDOR_NINTENDO & &
( ctx - > device - > product_id = = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT | |
ctx - > device - > product_id = = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT ) ) {
2024-06-12 23:36:16 -07:00
input_mode = k_eSwitchInputReportIDs_FullControllerState ;
}
2025-01-02 14:27:38 -08:00
break ;
2023-06-13 22:40:51 -07:00
}
2025-02-26 17:54:43 -08:00
// Wired controllers break if they are put into simple controller state
if ( input_mode = = k_eSwitchInputReportIDs_SimpleControllerState & &
! ctx - > device - > is_bluetooth ) {
input_mode = k_eSwitchInputReportIDs_FullControllerState ;
}
2023-06-13 22:40:51 -07:00
return input_mode ;
}
2023-12-24 08:12:14 -08:00
static Uint8 GetSensorInputMode ( SDL_DriverSwitch_Context * ctx )
{
Uint8 input_mode ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Determine the desired input mode
2023-12-24 08:12:14 -08:00
if ( ! ctx - > m_nInitialInputMode | |
ctx - > m_nInitialInputMode = = k_eSwitchInputReportIDs_SimpleControllerState ) {
input_mode = k_eSwitchInputReportIDs_FullControllerState ;
} else {
input_mode = ctx - > m_nInitialInputMode ;
}
return input_mode ;
}
2025-01-02 14:27:38 -08:00
static void UpdateInputMode ( SDL_DriverSwitch_Context * ctx )
{
Uint8 input_mode ;
if ( ctx - > m_bReportSensors ) {
input_mode = GetSensorInputMode ( ctx ) ;
} else {
input_mode = GetDefaultInputMode ( ctx ) ;
}
SetInputMode ( ctx , input_mode ) ;
}
static void SetEnhancedModeAvailable ( SDL_DriverSwitch_Context * ctx )
{
if ( ctx - > m_bEnhancedModeAvailable ) {
return ;
}
ctx - > m_bEnhancedModeAvailable = true ;
if ( ctx - > m_bSensorsSupported ) {
// Use the right sensor in the combined Joy-Con pair
if ( ! ctx - > device - > parent | |
ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
SDL_PrivateJoystickAddSensor ( ctx - > joystick , SDL_SENSOR_GYRO , 200.0f ) ;
SDL_PrivateJoystickAddSensor ( ctx - > joystick , SDL_SENSOR_ACCEL , 200.0f ) ;
}
if ( ctx - > device - > parent & &
ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConLeft ) {
SDL_PrivateJoystickAddSensor ( ctx - > joystick , SDL_SENSOR_GYRO_L , 200.0f ) ;
SDL_PrivateJoystickAddSensor ( ctx - > joystick , SDL_SENSOR_ACCEL_L , 200.0f ) ;
}
if ( ctx - > device - > parent & &
ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
SDL_PrivateJoystickAddSensor ( ctx - > joystick , SDL_SENSOR_GYRO_R , 200.0f ) ;
SDL_PrivateJoystickAddSensor ( ctx - > joystick , SDL_SENSOR_ACCEL_R , 200.0f ) ;
}
}
}
static void SetEnhancedReportHint ( SDL_DriverSwitch_Context * ctx , HIDAPI_Switch_EnhancedReportHint eEnhancedReportHint )
{
2025-02-26 10:40:03 -08:00
ctx - > m_eEnhancedReportHint = eEnhancedReportHint ;
2025-01-02 14:27:38 -08:00
switch ( eEnhancedReportHint ) {
case SWITCH_ENHANCED_REPORT_HINT_OFF :
2025-02-26 10:40:03 -08:00
ctx - > m_bEnhancedMode = false ;
2025-01-02 14:27:38 -08:00
break ;
case SWITCH_ENHANCED_REPORT_HINT_ON :
2025-02-26 10:40:03 -08:00
SetEnhancedModeAvailable ( ctx ) ;
ctx - > m_bEnhancedMode = true ;
2025-01-02 14:27:38 -08:00
break ;
case SWITCH_ENHANCED_REPORT_HINT_AUTO :
SetEnhancedModeAvailable ( ctx ) ;
break ;
}
UpdateInputMode ( ctx ) ;
}
static void UpdateEnhancedModeOnEnhancedReport ( SDL_DriverSwitch_Context * ctx )
{
if ( ctx - > m_eEnhancedReportHint = = SWITCH_ENHANCED_REPORT_HINT_AUTO ) {
SetEnhancedReportHint ( ctx , SWITCH_ENHANCED_REPORT_HINT_ON ) ;
}
}
static void UpdateEnhancedModeOnApplicationUsage ( SDL_DriverSwitch_Context * ctx )
{
if ( ctx - > m_eEnhancedReportHint = = SWITCH_ENHANCED_REPORT_HINT_AUTO ) {
SetEnhancedReportHint ( ctx , SWITCH_ENHANCED_REPORT_HINT_ON ) ;
}
}
static void SDLCALL SDL_EnhancedReportsChanged ( void * userdata , const char * name , const char * oldValue , const char * hint )
{
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) userdata ;
if ( hint & & SDL_strcasecmp ( hint , " auto " ) = = 0 ) {
SetEnhancedReportHint ( ctx , SWITCH_ENHANCED_REPORT_HINT_AUTO ) ;
} else if ( SDL_GetStringBoolean ( hint , true ) ) {
SetEnhancedReportHint ( ctx , SWITCH_ENHANCED_REPORT_HINT_ON ) ;
} else {
SetEnhancedReportHint ( ctx , SWITCH_ENHANCED_REPORT_HINT_OFF ) ;
}
}
2024-08-22 09:21:26 -07:00
static bool SetIMUEnabled ( SDL_DriverSwitch_Context * ctx , bool enabled )
2021-01-11 15:36:40 +08:00
{
Uint8 imu_data = enabled ? 1 : 0 ;
return WriteSubcommand ( ctx , k_eSwitchSubcommandIDs_EnableIMU , & imu_data , sizeof ( imu_data ) , NULL ) ;
}
2024-08-22 09:21:26 -07:00
static bool LoadStickCalibration ( SDL_DriverSwitch_Context * ctx )
2018-08-09 16:00:17 -07:00
{
2025-06-22 20:59:15 -07:00
Uint8 * pLeftStickCal = NULL ;
Uint8 * pRightStickCal = NULL ;
2018-08-09 16:00:17 -07:00
size_t stick , axis ;
2023-01-09 17:42:17 -06:00
SwitchSubcommandInputPacket_t * user_reply = NULL ;
SwitchSubcommandInputPacket_t * factory_reply = NULL ;
SwitchSPIOpData_t readUserParams ;
SwitchSPIOpData_t readFactoryParams ;
2025-06-22 20:59:15 -07:00
Uint8 userParamsReadSuccessCount = 0 ;
2018-08-09 16:00:17 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Read User Calibration Info
2023-01-09 17:42:17 -06:00
readUserParams . unAddress = k_unSPIStickUserCalibrationStartOffset ;
readUserParams . ucLength = k_unSPIStickUserCalibrationLength ;
2018-08-09 16:00:17 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// This isn't readable on all controllers, so ignore failure
2023-06-27 07:48:42 -07:00
WriteSubcommand ( ctx , k_eSwitchSubcommandIDs_SPIFlashRead , ( uint8_t * ) & readUserParams , sizeof ( readUserParams ) , & user_reply ) ;
2018-08-09 16:00:17 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Read Factory Calibration Info
2023-01-09 17:42:17 -06:00
readFactoryParams . unAddress = k_unSPIStickFactoryCalibrationStartOffset ;
readFactoryParams . ucLength = k_unSPIStickFactoryCalibrationLength ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Automatically select the user calibration if magic bytes are set
2023-06-27 07:48:42 -07:00
if ( user_reply & & user_reply - > stickUserCalibration . rgucLeftMagic [ 0 ] = = 0xB2 & & user_reply - > stickUserCalibration . rgucLeftMagic [ 1 ] = = 0xA1 ) {
2025-06-22 20:59:15 -07:00
userParamsReadSuccessCount + = 1 ;
2023-01-09 17:42:17 -06:00
pLeftStickCal = user_reply - > stickUserCalibration . rgucLeftCalibration ;
}
2023-06-27 07:48:42 -07:00
if ( user_reply & & user_reply - > stickUserCalibration . rgucRightMagic [ 0 ] = = 0xB2 & & user_reply - > stickUserCalibration . rgucRightMagic [ 1 ] = = 0xA1 ) {
2025-06-22 20:59:15 -07:00
userParamsReadSuccessCount + = 1 ;
2023-01-09 17:42:17 -06:00
pRightStickCal = user_reply - > stickUserCalibration . rgucRightCalibration ;
2025-07-15 17:41:32 -07:00
}
2025-06-22 20:59:15 -07:00
// Only read the factory calibration info if we failed to receive the correct magic bytes
if ( userParamsReadSuccessCount < 2 ) {
// Read Factory Calibration Info
readFactoryParams . unAddress = k_unSPIStickFactoryCalibrationStartOffset ;
readFactoryParams . ucLength = k_unSPIStickFactoryCalibrationLength ;
const int MAX_ATTEMPTS = 3 ;
for ( int attempt = 0 ; ; + + attempt ) {
if ( ! WriteSubcommand ( ctx , k_eSwitchSubcommandIDs_SPIFlashRead , ( uint8_t * ) & readFactoryParams , sizeof ( readFactoryParams ) , & factory_reply ) ) {
return false ;
}
if ( factory_reply - > stickFactoryCalibration . opData . unAddress = = k_unSPIStickFactoryCalibrationStartOffset ) {
// We successfully read the calibration data
pLeftStickCal = factory_reply - > stickFactoryCalibration . rgucLeftCalibration ;
pRightStickCal = factory_reply - > stickFactoryCalibration . rgucRightCalibration ;
break ;
}
if ( attempt = = MAX_ATTEMPTS ) {
return false ;
}
}
}
// If we still don't have calibration data, return false
if ( pLeftStickCal = = NULL | | pRightStickCal = = NULL )
{
return false ;
2023-01-09 17:42:17 -06:00
}
2018-08-09 16:00:17 -07:00
/* Stick calibration values are 12-bits each and are packed by bit
* For whatever reason the fields are in a different order for each stick
* Left : X - Max , Y - Max , X - Center , Y - Center , X - Min , Y - Min
2025-06-22 13:12:05 -07:00
* Right : X - Center , Y - Center , X - Min , Y - Min , X - Max , Y - Max
2018-08-09 16:00:17 -07:00
*/
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Left stick
ctx - > m_StickCalData [ 0 ] . axis [ 0 ] . sMax = ( ( pLeftStickCal [ 1 ] < < 8 ) & 0xF00 ) | pLeftStickCal [ 0 ] ; // X Axis max above center
ctx - > m_StickCalData [ 0 ] . axis [ 1 ] . sMax = ( pLeftStickCal [ 2 ] < < 4 ) | ( pLeftStickCal [ 1 ] > > 4 ) ; // Y Axis max above center
ctx - > m_StickCalData [ 0 ] . axis [ 0 ] . sCenter = ( ( pLeftStickCal [ 4 ] < < 8 ) & 0xF00 ) | pLeftStickCal [ 3 ] ; // X Axis center
ctx - > m_StickCalData [ 0 ] . axis [ 1 ] . sCenter = ( pLeftStickCal [ 5 ] < < 4 ) | ( pLeftStickCal [ 4 ] > > 4 ) ; // Y Axis center
ctx - > m_StickCalData [ 0 ] . axis [ 0 ] . sMin = ( ( pLeftStickCal [ 7 ] < < 8 ) & 0xF00 ) | pLeftStickCal [ 6 ] ; // X Axis min below center
ctx - > m_StickCalData [ 0 ] . axis [ 1 ] . sMin = ( pLeftStickCal [ 8 ] < < 4 ) | ( pLeftStickCal [ 7 ] > > 4 ) ; // Y Axis min below center
// Right stick
ctx - > m_StickCalData [ 1 ] . axis [ 0 ] . sCenter = ( ( pRightStickCal [ 1 ] < < 8 ) & 0xF00 ) | pRightStickCal [ 0 ] ; // X Axis center
ctx - > m_StickCalData [ 1 ] . axis [ 1 ] . sCenter = ( pRightStickCal [ 2 ] < < 4 ) | ( pRightStickCal [ 1 ] > > 4 ) ; // Y Axis center
2025-06-22 13:12:05 -07:00
ctx - > m_StickCalData [ 1 ] . axis [ 0 ] . sMin = ( ( pRightStickCal [ 4 ] < < 8 ) & 0xF00 ) | pRightStickCal [ 3 ] ; // X Axis min below center
ctx - > m_StickCalData [ 1 ] . axis [ 1 ] . sMin = ( pRightStickCal [ 5 ] < < 4 ) | ( pRightStickCal [ 4 ] > > 4 ) ; // Y Axis min below center
ctx - > m_StickCalData [ 1 ] . axis [ 0 ] . sMax = ( ( pRightStickCal [ 7 ] < < 8 ) & 0xF00 ) | pRightStickCal [ 6 ] ; // X Axis max above center
ctx - > m_StickCalData [ 1 ] . axis [ 1 ] . sMax = ( pRightStickCal [ 8 ] < < 4 ) | ( pRightStickCal [ 7 ] > > 4 ) ; // Y Axis max above center
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Filter out any values that were uninitialized (0xFFF) in the SPI read
2018-08-09 16:00:17 -07:00
for ( stick = 0 ; stick < 2 ; + + stick ) {
for ( axis = 0 ; axis < 2 ; + + axis ) {
if ( ctx - > m_StickCalData [ stick ] . axis [ axis ] . sCenter = = 0xFFF ) {
2022-09-26 18:39:18 -07:00
ctx - > m_StickCalData [ stick ] . axis [ axis ] . sCenter = 2048 ;
2018-08-09 16:00:17 -07:00
}
if ( ctx - > m_StickCalData [ stick ] . axis [ axis ] . sMax = = 0xFFF ) {
2022-09-26 18:39:18 -07:00
ctx - > m_StickCalData [ stick ] . axis [ axis ] . sMax = ( Sint16 ) ( ctx - > m_StickCalData [ stick ] . axis [ axis ] . sCenter * 0.7f ) ;
2018-08-09 16:00:17 -07:00
}
if ( ctx - > m_StickCalData [ stick ] . axis [ axis ] . sMin = = 0xFFF ) {
2022-09-26 18:39:18 -07:00
ctx - > m_StickCalData [ stick ] . axis [ axis ] . sMin = ( Sint16 ) ( ctx - > m_StickCalData [ stick ] . axis [ axis ] . sCenter * 0.7f ) ;
2018-08-09 16:00:17 -07:00
}
}
}
2022-09-26 18:18:16 -07:00
for ( stick = 0 ; stick < 2 ; + + stick ) {
2022-11-27 17:38:43 +01:00
for ( axis = 0 ; axis < 2 ; + + axis ) {
2022-09-26 18:18:16 -07:00
ctx - > m_StickExtents [ stick ] . axis [ axis ] . sMin = - ( Sint16 ) ( ctx - > m_StickCalData [ stick ] . axis [ axis ] . sMin * 0.7f ) ;
ctx - > m_StickExtents [ stick ] . axis [ axis ] . sMax = ( Sint16 ) ( ctx - > m_StickCalData [ stick ] . axis [ axis ] . sMax * 0.7f ) ;
2018-08-09 16:00:17 -07:00
}
2022-09-26 18:18:16 -07:00
}
for ( stick = 0 ; stick < 2 ; + + stick ) {
2022-11-27 17:38:43 +01:00
for ( axis = 0 ; axis < 2 ; + + axis ) {
2022-09-26 18:18:16 -07:00
ctx - > m_SimpleStickExtents [ stick ] . axis [ axis ] . sMin = ( Sint16 ) ( SDL_MIN_SINT16 * 0.5f ) ;
ctx - > m_SimpleStickExtents [ stick ] . axis [ axis ] . sMax = ( Sint16 ) ( SDL_MAX_SINT16 * 0.5f ) ;
2018-08-09 16:00:17 -07:00
}
}
2022-09-26 18:18:16 -07:00
2024-08-22 09:21:26 -07:00
return true ;
2018-08-09 16:00:17 -07:00
}
2024-08-22 09:21:26 -07:00
static bool LoadIMUCalibration ( SDL_DriverSwitch_Context * ctx )
2022-04-27 00:57:17 +08:00
{
2022-11-30 12:51:59 -08:00
SwitchSubcommandInputPacket_t * reply = NULL ;
2022-04-27 00:57:17 +08:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Read Calibration Info
2022-04-27 00:57:17 +08:00
SwitchSPIOpData_t readParams ;
readParams . unAddress = k_unSPIIMUScaleStartOffset ;
readParams . ucLength = k_unSPIIMUScaleLength ;
2023-06-21 10:28:45 -07:00
if ( WriteSubcommand ( ctx , k_eSwitchSubcommandIDs_SPIFlashRead , ( uint8_t * ) & readParams , sizeof ( readParams ) , & reply ) ) {
Uint8 * pIMUScale ;
Sint16 sAccelRawX , sAccelRawY , sAccelRawZ , sGyroRawX , sGyroRawY , sGyroRawZ ;
2025-06-13 07:46:14 -07:00
Sint16 sAccelSensCoeffX , sAccelSensCoeffY , sAccelSensCoeffZ ;
Sint16 sGyroSensCoeffX , sGyroSensCoeffY , sGyroSensCoeffZ ;
2022-04-27 00:57:17 +08:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// IMU scale gives us multipliers for converting raw values to real world values
2023-06-21 10:28:45 -07:00
pIMUScale = reply - > spiReadData . rgucReadData ;
2022-04-27 00:57:17 +08:00
2023-06-21 10:28:45 -07:00
sAccelRawX = ( pIMUScale [ 1 ] < < 8 ) | pIMUScale [ 0 ] ;
sAccelRawY = ( pIMUScale [ 3 ] < < 8 ) | pIMUScale [ 2 ] ;
sAccelRawZ = ( pIMUScale [ 5 ] < < 8 ) | pIMUScale [ 4 ] ;
2022-04-27 00:57:17 +08:00
2025-06-13 07:46:14 -07:00
sAccelSensCoeffX = ( pIMUScale [ 7 ] < < 8 ) | pIMUScale [ 6 ] ;
sAccelSensCoeffY = ( pIMUScale [ 9 ] < < 8 ) | pIMUScale [ 8 ] ;
sAccelSensCoeffZ = ( pIMUScale [ 11 ] < < 8 ) | pIMUScale [ 10 ] ;
2023-06-21 10:28:45 -07:00
sGyroRawX = ( pIMUScale [ 13 ] < < 8 ) | pIMUScale [ 12 ] ;
sGyroRawY = ( pIMUScale [ 15 ] < < 8 ) | pIMUScale [ 14 ] ;
sGyroRawZ = ( pIMUScale [ 17 ] < < 8 ) | pIMUScale [ 16 ] ;
2022-04-27 00:57:17 +08:00
2025-06-13 07:46:14 -07:00
sGyroSensCoeffX = ( pIMUScale [ 19 ] < < 8 ) | pIMUScale [ 18 ] ;
sGyroSensCoeffY = ( pIMUScale [ 21 ] < < 8 ) | pIMUScale [ 20 ] ;
sGyroSensCoeffZ = ( pIMUScale [ 23 ] < < 8 ) | pIMUScale [ 22 ] ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Check for user calibration data. If it's present and set, it'll override the factory settings
2023-06-21 10:28:45 -07:00
readParams . unAddress = k_unSPIIMUUserScaleStartOffset ;
readParams . ucLength = k_unSPIIMUUserScaleLength ;
if ( WriteSubcommand ( ctx , k_eSwitchSubcommandIDs_SPIFlashRead , ( uint8_t * ) & readParams , sizeof ( readParams ) , & reply ) & & ( pIMUScale [ 0 ] | pIMUScale [ 1 ] < < 8 ) = = 0xA1B2 ) {
pIMUScale = reply - > spiReadData . rgucReadData ;
2022-04-27 00:57:17 +08:00
2023-06-21 10:28:45 -07:00
sAccelRawX = ( pIMUScale [ 3 ] < < 8 ) | pIMUScale [ 2 ] ;
sAccelRawY = ( pIMUScale [ 5 ] < < 8 ) | pIMUScale [ 4 ] ;
sAccelRawZ = ( pIMUScale [ 7 ] < < 8 ) | pIMUScale [ 6 ] ;
2022-04-27 00:57:17 +08:00
2023-06-21 10:28:45 -07:00
sGyroRawX = ( pIMUScale [ 15 ] < < 8 ) | pIMUScale [ 14 ] ;
sGyroRawY = ( pIMUScale [ 17 ] < < 8 ) | pIMUScale [ 16 ] ;
sGyroRawZ = ( pIMUScale [ 19 ] < < 8 ) | pIMUScale [ 18 ] ;
}
2022-11-30 12:51:59 -08:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Accelerometer scale
2025-06-13 07:46:14 -07:00
ctx - > m_IMUScaleData . fAccelScaleX = SWITCH_ACCEL_SCALE_MULT / ( ( float ) sAccelSensCoeffX - ( float ) sAccelRawX ) * SDL_STANDARD_GRAVITY ;
ctx - > m_IMUScaleData . fAccelScaleY = SWITCH_ACCEL_SCALE_MULT / ( ( float ) sAccelSensCoeffY - ( float ) sAccelRawY ) * SDL_STANDARD_GRAVITY ;
ctx - > m_IMUScaleData . fAccelScaleZ = SWITCH_ACCEL_SCALE_MULT / ( ( float ) sAccelSensCoeffZ - ( float ) sAccelRawZ ) * SDL_STANDARD_GRAVITY ;
2022-04-27 00:57:17 +08:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Gyro scale
2025-06-13 07:46:14 -07:00
ctx - > m_IMUScaleData . fGyroScaleX = SWITCH_GYRO_SCALE_MULT / ( ( float ) sGyroSensCoeffX - ( float ) sGyroRawX ) * SDL_PI_F / 180.0f ;
ctx - > m_IMUScaleData . fGyroScaleY = SWITCH_GYRO_SCALE_MULT / ( ( float ) sGyroSensCoeffY - ( float ) sGyroRawY ) * SDL_PI_F / 180.0f ;
ctx - > m_IMUScaleData . fGyroScaleZ = SWITCH_GYRO_SCALE_MULT / ( ( float ) sGyroSensCoeffZ - ( float ) sGyroRawZ ) * SDL_PI_F / 180.0f ;
2022-04-27 00:57:17 +08:00
2023-06-21 10:28:45 -07:00
} else {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Use default values
2023-06-21 10:28:45 -07:00
const float accelScale = SDL_STANDARD_GRAVITY / SWITCH_ACCEL_SCALE ;
const float gyroScale = SDL_PI_F / 180.0f / SWITCH_GYRO_SCALE ;
2022-04-27 00:57:17 +08:00
2023-06-21 10:28:45 -07:00
ctx - > m_IMUScaleData . fAccelScaleX = accelScale ;
ctx - > m_IMUScaleData . fAccelScaleY = accelScale ;
ctx - > m_IMUScaleData . fAccelScaleZ = accelScale ;
2022-04-27 00:57:17 +08:00
2023-06-21 10:28:45 -07:00
ctx - > m_IMUScaleData . fGyroScaleX = gyroScale ;
ctx - > m_IMUScaleData . fGyroScaleY = gyroScale ;
ctx - > m_IMUScaleData . fGyroScaleZ = gyroScale ;
}
2024-08-22 09:21:26 -07:00
return true ;
2022-04-27 00:57:17 +08:00
}
2022-09-26 18:18:16 -07:00
static Sint16 ApplyStickCalibration ( SDL_DriverSwitch_Context * ctx , int nStick , int nAxis , Sint16 sRawValue )
2018-08-09 16:00:17 -07:00
{
2022-09-26 18:18:16 -07:00
sRawValue - = ctx - > m_StickCalData [ nStick ] . axis [ nAxis ] . sCenter ;
2018-08-09 16:00:17 -07:00
2025-06-21 19:55:05 -07:00
if ( sRawValue > = 0 ) {
if ( sRawValue > ctx - > m_StickExtents [ nStick ] . axis [ nAxis ] . sMax ) {
ctx - > m_StickExtents [ nStick ] . axis [ nAxis ] . sMax = sRawValue ;
}
return ( Sint16 ) HIDAPI_RemapVal ( sRawValue , 0 , ctx - > m_StickExtents [ nStick ] . axis [ nAxis ] . sMax , 0 , SDL_MAX_SINT16 ) ;
} else {
if ( sRawValue < ctx - > m_StickExtents [ nStick ] . axis [ nAxis ] . sMin ) {
ctx - > m_StickExtents [ nStick ] . axis [ nAxis ] . sMin = sRawValue ;
}
return ( Sint16 ) HIDAPI_RemapVal ( sRawValue , ctx - > m_StickExtents [ nStick ] . axis [ nAxis ] . sMin , 0 , SDL_MIN_SINT16 , 0 ) ;
2018-08-09 16:00:17 -07:00
}
}
2022-09-26 18:18:16 -07:00
static Sint16 ApplySimpleStickCalibration ( SDL_DriverSwitch_Context * ctx , int nStick , int nAxis , Sint16 sRawValue )
2018-08-09 16:00:17 -07:00
{
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// 0x8000 is the neutral value for all joystick axes
2022-09-26 18:18:16 -07:00
const Uint16 usJoystickCenter = 0x8000 ;
sRawValue - = usJoystickCenter ;
2025-06-21 19:55:05 -07:00
if ( sRawValue > = 0 ) {
if ( sRawValue > ctx - > m_SimpleStickExtents [ nStick ] . axis [ nAxis ] . sMax ) {
ctx - > m_SimpleStickExtents [ nStick ] . axis [ nAxis ] . sMax = sRawValue ;
}
return ( Sint16 ) HIDAPI_RemapVal ( sRawValue , 0 , ctx - > m_SimpleStickExtents [ nStick ] . axis [ nAxis ] . sMax , 0 , SDL_MAX_SINT16 ) ;
} else {
if ( sRawValue < ctx - > m_SimpleStickExtents [ nStick ] . axis [ nAxis ] . sMin ) {
ctx - > m_SimpleStickExtents [ nStick ] . axis [ nAxis ] . sMin = sRawValue ;
}
return ( Sint16 ) HIDAPI_RemapVal ( sRawValue , ctx - > m_SimpleStickExtents [ nStick ] . axis [ nAxis ] . sMin , 0 , SDL_MIN_SINT16 , 0 ) ;
2022-09-26 18:18:16 -07:00
}
2018-08-09 16:00:17 -07:00
}
2019-10-17 17:32:47 -07:00
static Uint8 RemapButton ( SDL_DriverSwitch_Context * ctx , Uint8 button )
{
2025-04-30 15:21:34 -07:00
if ( ctx - > m_bUseButtonLabels ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Use button labels instead of positions, e.g. Nintendo Online Classic controllers
2023-11-06 13:07:12 -08:00
switch ( button ) {
case SDL_GAMEPAD_BUTTON_SOUTH :
return SDL_GAMEPAD_BUTTON_EAST ;
case SDL_GAMEPAD_BUTTON_EAST :
return SDL_GAMEPAD_BUTTON_SOUTH ;
case SDL_GAMEPAD_BUTTON_WEST :
return SDL_GAMEPAD_BUTTON_NORTH ;
case SDL_GAMEPAD_BUTTON_NORTH :
return SDL_GAMEPAD_BUTTON_WEST ;
default :
break ;
2019-10-17 17:32:47 -07:00
}
}
return button ;
}
2022-11-30 12:51:59 -08:00
static int GetMaxWriteAttempts ( SDL_HIDAPI_Device * device )
2022-08-04 00:40:38 -07:00
{
if ( device - > vendor_id = = USB_VENDOR_NINTENDO & &
2022-08-08 08:22:20 -07:00
device - > product_id = = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// This device is a little slow and we know we're always on USB
2022-08-04 00:40:38 -07:00
return 20 ;
} else {
return 5 ;
}
}
2022-11-30 12:51:59 -08:00
static ESwitchDeviceInfoControllerType ReadJoyConControllerType ( SDL_HIDAPI_Device * device )
2022-07-28 21:39:32 -07:00
{
ESwitchDeviceInfoControllerType eControllerType = k_eSwitchDeviceInfoControllerType_Unknown ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
const int MAX_ATTEMPTS = 1 ; // Don't try too long, in case this is a zombie Bluetooth controller
2022-09-22 18:22:17 -07:00
int attempts = 0 ;
2022-07-28 21:39:32 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Create enough of a context to read the controller type from the device
2022-07-28 21:39:32 -07:00
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) SDL_calloc ( 1 , sizeof ( * ctx ) ) ;
if ( ctx ) {
ctx - > device = device ;
2024-08-22 09:21:26 -07:00
ctx - > m_bSyncWrite = true ;
2022-08-04 00:40:38 -07:00
ctx - > m_nMaxWriteAttempts = GetMaxWriteAttempts ( device ) ;
2022-07-28 21:39:32 -07:00
2023-06-21 12:14:50 -07:00
for ( ; ; ) {
+ + attempts ;
if ( device - > is_bluetooth ) {
2022-09-22 18:22:17 -07:00
SwitchSubcommandInputPacket_t * reply = NULL ;
if ( WriteSubcommand ( ctx , k_eSwitchSubcommandIDs_RequestDeviceInfo , NULL , 0 , & reply ) ) {
eControllerType = CalculateControllerType ( ctx , ( ESwitchDeviceInfoControllerType ) reply - > deviceInfo . ucDeviceType ) ;
2022-08-03 22:12:21 -07:00
}
2023-06-21 12:14:50 -07:00
} else {
2024-08-22 09:21:26 -07:00
if ( WriteProprietary ( ctx , k_eSwitchProprietaryCommandIDs_Status , NULL , 0 , true ) ) {
2023-06-21 12:14:50 -07:00
SwitchProprietaryStatusPacket_t * status = ( SwitchProprietaryStatusPacket_t * ) & ctx - > m_rgucReadBuffer [ 0 ] ;
eControllerType = CalculateControllerType ( ctx , ( ESwitchDeviceInfoControllerType ) status - > ucDeviceType ) ;
}
2022-07-28 21:39:32 -07:00
}
2023-06-21 12:14:50 -07:00
if ( eControllerType = = k_eSwitchDeviceInfoControllerType_Unknown & & attempts < MAX_ATTEMPTS ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Wait a bit and try again
2022-09-22 18:22:17 -07:00
SDL_Delay ( 100 ) ;
continue ;
}
2023-06-21 12:14:50 -07:00
break ;
2022-07-28 21:39:32 -07:00
}
SDL_free ( ctx ) ;
}
return eControllerType ;
}
2024-08-22 09:21:26 -07:00
static bool HasHomeLED ( SDL_DriverSwitch_Context * ctx )
2022-08-30 14:56:11 -07:00
{
Uint16 vendor_id = ctx - > device - > vendor_id ;
Uint16 product_id = ctx - > device - > product_id ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// The Power A Nintendo Switch Pro controllers don't have a Home LED
2022-08-30 14:56:11 -07:00
if ( vendor_id = = 0 & & product_id = = 0 ) {
2024-08-22 09:21:26 -07:00
return false ;
2022-08-30 14:56:11 -07:00
}
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// HORI Wireless Switch Pad
2022-08-30 14:56:11 -07:00
if ( vendor_id = = 0x0f0d & & product_id = = 0x00f6 ) {
2024-08-22 09:21:26 -07:00
return false ;
2022-08-30 14:56:11 -07:00
}
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Third party controllers don't have a home LED and will shut off if we try to set it
2023-06-17 12:42:55 -07:00
if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_Unknown | |
ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_LicProController ) {
2024-08-22 09:21:26 -07:00
return false ;
2023-06-14 10:15:06 -07:00
}
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// The Nintendo Online classic controllers don't have a Home LED
2022-08-30 14:56:11 -07:00
if ( vendor_id = = USB_VENDOR_NINTENDO & &
ctx - > m_eControllerType > k_eSwitchDeviceInfoControllerType_ProController ) {
2024-08-22 09:21:26 -07:00
return false ;
2022-08-30 14:56:11 -07:00
}
2024-08-22 09:21:26 -07:00
return true ;
2022-08-30 14:56:11 -07:00
}
2024-08-22 09:21:26 -07:00
static bool AlwaysUsesLabels ( Uint16 vendor_id , Uint16 product_id , ESwitchDeviceInfoControllerType eControllerType )
2022-08-30 14:56:11 -07:00
{
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Some controllers don't have a diamond button configuration, so should always use labels
2025-04-30 15:21:34 -07:00
if ( SDL_IsJoystickGameCube ( vendor_id , product_id ) ) {
return true ;
}
2022-08-30 14:56:11 -07:00
switch ( eControllerType ) {
2023-06-28 19:15:11 -07:00
case k_eSwitchDeviceInfoControllerType_HVCLeft :
case k_eSwitchDeviceInfoControllerType_HVCRight :
2022-08-30 14:56:11 -07:00
case k_eSwitchDeviceInfoControllerType_NESLeft :
case k_eSwitchDeviceInfoControllerType_NESRight :
case k_eSwitchDeviceInfoControllerType_N64 :
case k_eSwitchDeviceInfoControllerType_SEGA_Genesis :
2024-08-22 09:21:26 -07:00
return true ;
2022-08-30 14:56:11 -07:00
default :
2024-08-22 09:21:26 -07:00
return false ;
2022-08-30 14:56:11 -07:00
}
}
2022-11-30 12:51:59 -08:00
static void HIDAPI_DriverNintendoClassic_RegisterHints ( SDL_HintCallback callback , void * userdata )
2022-08-30 14:56:11 -07:00
{
SDL_AddHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC , callback , userdata ) ;
}
2022-11-30 12:51:59 -08:00
static void HIDAPI_DriverNintendoClassic_UnregisterHints ( SDL_HintCallback callback , void * userdata )
2022-08-30 14:56:11 -07:00
{
2024-08-31 07:23:51 -07:00
SDL_RemoveHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC , callback , userdata ) ;
2022-08-30 14:56:11 -07:00
}
2024-08-22 09:21:26 -07:00
static bool HIDAPI_DriverNintendoClassic_IsEnabled ( void )
2022-08-30 14:56:11 -07:00
{
2022-11-27 17:38:43 +01:00
return SDL_GetHintBoolean ( SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC , SDL_GetHintBoolean ( SDL_HINT_JOYSTICK_HIDAPI , SDL_HIDAPI_DEFAULT ) ) ;
2022-08-30 14:56:11 -07:00
}
2024-08-22 09:21:26 -07:00
static bool HIDAPI_DriverNintendoClassic_IsSupportedDevice ( SDL_HIDAPI_Device * device , const char * name , SDL_GamepadType type , Uint16 vendor_id , Uint16 product_id , Uint16 version , int interface_number , int interface_class , int interface_subclass , int interface_protocol )
2022-08-30 14:56:11 -07:00
{
if ( vendor_id = = USB_VENDOR_NINTENDO ) {
if ( product_id = = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT ) {
2023-06-28 19:15:11 -07:00
if ( SDL_strncmp ( name , " NES Controller " , 14 ) = = 0 | |
SDL_strncmp ( name , " HVC Controller " , 14 ) = = 0 ) {
2024-08-22 09:21:26 -07:00
return true ;
2022-08-30 14:56:11 -07:00
}
}
if ( product_id = = USB_PRODUCT_NINTENDO_N64_CONTROLLER ) {
2024-08-22 09:21:26 -07:00
return true ;
2022-08-30 14:56:11 -07:00
}
if ( product_id = = USB_PRODUCT_NINTENDO_SEGA_GENESIS_CONTROLLER ) {
2024-08-22 09:21:26 -07:00
return true ;
2022-08-30 14:56:11 -07:00
}
if ( product_id = = USB_PRODUCT_NINTENDO_SNES_CONTROLLER ) {
2024-08-22 09:21:26 -07:00
return true ;
2022-08-30 14:56:11 -07:00
}
}
2024-08-22 09:21:26 -07:00
return false ;
2022-08-30 14:56:11 -07:00
}
2022-11-30 12:51:59 -08:00
static void HIDAPI_DriverJoyCons_RegisterHints ( SDL_HintCallback callback , void * userdata )
2022-08-30 14:56:11 -07:00
{
SDL_AddHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS , callback , userdata ) ;
}
2022-11-30 12:51:59 -08:00
static void HIDAPI_DriverJoyCons_UnregisterHints ( SDL_HintCallback callback , void * userdata )
2022-08-30 14:56:11 -07:00
{
2024-08-31 07:23:51 -07:00
SDL_RemoveHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS , callback , userdata ) ;
2022-08-30 14:56:11 -07:00
}
2024-08-22 09:21:26 -07:00
static bool HIDAPI_DriverJoyCons_IsEnabled ( void )
2022-08-30 14:56:11 -07:00
{
2022-11-27 17:38:43 +01:00
return SDL_GetHintBoolean ( SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS , SDL_GetHintBoolean ( SDL_HINT_JOYSTICK_HIDAPI , SDL_HIDAPI_DEFAULT ) ) ;
2022-08-30 14:56:11 -07:00
}
2024-08-22 09:21:26 -07:00
static bool HIDAPI_DriverJoyCons_IsSupportedDevice ( SDL_HIDAPI_Device * device , const char * name , SDL_GamepadType type , Uint16 vendor_id , Uint16 product_id , Uint16 version , int interface_number , int interface_class , int interface_subclass , int interface_protocol )
2022-08-30 14:56:11 -07:00
{
if ( vendor_id = = USB_VENDOR_NINTENDO ) {
2022-10-07 11:29:49 -07:00
if ( product_id = = USB_PRODUCT_NINTENDO_SWITCH_PRO & & device & & device - > dev ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// This might be a Kinvoca Joy-Con that reports VID/PID as a Switch Pro controller
2022-08-30 14:56:11 -07:00
ESwitchDeviceInfoControllerType eControllerType = ReadJoyConControllerType ( device ) ;
if ( eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConLeft | |
eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
2024-08-22 09:21:26 -07:00
return true ;
2022-08-30 14:56:11 -07:00
}
}
if ( product_id = = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT | |
product_id = = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT | |
product_id = = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP ) {
2024-08-22 09:21:26 -07:00
return true ;
2022-08-30 14:56:11 -07:00
}
}
2024-08-22 09:21:26 -07:00
return false ;
2022-08-30 14:56:11 -07:00
}
2022-11-30 12:51:59 -08:00
static void HIDAPI_DriverSwitch_RegisterHints ( SDL_HintCallback callback , void * userdata )
2022-08-30 14:56:11 -07:00
{
SDL_AddHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_SWITCH , callback , userdata ) ;
}
2022-11-30 12:51:59 -08:00
static void HIDAPI_DriverSwitch_UnregisterHints ( SDL_HintCallback callback , void * userdata )
2022-08-30 14:56:11 -07:00
{
2024-08-31 07:23:51 -07:00
SDL_RemoveHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_SWITCH , callback , userdata ) ;
2022-08-30 14:56:11 -07:00
}
2024-08-22 09:21:26 -07:00
static bool HIDAPI_DriverSwitch_IsEnabled ( void )
2022-08-30 14:56:11 -07:00
{
2022-11-27 17:38:43 +01:00
return SDL_GetHintBoolean ( SDL_HINT_JOYSTICK_HIDAPI_SWITCH , SDL_GetHintBoolean ( SDL_HINT_JOYSTICK_HIDAPI , SDL_HIDAPI_DEFAULT ) ) ;
2022-08-30 14:56:11 -07:00
}
2024-08-22 09:21:26 -07:00
static bool HIDAPI_DriverSwitch_IsSupportedDevice ( SDL_HIDAPI_Device * device , const char * name , SDL_GamepadType type , Uint16 vendor_id , Uint16 product_id , Uint16 version , int interface_number , int interface_class , int interface_subclass , int interface_protocol )
2022-08-30 14:56:11 -07:00
{
/* The HORI Wireless Switch Pad enumerates as a HID device when connected via USB
with the same VID / PID as when connected over Bluetooth but doesn ' t actually
support communication over USB . The most reliable way to block this without allowing the
Fix remaining typos (#7921)
* Fix remaining typos
Found via `codespell -q 3 -S *.hex,*.pdf,./src/libm,./src/hidapi,./src/stdlib/SDL_malloc.c,./src/video/x11/edid.h -L caf,currenty,datas,einstance,fo,hda,lod,mata,parm,parms,pevent,pevents,pixelx,requestor,ser,statics,te,texturers,thid,uscaled,windowz`
2023-07-03 15:46:47 -04:00
controller to continually attempt to reconnect is to filter it out by manufacturer / product string .
2022-08-30 14:56:11 -07:00
Note that the controller does have a different product string when connected over Bluetooth .
*/
if ( SDL_strcmp ( name , " HORI Wireless Switch Pad " ) = = 0 ) {
2024-08-22 09:21:26 -07:00
return false ;
2022-08-30 14:56:11 -07:00
}
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// If it's handled by another driver, it's not handled here
2022-08-30 14:56:11 -07:00
if ( HIDAPI_DriverNintendoClassic_IsSupportedDevice ( device , name , type , vendor_id , product_id , version , interface_number , interface_class , interface_subclass , interface_protocol ) | |
HIDAPI_DriverJoyCons_IsSupportedDevice ( device , name , type , vendor_id , product_id , version , interface_number , interface_class , interface_subclass , interface_protocol ) ) {
2024-08-22 09:21:26 -07:00
return false ;
2022-08-30 14:56:11 -07:00
}
2025-08-30 09:52:08 -07:00
if ( type ! = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO ) {
return false ;
}
// The Nintendo Switch 2 Pro uses another driver
if ( vendor_id = = USB_VENDOR_NINTENDO & & product_id = = USB_PRODUCT_NINTENDO_SWITCH2_PRO ) {
return false ;
}
return true ;
2022-08-30 14:56:11 -07:00
}
2022-11-30 12:51:59 -08:00
static void UpdateDeviceIdentity ( SDL_HIDAPI_Device * device )
2022-08-03 21:31:12 -07:00
{
2022-09-22 18:22:17 -07:00
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) device - > context ;
2023-11-10 16:11:10 -08:00
if ( ctx - > m_bInputOnly ) {
if ( SDL_IsJoystickGameCube ( device - > vendor_id , device - > product_id ) ) {
2025-04-25 12:19:27 -07:00
device - > type = SDL_GAMEPAD_TYPE_GAMECUBE ;
2023-11-10 16:11:10 -08:00
}
} else {
char serial [ 18 ] ;
switch ( ctx - > m_eControllerType ) {
case k_eSwitchDeviceInfoControllerType_JoyConLeft :
HIDAPI_SetDeviceName ( device , " Nintendo Switch Joy-Con (L) " ) ;
HIDAPI_SetDeviceProduct ( device , USB_VENDOR_NINTENDO , USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT ) ;
device - > type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT ;
break ;
case k_eSwitchDeviceInfoControllerType_JoyConRight :
HIDAPI_SetDeviceName ( device , " Nintendo Switch Joy-Con (R) " ) ;
HIDAPI_SetDeviceProduct ( device , USB_VENDOR_NINTENDO , USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT ) ;
device - > type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT ;
break ;
case k_eSwitchDeviceInfoControllerType_ProController :
case k_eSwitchDeviceInfoControllerType_LicProController :
HIDAPI_SetDeviceName ( device , " Nintendo Switch Pro Controller " ) ;
HIDAPI_SetDeviceProduct ( device , USB_VENDOR_NINTENDO , USB_PRODUCT_NINTENDO_SWITCH_PRO ) ;
device - > type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO ;
break ;
case k_eSwitchDeviceInfoControllerType_HVCLeft :
HIDAPI_SetDeviceName ( device , " Nintendo HVC Controller (1) " ) ;
device - > type = SDL_GAMEPAD_TYPE_STANDARD ;
break ;
case k_eSwitchDeviceInfoControllerType_HVCRight :
HIDAPI_SetDeviceName ( device , " Nintendo HVC Controller (2) " ) ;
device - > type = SDL_GAMEPAD_TYPE_STANDARD ;
break ;
case k_eSwitchDeviceInfoControllerType_NESLeft :
HIDAPI_SetDeviceName ( device , " Nintendo NES Controller (L) " ) ;
device - > type = SDL_GAMEPAD_TYPE_STANDARD ;
break ;
case k_eSwitchDeviceInfoControllerType_NESRight :
HIDAPI_SetDeviceName ( device , " Nintendo NES Controller (R) " ) ;
device - > type = SDL_GAMEPAD_TYPE_STANDARD ;
break ;
case k_eSwitchDeviceInfoControllerType_SNES :
HIDAPI_SetDeviceName ( device , " Nintendo SNES Controller " ) ;
HIDAPI_SetDeviceProduct ( device , USB_VENDOR_NINTENDO , USB_PRODUCT_NINTENDO_SNES_CONTROLLER ) ;
device - > type = SDL_GAMEPAD_TYPE_STANDARD ;
break ;
case k_eSwitchDeviceInfoControllerType_N64 :
HIDAPI_SetDeviceName ( device , " Nintendo N64 Controller " ) ;
HIDAPI_SetDeviceProduct ( device , USB_VENDOR_NINTENDO , USB_PRODUCT_NINTENDO_N64_CONTROLLER ) ;
device - > type = SDL_GAMEPAD_TYPE_STANDARD ;
break ;
case k_eSwitchDeviceInfoControllerType_SEGA_Genesis :
HIDAPI_SetDeviceName ( device , " Nintendo SEGA Genesis Controller " ) ;
HIDAPI_SetDeviceProduct ( device , USB_VENDOR_NINTENDO , USB_PRODUCT_NINTENDO_SEGA_GENESIS_CONTROLLER ) ;
device - > type = SDL_GAMEPAD_TYPE_STANDARD ;
break ;
case k_eSwitchDeviceInfoControllerType_Unknown :
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// We couldn't read the device info for this controller, might not be fully compliant
2024-06-12 23:22:44 -07:00
if ( device - > vendor_id = = USB_VENDOR_NINTENDO ) {
switch ( device - > product_id ) {
case USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT :
ctx - > m_eControllerType = k_eSwitchDeviceInfoControllerType_JoyConLeft ;
HIDAPI_SetDeviceName ( device , " Nintendo Switch Joy-Con (L) " ) ;
device - > type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT ;
break ;
case USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT :
ctx - > m_eControllerType = k_eSwitchDeviceInfoControllerType_JoyConRight ;
HIDAPI_SetDeviceName ( device , " Nintendo Switch Joy-Con (R) " ) ;
device - > type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT ;
break ;
case USB_PRODUCT_NINTENDO_SWITCH_PRO :
ctx - > m_eControllerType = k_eSwitchDeviceInfoControllerType_ProController ;
HIDAPI_SetDeviceName ( device , " Nintendo Switch Pro Controller " ) ;
device - > type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO ;
break ;
default :
break ;
}
}
2023-11-10 16:11:10 -08:00
return ;
default :
device - > type = SDL_GAMEPAD_TYPE_STANDARD ;
break ;
}
device - > guid . data [ 15 ] = ctx - > m_eControllerType ;
( void ) SDL_snprintf ( serial , sizeof ( serial ) , " %.2x-%.2x-%.2x-%.2x-%.2x-%.2x " ,
ctx - > m_rgucMACAddress [ 0 ] ,
ctx - > m_rgucMACAddress [ 1 ] ,
ctx - > m_rgucMACAddress [ 2 ] ,
ctx - > m_rgucMACAddress [ 3 ] ,
ctx - > m_rgucMACAddress [ 4 ] ,
ctx - > m_rgucMACAddress [ 5 ] ) ;
HIDAPI_SetDeviceSerial ( device , serial ) ;
2022-08-03 21:31:12 -07:00
}
}
2024-08-22 09:21:26 -07:00
static bool HIDAPI_DriverSwitch_InitDevice ( SDL_HIDAPI_Device * device )
2019-12-19 15:01:30 -08:00
{
2022-09-22 18:22:17 -07:00
SDL_DriverSwitch_Context * ctx ;
ctx = ( SDL_DriverSwitch_Context * ) SDL_calloc ( 1 , sizeof ( * ctx ) ) ;
2023-11-09 22:29:15 +01:00
if ( ! ctx ) {
2024-08-22 09:21:26 -07:00
return false ;
2022-09-22 18:22:17 -07:00
}
ctx - > device = device ;
device - > context = ctx ;
ctx - > m_nMaxWriteAttempts = GetMaxWriteAttempts ( device ) ;
2024-08-22 09:21:26 -07:00
ctx - > m_bSyncWrite = true ;
2022-09-22 18:22:17 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Find out whether or not we can send output reports
2022-09-22 18:22:17 -07:00
ctx - > m_bInputOnly = SDL_IsJoystickNintendoSwitchProInputOnly ( device - > vendor_id , device - > product_id ) ;
if ( ! ctx - > m_bInputOnly ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Initialize rumble data, important for reading device info on the MOBAPAD M073
2025-11-20 09:24:07 -08:00
SetNeutralRumble ( device , & ctx - > m_RumblePacket . rumbleData [ 0 ] ) ;
SetNeutralRumble ( device , & ctx - > m_RumblePacket . rumbleData [ 1 ] ) ;
2023-06-09 18:41:21 -07:00
2023-06-17 12:42:55 -07:00
BReadDeviceInfo ( ctx ) ;
2022-07-28 21:39:32 -07:00
}
2023-11-10 16:11:10 -08:00
UpdateDeviceIdentity ( device ) ;
2022-09-22 18:22:17 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Prefer the USB device over the Bluetooth device
2022-09-26 14:20:34 -07:00
if ( device - > is_bluetooth ) {
if ( HIDAPI_HasConnectedUSBDevice ( device - > serial ) ) {
2024-08-22 09:21:26 -07:00
return true ;
2022-09-26 14:20:34 -07:00
}
} else {
HIDAPI_DisconnectBluetoothDevice ( device - > serial ) ;
}
2020-11-23 18:24:05 -08:00
return HIDAPI_JoystickConnected ( device , NULL ) ;
2019-12-19 15:01:30 -08:00
}
2022-11-30 12:51:59 -08:00
static int HIDAPI_DriverSwitch_GetDevicePlayerIndex ( SDL_HIDAPI_Device * device , SDL_JoystickID instance_id )
2019-12-20 20:12:03 -08:00
{
return - 1 ;
}
2022-11-30 12:51:59 -08:00
static void HIDAPI_DriverSwitch_SetDevicePlayerIndex ( SDL_HIDAPI_Device * device , SDL_JoystickID instance_id , int player_index )
2019-12-20 20:12:03 -08:00
{
2022-08-06 10:34:19 -07:00
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) device - > context ;
2022-09-22 18:22:17 -07:00
if ( ! ctx - > joystick ) {
2022-08-06 10:34:19 -07:00
return ;
}
ctx - > m_nPlayerIndex = player_index ;
UpdateSlotLED ( ctx ) ;
2019-12-20 20:12:03 -08:00
}
2024-08-22 09:21:26 -07:00
static bool HIDAPI_DriverSwitch_OpenJoystick ( SDL_HIDAPI_Device * device , SDL_Joystick * joystick )
2018-08-09 16:00:17 -07:00
{
2022-09-22 18:22:17 -07:00
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) device - > context ;
2018-08-09 16:00:17 -07:00
2022-12-13 14:03:40 -08:00
SDL_AssertJoysticksLocked ( ) ;
2022-09-22 18:22:17 -07:00
ctx - > joystick = joystick ;
2018-08-09 16:00:17 -07:00
2024-08-22 09:21:26 -07:00
ctx - > m_bSyncWrite = true ;
2018-08-09 16:00:17 -07:00
2019-10-17 17:32:47 -07:00
if ( ! ctx - > m_bInputOnly ) {
2025-02-26 11:21:34 -08:00
# ifdef SDL_PLATFORM_MACOS
// Wait for the OS to finish its handshake with the controller
SDL_Delay ( 250 ) ;
# endif
2024-07-06 05:29:12 -07:00
GetInitialInputMode ( ctx ) ;
2023-12-24 08:12:14 -08:00
ctx - > m_nCurrentInputMode = ctx - > m_nInitialInputMode ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Initialize rumble data
2025-11-20 09:24:07 -08:00
SetNeutralRumble ( device , & ctx - > m_RumblePacket . rumbleData [ 0 ] ) ;
SetNeutralRumble ( device , & ctx - > m_RumblePacket . rumbleData [ 1 ] ) ;
2018-08-09 16:00:17 -07:00
2022-09-26 14:20:34 -07:00
if ( ! device - > is_bluetooth ) {
2021-01-14 23:49:41 -08:00
if ( ! BTrySetupUSB ( ctx ) ) {
SDL_SetError ( " Couldn't setup USB mode " ) ;
2024-08-22 09:21:26 -07:00
return false ;
2021-01-14 23:49:41 -08:00
}
2019-10-17 16:59:05 -07:00
}
2018-08-09 16:00:17 -07:00
2023-06-17 12:42:55 -07:00
if ( ! LoadStickCalibration ( ctx ) ) {
SDL_SetError ( " Couldn't load stick calibration " ) ;
2024-08-22 09:21:26 -07:00
return false ;
2023-06-17 12:42:55 -07:00
}
2023-06-28 19:15:11 -07:00
if ( ctx - > m_eControllerType ! = k_eSwitchDeviceInfoControllerType_HVCLeft & &
ctx - > m_eControllerType ! = k_eSwitchDeviceInfoControllerType_HVCRight & &
ctx - > m_eControllerType ! = k_eSwitchDeviceInfoControllerType_NESLeft & &
2022-08-03 21:31:12 -07:00
ctx - > m_eControllerType ! = k_eSwitchDeviceInfoControllerType_NESRight & &
ctx - > m_eControllerType ! = k_eSwitchDeviceInfoControllerType_SNES & &
ctx - > m_eControllerType ! = k_eSwitchDeviceInfoControllerType_N64 & &
2025-07-15 17:41:32 -07:00
ctx - > m_eControllerType ! = k_eSwitchDeviceInfoControllerType_SEGA_Genesis & &
! ( device - > vendor_id = = USB_VENDOR_PDP & & device - > product_id = = USB_PRODUCT_PDP_REALMZ_WIRELESS ) ) {
2023-06-17 12:42:55 -07:00
if ( LoadIMUCalibration ( ctx ) ) {
2025-01-02 14:27:38 -08:00
ctx - > m_bSensorsSupported = true ;
2022-07-28 19:22:27 -07:00
}
2021-01-11 15:36:40 +08:00
}
2020-03-22 11:01:14 -07:00
2025-01-02 14:27:38 -08:00
// Enable vibration
SetVibrationEnabled ( ctx , 1 ) ;
2018-08-09 16:00:17 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Set desired input mode
2025-01-02 14:27:38 -08:00
SDL_AddHintCallback ( SDL_HINT_JOYSTICK_ENHANCED_REPORTS ,
SDL_EnhancedReportsChanged , ctx ) ;
2018-08-09 16:00:17 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Start sending USB reports
2022-09-26 14:20:34 -07:00
if ( ! device - > is_bluetooth ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// ForceUSB doesn't generate an ACK, so don't wait for a reply
2024-08-22 09:21:26 -07:00
if ( ! WriteProprietary ( ctx , k_eSwitchProprietaryCommandIDs_ForceUSB , NULL , 0 , false ) ) {
2019-10-17 16:59:05 -07:00
SDL_SetError ( " Couldn't start USB reports " ) ;
2024-08-22 09:21:26 -07:00
return false ;
2019-10-17 16:59:05 -07:00
}
}
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Set the LED state
2022-08-09 13:41:58 -07:00
if ( HasHomeLED ( ctx ) ) {
if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConLeft | |
ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
SDL_AddHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED ,
SDL_HomeLEDHintChanged , ctx ) ;
} else {
SDL_AddHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED ,
SDL_HomeLEDHintChanged , ctx ) ;
}
2019-10-22 10:57:07 -07:00
}
2019-10-17 17:32:47 -07:00
}
2025-04-30 15:21:34 -07:00
if ( AlwaysUsesLabels ( device - > vendor_id , device - > product_id , ctx - > m_eControllerType ) ) {
2024-08-22 09:21:26 -07:00
ctx - > m_bUseButtonLabels = true ;
2022-06-10 11:31:59 -07:00
}
2020-03-10 17:35:14 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Initialize player index (needed for setting LEDs)
2022-12-27 05:50:46 -08:00
ctx - > m_nPlayerIndex = SDL_GetJoystickPlayerIndex ( joystick ) ;
2024-08-22 09:21:26 -07:00
ctx - > m_bPlayerLights = SDL_GetHintBoolean ( SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED , true ) ;
2022-08-06 10:34:19 -07:00
UpdateSlotLED ( ctx ) ;
SDL_AddHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED ,
SDL_PlayerLEDHintChanged , ctx ) ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Initialize the joystick capabilities
2023-12-27 11:28:27 -08:00
joystick - > nbuttons = SDL_GAMEPAD_NUM_SWITCH_BUTTONS ;
2024-09-11 08:08:18 -07:00
joystick - > naxes = SDL_GAMEPAD_AXIS_COUNT ;
2023-12-27 11:28:27 -08:00
joystick - > nhats = 1 ;
2018-08-09 16:00:17 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Set up for input
2024-08-22 09:21:26 -07:00
ctx - > m_bSyncWrite = false ;
2022-12-02 01:17:17 -08:00
ctx - > m_ulLastIMUReset = ctx - > m_ulLastInput = SDL_GetTicks ( ) ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
ctx - > m_ulIMUUpdateIntervalNS = SDL_MS_TO_NS ( 5 ) ; // Start off at 5 ms update rate
2022-08-09 17:58:42 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Set up for vertical mode
2024-08-22 09:21:26 -07:00
ctx - > m_bVerticalMode = SDL_GetHintBoolean ( SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS , false ) ;
2022-10-03 00:19:34 +08:00
2024-08-22 09:21:26 -07:00
return true ;
2018-08-09 16:00:17 -07:00
}
2024-08-22 17:33:49 -07:00
static bool HIDAPI_DriverSwitch_ActuallyRumbleJoystick ( SDL_DriverSwitch_Context * ctx , Uint16 low_frequency_rumble , Uint16 high_frequency_rumble )
2018-08-09 16:00:17 -07:00
{
/* Experimentally determined rumble values. These will only matter on some controllers as tested ones
* seem to disregard these and just use any non - zero rumble values as a binary flag for constant rumble
*
* More information about these values can be found here :
* https : //github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md
*/
2021-11-07 11:48:16 -08:00
const Uint16 k_usHighFreq = 0x0074 ;
2022-11-30 12:51:59 -08:00
const Uint8 k_ucHighFreqAmp = EncodeRumbleHighAmplitude ( high_frequency_rumble ) ;
const Uint8 k_ucLowFreq = 0x3D ;
2021-11-07 11:48:16 -08:00
const Uint16 k_usLowFreqAmp = EncodeRumbleLowAmplitude ( low_frequency_rumble ) ;
2018-08-09 16:00:17 -07:00
2021-07-26 10:18:18 -07:00
if ( low_frequency_rumble | | high_frequency_rumble ) {
2025-11-20 09:24:07 -08:00
EncodeRumble ( ctx - > device , & ctx - > m_RumblePacket . rumbleData [ 0 ] , k_usHighFreq , k_ucHighFreqAmp , k_ucLowFreq , k_usLowFreqAmp ) ;
EncodeRumble ( ctx - > device , & ctx - > m_RumblePacket . rumbleData [ 1 ] , k_usHighFreq , k_ucHighFreqAmp , k_ucLowFreq , k_usLowFreqAmp ) ;
2018-08-09 16:00:17 -07:00
} else {
2025-11-20 09:24:07 -08:00
SetNeutralRumble ( ctx - > device , & ctx - > m_RumblePacket . rumbleData [ 0 ] ) ;
SetNeutralRumble ( ctx - > device , & ctx - > m_RumblePacket . rumbleData [ 1 ] ) ;
2018-08-09 16:00:17 -07:00
}
2023-11-03 09:27:29 -07:00
ctx - > m_bRumbleActive = ( low_frequency_rumble | | high_frequency_rumble ) ;
2021-07-26 10:18:18 -07:00
2018-08-09 16:00:17 -07:00
if ( ! WriteRumble ( ctx ) ) {
2022-01-17 17:22:30 +01:00
return SDL_SetError ( " Couldn't send rumble packet " ) ;
2018-08-09 16:00:17 -07:00
}
2024-08-22 17:33:49 -07:00
return true ;
2018-08-09 16:00:17 -07:00
}
2024-08-22 17:33:49 -07:00
static bool HIDAPI_DriverSwitch_SendPendingRumble ( SDL_DriverSwitch_Context * ctx )
2020-04-17 15:08:48 -07:00
{
2022-12-02 01:17:17 -08:00
if ( SDL_GetTicks ( ) < ( ctx - > m_ulRumbleSent + RUMBLE_WRITE_FREQUENCY_MS ) ) {
2024-08-22 17:33:49 -07:00
return true ;
2020-04-17 15:08:48 -07:00
}
if ( ctx - > m_bRumblePending ) {
2021-07-26 10:18:18 -07:00
Uint16 low_frequency_rumble = ( Uint16 ) ( ctx - > m_unRumblePending > > 16 ) ;
Uint16 high_frequency_rumble = ( Uint16 ) ctx - > m_unRumblePending ;
2020-04-17 15:08:48 -07:00
# ifdef DEBUG_RUMBLE
2025-01-22 12:59:57 -08:00
SDL_Log ( " Sent pending rumble %d/%d, %d ms after previous rumble " , low_frequency_rumble , high_frequency_rumble , SDL_GetTicks ( ) - ctx - > m_ulRumbleSent ) ;
2020-04-17 15:08:48 -07:00
# endif
2024-08-22 09:21:26 -07:00
ctx - > m_bRumblePending = false ;
2020-04-17 15:08:48 -07:00
ctx - > m_unRumblePending = 0 ;
2021-07-26 10:18:18 -07:00
return HIDAPI_DriverSwitch_ActuallyRumbleJoystick ( ctx , low_frequency_rumble , high_frequency_rumble ) ;
2020-04-17 15:08:48 -07:00
}
if ( ctx - > m_bRumbleZeroPending ) {
2024-08-22 09:21:26 -07:00
ctx - > m_bRumbleZeroPending = false ;
2020-04-17 15:08:48 -07:00
# ifdef DEBUG_RUMBLE
2025-01-22 12:59:57 -08:00
SDL_Log ( " Sent pending zero rumble, %d ms after previous rumble " , SDL_GetTicks ( ) - ctx - > m_ulRumbleSent ) ;
2020-04-17 15:08:48 -07:00
# endif
2021-07-26 10:18:18 -07:00
return HIDAPI_DriverSwitch_ActuallyRumbleJoystick ( ctx , 0 , 0 ) ;
2020-04-17 15:08:48 -07:00
}
2024-08-22 17:33:49 -07:00
return true ;
2020-04-17 15:08:48 -07:00
}
2024-08-22 17:33:49 -07:00
static bool HIDAPI_DriverSwitch_RumbleJoystick ( SDL_HIDAPI_Device * device , SDL_Joystick * joystick , Uint16 low_frequency_rumble , Uint16 high_frequency_rumble )
2020-04-17 15:08:48 -07:00
{
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) device - > context ;
2021-07-24 19:43:56 -07:00
if ( ctx - > m_bInputOnly ) {
return SDL_Unsupported ( ) ;
}
2022-07-28 19:22:27 -07:00
if ( device - > parent ) {
if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConLeft ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Just handle low frequency rumble
2022-07-28 19:22:27 -07:00
high_frequency_rumble = 0 ;
} else if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Just handle high frequency rumble
2022-07-28 19:22:27 -07:00
low_frequency_rumble = 0 ;
}
}
2020-04-17 15:08:48 -07:00
if ( ctx - > m_bRumblePending ) {
2024-08-22 17:33:49 -07:00
if ( ! HIDAPI_DriverSwitch_SendPendingRumble ( ctx ) ) {
return false ;
2020-04-17 15:08:48 -07:00
}
}
2022-12-02 01:17:17 -08:00
if ( SDL_GetTicks ( ) < ( ctx - > m_ulRumbleSent + RUMBLE_WRITE_FREQUENCY_MS ) ) {
2021-07-26 10:18:18 -07:00
if ( low_frequency_rumble | | high_frequency_rumble ) {
Uint32 unRumblePending = ( ( Uint32 ) low_frequency_rumble < < 16 ) | high_frequency_rumble ;
2020-04-17 15:08:48 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Keep the highest rumble intensity in the given interval
2020-04-17 15:08:48 -07:00
if ( unRumblePending > ctx - > m_unRumblePending ) {
ctx - > m_unRumblePending = unRumblePending ;
}
2024-08-22 09:21:26 -07:00
ctx - > m_bRumblePending = true ;
ctx - > m_bRumbleZeroPending = false ;
2020-04-17 15:08:48 -07:00
} else {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// When rumble is complete, turn it off
2024-08-22 09:21:26 -07:00
ctx - > m_bRumbleZeroPending = true ;
2020-04-17 15:08:48 -07:00
}
2024-08-22 17:33:49 -07:00
return true ;
2020-04-17 15:08:48 -07:00
}
# ifdef DEBUG_RUMBLE
2025-01-22 12:59:57 -08:00
SDL_Log ( " Sent rumble %d/%d " , low_frequency_rumble , high_frequency_rumble ) ;
2020-04-17 15:08:48 -07:00
# endif
2021-07-26 10:18:18 -07:00
return HIDAPI_DriverSwitch_ActuallyRumbleJoystick ( ctx , low_frequency_rumble , high_frequency_rumble ) ;
2020-04-17 15:08:48 -07:00
}
2024-08-22 17:33:49 -07:00
static bool HIDAPI_DriverSwitch_RumbleJoystickTriggers ( SDL_HIDAPI_Device * device , SDL_Joystick * joystick , Uint16 left_rumble , Uint16 right_rumble )
2020-11-11 18:57:37 -08:00
{
return SDL_Unsupported ( ) ;
}
2022-11-30 12:51:59 -08:00
static Uint32 HIDAPI_DriverSwitch_GetJoystickCapabilities ( SDL_HIDAPI_Device * device , SDL_Joystick * joystick )
2020-11-05 11:07:54 -08:00
{
2021-11-11 12:12:05 -06:00
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) device - > context ;
Uint32 result = 0 ;
2024-01-22 19:07:33 -08:00
if ( ctx - > m_bPlayerLights & & ! ctx - > m_bInputOnly ) {
result | = SDL_JOYSTICK_CAP_PLAYER_LED ;
}
2023-02-20 18:24:52 -08:00
if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_ProController & & ! ctx - > m_bInputOnly ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Doesn't have an RGB LED, so don't return SDL_JOYSTICK_CAP_RGB_LED here
2024-01-22 19:07:33 -08:00
result | = SDL_JOYSTICK_CAP_RUMBLE ;
2026-01-24 11:51:39 +05:00
// But has the HOME LED, so treat it like a mono LED
result | = SDL_JOYSTICK_CAP_MONO_LED ;
2023-02-20 17:14:18 -08:00
} else if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConLeft | |
ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
2024-01-22 19:07:33 -08:00
result | = SDL_JOYSTICK_CAP_RUMBLE ;
2026-01-24 11:51:39 +05:00
if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
result | = SDL_JOYSTICK_CAP_MONO_LED ; // Right JoyCon also have the HOME LED
}
2021-11-11 12:12:05 -06:00
}
return result ;
2020-11-05 11:07:54 -08:00
}
2024-08-22 17:33:49 -07:00
static bool HIDAPI_DriverSwitch_SetJoystickLED ( SDL_HIDAPI_Device * device , SDL_Joystick * joystick , Uint8 red , Uint8 green , Uint8 blue )
2020-04-30 11:57:29 -04:00
{
2026-01-24 11:51:39 +05:00
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) device - > context ;
if ( ! ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_ProController & & ! ctx - > m_bInputOnly ) & &
ctx - > m_eControllerType ! = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
return SDL_Unsupported ( ) ;
}
int value = ( int ) ( ( SDL_max ( red , SDL_max ( green , blue ) ) / 255.0f ) * 100.0f ) ; // The colors are received between 0-255 and we need them to be 0-100
return SetHomeLED ( ctx , ( Uint8 ) value ) ;
2020-04-30 11:57:29 -04:00
}
2024-08-22 17:33:49 -07:00
static bool HIDAPI_DriverSwitch_SendJoystickEffect ( SDL_HIDAPI_Device * device , SDL_Joystick * joystick , const void * data , int size )
2021-07-08 13:22:41 -07:00
{
2023-05-09 17:08:47 -07:00
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) device - > context ;
if ( size = = sizeof ( SwitchCommonOutputPacket_t ) ) {
const SwitchCommonOutputPacket_t * packet = ( SwitchCommonOutputPacket_t * ) data ;
if ( packet - > ucPacketType ! = k_eSwitchOutputReportIDs_Rumble ) {
return SDL_SetError ( " Unknown Nintendo Switch Pro effect type " ) ;
}
SDL_copyp ( & ctx - > m_RumblePacket . rumbleData [ 0 ] , & packet - > rumbleData [ 0 ] ) ;
SDL_copyp ( & ctx - > m_RumblePacket . rumbleData [ 1 ] , & packet - > rumbleData [ 1 ] ) ;
if ( ! WriteRumble ( ctx ) ) {
2024-08-22 17:33:49 -07:00
return false ;
2023-05-09 17:08:47 -07:00
}
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// This overwrites any internal rumble
2024-08-22 09:21:26 -07:00
ctx - > m_bRumblePending = false ;
ctx - > m_bRumbleZeroPending = false ;
2024-08-22 17:33:49 -07:00
return true ;
2023-06-02 15:52:56 -07:00
} else if ( size > = 2 & & size < = 256 ) {
const Uint8 * payload = ( const Uint8 * ) data ;
ESwitchSubcommandIDs cmd = ( ESwitchSubcommandIDs ) payload [ 0 ] ;
if ( cmd = = k_eSwitchSubcommandIDs_SetInputReportMode & & ! device - > is_bluetooth ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Going into simple mode over USB disables input reports, so don't do that
2024-08-22 17:33:49 -07:00
return true ;
2023-06-02 15:52:56 -07:00
}
2023-06-14 00:02:32 -07:00
if ( cmd = = k_eSwitchSubcommandIDs_SetHomeLight & & ! HasHomeLED ( ctx ) ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Setting the home LED when it's not supported can cause the controller to reset
2024-08-22 17:33:49 -07:00
return true ;
2023-06-14 00:02:32 -07:00
}
2023-06-02 15:52:56 -07:00
if ( ! WriteSubcommand ( ctx , cmd , & payload [ 1 ] , ( Uint8 ) ( size - 1 ) , NULL ) ) {
2024-08-22 17:33:49 -07:00
return false ;
2023-06-02 15:52:56 -07:00
}
2024-08-22 17:33:49 -07:00
return true ;
2023-05-09 17:08:47 -07:00
}
2021-07-26 10:18:18 -07:00
return SDL_Unsupported ( ) ;
2021-07-08 13:22:41 -07:00
}
2024-08-22 17:33:49 -07:00
static bool HIDAPI_DriverSwitch_SetJoystickSensorsEnabled ( SDL_HIDAPI_Device * device , SDL_Joystick * joystick , bool enabled )
2020-11-17 10:30:20 -08:00
{
2022-11-30 12:51:59 -08:00
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) device - > context ;
2023-06-13 22:40:51 -07:00
2025-01-02 14:27:38 -08:00
UpdateEnhancedModeOnApplicationUsage ( ctx ) ;
if ( ! ctx - > m_bSensorsSupported | | ( enabled & & ! ctx - > m_bEnhancedMode ) ) {
return SDL_Unsupported ( ) ;
2023-06-13 22:40:51 -07:00
}
2022-11-30 12:51:59 -08:00
2021-01-11 15:36:40 +08:00
ctx - > m_bReportSensors = enabled ;
2022-09-27 12:34:03 -07:00
ctx - > m_unIMUSamples = 0 ;
2022-12-02 01:17:17 -08:00
ctx - > m_ulIMUSampleTimestampNS = SDL_GetTicksNS ( ) ;
2021-01-11 15:36:40 +08:00
2025-01-02 14:27:38 -08:00
UpdateInputMode ( ctx ) ;
SetIMUEnabled ( ctx , enabled ) ;
2024-08-22 17:33:49 -07:00
return true ;
2021-01-11 15:36:40 +08:00
}
2019-10-17 16:59:05 -07:00
static void HandleInputOnlyControllerState ( SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SwitchInputOnlyControllerStatePacket_t * packet )
{
Sint16 axis ;
2022-12-03 11:15:50 -08:00
Uint64 timestamp = SDL_GetTicksNS ( ) ;
2019-10-17 16:59:05 -07:00
if ( packet - > rgucButtons [ 0 ] ! = ctx - > m_lastInputOnlyState . rgucButtons [ 0 ] ) {
Uint8 data = packet - > rgucButtons [ 0 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_SOUTH ) , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_EAST ) , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_WEST ) , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_NORTH ) , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_SHOULDER , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER , ( ( data & 0x20 ) ! = 0 ) ) ;
2019-10-17 16:59:05 -07:00
}
if ( packet - > rgucButtons [ 1 ] ! = ctx - > m_lastInputOnlyState . rgucButtons [ 1 ] ) {
Uint8 data = packet - > rgucButtons [ 1 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_BACK , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_START , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_STICK , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_STICK , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_GUIDE , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_SHARE , ( ( data & 0x20 ) ! = 0 ) ) ;
2019-10-17 16:59:05 -07:00
}
if ( packet - > ucStickHat ! = ctx - > m_lastInputOnlyState . ucStickHat ) {
2023-12-27 11:28:27 -08:00
Uint8 hat ;
2019-10-17 16:59:05 -07:00
switch ( packet - > ucStickHat ) {
case 0 :
2023-12-27 11:28:27 -08:00
hat = SDL_HAT_UP ;
2019-10-17 16:59:05 -07:00
break ;
case 1 :
2023-12-27 11:28:27 -08:00
hat = SDL_HAT_RIGHTUP ;
2019-10-17 16:59:05 -07:00
break ;
case 2 :
2023-12-27 11:28:27 -08:00
hat = SDL_HAT_RIGHT ;
2019-10-17 16:59:05 -07:00
break ;
case 3 :
2023-12-27 11:28:27 -08:00
hat = SDL_HAT_RIGHTDOWN ;
2019-10-17 16:59:05 -07:00
break ;
case 4 :
2023-12-27 11:28:27 -08:00
hat = SDL_HAT_DOWN ;
2019-10-17 16:59:05 -07:00
break ;
case 5 :
2023-12-27 11:28:27 -08:00
hat = SDL_HAT_LEFTDOWN ;
2019-10-17 16:59:05 -07:00
break ;
case 6 :
2023-12-27 11:28:27 -08:00
hat = SDL_HAT_LEFT ;
2019-10-17 16:59:05 -07:00
break ;
case 7 :
2023-12-27 11:28:27 -08:00
hat = SDL_HAT_LEFTUP ;
2019-10-17 16:59:05 -07:00
break ;
default :
2023-12-27 11:28:27 -08:00
hat = SDL_HAT_CENTERED ;
2019-10-17 16:59:05 -07:00
break ;
}
2023-12-27 11:28:27 -08:00
SDL_SendJoystickHat ( timestamp , joystick , 0 , hat ) ;
2019-10-17 16:59:05 -07:00
}
2024-06-13 11:25:01 -07:00
axis = ( packet - > rgucButtons [ 0 ] & 0x40 ) ? 32767 : - 32768 ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFT_TRIGGER , axis ) ;
axis = ( packet - > rgucButtons [ 0 ] & 0x80 ) ? 32767 : - 32768 ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHT_TRIGGER , axis ) ;
2019-10-17 16:59:05 -07:00
if ( packet - > rgucJoystickLeft [ 0 ] ! = ctx - > m_lastInputOnlyState . rgucJoystickLeft [ 0 ] ) {
2021-01-23 11:21:01 -08:00
axis = ( Sint16 ) HIDAPI_RemapVal ( packet - > rgucJoystickLeft [ 0 ] , SDL_MIN_UINT8 , SDL_MAX_UINT8 , SDL_MIN_SINT16 , SDL_MAX_SINT16 ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , axis ) ;
2019-10-17 16:59:05 -07:00
}
if ( packet - > rgucJoystickLeft [ 1 ] ! = ctx - > m_lastInputOnlyState . rgucJoystickLeft [ 1 ] ) {
2021-01-23 11:21:01 -08:00
axis = ( Sint16 ) HIDAPI_RemapVal ( packet - > rgucJoystickLeft [ 1 ] , SDL_MIN_UINT8 , SDL_MAX_UINT8 , SDL_MIN_SINT16 , SDL_MAX_SINT16 ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , axis ) ;
2019-10-17 16:59:05 -07:00
}
if ( packet - > rgucJoystickRight [ 0 ] ! = ctx - > m_lastInputOnlyState . rgucJoystickRight [ 0 ] ) {
2021-01-23 11:21:01 -08:00
axis = ( Sint16 ) HIDAPI_RemapVal ( packet - > rgucJoystickRight [ 0 ] , SDL_MIN_UINT8 , SDL_MAX_UINT8 , SDL_MIN_SINT16 , SDL_MAX_SINT16 ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , axis ) ;
2019-10-17 16:59:05 -07:00
}
if ( packet - > rgucJoystickRight [ 1 ] ! = ctx - > m_lastInputOnlyState . rgucJoystickRight [ 1 ] ) {
2021-01-23 11:21:01 -08:00
axis = ( Sint16 ) HIDAPI_RemapVal ( packet - > rgucJoystickRight [ 1 ] , SDL_MIN_UINT8 , SDL_MAX_UINT8 , SDL_MIN_SINT16 , SDL_MAX_SINT16 ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , axis ) ;
2019-10-17 16:59:05 -07:00
}
ctx - > m_lastInputOnlyState = * packet ;
}
2024-06-12 22:28:47 -07:00
static void HandleCombinedSimpleControllerStateL ( Uint64 timestamp , SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SwitchSimpleStatePacket_t * packet )
2018-08-09 16:00:17 -07:00
{
2024-06-12 22:28:47 -07:00
if ( packet - > rgucButtons [ 0 ] ! = ctx - > m_lastSimpleState . rgucButtons [ 0 ] ) {
Uint8 data = packet - > rgucButtons [ 0 ] ;
Uint8 hat = 0 ;
if ( data & 0x01 ) {
hat | = SDL_HAT_LEFT ;
}
if ( data & 0x02 ) {
hat | = SDL_HAT_DOWN ;
}
if ( data & 0x04 ) {
hat | = SDL_HAT_UP ;
}
if ( data & 0x08 ) {
hat | = SDL_HAT_RIGHT ;
}
SDL_SendJoystickHat ( timestamp , joystick , 0 , hat ) ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1 , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2 , ( ( data & 0x20 ) ! = 0 ) ) ;
2024-06-12 22:28:47 -07:00
}
if ( packet - > rgucButtons [ 1 ] ! = ctx - > m_lastSimpleState . rgucButtons [ 1 ] ) {
Uint8 data = packet - > rgucButtons [ 1 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_BACK , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_STICK , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_SHARE , ( ( data & 0x20 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_SHOULDER , ( ( data & 0x40 ) ! = 0 ) ) ;
2024-06-12 22:28:47 -07:00
}
Sint16 axis = ( packet - > rgucButtons [ 1 ] & 0x80 ) ? 32767 : - 32768 ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFT_TRIGGER , axis ) ;
if ( packet - > ucStickHat ! = ctx - > m_lastSimpleState . ucStickHat ) {
switch ( packet - > ucStickHat ) {
case 0 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , 0 ) ;
break ;
case 1 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MAX ) ;
break ;
case 2 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MAX ) ;
break ;
case 3 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MAX ) ;
break ;
case 4 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , 0 ) ;
break ;
case 5 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MIN ) ;
break ;
case 6 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MIN ) ;
break ;
case 7 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MIN ) ;
break ;
default :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , 0 ) ;
break ;
}
}
}
static void HandleCombinedSimpleControllerStateR ( Uint64 timestamp , SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SwitchSimpleStatePacket_t * packet )
{
if ( packet - > rgucButtons [ 0 ] ! = ctx - > m_lastSimpleState . rgucButtons [ 0 ] ) {
Uint8 data = packet - > rgucButtons [ 0 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_EAST ) , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_NORTH ) , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_SOUTH ) , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_WEST ) , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2 , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1 , ( ( data & 0x20 ) ! = 0 ) ) ;
2024-06-12 22:28:47 -07:00
}
if ( packet - > rgucButtons [ 1 ] ! = ctx - > m_lastSimpleState . rgucButtons [ 1 ] ) {
Uint8 data = packet - > rgucButtons [ 1 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_START , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_STICK , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_GUIDE , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER , ( ( data & 0x40 ) ! = 0 ) ) ;
2024-06-12 22:28:47 -07:00
}
2018-08-09 16:00:17 -07:00
2024-06-12 22:28:47 -07:00
Sint16 axis = ( packet - > rgucButtons [ 1 ] & 0x80 ) ? 32767 : - 32768 ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHT_TRIGGER , axis ) ;
if ( packet - > ucStickHat ! = ctx - > m_lastSimpleState . ucStickHat ) {
switch ( packet - > ucStickHat ) {
case 0 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , 0 ) ;
break ;
case 1 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , SDL_JOYSTICK_AXIS_MIN ) ;
break ;
case 2 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , SDL_JOYSTICK_AXIS_MIN ) ;
break ;
case 3 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , SDL_JOYSTICK_AXIS_MIN ) ;
break ;
case 4 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , 0 ) ;
break ;
case 5 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , SDL_JOYSTICK_AXIS_MAX ) ;
break ;
case 6 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , SDL_JOYSTICK_AXIS_MAX ) ;
break ;
case 7 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , SDL_JOYSTICK_AXIS_MAX ) ;
break ;
default :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , 0 ) ;
break ;
}
}
}
static void HandleMiniSimpleControllerStateL ( Uint64 timestamp , SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SwitchSimpleStatePacket_t * packet )
{
2018-08-09 16:00:17 -07:00
if ( packet - > rgucButtons [ 0 ] ! = ctx - > m_lastSimpleState . rgucButtons [ 0 ] ) {
Uint8 data = packet - > rgucButtons [ 0 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_SOUTH ) , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_EAST ) , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_WEST ) , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_NORTH ) , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_SHOULDER , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER , ( ( data & 0x20 ) ! = 0 ) ) ;
2024-06-12 22:28:47 -07:00
}
2018-08-09 16:00:17 -07:00
2024-06-12 22:28:47 -07:00
if ( packet - > rgucButtons [ 1 ] ! = ctx - > m_lastSimpleState . rgucButtons [ 1 ] ) {
Uint8 data = packet - > rgucButtons [ 1 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_START , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_STICK , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_GUIDE , ( ( data & 0x20 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1 , ( ( data & 0x40 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2 , ( ( data & 0x80 ) ! = 0 ) ) ;
2024-06-12 22:28:47 -07:00
}
2018-08-09 16:00:17 -07:00
2024-06-12 22:28:47 -07:00
if ( packet - > ucStickHat ! = ctx - > m_lastSimpleState . ucStickHat ) {
switch ( packet - > ucStickHat ) {
case 0 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MIN ) ;
break ;
case 1 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MIN ) ;
break ;
case 2 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , 0 ) ;
break ;
case 3 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MAX ) ;
break ;
case 4 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MAX ) ;
break ;
case 5 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MAX ) ;
break ;
case 6 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , 0 ) ;
break ;
case 7 :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MIN ) ;
break ;
default :
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , 0 ) ;
break ;
}
}
}
static void HandleMiniSimpleControllerStateR ( Uint64 timestamp , SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SwitchSimpleStatePacket_t * packet )
{
if ( packet - > rgucButtons [ 0 ] ! = ctx - > m_lastSimpleState . rgucButtons [ 0 ] ) {
Uint8 data = packet - > rgucButtons [ 0 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_SOUTH ) , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_EAST ) , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_WEST ) , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_NORTH ) , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_SHOULDER , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER , ( ( data & 0x20 ) ! = 0 ) ) ;
2018-08-09 16:00:17 -07:00
}
if ( packet - > rgucButtons [ 1 ] ! = ctx - > m_lastSimpleState . rgucButtons [ 1 ] ) {
Uint8 data = packet - > rgucButtons [ 1 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_START , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_STICK , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_GUIDE , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_SHARE , ( ( data & 0x20 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1 , ( ( data & 0x40 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2 , ( ( data & 0x80 ) ! = 0 ) ) ;
2018-08-09 16:00:17 -07:00
}
if ( packet - > ucStickHat ! = ctx - > m_lastSimpleState . ucStickHat ) {
switch ( packet - > ucStickHat ) {
case 0 :
2024-06-12 22:28:47 -07:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MIN ) ;
2018-08-09 16:00:17 -07:00
break ;
case 1 :
2024-06-12 22:28:47 -07:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MIN ) ;
2018-08-09 16:00:17 -07:00
break ;
case 2 :
2024-06-12 22:28:47 -07:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , 0 ) ;
2018-08-09 16:00:17 -07:00
break ;
case 3 :
2024-06-12 22:28:47 -07:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MAX ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MAX ) ;
2018-08-09 16:00:17 -07:00
break ;
case 4 :
2024-06-12 22:28:47 -07:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MAX ) ;
2018-08-09 16:00:17 -07:00
break ;
case 5 :
2024-06-12 22:28:47 -07:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MAX ) ;
2018-08-09 16:00:17 -07:00
break ;
case 6 :
2024-06-12 22:28:47 -07:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , 0 ) ;
2018-08-09 16:00:17 -07:00
break ;
case 7 :
2024-06-12 22:28:47 -07:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , SDL_JOYSTICK_AXIS_MIN ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , SDL_JOYSTICK_AXIS_MIN ) ;
2018-08-09 16:00:17 -07:00
break ;
default :
2024-06-12 22:28:47 -07:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , 0 ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , 0 ) ;
2018-08-09 16:00:17 -07:00
break ;
}
}
2024-06-12 22:28:47 -07:00
}
2018-08-09 16:00:17 -07:00
2024-06-12 22:28:47 -07:00
static void HandleSimpleControllerState ( SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SwitchSimpleStatePacket_t * packet )
{
Uint64 timestamp = SDL_GetTicksNS ( ) ;
2018-08-09 16:00:17 -07:00
2024-06-12 22:28:47 -07:00
if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConLeft ) {
if ( ctx - > device - > parent | | ctx - > m_bVerticalMode ) {
HandleCombinedSimpleControllerStateL ( timestamp , joystick , ctx , packet ) ;
} else {
HandleMiniSimpleControllerStateL ( timestamp , joystick , ctx , packet ) ;
}
} else if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
if ( ctx - > device - > parent | | ctx - > m_bVerticalMode ) {
HandleCombinedSimpleControllerStateR ( timestamp , joystick , ctx , packet ) ;
} else {
HandleMiniSimpleControllerStateR ( timestamp , joystick , ctx , packet ) ;
}
} else {
Sint16 axis ;
2018-08-09 16:00:17 -07:00
2024-06-12 22:28:47 -07:00
if ( packet - > rgucButtons [ 0 ] ! = ctx - > m_lastSimpleState . rgucButtons [ 0 ] ) {
Uint8 data = packet - > rgucButtons [ 0 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_SOUTH ) , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_EAST ) , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_WEST ) , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_NORTH ) , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_SHOULDER , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER , ( ( data & 0x20 ) ! = 0 ) ) ;
2024-06-12 22:28:47 -07:00
}
if ( packet - > rgucButtons [ 1 ] ! = ctx - > m_lastSimpleState . rgucButtons [ 1 ] ) {
Uint8 data = packet - > rgucButtons [ 1 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_BACK , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_START , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_STICK , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_STICK , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_GUIDE , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_SHARE , ( ( data & 0x20 ) ! = 0 ) ) ;
2024-06-12 22:28:47 -07:00
}
if ( packet - > ucStickHat ! = ctx - > m_lastSimpleState . ucStickHat ) {
Uint8 hat ;
switch ( packet - > ucStickHat ) {
case 0 :
hat = SDL_HAT_UP ;
break ;
case 1 :
hat = SDL_HAT_RIGHTUP ;
break ;
case 2 :
hat = SDL_HAT_RIGHT ;
break ;
case 3 :
hat = SDL_HAT_RIGHTDOWN ;
break ;
case 4 :
hat = SDL_HAT_DOWN ;
break ;
case 5 :
hat = SDL_HAT_LEFTDOWN ;
break ;
case 6 :
hat = SDL_HAT_LEFT ;
break ;
case 7 :
hat = SDL_HAT_LEFTUP ;
break ;
default :
hat = SDL_HAT_CENTERED ;
break ;
}
SDL_SendJoystickHat ( timestamp , joystick , 0 , hat ) ;
}
2018-08-09 16:00:17 -07:00
2024-06-13 11:25:01 -07:00
axis = ( packet - > rgucButtons [ 0 ] & 0x40 ) ? 32767 : - 32768 ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFT_TRIGGER , axis ) ;
2024-06-13 11:35:29 -07:00
axis = ( ( packet - > rgucButtons [ 0 ] & 0x80 ) | | ( packet - > rgucButtons [ 1 ] & 0x80 ) ) ? 32767 : - 32768 ;
2024-06-13 11:25:01 -07:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHT_TRIGGER , axis ) ;
2024-06-12 22:28:47 -07:00
axis = ApplySimpleStickCalibration ( ctx , 0 , 0 , packet - > sJoystickLeft [ 0 ] ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , axis ) ;
axis = ApplySimpleStickCalibration ( ctx , 0 , 1 , packet - > sJoystickLeft [ 1 ] ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , axis ) ;
axis = ApplySimpleStickCalibration ( ctx , 1 , 0 , packet - > sJoystickRight [ 0 ] ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , axis ) ;
axis = ApplySimpleStickCalibration ( ctx , 1 , 1 , packet - > sJoystickRight [ 1 ] ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , axis ) ;
}
2018-08-09 16:00:17 -07:00
ctx - > m_lastSimpleState = * packet ;
}
2023-05-23 11:29:41 -07:00
static void SendSensorUpdate ( Uint64 timestamp , SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SDL_SensorType type , Uint64 sensor_timestamp , const Sint16 * values )
2021-07-29 06:43:39 -07:00
{
float data [ 3 ] ;
/* Note the order of components has been shuffled to match PlayStation controllers,
* since that ' s our de facto standard from already supporting those controllers , and
* users will want consistent axis mappings across devices .
*/
2022-11-30 12:51:59 -08:00
if ( type = = SDL_SENSOR_GYRO | | type = = SDL_SENSOR_GYRO_L | | type = = SDL_SENSOR_GYRO_R ) {
2022-04-27 00:57:17 +08:00
data [ 0 ] = - ( ctx - > m_IMUScaleData . fGyroScaleY * ( float ) values [ 1 ] ) ;
data [ 1 ] = ctx - > m_IMUScaleData . fGyroScaleZ * ( float ) values [ 2 ] ;
data [ 2 ] = - ( ctx - > m_IMUScaleData . fGyroScaleX * ( float ) values [ 0 ] ) ;
2021-07-29 14:23:15 -07:00
} else {
2022-04-27 00:57:17 +08:00
data [ 0 ] = - ( ctx - > m_IMUScaleData . fAccelScaleY * ( float ) values [ 1 ] ) ;
data [ 1 ] = ctx - > m_IMUScaleData . fAccelScaleZ * ( float ) values [ 2 ] ;
data [ 2 ] = - ( ctx - > m_IMUScaleData . fAccelScaleX * ( float ) values [ 0 ] ) ;
2021-07-29 14:23:15 -07:00
}
2021-07-29 06:43:39 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Right Joy-Con flips some axes, so let's flip them back for consistency
2021-07-29 06:43:39 -07:00
if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
data [ 0 ] = - data [ 0 ] ;
data [ 1 ] = - data [ 1 ] ;
}
2022-08-08 17:19:12 -07:00
if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConLeft & &
2022-10-02 10:15:39 -07:00
! ctx - > device - > parent & & ! ctx - > m_bVerticalMode ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Mini-gamepad mode, swap some axes around
2022-08-08 17:19:12 -07:00
float tmp = data [ 2 ] ;
data [ 2 ] = - data [ 0 ] ;
data [ 0 ] = tmp ;
}
if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight & &
2022-10-02 10:15:39 -07:00
! ctx - > device - > parent & & ! ctx - > m_bVerticalMode ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Mini-gamepad mode, swap some axes around
2022-08-08 17:19:12 -07:00
float tmp = data [ 2 ] ;
data [ 2 ] = data [ 0 ] ;
data [ 0 ] = - tmp ;
}
2022-12-27 15:05:51 -08:00
SDL_SendJoystickSensor ( timestamp , joystick , type , sensor_timestamp , data , 3 ) ;
2021-07-29 06:43:39 -07:00
}
2022-12-03 11:15:50 -08:00
static void HandleCombinedControllerStateL ( Uint64 timestamp , SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SwitchStatePacket_t * packet )
2018-08-09 16:00:17 -07:00
{
Sint16 axis ;
if ( packet - > controllerState . rgucButtons [ 1 ] ! = ctx - > m_lastFullState . controllerState . rgucButtons [ 1 ] ) {
Uint8 data = packet - > controllerState . rgucButtons [ 1 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_BACK , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_STICK , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_SHARE , ( ( data & 0x20 ) ! = 0 ) ) ;
2018-08-09 16:00:17 -07:00
}
if ( packet - > controllerState . rgucButtons [ 2 ] ! = ctx - > m_lastFullState . controllerState . rgucButtons [ 2 ] ) {
Uint8 data = packet - > controllerState . rgucButtons [ 2 ] ;
2023-12-27 11:28:27 -08:00
Uint8 hat = 0 ;
if ( data & 0x01 ) {
hat | = SDL_HAT_DOWN ;
}
if ( data & 0x02 ) {
hat | = SDL_HAT_UP ;
}
if ( data & 0x04 ) {
hat | = SDL_HAT_RIGHT ;
}
if ( data & 0x08 ) {
hat | = SDL_HAT_LEFT ;
}
SDL_SendJoystickHat ( timestamp , joystick , 0 , hat ) ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2 , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1 , ( ( data & 0x20 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_SHOULDER , ( ( data & 0x40 ) ! = 0 ) ) ;
2018-08-09 16:00:17 -07:00
axis = ( data & 0x80 ) ? 32767 : - 32768 ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFT_TRIGGER , axis ) ;
2018-08-09 16:00:17 -07:00
}
axis = packet - > controllerState . rgucJoystickLeft [ 0 ] | ( ( packet - > controllerState . rgucJoystickLeft [ 1 ] & 0xF ) < < 8 ) ;
axis = ApplyStickCalibration ( ctx , 0 , 0 , axis ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , axis ) ;
2018-08-09 16:00:17 -07:00
axis = ( ( packet - > controllerState . rgucJoystickLeft [ 1 ] & 0xF0 ) > > 4 ) | ( packet - > controllerState . rgucJoystickLeft [ 2 ] < < 4 ) ;
axis = ApplyStickCalibration ( ctx , 0 , 1 , axis ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , ~ axis ) ;
2022-07-28 19:22:27 -07:00
}
2022-12-03 11:15:50 -08:00
static void HandleCombinedControllerStateR ( Uint64 timestamp , SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SwitchStatePacket_t * packet )
2022-07-28 19:22:27 -07:00
{
Sint16 axis ;
if ( packet - > controllerState . rgucButtons [ 0 ] ! = ctx - > m_lastFullState . controllerState . rgucButtons [ 0 ] ) {
Uint8 data = packet - > controllerState . rgucButtons [ 0 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_SOUTH ) , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_EAST ) , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_WEST ) , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_NORTH ) , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1 , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2 , ( ( data & 0x20 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER , ( ( data & 0x40 ) ! = 0 ) ) ;
2022-07-28 19:22:27 -07:00
axis = ( data & 0x80 ) ? 32767 : - 32768 ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHT_TRIGGER , axis ) ;
2022-07-28 19:22:27 -07:00
}
if ( packet - > controllerState . rgucButtons [ 1 ] ! = ctx - > m_lastFullState . controllerState . rgucButtons [ 1 ] ) {
Uint8 data = packet - > controllerState . rgucButtons [ 1 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_START , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_STICK , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_GUIDE , ( ( data & 0x10 ) ! = 0 ) ) ;
2022-07-28 19:22:27 -07:00
}
2018-08-09 16:00:17 -07:00
axis = packet - > controllerState . rgucJoystickRight [ 0 ] | ( ( packet - > controllerState . rgucJoystickRight [ 1 ] & 0xF ) < < 8 ) ;
axis = ApplyStickCalibration ( ctx , 1 , 0 , axis ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , axis ) ;
2018-08-09 16:00:17 -07:00
axis = ( ( packet - > controllerState . rgucJoystickRight [ 1 ] & 0xF0 ) > > 4 ) | ( packet - > controllerState . rgucJoystickRight [ 2 ] < < 4 ) ;
axis = ApplyStickCalibration ( ctx , 1 , 1 , axis ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , ~ axis ) ;
2022-07-28 19:22:27 -07:00
}
2024-06-12 22:28:47 -07:00
static void HandleMiniControllerStateL ( Uint64 timestamp , SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SwitchStatePacket_t * packet )
{
Sint16 axis ;
if ( packet - > controllerState . rgucButtons [ 1 ] ! = ctx - > m_lastFullState . controllerState . rgucButtons [ 1 ] ) {
Uint8 data = packet - > controllerState . rgucButtons [ 1 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_START , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_STICK , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_GUIDE , ( ( data & 0x20 ) ! = 0 ) ) ;
2024-06-12 22:28:47 -07:00
}
if ( packet - > controllerState . rgucButtons [ 2 ] ! = ctx - > m_lastFullState . controllerState . rgucButtons [ 2 ] ) {
Uint8 data = packet - > controllerState . rgucButtons [ 2 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_SOUTH ) , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_EAST ) , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_WEST ) , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_NORTH ) , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_SHOULDER , ( ( data & 0x20 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1 , ( ( data & 0x40 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2 , ( ( data & 0x80 ) ! = 0 ) ) ;
2024-06-12 22:28:47 -07:00
}
axis = packet - > controllerState . rgucJoystickLeft [ 0 ] | ( ( packet - > controllerState . rgucJoystickLeft [ 1 ] & 0xF ) < < 8 ) ;
axis = ApplyStickCalibration ( ctx , 0 , 0 , axis ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , ~ axis ) ;
axis = ( ( packet - > controllerState . rgucJoystickLeft [ 1 ] & 0xF0 ) > > 4 ) | ( packet - > controllerState . rgucJoystickLeft [ 2 ] < < 4 ) ;
axis = ApplyStickCalibration ( ctx , 0 , 1 , axis ) ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , ~ axis ) ;
}
2022-12-03 11:15:50 -08:00
static void HandleMiniControllerStateR ( Uint64 timestamp , SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SwitchStatePacket_t * packet )
2022-07-28 19:22:27 -07:00
{
Sint16 axis ;
if ( packet - > controllerState . rgucButtons [ 0 ] ! = ctx - > m_lastFullState . controllerState . rgucButtons [ 0 ] ) {
Uint8 data = packet - > controllerState . rgucButtons [ 0 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_SOUTH ) , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_EAST ) , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_WEST ) , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_NORTH ) , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_SHOULDER , ( ( data & 0x20 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1 , ( ( data & 0x40 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2 , ( ( data & 0x80 ) ! = 0 ) ) ;
2022-07-28 19:22:27 -07:00
}
if ( packet - > controllerState . rgucButtons [ 1 ] ! = ctx - > m_lastFullState . controllerState . rgucButtons [ 1 ] ) {
Uint8 data = packet - > controllerState . rgucButtons [ 1 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_START , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_STICK , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_GUIDE , ( ( data & 0x10 ) ! = 0 ) ) ;
2022-07-28 19:22:27 -07:00
}
axis = packet - > controllerState . rgucJoystickRight [ 0 ] | ( ( packet - > controllerState . rgucJoystickRight [ 1 ] & 0xF ) < < 8 ) ;
axis = ApplyStickCalibration ( ctx , 1 , 0 , axis ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , axis ) ;
2022-07-28 19:22:27 -07:00
axis = ( ( packet - > controllerState . rgucJoystickRight [ 1 ] & 0xF0 ) > > 4 ) | ( packet - > controllerState . rgucJoystickRight [ 2 ] < < 4 ) ;
axis = ApplyStickCalibration ( ctx , 1 , 1 , axis ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , axis ) ;
2022-07-28 19:22:27 -07:00
}
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
static void HandleFullControllerState ( SDL_Joystick * joystick , SDL_DriverSwitch_Context * ctx , SwitchStatePacket_t * packet ) SDL_NO_THREAD_SAFETY_ANALYSIS // We unlock and lock the device lock to be able to change IMU state
2022-07-28 19:22:27 -07:00
{
2022-12-03 11:15:50 -08:00
Uint64 timestamp = SDL_GetTicksNS ( ) ;
2022-07-28 19:22:27 -07:00
if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConLeft ) {
2022-10-03 00:19:34 +08:00
if ( ctx - > device - > parent | | ctx - > m_bVerticalMode ) {
2022-12-03 11:15:50 -08:00
HandleCombinedControllerStateL ( timestamp , joystick , ctx , packet ) ;
2022-07-28 19:22:27 -07:00
} else {
2022-12-03 11:15:50 -08:00
HandleMiniControllerStateL ( timestamp , joystick , ctx , packet ) ;
2022-07-28 19:22:27 -07:00
}
} else if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
2022-10-03 00:19:34 +08:00
if ( ctx - > device - > parent | | ctx - > m_bVerticalMode ) {
2022-12-03 11:15:50 -08:00
HandleCombinedControllerStateR ( timestamp , joystick , ctx , packet ) ;
2022-07-28 19:22:27 -07:00
} else {
2022-12-03 11:15:50 -08:00
HandleMiniControllerStateR ( timestamp , joystick , ctx , packet ) ;
2022-07-28 19:22:27 -07:00
}
} else {
Sint16 axis ;
if ( packet - > controllerState . rgucButtons [ 0 ] ! = ctx - > m_lastFullState . controllerState . rgucButtons [ 0 ] ) {
Uint8 data = packet - > controllerState . rgucButtons [ 0 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_SOUTH ) , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_EAST ) , ( ( data & 0x08 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_WEST ) , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , RemapButton ( ctx , SDL_GAMEPAD_BUTTON_NORTH ) , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER , ( ( data & 0x40 ) ! = 0 ) ) ;
2022-07-28 19:22:27 -07:00
}
if ( packet - > controllerState . rgucButtons [ 1 ] ! = ctx - > m_lastFullState . controllerState . rgucButtons [ 1 ] ) {
Uint8 data = packet - > controllerState . rgucButtons [ 1 ] ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_BACK , ( ( data & 0x01 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_START , ( ( data & 0x02 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_RIGHT_STICK , ( ( data & 0x04 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_STICK , ( ( data & 0x08 ) ! = 0 ) ) ;
2022-07-28 19:22:27 -07:00
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_GUIDE , ( ( data & 0x10 ) ! = 0 ) ) ;
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_SWITCH_SHARE , ( ( data & 0x20 ) ! = 0 ) ) ;
2022-07-28 19:22:27 -07:00
}
if ( packet - > controllerState . rgucButtons [ 2 ] ! = ctx - > m_lastFullState . controllerState . rgucButtons [ 2 ] ) {
Uint8 data = packet - > controllerState . rgucButtons [ 2 ] ;
2023-12-27 11:28:27 -08:00
Uint8 hat = 0 ;
if ( data & 0x01 ) {
hat | = SDL_HAT_DOWN ;
}
if ( data & 0x02 ) {
hat | = SDL_HAT_UP ;
}
if ( data & 0x04 ) {
hat | = SDL_HAT_RIGHT ;
}
if ( data & 0x08 ) {
hat | = SDL_HAT_LEFT ;
}
SDL_SendJoystickHat ( timestamp , joystick , 0 , hat ) ;
2024-09-09 09:18:02 -07:00
SDL_SendJoystickButton ( timestamp , joystick , SDL_GAMEPAD_BUTTON_LEFT_SHOULDER , ( ( data & 0x40 ) ! = 0 ) ) ;
2022-07-28 19:22:27 -07:00
}
2024-06-13 11:25:01 -07:00
axis = ( packet - > controllerState . rgucButtons [ 0 ] & 0x80 ) ? 32767 : - 32768 ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHT_TRIGGER , axis ) ;
axis = ( packet - > controllerState . rgucButtons [ 2 ] & 0x80 ) ? 32767 : - 32768 ;
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFT_TRIGGER , axis ) ;
2022-07-28 19:22:27 -07:00
axis = packet - > controllerState . rgucJoystickLeft [ 0 ] | ( ( packet - > controllerState . rgucJoystickLeft [ 1 ] & 0xF ) < < 8 ) ;
axis = ApplyStickCalibration ( ctx , 0 , 0 , axis ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTX , axis ) ;
2022-07-28 19:22:27 -07:00
axis = ( ( packet - > controllerState . rgucJoystickLeft [ 1 ] & 0xF0 ) > > 4 ) | ( packet - > controllerState . rgucJoystickLeft [ 2 ] < < 4 ) ;
axis = ApplyStickCalibration ( ctx , 0 , 1 , axis ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_LEFTY , ~ axis ) ;
2022-07-28 19:22:27 -07:00
axis = packet - > controllerState . rgucJoystickRight [ 0 ] | ( ( packet - > controllerState . rgucJoystickRight [ 1 ] & 0xF ) < < 8 ) ;
axis = ApplyStickCalibration ( ctx , 1 , 0 , axis ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTX , axis ) ;
2022-07-28 19:22:27 -07:00
axis = ( ( packet - > controllerState . rgucJoystickRight [ 1 ] & 0xF0 ) > > 4 ) | ( packet - > controllerState . rgucJoystickRight [ 2 ] < < 4 ) ;
axis = ApplyStickCalibration ( ctx , 1 , 1 , axis ) ;
2022-12-27 15:05:51 -08:00
SDL_SendJoystickAxis ( timestamp , joystick , SDL_GAMEPAD_AXIS_RIGHTY , ~ axis ) ;
2022-07-28 19:22:27 -07:00
}
2018-08-09 16:00:17 -07:00
2024-12-27 13:57:53 -08:00
/* High nibble of battery/connection byte is battery level, low nibble is connection status (always 0 on 8BitDo Pro 2)
2024-03-30 10:55:13 -07:00
* LSB of connection nibble is USB / Switch connection status
* LSB of the battery nibble is used to report charging .
* The battery level is reported from 0 ( empty ) - 8 ( full )
*/
int charging = ( packet - > controllerState . ucBatteryAndConnection & 0x10 ) ;
int level = ( packet - > controllerState . ucBatteryAndConnection & 0xE0 ) > > 4 ;
if ( charging ) {
if ( level = = 8 ) {
2025-10-13 10:34:22 -07:00
ctx - > m_ePowerState = SDL_POWERSTATE_CHARGED ;
2018-08-09 16:00:17 -07:00
} else {
2025-10-13 10:34:22 -07:00
ctx - > m_ePowerState = SDL_POWERSTATE_CHARGING ;
2018-08-09 16:00:17 -07:00
}
2024-03-30 10:55:13 -07:00
} else {
2025-10-13 10:34:22 -07:00
ctx - > m_ePowerState = SDL_POWERSTATE_ON_BATTERY ;
}
ctx - > m_nPowerPercent = ( int ) SDL_roundf ( ( level / 8.0f ) * 100.0f ) ;
if ( ! ctx - > device - > parent ) {
SDL_PowerState state = ctx - > m_ePowerState ;
int percent = ctx - > m_nPowerPercent ;
SDL_SendJoystickPowerInfo ( joystick , state , percent ) ;
} else if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
SDL_DriverSwitch_Context * other = ( SDL_DriverSwitch_Context * ) ctx - > device - > parent - > children [ 0 ] - > context ;
SDL_PowerState state = ( SDL_PowerState ) SDL_min ( ctx - > m_ePowerState , other - > m_ePowerState ) ;
int percent = SDL_min ( ctx - > m_nPowerPercent , other - > m_nPowerPercent ) ;
SDL_SendJoystickPowerInfo ( joystick , state , percent ) ;
2018-08-09 16:00:17 -07:00
}
2021-01-11 15:36:40 +08:00
if ( ctx - > m_bReportSensors ) {
2025-11-05 17:08:22 -08:00
// Need to copy the imuState to an aligned variable
SwitchControllerIMUState_t imuState [ 3 ] ;
2025-11-17 16:06:58 -08:00
SDL_COMPILE_TIME_ASSERT ( imuState_size , sizeof ( imuState ) = = sizeof ( packet - > imuState ) ) ;
SDL_memcpy ( imuState , packet - > imuState , sizeof ( packet - > imuState ) ) ;
2025-11-05 17:08:22 -08:00
bool bHasSensorData = ( imuState [ 0 ] . sAccelZ ! = 0 | |
imuState [ 0 ] . sAccelY ! = 0 | |
imuState [ 0 ] . sAccelX ! = 0 ) ;
2022-08-08 20:09:49 -07:00
if ( bHasSensorData ) {
2022-09-27 12:34:03 -07:00
const Uint32 IMU_UPDATE_RATE_SAMPLE_FREQUENCY = 1000 ;
2022-12-04 08:31:19 -08:00
Uint64 sensor_timestamp [ 3 ] ;
2022-09-27 12:34:03 -07:00
2024-08-22 09:21:26 -07:00
ctx - > m_bHasSensorData = true ;
2021-01-18 19:57:29 +08:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// We got three IMU samples, calculate the IMU update rate and timestamps
2022-09-27 12:34:03 -07:00
ctx - > m_unIMUSamples + = 3 ;
if ( ctx - > m_unIMUSamples > = IMU_UPDATE_RATE_SAMPLE_FREQUENCY ) {
2022-12-02 01:17:17 -08:00
Uint64 now = SDL_GetTicksNS ( ) ;
Uint64 elapsed = ( now - ctx - > m_ulIMUSampleTimestampNS ) ;
2022-09-27 12:34:03 -07:00
if ( elapsed > 0 ) {
2022-12-02 01:17:17 -08:00
ctx - > m_ulIMUUpdateIntervalNS = elapsed / ctx - > m_unIMUSamples ;
2022-09-27 12:34:03 -07:00
}
ctx - > m_unIMUSamples = 0 ;
2022-12-02 01:17:17 -08:00
ctx - > m_ulIMUSampleTimestampNS = now ;
2022-09-27 12:34:03 -07:00
}
2022-12-02 01:17:17 -08:00
ctx - > m_ulTimestampNS + = ctx - > m_ulIMUUpdateIntervalNS ;
2022-12-04 08:31:19 -08:00
sensor_timestamp [ 0 ] = ctx - > m_ulTimestampNS ;
2022-12-02 01:17:17 -08:00
ctx - > m_ulTimestampNS + = ctx - > m_ulIMUUpdateIntervalNS ;
2022-12-04 08:31:19 -08:00
sensor_timestamp [ 1 ] = ctx - > m_ulTimestampNS ;
2022-12-02 01:17:17 -08:00
ctx - > m_ulTimestampNS + = ctx - > m_ulIMUUpdateIntervalNS ;
2022-12-04 08:31:19 -08:00
sensor_timestamp [ 2 ] = ctx - > m_ulTimestampNS ;
2022-09-27 12:34:03 -07:00
2022-09-07 00:00:27 -07:00
if ( ! ctx - > device - > parent | |
ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
2025-11-05 17:08:22 -08:00
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_GYRO , sensor_timestamp [ 0 ] , & imuState [ 2 ] . sGyroX ) ;
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_ACCEL , sensor_timestamp [ 0 ] , & imuState [ 2 ] . sAccelX ) ;
2022-10-11 10:44:20 +08:00
2025-11-05 17:08:22 -08:00
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_GYRO , sensor_timestamp [ 1 ] , & imuState [ 1 ] . sGyroX ) ;
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_ACCEL , sensor_timestamp [ 1 ] , & imuState [ 1 ] . sAccelX ) ;
2022-10-11 10:44:20 +08:00
2025-11-05 17:08:22 -08:00
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_GYRO , sensor_timestamp [ 2 ] , & imuState [ 0 ] . sGyroX ) ;
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_ACCEL , sensor_timestamp [ 2 ] , & imuState [ 0 ] . sAccelX ) ;
2022-09-07 00:00:27 -07:00
}
if ( ctx - > device - > parent & &
ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConLeft ) {
2025-11-05 17:08:22 -08:00
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_GYRO_L , sensor_timestamp [ 0 ] , & imuState [ 2 ] . sGyroX ) ;
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_ACCEL_L , sensor_timestamp [ 0 ] , & imuState [ 2 ] . sAccelX ) ;
2022-10-11 10:44:20 +08:00
2025-11-05 17:08:22 -08:00
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_GYRO_L , sensor_timestamp [ 1 ] , & imuState [ 1 ] . sGyroX ) ;
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_ACCEL_L , sensor_timestamp [ 1 ] , & imuState [ 1 ] . sAccelX ) ;
2022-10-11 10:44:20 +08:00
2025-11-05 17:08:22 -08:00
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_GYRO_L , sensor_timestamp [ 2 ] , & imuState [ 0 ] . sGyroX ) ;
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_ACCEL_L , sensor_timestamp [ 2 ] , & imuState [ 0 ] . sAccelX ) ;
2022-09-07 00:00:27 -07:00
}
if ( ctx - > device - > parent & &
ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
2025-11-05 17:08:22 -08:00
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_GYRO_R , sensor_timestamp [ 0 ] , & imuState [ 2 ] . sGyroX ) ;
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_ACCEL_R , sensor_timestamp [ 0 ] , & imuState [ 2 ] . sAccelX ) ;
2022-10-11 10:44:20 +08:00
2025-11-05 17:08:22 -08:00
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_GYRO_R , sensor_timestamp [ 1 ] , & imuState [ 1 ] . sGyroX ) ;
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_ACCEL_R , sensor_timestamp [ 1 ] , & imuState [ 1 ] . sAccelX ) ;
2022-10-11 10:44:20 +08:00
2025-11-05 17:08:22 -08:00
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_GYRO_R , sensor_timestamp [ 2 ] , & imuState [ 0 ] . sGyroX ) ;
SendSensorUpdate ( timestamp , joystick , ctx , SDL_SENSOR_ACCEL_R , sensor_timestamp [ 2 ] , & imuState [ 0 ] . sAccelX ) ;
2022-09-07 00:00:27 -07:00
}
2022-08-08 20:09:49 -07:00
} else if ( ctx - > m_bHasSensorData ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Uh oh, someone turned off the IMU?
2022-12-02 01:17:17 -08:00
const int IMU_RESET_DELAY_MS = 3000 ;
Uint64 now = SDL_GetTicks ( ) ;
2022-08-09 15:39:39 -07:00
2022-12-02 01:17:17 -08:00
if ( now > = ( ctx - > m_ulLastIMUReset + IMU_RESET_DELAY_MS ) ) {
2022-08-09 21:30:11 -07:00
SDL_HIDAPI_Device * device = ctx - > device ;
if ( device - > updating ) {
SDL_UnlockMutex ( device - > dev_lock ) ;
}
2022-08-09 15:39:39 -07:00
2024-08-22 09:21:26 -07:00
SetIMUEnabled ( ctx , true ) ;
2022-08-09 15:39:39 -07:00
2022-08-09 21:30:11 -07:00
if ( device - > updating ) {
SDL_LockMutex ( device - > dev_lock ) ;
}
2022-12-02 01:17:17 -08:00
ctx - > m_ulLastIMUReset = now ;
2022-08-09 15:39:39 -07:00
}
2022-08-08 20:09:49 -07:00
} else {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// We have never gotten IMU data, probably not supported on this device
2022-08-08 20:09:49 -07:00
}
2021-01-11 15:36:40 +08:00
}
2018-08-09 16:00:17 -07:00
ctx - > m_lastFullState = * packet ;
}
2024-08-22 09:21:26 -07:00
static bool HIDAPI_DriverSwitch_UpdateDevice ( SDL_HIDAPI_Device * device )
2018-08-09 16:00:17 -07:00
{
2019-12-19 15:01:30 -08:00
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) device - > context ;
SDL_Joystick * joystick = NULL ;
2018-08-29 20:23:36 -07:00
int size ;
2022-09-26 23:00:58 -07:00
int packet_count = 0 ;
2022-12-02 01:17:17 -08:00
Uint64 now = SDL_GetTicks ( ) ;
2022-09-26 14:20:34 -07:00
2019-12-19 15:01:30 -08:00
if ( device - > num_joysticks > 0 ) {
2024-07-14 12:06:35 -07:00
joystick = SDL_GetJoystickFromID ( device - > joysticks [ 0 ] ) ;
2019-12-19 15:01:30 -08:00
}
2018-08-15 19:53:26 -07:00
while ( ( size = ReadInput ( ctx ) ) > 0 ) {
2020-11-06 11:30:52 -08:00
# ifdef DEBUG_SWITCH_PROTOCOL
HIDAPI_DumpPacket ( " Nintendo Switch packet: size = %d " , ctx - > m_rgucReadBuffer , size ) ;
# endif
2022-09-26 23:00:58 -07:00
+ + packet_count ;
2022-12-02 01:17:17 -08:00
ctx - > m_ulLastInput = now ;
2022-09-26 23:00:58 -07:00
2023-11-09 22:29:15 +01:00
if ( ! joystick ) {
2022-09-26 23:00:58 -07:00
continue ;
}
if ( ctx - > m_bInputOnly ) {
HandleInputOnlyControllerState ( joystick , ctx , ( SwitchInputOnlyControllerStatePacket_t * ) & ctx - > m_rgucReadBuffer [ 0 ] ) ;
} else {
2024-06-20 14:37:30 -07:00
if ( ctx - > m_rgucReadBuffer [ 0 ] = = k_eSwitchInputReportIDs_SubcommandReply ) {
continue ;
}
2023-12-24 08:12:14 -08:00
ctx - > m_nCurrentInputMode = ctx - > m_rgucReadBuffer [ 0 ] ;
2022-09-26 23:00:58 -07:00
switch ( ctx - > m_rgucReadBuffer [ 0 ] ) {
case k_eSwitchInputReportIDs_SimpleControllerState :
HandleSimpleControllerState ( joystick , ctx , ( SwitchSimpleStatePacket_t * ) & ctx - > m_rgucReadBuffer [ 1 ] ) ;
break ;
case k_eSwitchInputReportIDs_FullControllerState :
2023-06-26 10:54:52 -06:00
case k_eSwitchInputReportIDs_FullControllerAndMcuState :
2025-01-02 14:27:38 -08:00
// This is the extended report, we can enable sensors now in auto mode
UpdateEnhancedModeOnEnhancedReport ( ctx ) ;
2022-09-26 23:00:58 -07:00
HandleFullControllerState ( joystick , ctx , ( SwitchStatePacket_t * ) & ctx - > m_rgucReadBuffer [ 1 ] ) ;
break ;
default :
break ;
2019-10-17 16:59:05 -07:00
}
2018-08-09 16:00:17 -07:00
}
}
2022-09-22 18:22:17 -07:00
if ( joystick ) {
2022-09-26 23:00:58 -07:00
if ( packet_count = = 0 ) {
if ( ! ctx - > m_bInputOnly & & ! device - > is_bluetooth & &
ctx - > device - > product_id ! = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP ) {
2022-12-02 01:17:17 -08:00
const int INPUT_WAIT_TIMEOUT_MS = 100 ;
if ( now > = ( ctx - > m_ulLastInput + INPUT_WAIT_TIMEOUT_MS ) ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Steam may have put the controller back into non-reporting mode
2024-08-22 09:21:26 -07:00
bool wasSyncWrite = ctx - > m_bSyncWrite ;
2023-02-08 14:22:39 -08:00
2024-08-22 09:21:26 -07:00
ctx - > m_bSyncWrite = true ;
WriteProprietary ( ctx , k_eSwitchProprietaryCommandIDs_ForceUSB , NULL , 0 , false ) ;
2023-02-08 14:22:39 -08:00
ctx - > m_bSyncWrite = wasSyncWrite ;
2022-09-26 23:00:58 -07:00
}
2024-06-12 22:28:47 -07:00
} else if ( device - > is_bluetooth & &
ctx - > m_nCurrentInputMode ! = k_eSwitchInputReportIDs_SimpleControllerState ) {
2022-12-02 01:17:17 -08:00
const int INPUT_WAIT_TIMEOUT_MS = 3000 ;
if ( now > = ( ctx - > m_ulLastInput + INPUT_WAIT_TIMEOUT_MS ) ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Bluetooth may have disconnected, try reopening the controller
2022-09-26 23:00:58 -07:00
size = - 1 ;
}
2022-09-22 18:22:17 -07:00
}
2022-08-09 13:25:52 -07:00
}
2022-07-27 09:00:39 -07:00
2022-09-26 23:00:58 -07:00
if ( ctx - > m_bRumblePending | | ctx - > m_bRumbleZeroPending ) {
HIDAPI_DriverSwitch_SendPendingRumble ( ctx ) ;
} else if ( ctx - > m_bRumbleActive & &
2022-12-02 01:17:17 -08:00
now > = ( ctx - > m_ulRumbleSent + RUMBLE_REFRESH_FREQUENCY_MS ) ) {
2020-04-17 15:08:48 -07:00
# ifdef DEBUG_RUMBLE
2025-01-22 12:59:57 -08:00
SDL_Log ( " Sent continuing rumble, %d ms after previous rumble " , now - ctx - > m_ulRumbleSent ) ;
2020-04-17 15:08:48 -07:00
# endif
2022-09-26 23:00:58 -07:00
WriteRumble ( ctx ) ;
}
}
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Reconnect the Bluetooth device once the USB device is gone
2022-09-26 23:00:58 -07:00
if ( device - > num_joysticks = = 0 & & device - > is_bluetooth & & packet_count > 0 & &
2025-02-25 18:21:47 -08:00
! device - > parent & &
2022-09-26 23:00:58 -07:00
! HIDAPI_HasConnectedUSBDevice ( device - > serial ) ) {
HIDAPI_JoystickConnected ( device , NULL ) ;
2020-02-07 11:44:57 -08:00
}
2022-09-26 23:00:58 -07:00
if ( size < 0 & & device - > num_joysticks > 0 ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Read error, device is disconnected
2022-09-22 18:22:17 -07:00
HIDAPI_JoystickDisconnected ( device , device - > joysticks [ 0 ] ) ;
2019-12-19 15:01:30 -08:00
}
2024-08-22 17:33:49 -07:00
return ( size > = 0 ) ;
2018-08-09 16:00:17 -07:00
}
2022-11-30 12:51:59 -08:00
static void HIDAPI_DriverSwitch_CloseJoystick ( SDL_HIDAPI_Device * device , SDL_Joystick * joystick )
2018-08-09 16:00:17 -07:00
{
2019-12-19 15:01:30 -08:00
SDL_DriverSwitch_Context * ctx = ( SDL_DriverSwitch_Context * ) device - > context ;
2018-08-09 16:00:17 -07:00
2019-10-17 17:32:47 -07:00
if ( ! ctx - > m_bInputOnly ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Restore simple input mode for other applications
2023-12-24 08:12:14 -08:00
if ( ! ctx - > m_nInitialInputMode | |
ctx - > m_nInitialInputMode = = k_eSwitchInputReportIDs_SimpleControllerState ) {
SetInputMode ( ctx , k_eSwitchInputReportIDs_SimpleControllerState ) ;
}
2019-10-17 17:32:47 -07:00
}
2025-01-02 14:27:38 -08:00
SDL_RemoveHintCallback ( SDL_HINT_JOYSTICK_ENHANCED_REPORTS ,
SDL_EnhancedReportsChanged , ctx ) ;
2022-08-09 13:41:58 -07:00
if ( ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConLeft | |
ctx - > m_eControllerType = = k_eSwitchDeviceInfoControllerType_JoyConRight ) {
2024-08-31 07:23:51 -07:00
SDL_RemoveHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED ,
2022-08-09 13:41:58 -07:00
SDL_HomeLEDHintChanged , ctx ) ;
} else {
2024-08-31 07:23:51 -07:00
SDL_RemoveHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED ,
2022-08-09 13:41:58 -07:00
SDL_HomeLEDHintChanged , ctx ) ;
}
2022-07-25 11:26:18 -07:00
2024-08-31 07:23:51 -07:00
SDL_RemoveHintCallback ( SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED ,
2022-08-06 10:34:19 -07:00
SDL_PlayerLEDHintChanged , ctx ) ;
2022-09-22 18:22:17 -07:00
ctx - > joystick = NULL ;
2025-01-12 10:45:54 -08:00
ctx - > m_bReportSensors = false ;
ctx - > m_bEnhancedMode = false ;
ctx - > m_bEnhancedModeAvailable = false ;
2019-12-19 15:01:30 -08:00
}
2022-11-30 12:51:59 -08:00
static void HIDAPI_DriverSwitch_FreeDevice ( SDL_HIDAPI_Device * device )
2019-12-19 15:01:30 -08:00
{
2018-08-09 16:00:17 -07:00
}
2022-11-30 12:51:59 -08:00
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverNintendoClassic = {
2022-08-03 13:07:47 -07:00
SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC ,
2024-08-22 09:21:26 -07:00
true ,
2022-08-19 11:11:23 -07:00
HIDAPI_DriverNintendoClassic_RegisterHints ,
HIDAPI_DriverNintendoClassic_UnregisterHints ,
HIDAPI_DriverNintendoClassic_IsEnabled ,
2022-08-03 13:07:47 -07:00
HIDAPI_DriverNintendoClassic_IsSupportedDevice ,
HIDAPI_DriverSwitch_InitDevice ,
HIDAPI_DriverSwitch_GetDevicePlayerIndex ,
HIDAPI_DriverSwitch_SetDevicePlayerIndex ,
HIDAPI_DriverSwitch_UpdateDevice ,
HIDAPI_DriverSwitch_OpenJoystick ,
HIDAPI_DriverSwitch_RumbleJoystick ,
HIDAPI_DriverSwitch_RumbleJoystickTriggers ,
HIDAPI_DriverSwitch_GetJoystickCapabilities ,
HIDAPI_DriverSwitch_SetJoystickLED ,
HIDAPI_DriverSwitch_SendJoystickEffect ,
HIDAPI_DriverSwitch_SetJoystickSensorsEnabled ,
HIDAPI_DriverSwitch_CloseJoystick ,
HIDAPI_DriverSwitch_FreeDevice ,
} ;
2022-11-30 12:51:59 -08:00
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverJoyCons = {
2022-08-03 13:07:47 -07:00
SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS ,
2024-08-22 09:21:26 -07:00
true ,
2022-08-19 11:11:23 -07:00
HIDAPI_DriverJoyCons_RegisterHints ,
HIDAPI_DriverJoyCons_UnregisterHints ,
HIDAPI_DriverJoyCons_IsEnabled ,
2022-08-03 13:07:47 -07:00
HIDAPI_DriverJoyCons_IsSupportedDevice ,
HIDAPI_DriverSwitch_InitDevice ,
HIDAPI_DriverSwitch_GetDevicePlayerIndex ,
HIDAPI_DriverSwitch_SetDevicePlayerIndex ,
HIDAPI_DriverSwitch_UpdateDevice ,
HIDAPI_DriverSwitch_OpenJoystick ,
HIDAPI_DriverSwitch_RumbleJoystick ,
HIDAPI_DriverSwitch_RumbleJoystickTriggers ,
HIDAPI_DriverSwitch_GetJoystickCapabilities ,
HIDAPI_DriverSwitch_SetJoystickLED ,
HIDAPI_DriverSwitch_SendJoystickEffect ,
HIDAPI_DriverSwitch_SetJoystickSensorsEnabled ,
HIDAPI_DriverSwitch_CloseJoystick ,
HIDAPI_DriverSwitch_FreeDevice ,
} ;
2022-11-30 12:51:59 -08:00
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch = {
2018-08-09 16:00:17 -07:00
SDL_HINT_JOYSTICK_HIDAPI_SWITCH ,
2024-08-22 09:21:26 -07:00
true ,
2022-08-19 11:11:23 -07:00
HIDAPI_DriverSwitch_RegisterHints ,
HIDAPI_DriverSwitch_UnregisterHints ,
HIDAPI_DriverSwitch_IsEnabled ,
2018-08-09 16:00:17 -07:00
HIDAPI_DriverSwitch_IsSupportedDevice ,
2019-12-19 15:01:30 -08:00
HIDAPI_DriverSwitch_InitDevice ,
2019-12-20 20:12:03 -08:00
HIDAPI_DriverSwitch_GetDevicePlayerIndex ,
HIDAPI_DriverSwitch_SetDevicePlayerIndex ,
2019-12-19 15:01:30 -08:00
HIDAPI_DriverSwitch_UpdateDevice ,
HIDAPI_DriverSwitch_OpenJoystick ,
HIDAPI_DriverSwitch_RumbleJoystick ,
2020-11-11 18:57:37 -08:00
HIDAPI_DriverSwitch_RumbleJoystickTriggers ,
2021-11-11 11:13:08 -06:00
HIDAPI_DriverSwitch_GetJoystickCapabilities ,
2020-04-30 11:57:29 -04:00
HIDAPI_DriverSwitch_SetJoystickLED ,
2021-07-08 13:22:41 -07:00
HIDAPI_DriverSwitch_SendJoystickEffect ,
2020-11-17 10:30:20 -08:00
HIDAPI_DriverSwitch_SetJoystickSensorsEnabled ,
2019-12-19 15:01:30 -08:00
HIDAPI_DriverSwitch_CloseJoystick ,
2020-03-16 14:49:20 -07:00
HIDAPI_DriverSwitch_FreeDevice ,
2018-08-09 16:00:17 -07:00
} ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
# endif // SDL_JOYSTICK_HIDAPI_SWITCH
2018-08-09 16:00:17 -07:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
# endif // SDL_JOYSTICK_HIDAPI