From c8211964d139a33cc116ea58bdf6d1e73e47ef65 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Svoboda?= <[EMAIL REDACTED]>
Date: Tue, 3 Nov 2026 01:32:49 +0100
Subject: [PATCH] hidapi: add trigger rumble for the Flydigi Vader 5 Pro
(#16529)
---
src/joystick/hidapi/SDL_hidapi_flydigi.c | 52 +++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/src/joystick/hidapi/SDL_hidapi_flydigi.c b/src/joystick/hidapi/SDL_hidapi_flydigi.c
index 136253ef04247..537514d55e55d 100644
--- a/src/joystick/hidapi/SDL_hidapi_flydigi.c
+++ b/src/joystick/hidapi/SDL_hidapi_flydigi.c
@@ -88,6 +88,7 @@ typedef struct
bool has_cz;
bool has_lmrm;
bool has_circle;
+ bool has_trigger_rumble;
bool wireless;
bool sensors_supported;
bool sensors_enabled;
@@ -100,6 +101,10 @@ typedef struct
Uint64 next_status_request;
Uint64 last_packet;
bool acquired;
+ Uint8 low_frequency_rumble;
+ Uint8 high_frequency_rumble;
+ Uint8 left_trigger_rumble;
+ Uint8 right_trigger_rumble;
Uint8 last_state[USB_PACKET_LENGTH];
} SDL_DriverFlydigi_Context;
@@ -281,6 +286,7 @@ static void HIDAPI_DriverFlydigi_UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
ctx->has_cz = true;
ctx->has_lmrm = true;
ctx->has_circle = true;
+ ctx->has_trigger_rumble = true;
ctx->sensors_supported = true;
ctx->accelScale = SDL_STANDARD_GRAVITY / 4096.0f;
ctx->gyroScale = DEG2RAD(2000.0f);
@@ -668,6 +674,10 @@ static bool HIDAPI_DriverFlydigi_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joy
SDL_AssertJoysticksLocked();
SDL_zeroa(ctx->last_state);
+ ctx->low_frequency_rumble = 0;
+ ctx->high_frequency_rumble = 0;
+ ctx->left_trigger_rumble = 0;
+ ctx->right_trigger_rumble = 0;
// Initialize the joystick capabilities
joystick->nbuttons = SDL_GAMEPAD_NUM_BASE_FLYDIGI_BUTTONS;
@@ -695,8 +705,28 @@ static bool HIDAPI_DriverFlydigi_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joy
return true;
}
+static bool HIDAPI_DriverFlydigi_SendRumbleV2(SDL_DriverFlydigi_Context *ctx)
+{
+ SDL_HIDAPI_Device *device = ctx->device;
+ Uint8 rumble_packet[] = { FLYDIGI_V2_CMD_REPORT_ID, FLYDIGI_V2_MAGIC1, FLYDIGI_V2_MAGIC2, FLYDIGI_V2_HAPTIC_COMMAND, 6, 0, 0, 0, 0, 0 };
+ rumble_packet[5] = ctx->low_frequency_rumble;
+ rumble_packet[6] = ctx->high_frequency_rumble;
+ rumble_packet[7] = ctx->left_trigger_rumble;
+ rumble_packet[8] = ctx->right_trigger_rumble;
+ if (HIDAPI_DriverFlydigi_UsesUnnumberedReports(device)) {
+ rumble_packet[0] = 0;
+ }
+
+ if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
+ return SDL_SetError("Couldn't send rumble packet");
+ }
+ return true;
+}
+
static bool HIDAPI_DriverFlydigi_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
+ SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
+
if (device->vendor_id == USB_VENDOR_FLYDIGI_V1) {
Uint8 rumble_packet[] = { FLYDIGI_V1_CMD_REPORT_ID, FLYDIGI_V1_HAPTIC_COMMAND, 0x00, 0x00 };
rumble_packet[2] = low_frequency_rumble >> 8;
@@ -720,9 +750,28 @@ static bool HIDAPI_DriverFlydigi_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_J
return true;
}
+static bool HIDAPI_DriverFlydigi_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
+{
+ SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
+
+ if (!ctx->has_trigger_rumble) {
+ return SDL_Unsupported();
+ }
+
+ ctx->left_trigger_rumble = left_rumble >> 8;
+ ctx->right_trigger_rumble = right_rumble >> 8;
+ return HIDAPI_DriverFlydigi_SendRumbleV2(ctx);
+}
+
static Uint32 HIDAPI_DriverFlydigi_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
- return SDL_JOYSTICK_CAP_RUMBLE;
+ SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
+ Uint32 caps = SDL_JOYSTICK_CAP_RUMBLE;
+
+ if (ctx->has_trigger_rumble) {
+ caps |= SDL_JOYSTICK_CAP_TRIGGER_RUMBLE;
+ }
+ return caps;
}
static bool HIDAPI_DriverFlydigi_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
@@ -1136,6 +1185,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverFlydigi = {
.UpdateDevice = HIDAPI_DriverFlydigi_UpdateDevice,
.OpenJoystick = HIDAPI_DriverFlydigi_OpenJoystick,
.RumbleJoystick = HIDAPI_DriverFlydigi_RumbleJoystick,
+ .RumbleJoystickTriggers = HIDAPI_DriverFlydigi_RumbleJoystickTriggers,
.GetJoystickCapabilities = HIDAPI_DriverFlydigi_GetJoystickCapabilities,
.SetJoystickSensorsEnabled = HIDAPI_DriverFlydigi_SetJoystickSensorsEnabled,
.CloseJoystick = HIDAPI_DriverFlydigi_CloseJoystick,