Skip to content

Commit

Permalink
Fix: Effect magnitude is now correct
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandroasm committed Jan 24, 2017
1 parent 8aae104 commit 177cac0
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions GenericFFBDriver/vibration/VibrationController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <algorithm>
#include <Hidsdi.h>

#define DISABLE_INFINITE_VIBRATION

#define MAX_EFFECTS 5
#define MAXC(a, b) ((a) > (b) ? (a) : (b))

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

if (VibEffects[k].dwStopFrame != INFINITE) {
DWORD dt = VibEffects[k].dwStopFrame - VibEffects[k].dwStartFrame;
DWORD frmStart = VibEffects[k].dwStartFrame;
DWORD frmStop = VibEffects[k].dwStopFrame;

DWORD dt = frmStart <= frmStop ? frmStop - frmStart : frmStart + 100;
//if (dt > 750)
// dt = 750;

VibEffects[k].dwStopFrame = frame + dt;
}
#ifdef DISABLE_INFINITE_VIBRATION
else {
VibEffects[k].dwStopFrame = frame + 1000;
}
#endif


forceX = MAXC(forceX, VibEffects[k].forceX);
forceY = MAXC(forceY, VibEffects[k].forceY);
Expand Down Expand Up @@ -200,7 +214,9 @@ namespace vibration {
byte magnitude = 0xfe;
if (peff->cbTypeSpecificParams == 4) {
LPDICONSTANTFORCE effParams = (LPDICONSTANTFORCE)peff->lpvTypeSpecificParams;
magnitude = (byte)(round((((double)effParams->lMagnitude) / 10000.0) * 254.0));
double mag = (((double)effParams->lMagnitude) + 10000.0) / 20000.0;

magnitude = (byte)(round(mag * 254.0));
}

if (peff->cAxes == 1) {
Expand Down

0 comments on commit 177cac0

Please sign in to comment.