mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-04 17:06:25 +00:00
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594
This commit is contained in:
@@ -27,7 +27,6 @@
|
||||
#include "SDL_hidapijoystick_c.h"
|
||||
#include "SDL_hidapi_rumble.h"
|
||||
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_PS5
|
||||
|
||||
/* Define this if you want to log all packets from the controller */
|
||||
@@ -36,14 +35,14 @@
|
||||
/* Define this if you want to log calibration data */
|
||||
/*#define DEBUG_PS5_CALIBRATION*/
|
||||
|
||||
#define GYRO_RES_PER_DEGREE 1024.0f
|
||||
#define ACCEL_RES_PER_G 8192.0f
|
||||
#define GYRO_RES_PER_DEGREE 1024.0f
|
||||
#define ACCEL_RES_PER_G 8192.0f
|
||||
#define BLUETOOTH_DISCONNECT_TIMEOUT_MS 500
|
||||
|
||||
#define LOAD16(A, B) (Sint16)((Uint16)(A) | (((Uint16)(B)) << 8))
|
||||
#define LOAD32(A, B, C, D) ((((Uint32)(A)) << 0) | \
|
||||
(((Uint32)(B)) << 8) | \
|
||||
(((Uint32)(C)) << 16) | \
|
||||
#define LOAD16(A, B) (Sint16)((Uint16)(A) | (((Uint16)(B)) << 8))
|
||||
#define LOAD32(A, B, C, D) ((((Uint32)(A)) << 0) | \
|
||||
(((Uint32)(B)) << 8) | \
|
||||
(((Uint32)(C)) << 16) | \
|
||||
(((Uint32)(D)) << 24))
|
||||
|
||||
typedef enum
|
||||
@@ -75,128 +74,132 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Uint8 ucLeftJoystickX; /* 0 */
|
||||
Uint8 ucLeftJoystickY; /* 1 */
|
||||
Uint8 ucRightJoystickX; /* 2 */
|
||||
Uint8 ucRightJoystickY; /* 3 */
|
||||
Uint8 ucTriggerLeft; /* 4 */
|
||||
Uint8 ucTriggerRight; /* 5 */
|
||||
Uint8 ucCounter; /* 6 */
|
||||
Uint8 rgucButtonsAndHat[4]; /* 7 */
|
||||
Uint8 rgucPacketSequence[4]; /* 11 - 32 bit little endian */
|
||||
Uint8 rgucGyroX[2]; /* 15 */
|
||||
Uint8 rgucGyroY[2]; /* 17 */
|
||||
Uint8 rgucGyroZ[2]; /* 19 */
|
||||
Uint8 rgucAccelX[2]; /* 21 */
|
||||
Uint8 rgucAccelY[2]; /* 23 */
|
||||
Uint8 rgucAccelZ[2]; /* 25 */
|
||||
Uint8 rgucSensorTimestamp[4]; /* 27 - 32 bit little endian */
|
||||
Uint8 ucLeftJoystickX; /* 0 */
|
||||
Uint8 ucLeftJoystickY; /* 1 */
|
||||
Uint8 ucRightJoystickX; /* 2 */
|
||||
Uint8 ucRightJoystickY; /* 3 */
|
||||
Uint8 ucTriggerLeft; /* 4 */
|
||||
Uint8 ucTriggerRight; /* 5 */
|
||||
Uint8 ucCounter; /* 6 */
|
||||
Uint8 rgucButtonsAndHat[4]; /* 7 */
|
||||
Uint8 rgucPacketSequence[4]; /* 11 - 32 bit little endian */
|
||||
Uint8 rgucGyroX[2]; /* 15 */
|
||||
Uint8 rgucGyroY[2]; /* 17 */
|
||||
Uint8 rgucGyroZ[2]; /* 19 */
|
||||
Uint8 rgucAccelX[2]; /* 21 */
|
||||
Uint8 rgucAccelY[2]; /* 23 */
|
||||
Uint8 rgucAccelZ[2]; /* 25 */
|
||||
Uint8 rgucSensorTimestamp[4]; /* 27 - 32 bit little endian */
|
||||
|
||||
} PS5StatePacketCommon_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Uint8 ucLeftJoystickX; /* 0 */
|
||||
Uint8 ucLeftJoystickY; /* 1 */
|
||||
Uint8 ucRightJoystickX; /* 2 */
|
||||
Uint8 ucRightJoystickY; /* 3 */
|
||||
Uint8 ucTriggerLeft; /* 4 */
|
||||
Uint8 ucTriggerRight; /* 5 */
|
||||
Uint8 ucCounter; /* 6 */
|
||||
Uint8 rgucButtonsAndHat[4]; /* 7 */
|
||||
Uint8 rgucPacketSequence[4]; /* 11 - 32 bit little endian */
|
||||
Uint8 rgucGyroX[2]; /* 15 */
|
||||
Uint8 rgucGyroY[2]; /* 17 */
|
||||
Uint8 rgucGyroZ[2]; /* 19 */
|
||||
Uint8 rgucAccelX[2]; /* 21 */
|
||||
Uint8 rgucAccelY[2]; /* 23 */
|
||||
Uint8 rgucAccelZ[2]; /* 25 */
|
||||
Uint8 rgucSensorTimestamp[4]; /* 27 - 32 bit little endian */
|
||||
Uint8 ucSensorTemp; /* 31 */
|
||||
Uint8 ucTouchpadCounter1; /* 32 - high bit clear + counter */
|
||||
Uint8 rgucTouchpadData1[3]; /* 33 - X/Y, 12 bits per axis */
|
||||
Uint8 ucTouchpadCounter2; /* 36 - high bit clear + counter */
|
||||
Uint8 rgucTouchpadData2[3]; /* 37 - X/Y, 12 bits per axis */
|
||||
Uint8 rgucUnknown1[8]; /* 40 */
|
||||
Uint8 rgucTimer2[4]; /* 48 - 32 bit little endian */
|
||||
Uint8 ucBatteryLevel; /* 52 */
|
||||
Uint8 ucConnectState; /* 53 - 0x08 = USB, 0x01 = headphone */
|
||||
Uint8 ucLeftJoystickX; /* 0 */
|
||||
Uint8 ucLeftJoystickY; /* 1 */
|
||||
Uint8 ucRightJoystickX; /* 2 */
|
||||
Uint8 ucRightJoystickY; /* 3 */
|
||||
Uint8 ucTriggerLeft; /* 4 */
|
||||
Uint8 ucTriggerRight; /* 5 */
|
||||
Uint8 ucCounter; /* 6 */
|
||||
Uint8 rgucButtonsAndHat[4]; /* 7 */
|
||||
Uint8 rgucPacketSequence[4]; /* 11 - 32 bit little endian */
|
||||
Uint8 rgucGyroX[2]; /* 15 */
|
||||
Uint8 rgucGyroY[2]; /* 17 */
|
||||
Uint8 rgucGyroZ[2]; /* 19 */
|
||||
Uint8 rgucAccelX[2]; /* 21 */
|
||||
Uint8 rgucAccelY[2]; /* 23 */
|
||||
Uint8 rgucAccelZ[2]; /* 25 */
|
||||
Uint8 rgucSensorTimestamp[4]; /* 27 - 32 bit little endian */
|
||||
Uint8 ucSensorTemp; /* 31 */
|
||||
Uint8 ucTouchpadCounter1; /* 32 - high bit clear + counter */
|
||||
Uint8 rgucTouchpadData1[3]; /* 33 - X/Y, 12 bits per axis */
|
||||
Uint8 ucTouchpadCounter2; /* 36 - high bit clear + counter */
|
||||
Uint8 rgucTouchpadData2[3]; /* 37 - X/Y, 12 bits per axis */
|
||||
Uint8 rgucUnknown1[8]; /* 40 */
|
||||
Uint8 rgucTimer2[4]; /* 48 - 32 bit little endian */
|
||||
Uint8 ucBatteryLevel; /* 52 */
|
||||
Uint8 ucConnectState; /* 53 - 0x08 = USB, 0x01 = headphone */
|
||||
|
||||
/* There's more unknown data at the end, and a 32-bit CRC on Bluetooth */
|
||||
} PS5StatePacket_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Uint8 ucLeftJoystickX; /* 0 */
|
||||
Uint8 ucLeftJoystickY; /* 1 */
|
||||
Uint8 ucRightJoystickX; /* 2 */
|
||||
Uint8 ucRightJoystickY; /* 3 */
|
||||
Uint8 ucTriggerLeft; /* 4 */
|
||||
Uint8 ucTriggerRight; /* 5 */
|
||||
Uint8 ucCounter; /* 6 */
|
||||
Uint8 rgucButtonsAndHat[4]; /* 7 */
|
||||
Uint8 rgucPacketSequence[4]; /* 11 - 32 bit little endian */
|
||||
Uint8 rgucGyroX[2]; /* 15 */
|
||||
Uint8 rgucGyroY[2]; /* 17 */
|
||||
Uint8 rgucGyroZ[2]; /* 19 */
|
||||
Uint8 rgucAccelX[2]; /* 21 */
|
||||
Uint8 rgucAccelY[2]; /* 23 */
|
||||
Uint8 rgucAccelZ[2]; /* 25 */
|
||||
Uint8 rgucSensorTimestamp[4]; /* 27 - 32 bit little endian */
|
||||
Uint8 ucTouchpadCounter1; /* 31 - high bit clear + counter */
|
||||
Uint8 rgucTouchpadData1[3]; /* 32 - X/Y, 12 bits per axis */
|
||||
Uint8 ucTouchpadCounter2; /* 35 - high bit clear + counter */
|
||||
Uint8 rgucTouchpadData2[3]; /* 36 - X/Y, 12 bits per axis */
|
||||
Uint8 ucLeftJoystickX; /* 0 */
|
||||
Uint8 ucLeftJoystickY; /* 1 */
|
||||
Uint8 ucRightJoystickX; /* 2 */
|
||||
Uint8 ucRightJoystickY; /* 3 */
|
||||
Uint8 ucTriggerLeft; /* 4 */
|
||||
Uint8 ucTriggerRight; /* 5 */
|
||||
Uint8 ucCounter; /* 6 */
|
||||
Uint8 rgucButtonsAndHat[4]; /* 7 */
|
||||
Uint8 rgucPacketSequence[4]; /* 11 - 32 bit little endian */
|
||||
Uint8 rgucGyroX[2]; /* 15 */
|
||||
Uint8 rgucGyroY[2]; /* 17 */
|
||||
Uint8 rgucGyroZ[2]; /* 19 */
|
||||
Uint8 rgucAccelX[2]; /* 21 */
|
||||
Uint8 rgucAccelY[2]; /* 23 */
|
||||
Uint8 rgucAccelZ[2]; /* 25 */
|
||||
Uint8 rgucSensorTimestamp[4]; /* 27 - 32 bit little endian */
|
||||
Uint8 ucTouchpadCounter1; /* 31 - high bit clear + counter */
|
||||
Uint8 rgucTouchpadData1[3]; /* 32 - X/Y, 12 bits per axis */
|
||||
Uint8 ucTouchpadCounter2; /* 35 - high bit clear + counter */
|
||||
Uint8 rgucTouchpadData2[3]; /* 36 - X/Y, 12 bits per axis */
|
||||
|
||||
/* There's more unknown data at the end, and a 32-bit CRC on Bluetooth */
|
||||
} PS5StatePacketAlt_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Uint8 ucEnableBits1; /* 0 */
|
||||
Uint8 ucEnableBits2; /* 1 */
|
||||
Uint8 ucRumbleRight; /* 2 */
|
||||
Uint8 ucRumbleLeft; /* 3 */
|
||||
Uint8 ucHeadphoneVolume; /* 4 */
|
||||
Uint8 ucSpeakerVolume; /* 5 */
|
||||
Uint8 ucMicrophoneVolume; /* 6 */
|
||||
Uint8 ucAudioEnableBits; /* 7 */
|
||||
Uint8 ucMicLightMode; /* 8 */
|
||||
Uint8 ucAudioMuteBits; /* 9 */
|
||||
Uint8 rgucRightTriggerEffect[11]; /* 10 */
|
||||
Uint8 rgucLeftTriggerEffect[11]; /* 21 */
|
||||
Uint8 rgucUnknown1[6]; /* 32 */
|
||||
Uint8 ucEnableBits3; /* 38 */
|
||||
Uint8 rgucUnknown2[2]; /* 39 */
|
||||
Uint8 ucLedAnim; /* 41 */
|
||||
Uint8 ucLedBrightness; /* 42 */
|
||||
Uint8 ucPadLights; /* 43 */
|
||||
Uint8 ucLedRed; /* 44 */
|
||||
Uint8 ucLedGreen; /* 45 */
|
||||
Uint8 ucLedBlue; /* 46 */
|
||||
Uint8 ucEnableBits1; /* 0 */
|
||||
Uint8 ucEnableBits2; /* 1 */
|
||||
Uint8 ucRumbleRight; /* 2 */
|
||||
Uint8 ucRumbleLeft; /* 3 */
|
||||
Uint8 ucHeadphoneVolume; /* 4 */
|
||||
Uint8 ucSpeakerVolume; /* 5 */
|
||||
Uint8 ucMicrophoneVolume; /* 6 */
|
||||
Uint8 ucAudioEnableBits; /* 7 */
|
||||
Uint8 ucMicLightMode; /* 8 */
|
||||
Uint8 ucAudioMuteBits; /* 9 */
|
||||
Uint8 rgucRightTriggerEffect[11]; /* 10 */
|
||||
Uint8 rgucLeftTriggerEffect[11]; /* 21 */
|
||||
Uint8 rgucUnknown1[6]; /* 32 */
|
||||
Uint8 ucEnableBits3; /* 38 */
|
||||
Uint8 rgucUnknown2[2]; /* 39 */
|
||||
Uint8 ucLedAnim; /* 41 */
|
||||
Uint8 ucLedBrightness; /* 42 */
|
||||
Uint8 ucPadLights; /* 43 */
|
||||
Uint8 ucLedRed; /* 44 */
|
||||
Uint8 ucLedGreen; /* 45 */
|
||||
Uint8 ucLedBlue; /* 46 */
|
||||
} DS5EffectsState_t;
|
||||
|
||||
typedef enum {
|
||||
k_EDS5EffectRumbleStart = (1 << 0),
|
||||
k_EDS5EffectRumble = (1 << 1),
|
||||
k_EDS5EffectLEDReset = (1 << 2),
|
||||
k_EDS5EffectLED = (1 << 3),
|
||||
k_EDS5EffectPadLights = (1 << 4),
|
||||
k_EDS5EffectMicLight = (1 << 5)
|
||||
typedef enum
|
||||
{
|
||||
k_EDS5EffectRumbleStart = (1 << 0),
|
||||
k_EDS5EffectRumble = (1 << 1),
|
||||
k_EDS5EffectLEDReset = (1 << 2),
|
||||
k_EDS5EffectLED = (1 << 3),
|
||||
k_EDS5EffectPadLights = (1 << 4),
|
||||
k_EDS5EffectMicLight = (1 << 5)
|
||||
} EDS5Effect;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
k_EDS5LEDResetStateNone,
|
||||
k_EDS5LEDResetStatePending,
|
||||
k_EDS5LEDResetStateComplete,
|
||||
} EDS5LEDResetState;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
Sint16 bias;
|
||||
float sensitivity;
|
||||
} IMUCalibrationData;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
SDL_HIDAPI_Device *device;
|
||||
SDL_Joystick *joystick;
|
||||
SDL_bool use_alternate_report;
|
||||
@@ -235,20 +238,17 @@ typedef struct {
|
||||
|
||||
static int HIDAPI_DriverPS5_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size);
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_RegisterHints(SDL_HintCallback callback, void *userdata)
|
||||
static void HIDAPI_DriverPS5_RegisterHints(SDL_HintCallback callback, void *userdata)
|
||||
{
|
||||
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS5, callback, userdata);
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_UnregisterHints(SDL_HintCallback callback, void *userdata)
|
||||
static void HIDAPI_DriverPS5_UnregisterHints(SDL_HintCallback callback, void *userdata)
|
||||
{
|
||||
SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS5, callback, userdata);
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverPS5_IsEnabled(void)
|
||||
static SDL_bool HIDAPI_DriverPS5_IsEnabled(void)
|
||||
{
|
||||
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS5, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
|
||||
}
|
||||
@@ -260,8 +260,7 @@ static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report
|
||||
return SDL_hid_get_feature_report(dev, report, length);
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverPS5_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
|
||||
static SDL_bool HIDAPI_DriverPS5_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
|
||||
{
|
||||
Uint8 data[USB_PACKET_LENGTH];
|
||||
int size;
|
||||
@@ -287,8 +286,7 @@ HIDAPI_DriverPS5_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name,
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
SetLedsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
|
||||
static void SetLedsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
|
||||
{
|
||||
/* This list is the same as what hid-sony.c uses in the Linux kernel.
|
||||
The first 4 values correspond to what the PS4 assigns.
|
||||
@@ -314,8 +312,7 @@ SetLedsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
|
||||
effects->ucLedBlue = colors[player_index][2];
|
||||
}
|
||||
|
||||
static void
|
||||
SetLightsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
|
||||
static void SetLightsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
|
||||
{
|
||||
static const Uint8 lights[] = {
|
||||
0x04,
|
||||
@@ -333,11 +330,10 @@ SetLightsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||
static SDL_bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx;
|
||||
Uint8 data[USB_PACKET_LENGTH*2];
|
||||
Uint8 data[USB_PACKET_LENGTH * 2];
|
||||
int size;
|
||||
char serial[18];
|
||||
SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
|
||||
@@ -401,7 +397,7 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||
*/
|
||||
if (ReadFeatureReport(device->dev, k_EPS5FeatureReportIdSerialNumber, data, sizeof(data)) >= 7) {
|
||||
SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
}
|
||||
|
||||
/* Read the firmware version
|
||||
@@ -490,14 +486,12 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||
return HIDAPI_JoystickConnected(device, NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverPS5_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
|
||||
static int HIDAPI_DriverPS5_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_LoadCalibrationData(SDL_HIDAPI_Device *device)
|
||||
static void HIDAPI_DriverPS5_LoadCalibrationData(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
int i, size;
|
||||
@@ -589,8 +583,7 @@ HIDAPI_DriverPS5_LoadCalibrationData(SDL_HIDAPI_Device *device)
|
||||
}
|
||||
}
|
||||
|
||||
static float
|
||||
HIDAPI_DriverPS5_ApplyCalibrationData(SDL_DriverPS5_Context *ctx, int index, Sint16 value)
|
||||
static float HIDAPI_DriverPS5_ApplyCalibrationData(SDL_DriverPS5_Context *ctx, int index, Sint16 value)
|
||||
{
|
||||
float result;
|
||||
|
||||
@@ -613,8 +606,7 @@ HIDAPI_DriverPS5_ApplyCalibrationData(SDL_DriverPS5_Context *ctx, int index, Sin
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, int effect_mask)
|
||||
static int HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, int effect_mask)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
DS5EffectsState_t effects;
|
||||
@@ -626,7 +618,7 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, int effect_mask)
|
||||
SDL_zero(effects);
|
||||
|
||||
/* Make sure the Bluetooth connection sequence has completed before sending LED color change */
|
||||
if (device->is_bluetooth &&
|
||||
if (device->is_bluetooth &&
|
||||
(effect_mask & (k_EDS5EffectLED | k_EDS5EffectPadLights)) != 0) {
|
||||
if (ctx->led_reset_state != k_EDS5LEDResetStateComplete) {
|
||||
ctx->led_reset_state = k_EDS5LEDResetStatePending;
|
||||
@@ -691,14 +683,13 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, int effect_mask)
|
||||
if ((effect_mask & k_EDS5EffectMicLight) != 0) {
|
||||
effects.ucEnableBits2 |= 0x01; /* Enable microphone light */
|
||||
|
||||
effects.ucMicLightMode = 0; /* Bitmask, 0x00 = off, 0x01 = solid, 0x02 = pulse */
|
||||
effects.ucMicLightMode = 0; /* Bitmask, 0x00 = off, 0x01 = solid, 0x02 = pulse */
|
||||
}
|
||||
|
||||
return HIDAPI_DriverPS5_SendJoystickEffect(device, ctx->joystick, &effects, sizeof(effects));
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_CheckPendingLEDReset(SDL_HIDAPI_Device *device)
|
||||
static void HIDAPI_DriverPS5_CheckPendingLEDReset(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
SDL_bool led_reset_complete = SDL_FALSE;
|
||||
@@ -729,8 +720,7 @@ HIDAPI_DriverPS5_CheckPendingLEDReset(SDL_HIDAPI_Device *device)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_TickleBluetooth(SDL_HIDAPI_Device *device)
|
||||
static void HIDAPI_DriverPS5_TickleBluetooth(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
/* This is just a dummy packet that should have no effect, since we don't set the CRC */
|
||||
Uint8 data[78];
|
||||
@@ -738,15 +728,14 @@ HIDAPI_DriverPS5_TickleBluetooth(SDL_HIDAPI_Device *device)
|
||||
SDL_zeroa(data);
|
||||
|
||||
data[0] = k_EPS5ReportIdBluetoothEffects;
|
||||
data[1] = 0x02; /* Magic value */
|
||||
data[1] = 0x02; /* Magic value */
|
||||
|
||||
if (SDL_HIDAPI_LockRumble() == 0) {
|
||||
SDL_HIDAPI_SendRumbleAndUnlock(device, data, sizeof(data));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_SetEnhancedMode(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
static void HIDAPI_DriverPS5_SetEnhancedMode(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
|
||||
@@ -798,8 +787,7 @@ static void SDLCALL SDL_PS5PlayerLEDHintChanged(void *userdata, const char *name
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
|
||||
static void HIDAPI_DriverPS5_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
|
||||
@@ -813,8 +801,7 @@ HIDAPI_DriverPS5_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID
|
||||
HIDAPI_DriverPS5_UpdateEffects(device, (k_EDS5EffectLED | k_EDS5EffectPadLights));
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
static SDL_bool HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
|
||||
@@ -852,8 +839,7 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverPS5_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
static int HIDAPI_DriverPS5_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
|
||||
@@ -871,14 +857,12 @@ HIDAPI_DriverPS5_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
|
||||
return HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectRumble);
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverPS5_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
static int HIDAPI_DriverPS5_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static Uint32
|
||||
HIDAPI_DriverPS5_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
static Uint32 HIDAPI_DriverPS5_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
Uint32 result = 0;
|
||||
@@ -895,8 +879,7 @@ HIDAPI_DriverPS5_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverPS5_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
static int HIDAPI_DriverPS5_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
|
||||
@@ -912,8 +895,7 @@ HIDAPI_DriverPS5_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
|
||||
return HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectLED);
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverPS5_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size)
|
||||
static int HIDAPI_DriverPS5_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
Uint8 data[78];
|
||||
@@ -934,7 +916,7 @@ HIDAPI_DriverPS5_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joy
|
||||
|
||||
if (device->is_bluetooth) {
|
||||
data[0] = k_EPS5ReportIdBluetoothEffects;
|
||||
data[1] = 0x02; /* Magic value */
|
||||
data[1] = 0x02; /* Magic value */
|
||||
|
||||
report_size = 78;
|
||||
offset = 2;
|
||||
@@ -981,8 +963,7 @@ HIDAPI_DriverPS5_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joy
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled)
|
||||
static int HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
|
||||
@@ -999,8 +980,7 @@ HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5SimpleStatePacket_t *packet)
|
||||
static void HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5SimpleStatePacket_t *packet)
|
||||
{
|
||||
Sint16 axis;
|
||||
|
||||
@@ -1093,8 +1073,7 @@ HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL_hid_device
|
||||
SDL_memcpy(&ctx->last_state.simple, packet, sizeof(ctx->last_state.simple));
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacketCommon_t *packet)
|
||||
static void HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacketCommon_t *packet)
|
||||
{
|
||||
Sint16 axis;
|
||||
|
||||
@@ -1223,8 +1202,7 @@ HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL_hid_device
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacket_t *packet)
|
||||
static void HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacket_t *packet)
|
||||
{
|
||||
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
|
||||
static const float TOUCHPAD_SCALEY = 1.0f / 1070;
|
||||
@@ -1266,8 +1244,7 @@ HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev,
|
||||
SDL_memcpy(&ctx->last_state, packet, sizeof(ctx->last_state));
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_HandleStatePacketAlt(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacketAlt_t *packet)
|
||||
static void HIDAPI_DriverPS5_HandleStatePacketAlt(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacketAlt_t *packet)
|
||||
{
|
||||
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
|
||||
static const float TOUCHPAD_SCALEY = 1.0f / 1070;
|
||||
@@ -1276,21 +1253,20 @@ HIDAPI_DriverPS5_HandleStatePacketAlt(SDL_Joystick *joystick, SDL_hid_device *de
|
||||
|
||||
if (ctx->report_touchpad) {
|
||||
touchpad_state = ((packet->ucTouchpadCounter1 & 0x80) == 0) ? SDL_PRESSED : SDL_RELEASED;
|
||||
touchpad_x = packet->rgucTouchpadData1[0] | (((int) packet->rgucTouchpadData1[1] & 0x0F) << 8);
|
||||
touchpad_y = (packet->rgucTouchpadData1[1] >> 4) | ((int) packet->rgucTouchpadData1[2] << 4);
|
||||
touchpad_x = packet->rgucTouchpadData1[0] | (((int)packet->rgucTouchpadData1[1] & 0x0F) << 8);
|
||||
touchpad_y = (packet->rgucTouchpadData1[1] >> 4) | ((int)packet->rgucTouchpadData1[2] << 4);
|
||||
SDL_PrivateJoystickTouchpad(joystick, 0, 0, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
|
||||
|
||||
touchpad_state = ((packet->ucTouchpadCounter2 & 0x80) == 0) ? SDL_PRESSED : SDL_RELEASED;
|
||||
touchpad_x = packet->rgucTouchpadData2[0] | (((int) packet->rgucTouchpadData2[1] & 0x0F) << 8);
|
||||
touchpad_y = (packet->rgucTouchpadData2[1] >> 4) | ((int) packet->rgucTouchpadData2[2] << 4);
|
||||
touchpad_x = packet->rgucTouchpadData2[0] | (((int)packet->rgucTouchpadData2[1] & 0x0F) << 8);
|
||||
touchpad_y = (packet->rgucTouchpadData2[1] >> 4) | ((int)packet->rgucTouchpadData2[2] << 4);
|
||||
SDL_PrivateJoystickTouchpad(joystick, 0, 1, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
|
||||
}
|
||||
|
||||
SDL_memcpy(&ctx->last_state, packet, sizeof(ctx->last_state));
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
VerifyCRC(Uint8 *data, int size)
|
||||
static SDL_bool VerifyCRC(Uint8 *data, int size)
|
||||
{
|
||||
Uint8 ubHdr = 0xA1; /* hidp header is part of the CRC calculation */
|
||||
Uint32 unCRC, unPacketCRC;
|
||||
@@ -1305,8 +1281,7 @@ VerifyCRC(Uint8 *data, int size)
|
||||
return (unCRC == unPacketCRC) ? SDL_TRUE : SDL_FALSE;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverPS5_IsPacketValid(SDL_DriverPS5_Context *ctx, Uint8 *data, int size)
|
||||
static SDL_bool HIDAPI_DriverPS5_IsPacketValid(SDL_DriverPS5_Context *ctx, Uint8 *data, int size)
|
||||
{
|
||||
switch (data[0]) {
|
||||
case k_EPS5ReportIdState:
|
||||
@@ -1323,12 +1298,11 @@ HIDAPI_DriverPS5_IsPacketValid(SDL_DriverPS5_Context *ctx, Uint8 *data, int size
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
static SDL_bool HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
SDL_Joystick *joystick = NULL;
|
||||
Uint8 data[USB_PACKET_LENGTH*2];
|
||||
Uint8 data[USB_PACKET_LENGTH * 2];
|
||||
int size;
|
||||
int packet_count = 0;
|
||||
Uint32 now = SDL_GetTicks();
|
||||
@@ -1411,8 +1385,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
return size >= 0;
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
static void HIDAPI_DriverPS5_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
|
||||
@@ -1425,13 +1398,11 @@ HIDAPI_DriverPS5_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick
|
||||
ctx->joystick = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_FreeDevice(SDL_HIDAPI_Device *device)
|
||||
static void HIDAPI_DriverPS5_FreeDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
}
|
||||
|
||||
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5 =
|
||||
{
|
||||
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5 = {
|
||||
SDL_HINT_JOYSTICK_HIDAPI_PS5,
|
||||
SDL_TRUE,
|
||||
HIDAPI_DriverPS5_RegisterHints,
|
||||
|
Reference in New Issue
Block a user