DualSense adaptive trigger support (#1561)

This commit is contained in:
ABeltramo 2025-04-02 04:45:25 +02:00 committed by GitHub
commit d9c7a245ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 83 additions and 1 deletions

View file

@ -900,6 +900,22 @@ void SdlInputHandler::setControllerLED(uint16_t controllerNumber, uint8_t r, uin
#endif
}
void SdlInputHandler::setAdaptiveTriggers(uint16_t controllerNumber, DualSenseOutputReport *report){
#if SDL_VERSION_ATLEAST(2, 0, 16)
// Make sure the controller number is within our supported count
if (controllerNumber <= MAX_GAMEPADS &&
// and we have a valid controller
m_GamepadState[controllerNumber].controller != nullptr &&
// and it's a PS5 controller
SDL_GameControllerGetType(m_GamepadState[controllerNumber].controller) == SDL_CONTROLLER_TYPE_PS5) {
SDL_GameControllerSendEffect(m_GamepadState[controllerNumber].controller, report, sizeof(*report));
}
#endif
SDL_free(report);
}
QString SdlInputHandler::getUnmappedGamepads()
{
QString ret;

View file

@ -38,6 +38,37 @@ struct GamepadState {
unsigned char lt, rt;
};
struct DualSenseOutputReport{
uint8_t validFlag0;
uint8_t validFlag1;
/* For DualShock 4 compatibility mode. */
uint8_t motorRight;
uint8_t motorLeft;
/* Audio controls */
uint8_t reserved[4];
uint8_t muteButtonLed;
uint8_t powerSaveControl;
uint8_t rightTriggerEffectType;
uint8_t rightTriggerEffect[DS_EFFECT_PAYLOAD_SIZE];
uint8_t leftTriggerEffectType;
uint8_t leftTriggerEffect[DS_EFFECT_PAYLOAD_SIZE];
uint8_t reserved2[6];
/* LEDs and lightbar */
uint8_t validFlag2;
uint8_t reserved3[2];
uint8_t lightbarSetup;
uint8_t ledBrightness;
uint8_t playerLeds;
uint8_t lightbarRed;
uint8_t lightbarGreen;
uint8_t lightbarBlue;
};
// activeGamepadMask is a short, so we're bounded by the number of mask bits
#define MAX_GAMEPADS 16
@ -95,6 +126,8 @@ public:
void setControllerLED(uint16_t controllerNumber, uint8_t r, uint8_t g, uint8_t b);
void setAdaptiveTriggers(uint16_t controllerNumber, DualSenseOutputReport *report);
void handleTouchFingerEvent(SDL_TouchFingerEvent* event);
int getAttachedGamepadMask();