Skip to content

Commit 177cac0

Browse files
committed
Fix: Effect magnitude is now correct
1 parent 8aae104 commit 177cac0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

GenericFFBDriver/vibration/VibrationController.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <algorithm>
33
#include <Hidsdi.h>
44

5+
#define DISABLE_INFINITE_VIBRATION
6+
57
#define MAX_EFFECTS 5
68
#define MAXC(a, b) ((a) > (b) ? (a) : (b))
79

@@ -130,9 +132,21 @@ namespace vibration {
130132
VibEffects[k].started = TRUE;
131133

132134
if (VibEffects[k].dwStopFrame != INFINITE) {
133-
DWORD dt = VibEffects[k].dwStopFrame - VibEffects[k].dwStartFrame;
135+
DWORD frmStart = VibEffects[k].dwStartFrame;
136+
DWORD frmStop = VibEffects[k].dwStopFrame;
137+
138+
DWORD dt = frmStart <= frmStop ? frmStop - frmStart : frmStart + 100;
139+
//if (dt > 750)
140+
// dt = 750;
141+
134142
VibEffects[k].dwStopFrame = frame + dt;
135143
}
144+
#ifdef DISABLE_INFINITE_VIBRATION
145+
else {
146+
VibEffects[k].dwStopFrame = frame + 1000;
147+
}
148+
#endif
149+
136150

137151
forceX = MAXC(forceX, VibEffects[k].forceX);
138152
forceY = MAXC(forceY, VibEffects[k].forceY);
@@ -200,7 +214,9 @@ namespace vibration {
200214
byte magnitude = 0xfe;
201215
if (peff->cbTypeSpecificParams == 4) {
202216
LPDICONSTANTFORCE effParams = (LPDICONSTANTFORCE)peff->lpvTypeSpecificParams;
203-
magnitude = (byte)(round((((double)effParams->lMagnitude) / 10000.0) * 254.0));
217+
double mag = (((double)effParams->lMagnitude) + 10000.0) / 20000.0;
218+
219+
magnitude = (byte)(round(mag * 254.0));
204220
}
205221

206222
if (peff->cAxes == 1) {

0 commit comments

Comments
 (0)