Use proper delta time for trackball mode

It had been using the previous poll delta time instead
This commit is contained in:
Travis Nickles 2018-01-03 03:55:40 -06:00
parent 4bb6b08f72
commit f906554743
3 changed files with 35 additions and 35 deletions

View File

@ -141,8 +141,8 @@ namespace DS4Windows
if (Global.getTrackballMode(deviceNum)) if (Global.getTrackballMode(deviceNum))
{ {
int iIndex = trackballBufferTail; int iIndex = trackballBufferTail;
trackballXBuffer[iIndex] = (arg.touches[0].deltaX * TRACKBALL_SCALE) / dev.getCurrentStateRef().Motion.elapsed; trackballXBuffer[iIndex] = (arg.touches[0].deltaX * TRACKBALL_SCALE) / dev.getCurrentStateRef().elapsedTime;
trackballYBuffer[iIndex] = (arg.touches[0].deltaY * TRACKBALL_SCALE) / dev.getCurrentStateRef().Motion.elapsed; trackballYBuffer[iIndex] = (arg.touches[0].deltaY * TRACKBALL_SCALE) / dev.getCurrentStateRef().elapsedTime;
trackballBufferTail = (iIndex + 1) % TRACKBALL_BUFFER_LEN; trackballBufferTail = (iIndex + 1) % TRACKBALL_BUFFER_LEN;
if (trackballBufferHead == trackballBufferTail) if (trackballBufferHead == trackballBufferTail)
trackballBufferHead = (trackballBufferHead + 1) % TRACKBALL_BUFFER_LEN; trackballBufferHead = (trackballBufferHead + 1) % TRACKBALL_BUFFER_LEN;
@ -284,12 +284,12 @@ namespace DS4Windows
int signX = Math.Sign(trackballXVel); int signX = Math.Sign(trackballXVel);
int signY = Math.Sign(trackballYVel); int signY = Math.Sign(trackballYVel);
double trackXvDecay = Math.Min(Math.Abs(trackballXVel), trackballAccel * s.Motion.elapsed * normX); double trackXvDecay = Math.Min(Math.Abs(trackballXVel), trackballAccel * s.elapsedTime * normX);
double trackYvDecay = Math.Min(Math.Abs(trackballYVel), trackballAccel * s.Motion.elapsed * normY); double trackYvDecay = Math.Min(Math.Abs(trackballYVel), trackballAccel * s.elapsedTime * normY);
double xVNew = trackballXVel - (trackXvDecay * signX); double xVNew = trackballXVel - (trackXvDecay * signX);
double yVNew = trackballYVel - (trackYvDecay * signY); double yVNew = trackballYVel - (trackYvDecay * signY);
double xMotion = (xVNew * s.Motion.elapsed) / TRACKBALL_SCALE; double xMotion = (xVNew * s.elapsedTime) / TRACKBALL_SCALE;
double yMotion = (yVNew * s.Motion.elapsed) / TRACKBALL_SCALE; double yMotion = (yVNew * s.elapsedTime) / TRACKBALL_SCALE;
if (xMotion != 0.0) if (xMotion != 0.0)
{ {
xMotion += trackballDXRemain; xMotion += trackballDXRemain;
@ -363,12 +363,12 @@ namespace DS4Windows
double normY = Math.Abs(Math.Sin(tempAngle)); double normY = Math.Abs(Math.Sin(tempAngle));
int signX = Math.Sign(trackballXVel); int signX = Math.Sign(trackballXVel);
int signY = Math.Sign(trackballYVel); int signY = Math.Sign(trackballYVel);
double trackXvDecay = Math.Min(Math.Abs(trackballXVel), trackballAccel * s.Motion.elapsed * normX); double trackXvDecay = Math.Min(Math.Abs(trackballXVel), trackballAccel * s.elapsedTime * normX);
double trackYvDecay = Math.Min(Math.Abs(trackballYVel), trackballAccel * s.Motion.elapsed * normY); double trackYvDecay = Math.Min(Math.Abs(trackballYVel), trackballAccel * s.elapsedTime * normY);
double xVNew = trackballXVel - (trackXvDecay * signX); double xVNew = trackballXVel - (trackXvDecay * signX);
double yVNew = trackballYVel - (trackYvDecay * signY); double yVNew = trackballYVel - (trackYvDecay * signY);
double xMotion = (xVNew * s.Motion.elapsed) / TRACKBALL_SCALE; double xMotion = (xVNew * s.elapsedTime) / TRACKBALL_SCALE;
double yMotion = (yVNew * s.Motion.elapsed) / TRACKBALL_SCALE; double yMotion = (yVNew * s.elapsedTime) / TRACKBALL_SCALE;
if (xMotion != 0.0) if (xMotion != 0.0)
{ {
xMotion += trackballDXRemain; xMotion += trackballDXRemain;

View File

@ -845,6 +845,27 @@ namespace DS4Windows
//Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> power subsystem octet: 0x" + inputReport[30].ToString("x02")); //Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> power subsystem octet: 0x" + inputReport[30].ToString("x02"));
} }
tempStamp = (uint)((ushort)(inputReport[11] << 8) | inputReport[10]);
if (timeStampInit == false)
{
timeStampInit = true;
deltaTimeCurrent = tempStamp * 16u / 3u;
}
else if (timeStampPrevious > tempStamp)
{
tempDelta = ushort.MaxValue - timeStampPrevious + tempStamp + 1u;
deltaTimeCurrent = tempDelta * 16u / 3u;
}
else
{
tempDelta = tempStamp - timeStampPrevious;
deltaTimeCurrent = tempDelta * 16u / 3u;
}
timeStampPrevious = tempStamp;
elapsedDeltaTime = 0.000001 * deltaTimeCurrent; // Convert from microseconds to seconds
cState.elapsedTime = elapsedDeltaTime;
// XXX DS4State mapping needs fixup, turn touches into an array[4] of structs. And include the touchpad details there instead. // XXX DS4State mapping needs fixup, turn touches into an array[4] of structs. And include the touchpad details there instead.
try try
{ {
@ -869,27 +890,6 @@ namespace DS4Windows
} }
catch { currerror = "Index out of bounds: touchpad"; } catch { currerror = "Index out of bounds: touchpad"; }
tempStamp = (uint)((ushort)(inputReport[11] << 8) | inputReport[10]);
if (timeStampInit == false)
{
timeStampInit = true;
deltaTimeCurrent = tempStamp * 16u / 3u;
}
else if (timeStampPrevious > tempStamp)
{
tempDelta = ushort.MaxValue - timeStampPrevious + tempStamp + 1u;
deltaTimeCurrent = tempDelta * 16u / 3u;
}
else
{
tempDelta = tempStamp - timeStampPrevious;
deltaTimeCurrent = tempDelta * 16u / 3u;
}
cState.elapsedMicroSec = deltaTimeCurrent;
timeStampPrevious = tempStamp;
elapsedDeltaTime = 0.000001 * deltaTimeCurrent; // Convert from microseconds to seconds
// Store Gyro and Accel values // Store Gyro and Accel values
Array.Copy(inputReport, 13, gyro, 0, 6); Array.Copy(inputReport, 13, gyro, 0, 6);
Array.Copy(inputReport, 19, accel, 0, 6); Array.Copy(inputReport, 19, accel, 0, 6);

View File

@ -23,7 +23,7 @@ namespace DS4Windows
public double LYUnit; public double LYUnit;
public double RXUnit; public double RXUnit;
public double RYUnit; public double RYUnit;
public uint elapsedMicroSec = 0; public double elapsedTime = 0.0;
public SixAxis Motion = null; public SixAxis Motion = null;
public static readonly int DEFAULT_AXISDIR_VALUE = 127; public static readonly int DEFAULT_AXISDIR_VALUE = 127;
@ -47,7 +47,7 @@ namespace DS4Windows
LYUnit = 0.0; LYUnit = 0.0;
RXUnit = 0.0; RXUnit = 0.0;
RYUnit = 0.0; RYUnit = 0.0;
elapsedMicroSec = 0; elapsedTime = 0.0;
Motion = new SixAxis(0, 0, 0, 0, 0, 0, 0.0); Motion = new SixAxis(0, 0, 0, 0, 0, 0, 0.0);
} }
@ -95,7 +95,7 @@ namespace DS4Windows
LYUnit = state.LYUnit; LYUnit = state.LYUnit;
RXUnit = state.RXUnit; RXUnit = state.RXUnit;
RYUnit = state.RYUnit; RYUnit = state.RYUnit;
elapsedMicroSec = state.elapsedMicroSec; elapsedTime = state.elapsedTime;
Motion = state.Motion; Motion = state.Motion;
} }
@ -148,7 +148,7 @@ namespace DS4Windows
state.LYUnit = LYUnit; state.LYUnit = LYUnit;
state.RXUnit = RXUnit; state.RXUnit = RXUnit;
state.RYUnit = RYUnit; state.RYUnit = RYUnit;
state.elapsedMicroSec = elapsedMicroSec; state.elapsedTime = elapsedTime;
state.Motion = Motion; state.Motion = Motion;
} }