From 892eb2b859849daae1ca6df3535c77278fe36861 Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Tue, 29 Oct 2024 22:06:07 +0100 Subject: [PATCH] idz, idac, swdc: fixed rumble effect --- dist/idac/segatools.ini | 1 - dist/idz/segatools.ini | 1 - dist/swdc/segatools.ini | 1 - idacio/di-dev.c | 116 ++++++++++++++++++---------------------- idzio/di-dev.c | 116 ++++++++++++++++++---------------------- swdcio/di-dev.c | 116 ++++++++++++++++++---------------------- 6 files changed, 156 insertions(+), 195 deletions(-) diff --git a/dist/idac/segatools.ini b/dist/idac/segatools.ini index da94d64..a2387af 100644 --- a/dist/idac/segatools.ini +++ b/dist/idac/segatools.ini @@ -250,7 +250,6 @@ constantForceStrength=100 damperStrength=100 ; Rumble strength, used for road surface effects. -; WARNING: THIS WILL CRASH ON FANATEC (maybe even more) WHEELS! rumbleStrength=100 ; Rumble duration factor from ms to µs, used to scale the duration of the rumble effect. rumbleDuration=1000 diff --git a/dist/idz/segatools.ini b/dist/idz/segatools.ini index 126a5b7..e617de2 100644 --- a/dist/idz/segatools.ini +++ b/dist/idz/segatools.ini @@ -240,7 +240,6 @@ constantForceStrength=100 damperStrength=100 ; Rumble strength, used for road surface effects. -; WARNING: THIS WILL CRASH ON FANATEC (maybe even more) WHEELS! rumbleStrength=100 ; Rumble duration factor from ms to µs, used to scale the duration of the rumble effect. rumbleDuration=1000 \ No newline at end of file diff --git a/dist/swdc/segatools.ini b/dist/swdc/segatools.ini index b6b15b8..1b24a74 100644 --- a/dist/swdc/segatools.ini +++ b/dist/swdc/segatools.ini @@ -200,7 +200,6 @@ constantForceStrength=100 damperStrength=100 ; Rumble strength, used for road surface effects. -; WARNING: THIS WILL CRASH ON FANATEC (maybe even more) WHEELS! rumbleStrength=100 ; Rumble duration factor from ms to µs, used to scale the duration of the rumble effect. rumbleDuration=1000 diff --git a/idacio/di-dev.c b/idacio/di-dev.c index a8b6e0b..5f959f6 100644 --- a/idacio/di-dev.c +++ b/idacio/di-dev.c @@ -37,9 +37,9 @@ HRESULT idac_di_dev_init( } HRESULT idac_di_dev_poll( - IDirectInputDevice8W *dev, - HWND wnd, - union idac_di_state *out) + IDirectInputDevice8W *dev, + HWND wnd, + union idac_di_state *out) { HRESULT hr; MSG msg; @@ -59,17 +59,14 @@ HRESULT idac_di_dev_poll( } hr = IDirectInputDevice8_GetDeviceState( - dev, - sizeof(out->st), - &out->st); + dev, + sizeof(out->st), + &out->st); if (FAILED(hr)) { - dprintf("DirectInput: GetDeviceState error: %08x\n", (int) hr); + dprintf("DirectInput: GetDeviceState error: %08x\n", (int)hr); } - /* JVS lacks a protocol for reporting hardware errors from poll command - responses, so this ends up returning zeroed input state instead. */ - return hr; } @@ -80,29 +77,26 @@ HRESULT idac_di_dev_start(IDirectInputDevice8W *dev, HWND wnd) { assert(wnd != NULL); hr = IDirectInputDevice8_SetCooperativeLevel( - dev, - wnd, - DISCL_BACKGROUND | DISCL_EXCLUSIVE); + dev, + wnd, + DISCL_BACKGROUND | DISCL_EXCLUSIVE); if (FAILED(hr)) { - dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int) hr); - + dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int)hr); return hr; } hr = IDirectInputDevice8_SetDataFormat(dev, &c_dfDIJoystick); if (FAILED(hr)) { - dprintf("DirectInput: SetDataFormat failed: %08x\n", (int) hr); - + dprintf("DirectInput: SetDataFormat failed: %08x\n", (int)hr); return hr; } hr = IDirectInputDevice8_Acquire(dev); if (FAILED(hr)) { - dprintf("DirectInput: Acquire failed: %08x\n", (int) hr); - + dprintf("DirectInput: Acquire failed: %08x\n", (int)hr); return hr; } @@ -168,7 +162,6 @@ void idac_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force) cf.lMagnitude = (direction_ffb == 0) ? -magnitude : magnitude; axis = DIJOFS_X; - /* Irrelevant as magnitude descripbes the direction */ direction = 0; memset(&fx, 0, sizeof(fx)); @@ -184,38 +177,38 @@ void idac_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force) fx.cbTypeSpecificParams = sizeof(cf); fx.lpvTypeSpecificParams = &cf; + /* Check if the effect already exists */ if (idac_di_fx != NULL) { - // Try to update the existing effect hr = IDirectInputEffect_SetParameters(idac_di_fx, &fx, DIEP_TYPESPECIFICPARAMS); - if (SUCCEEDED(hr)) { - return; - } else { + return; // Successfully updated existing effect + } + else { dprintf("DirectInput: Failed to update constant force feedback, recreating effect: %08x\n", (int)hr); - // Stop and release the current effect if updating fails IDirectInputEffect_Stop(idac_di_fx); IDirectInputEffect_Release(idac_di_fx); - idac_di_fx = NULL; + idac_di_fx = NULL; // Reset the pointer } } - // Create a new constant force effect + /* Create a new constant force effect */ IDirectInputEffect *obj; hr = IDirectInputDevice8_CreateEffect( - idac_di_dev, - &GUID_ConstantForce, - &fx, - &obj, - NULL); + idac_di_dev, + &GUID_ConstantForce, + &fx, + &obj, + NULL); if (FAILED(hr)) { - dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int) hr); + dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int)hr); return; } + /* Start the effect */ hr = IDirectInputEffect_Start(obj, INFINITE, 0); if (FAILED(hr)) { - dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int) hr); + dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int)hr); IDirectInputEffect_Release(obj); return; } @@ -239,9 +232,6 @@ void idac_di_ffb_rumble(uint8_t force, uint8_t period) DIPERIODIC pe; HRESULT hr; - /* Duration in microseconds, - Might be totally wrong as especially on FANATEC wheels as this code will - crash the game. TODO: Figure out why this effect will crash on FANATEC! */ DWORD duration = (DWORD)((double)force * ffb_duration); memset(&pe, 0, sizeof(pe)); @@ -256,7 +246,7 @@ void idac_di_ffb_rumble(uint8_t force, uint8_t period) memset(&fx, 0, sizeof(fx)); fx.dwSize = sizeof(fx); fx.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; - fx.dwDuration = duration; + fx.dwDuration = INFINITE; fx.dwGain = DI_FFNOMINALMAX; fx.dwTriggerButton = DIEB_NOTRIGGER; fx.dwTriggerRepeatInterval = INFINITE; @@ -266,37 +256,38 @@ void idac_di_ffb_rumble(uint8_t force, uint8_t period) fx.cbTypeSpecificParams = sizeof(pe); fx.lpvTypeSpecificParams = &pe; + /* Check if the effect already exists */ if (idac_di_fx_rumble != NULL) { - // Try to update the existing effect hr = IDirectInputEffect_SetParameters(idac_di_fx_rumble, &fx, DIEP_TYPESPECIFICPARAMS); - if (SUCCEEDED(hr)) { return; - } else { - dprintf("DirectInput: Failed to update periodic force feedback, recreating effect: %08x\n", (int)hr); - // Stop and release the current effect if updating fails + } + else { + dprintf("DirectInput: Failed to update rumble feedback, recreating effect: %08x\n", (int)hr); IDirectInputEffect_Stop(idac_di_fx_rumble); IDirectInputEffect_Release(idac_di_fx_rumble); idac_di_fx_rumble = NULL; } } + /* Create a new rumble effect */ IDirectInputEffect *obj; hr = IDirectInputDevice8_CreateEffect( - idac_di_dev, - &GUID_Sine, - &fx, - &obj, - NULL); + idac_di_dev, + &GUID_Sine, + &fx, + &obj, + NULL); if (FAILED(hr)) { - dprintf("DirectInput: Periodic force feedback creation failed: %08x\n", (int) hr); + dprintf("DirectInput: Rumble effect creation failed: %08x\n", (int)hr); return; } + /* Start the effect */ hr = IDirectInputEffect_Start(obj, INFINITE, 0); if (FAILED(hr)) { - dprintf("DirectInput: Periodic force feedback start failed: %08x\n", (int) hr); + dprintf("DirectInput: Rumble effect start failed: %08x\n", (int)hr); IDirectInputEffect_Release(obj); return; } @@ -343,38 +334,35 @@ void idac_di_ffb_damper(uint8_t force) fx.cbTypeSpecificParams = sizeof(cond); fx.lpvTypeSpecificParams = &cond; + /* Check if the damper effect already exists */ if (idac_di_fx_damper != NULL) { - // Try to update the existing effect hr = IDirectInputEffect_SetParameters(idac_di_fx_damper, &fx, DIEP_TYPESPECIFICPARAMS); - if (SUCCEEDED(hr)) { return; - } else { - dprintf("DirectInput: Failed to update damper force feedback, recreating effect: %08x\n", (int)hr); - // Stop and release the current effect if updating fails + } + else { IDirectInputEffect_Stop(idac_di_fx_damper); IDirectInputEffect_Release(idac_di_fx_damper); idac_di_fx_damper = NULL; } } - // Create a new damper force effect + /* Create a new damper effect */ IDirectInputEffect *obj; hr = IDirectInputDevice8_CreateEffect( - idac_di_dev, - &GUID_Damper, - &fx, - &obj, - NULL); + idac_di_dev, + &GUID_Damper, + &fx, + &obj, + NULL); if (FAILED(hr)) { - dprintf("DirectInput: Damper force feedback creation failed: %08x\n", (int) hr); return; } - hr = IDirectInputEffect_Start(obj, INFINITE, 0); + /* Start the effect */ + hr = IDirectInputEffect_Start(obj, fx.dwDuration, 0); if (FAILED(hr)) { - dprintf("DirectInput: Damper force feedback start failed: %08x\n", (int) hr); IDirectInputEffect_Release(obj); return; } diff --git a/idzio/di-dev.c b/idzio/di-dev.c index 053eb9c..10b67d6 100644 --- a/idzio/di-dev.c +++ b/idzio/di-dev.c @@ -37,9 +37,9 @@ HRESULT idz_di_dev_init( } HRESULT idz_di_dev_poll( - IDirectInputDevice8W *dev, - HWND wnd, - union idz_di_state *out) + IDirectInputDevice8W *dev, + HWND wnd, + union idz_di_state *out) { HRESULT hr; MSG msg; @@ -59,17 +59,14 @@ HRESULT idz_di_dev_poll( } hr = IDirectInputDevice8_GetDeviceState( - dev, - sizeof(out->st), - &out->st); + dev, + sizeof(out->st), + &out->st); if (FAILED(hr)) { - dprintf("DirectInput: GetDeviceState error: %08x\n", (int) hr); + dprintf("DirectInput: GetDeviceState error: %08x\n", (int)hr); } - /* JVS lacks a protocol for reporting hardware errors from poll command - responses, so this ends up returning zeroed input state instead. */ - return hr; } @@ -80,29 +77,26 @@ HRESULT idz_di_dev_start(IDirectInputDevice8W *dev, HWND wnd) { assert(wnd != NULL); hr = IDirectInputDevice8_SetCooperativeLevel( - dev, - wnd, - DISCL_BACKGROUND | DISCL_EXCLUSIVE); + dev, + wnd, + DISCL_BACKGROUND | DISCL_EXCLUSIVE); if (FAILED(hr)) { - dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int) hr); - + dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int)hr); return hr; } hr = IDirectInputDevice8_SetDataFormat(dev, &c_dfDIJoystick); if (FAILED(hr)) { - dprintf("DirectInput: SetDataFormat failed: %08x\n", (int) hr); - + dprintf("DirectInput: SetDataFormat failed: %08x\n", (int)hr); return hr; } hr = IDirectInputDevice8_Acquire(dev); if (FAILED(hr)) { - dprintf("DirectInput: Acquire failed: %08x\n", (int) hr); - + dprintf("DirectInput: Acquire failed: %08x\n", (int)hr); return hr; } @@ -168,7 +162,6 @@ void idz_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force) cf.lMagnitude = (direction_ffb == 0) ? -magnitude : magnitude; axis = DIJOFS_X; - /* Irrelevant as magnitude descripbes the direction */ direction = 0; memset(&fx, 0, sizeof(fx)); @@ -184,38 +177,38 @@ void idz_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force) fx.cbTypeSpecificParams = sizeof(cf); fx.lpvTypeSpecificParams = &cf; + /* Check if the effect already exists */ if (idz_di_fx != NULL) { - // Try to update the existing effect hr = IDirectInputEffect_SetParameters(idz_di_fx, &fx, DIEP_TYPESPECIFICPARAMS); - if (SUCCEEDED(hr)) { - return; - } else { + return; // Successfully updated existing effect + } + else { dprintf("DirectInput: Failed to update constant force feedback, recreating effect: %08x\n", (int)hr); - // Stop and release the current effect if updating fails IDirectInputEffect_Stop(idz_di_fx); IDirectInputEffect_Release(idz_di_fx); - idz_di_fx = NULL; + idz_di_fx = NULL; // Reset the pointer } } - // Create a new constant force effect + /* Create a new constant force effect */ IDirectInputEffect *obj; hr = IDirectInputDevice8_CreateEffect( - idz_di_dev, - &GUID_ConstantForce, - &fx, - &obj, - NULL); + idz_di_dev, + &GUID_ConstantForce, + &fx, + &obj, + NULL); if (FAILED(hr)) { - dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int) hr); + dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int)hr); return; } + /* Start the effect */ hr = IDirectInputEffect_Start(obj, INFINITE, 0); if (FAILED(hr)) { - dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int) hr); + dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int)hr); IDirectInputEffect_Release(obj); return; } @@ -239,9 +232,6 @@ void idz_di_ffb_rumble(uint8_t force, uint8_t period) DIPERIODIC pe; HRESULT hr; - /* Duration in microseconds, - Might be totally wrong as especially on FANATEC wheels as this code will - crash the game. TODO: Figure out why this effect will crash on FANATEC! */ DWORD duration = (DWORD)((double)force * ffb_duration); memset(&pe, 0, sizeof(pe)); @@ -256,7 +246,7 @@ void idz_di_ffb_rumble(uint8_t force, uint8_t period) memset(&fx, 0, sizeof(fx)); fx.dwSize = sizeof(fx); fx.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; - fx.dwDuration = duration; + fx.dwDuration = INFINITE; fx.dwGain = DI_FFNOMINALMAX; fx.dwTriggerButton = DIEB_NOTRIGGER; fx.dwTriggerRepeatInterval = INFINITE; @@ -266,37 +256,38 @@ void idz_di_ffb_rumble(uint8_t force, uint8_t period) fx.cbTypeSpecificParams = sizeof(pe); fx.lpvTypeSpecificParams = &pe; + /* Check if the effect already exists */ if (idz_di_fx_rumble != NULL) { - // Try to update the existing effect hr = IDirectInputEffect_SetParameters(idz_di_fx_rumble, &fx, DIEP_TYPESPECIFICPARAMS); - if (SUCCEEDED(hr)) { return; - } else { - dprintf("DirectInput: Failed to update periodic force feedback, recreating effect: %08x\n", (int)hr); - // Stop and release the current effect if updating fails + } + else { + dprintf("DirectInput: Failed to update rumble feedback, recreating effect: %08x\n", (int)hr); IDirectInputEffect_Stop(idz_di_fx_rumble); IDirectInputEffect_Release(idz_di_fx_rumble); idz_di_fx_rumble = NULL; } } + /* Create a new rumble effect */ IDirectInputEffect *obj; hr = IDirectInputDevice8_CreateEffect( - idz_di_dev, - &GUID_Sine, - &fx, - &obj, - NULL); + idz_di_dev, + &GUID_Sine, + &fx, + &obj, + NULL); if (FAILED(hr)) { - dprintf("DirectInput: Periodic force feedback creation failed: %08x\n", (int) hr); + dprintf("DirectInput: Rumble effect creation failed: %08x\n", (int)hr); return; } + /* Start the effect */ hr = IDirectInputEffect_Start(obj, INFINITE, 0); if (FAILED(hr)) { - dprintf("DirectInput: Periodic force feedback start failed: %08x\n", (int) hr); + dprintf("DirectInput: Rumble effect start failed: %08x\n", (int)hr); IDirectInputEffect_Release(obj); return; } @@ -343,38 +334,35 @@ void idz_di_ffb_damper(uint8_t force) fx.cbTypeSpecificParams = sizeof(cond); fx.lpvTypeSpecificParams = &cond; + /* Check if the damper effect already exists */ if (idz_di_fx_damper != NULL) { - // Try to update the existing effect hr = IDirectInputEffect_SetParameters(idz_di_fx_damper, &fx, DIEP_TYPESPECIFICPARAMS); - if (SUCCEEDED(hr)) { return; - } else { - dprintf("DirectInput: Failed to update damper force feedback, recreating effect: %08x\n", (int)hr); - // Stop and release the current effect if updating fails + } + else { IDirectInputEffect_Stop(idz_di_fx_damper); IDirectInputEffect_Release(idz_di_fx_damper); idz_di_fx_damper = NULL; } } - // Create a new damper force effect + /* Create a new damper effect */ IDirectInputEffect *obj; hr = IDirectInputDevice8_CreateEffect( - idz_di_dev, - &GUID_Damper, - &fx, - &obj, - NULL); + idz_di_dev, + &GUID_Damper, + &fx, + &obj, + NULL); if (FAILED(hr)) { - dprintf("DirectInput: Damper force feedback creation failed: %08x\n", (int) hr); return; } - hr = IDirectInputEffect_Start(obj, INFINITE, 0); + /* Start the effect */ + hr = IDirectInputEffect_Start(obj, fx.dwDuration, 0); if (FAILED(hr)) { - dprintf("DirectInput: Damper force feedback start failed: %08x\n", (int) hr); IDirectInputEffect_Release(obj); return; } diff --git a/swdcio/di-dev.c b/swdcio/di-dev.c index 85db2fb..4f099cc 100644 --- a/swdcio/di-dev.c +++ b/swdcio/di-dev.c @@ -37,9 +37,9 @@ HRESULT swdc_di_dev_init( } HRESULT swdc_di_dev_poll( - IDirectInputDevice8W *dev, - HWND wnd, - union swdc_di_state *out) + IDirectInputDevice8W *dev, + HWND wnd, + union swdc_di_state *out) { HRESULT hr; MSG msg; @@ -59,17 +59,14 @@ HRESULT swdc_di_dev_poll( } hr = IDirectInputDevice8_GetDeviceState( - dev, - sizeof(out->st), - &out->st); + dev, + sizeof(out->st), + &out->st); if (FAILED(hr)) { - dprintf("DirectInput: GetDeviceState error: %08x\n", (int) hr); + dprintf("DirectInput: GetDeviceState error: %08x\n", (int)hr); } - /* JVS lacks a protocol for reporting hardware errors from poll command - responses, so this ends up returning zeroed input state instead. */ - return hr; } @@ -80,29 +77,26 @@ HRESULT swdc_di_dev_start(IDirectInputDevice8W *dev, HWND wnd) { assert(wnd != NULL); hr = IDirectInputDevice8_SetCooperativeLevel( - dev, - wnd, - DISCL_BACKGROUND | DISCL_EXCLUSIVE); + dev, + wnd, + DISCL_BACKGROUND | DISCL_EXCLUSIVE); if (FAILED(hr)) { - dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int) hr); - + dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int)hr); return hr; } hr = IDirectInputDevice8_SetDataFormat(dev, &c_dfDIJoystick); if (FAILED(hr)) { - dprintf("DirectInput: SetDataFormat failed: %08x\n", (int) hr); - + dprintf("DirectInput: SetDataFormat failed: %08x\n", (int)hr); return hr; } hr = IDirectInputDevice8_Acquire(dev); if (FAILED(hr)) { - dprintf("DirectInput: Acquire failed: %08x\n", (int) hr); - + dprintf("DirectInput: Acquire failed: %08x\n", (int)hr); return hr; } @@ -168,7 +162,6 @@ void swdc_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force) cf.lMagnitude = (direction_ffb == 0) ? -magnitude : magnitude; axis = DIJOFS_X; - /* Irrelevant as magnitude descripbes the direction */ direction = 0; memset(&fx, 0, sizeof(fx)); @@ -184,38 +177,38 @@ void swdc_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force) fx.cbTypeSpecificParams = sizeof(cf); fx.lpvTypeSpecificParams = &cf; + /* Check if the effect already exists */ if (swdc_di_fx != NULL) { - // Try to update the existing effect hr = IDirectInputEffect_SetParameters(swdc_di_fx, &fx, DIEP_TYPESPECIFICPARAMS); - if (SUCCEEDED(hr)) { - return; - } else { + return; // Successfully updated existing effect + } + else { dprintf("DirectInput: Failed to update constant force feedback, recreating effect: %08x\n", (int)hr); - // Stop and release the current effect if updating fails IDirectInputEffect_Stop(swdc_di_fx); IDirectInputEffect_Release(swdc_di_fx); - swdc_di_fx = NULL; + swdc_di_fx = NULL; // Reset the pointer } } - // Create a new constant force effect + /* Create a new constant force effect */ IDirectInputEffect *obj; hr = IDirectInputDevice8_CreateEffect( - swdc_di_dev, - &GUID_ConstantForce, - &fx, - &obj, - NULL); + swdc_di_dev, + &GUID_ConstantForce, + &fx, + &obj, + NULL); if (FAILED(hr)) { - dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int) hr); + dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int)hr); return; } + /* Start the effect */ hr = IDirectInputEffect_Start(obj, INFINITE, 0); if (FAILED(hr)) { - dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int) hr); + dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int)hr); IDirectInputEffect_Release(obj); return; } @@ -239,9 +232,6 @@ void swdc_di_ffb_rumble(uint8_t force, uint8_t period) DIPERIODIC pe; HRESULT hr; - /* Duration in microseconds, - Might be totally wrong as especially on FANATEC wheels as this code will - crash the game. TODO: Figure out why this effect will crash on FANATEC! */ DWORD duration = (DWORD)((double)force * ffb_duration); memset(&pe, 0, sizeof(pe)); @@ -256,7 +246,7 @@ void swdc_di_ffb_rumble(uint8_t force, uint8_t period) memset(&fx, 0, sizeof(fx)); fx.dwSize = sizeof(fx); fx.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; - fx.dwDuration = duration; + fx.dwDuration = INFINITE; fx.dwGain = DI_FFNOMINALMAX; fx.dwTriggerButton = DIEB_NOTRIGGER; fx.dwTriggerRepeatInterval = INFINITE; @@ -266,37 +256,38 @@ void swdc_di_ffb_rumble(uint8_t force, uint8_t period) fx.cbTypeSpecificParams = sizeof(pe); fx.lpvTypeSpecificParams = &pe; + /* Check if the effect already exists */ if (swdc_di_fx_rumble != NULL) { - // Try to update the existing effect hr = IDirectInputEffect_SetParameters(swdc_di_fx_rumble, &fx, DIEP_TYPESPECIFICPARAMS); - if (SUCCEEDED(hr)) { return; - } else { - dprintf("DirectInput: Failed to update periodic force feedback, recreating effect: %08x\n", (int)hr); - // Stop and release the current effect if updating fails + } + else { + dprintf("DirectInput: Failed to update rumble feedback, recreating effect: %08x\n", (int)hr); IDirectInputEffect_Stop(swdc_di_fx_rumble); IDirectInputEffect_Release(swdc_di_fx_rumble); swdc_di_fx_rumble = NULL; } } + /* Create a new rumble effect */ IDirectInputEffect *obj; hr = IDirectInputDevice8_CreateEffect( - swdc_di_dev, - &GUID_Sine, - &fx, - &obj, - NULL); + swdc_di_dev, + &GUID_Sine, + &fx, + &obj, + NULL); if (FAILED(hr)) { - dprintf("DirectInput: Periodic force feedback creation failed: %08x\n", (int) hr); + dprintf("DirectInput: Rumble effect creation failed: %08x\n", (int)hr); return; } + /* Start the effect */ hr = IDirectInputEffect_Start(obj, INFINITE, 0); if (FAILED(hr)) { - dprintf("DirectInput: Periodic force feedback start failed: %08x\n", (int) hr); + dprintf("DirectInput: Rumble effect start failed: %08x\n", (int)hr); IDirectInputEffect_Release(obj); return; } @@ -343,38 +334,35 @@ void swdc_di_ffb_damper(uint8_t force) fx.cbTypeSpecificParams = sizeof(cond); fx.lpvTypeSpecificParams = &cond; + /* Check if the damper effect already exists */ if (swdc_di_fx_damper != NULL) { - // Try to update the existing effect hr = IDirectInputEffect_SetParameters(swdc_di_fx_damper, &fx, DIEP_TYPESPECIFICPARAMS); - if (SUCCEEDED(hr)) { return; - } else { - dprintf("DirectInput: Failed to update damper force feedback, recreating effect: %08x\n", (int)hr); - // Stop and release the current effect if updating fails + } + else { IDirectInputEffect_Stop(swdc_di_fx_damper); IDirectInputEffect_Release(swdc_di_fx_damper); swdc_di_fx_damper = NULL; } } - // Create a new damper force effect + /* Create a new damper effect */ IDirectInputEffect *obj; hr = IDirectInputDevice8_CreateEffect( - swdc_di_dev, - &GUID_Damper, - &fx, - &obj, - NULL); + swdc_di_dev, + &GUID_Damper, + &fx, + &obj, + NULL); if (FAILED(hr)) { - dprintf("DirectInput: Damper force feedback creation failed: %08x\n", (int) hr); return; } - hr = IDirectInputEffect_Start(obj, INFINITE, 0); + /* Start the effect */ + hr = IDirectInputEffect_Start(obj, fx.dwDuration, 0); if (FAILED(hr)) { - dprintf("DirectInput: Damper force feedback start failed: %08x\n", (int) hr); IDirectInputEffect_Release(obj); return; }