mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-11-27 03:24:20 +01:00
Change SixAxis routines
Hopefully I won't regret this later
This commit is contained in:
parent
9ae43db945
commit
39d0579f09
@ -24,11 +24,10 @@ namespace DS4Windows
|
|||||||
public int outputAccelX, outputAccelY, outputAccelZ;
|
public int outputAccelX, outputAccelY, outputAccelZ;
|
||||||
public double accelXG, accelYG, accelZG;
|
public double accelXG, accelYG, accelZG;
|
||||||
public double angVelYaw, angVelPitch, angVelRoll;
|
public double angVelYaw, angVelPitch, angVelRoll;
|
||||||
public readonly int gyroYawFull, gyroPitchFull, gyroRollFull;
|
public int gyroYawFull, gyroPitchFull, gyroRollFull;
|
||||||
public readonly int accelXFull, accelYFull, accelZFull;
|
public int accelXFull, accelYFull, accelZFull;
|
||||||
public readonly byte touchID;
|
public double elapsed;
|
||||||
public readonly double elapsed;
|
public SixAxis previousAxis = null;
|
||||||
public readonly SixAxis previousAxis = null;
|
|
||||||
|
|
||||||
double recip = 1d / 8192d;
|
double recip = 1d / 8192d;
|
||||||
double tempDouble = 0d;
|
double tempDouble = 0d;
|
||||||
@ -36,6 +35,42 @@ namespace DS4Windows
|
|||||||
public SixAxis(int X, int Y, int Z,
|
public SixAxis(int X, int Y, int Z,
|
||||||
int aX, int aY, int aZ,
|
int aX, int aY, int aZ,
|
||||||
double elapsedDelta, SixAxis prevAxis = null)
|
double elapsedDelta, SixAxis prevAxis = null)
|
||||||
|
{
|
||||||
|
populate(X, Y, Z, aX, aY, aZ, elapsedDelta, prevAxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copy(SixAxis src)
|
||||||
|
{
|
||||||
|
gyroYaw = src.gyroYaw;
|
||||||
|
gyroPitch = src.gyroPitch;
|
||||||
|
gyroRoll = src.gyroRoll;
|
||||||
|
|
||||||
|
gyroYawFull = src.gyroYawFull;
|
||||||
|
accelXFull = src.accelXFull; accelYFull = src.accelYFull; accelZFull = src.accelZFull;
|
||||||
|
|
||||||
|
angVelYaw = src.angVelYaw;
|
||||||
|
angVelPitch = src.angVelPitch;
|
||||||
|
angVelRoll = src.angVelRoll;
|
||||||
|
|
||||||
|
accelXG = src.accelXG;
|
||||||
|
accelYG = src.accelYG;
|
||||||
|
accelZG = src.accelZG;
|
||||||
|
|
||||||
|
// Put accel ranges between 0 - 128 abs
|
||||||
|
accelX = src.accelX;
|
||||||
|
accelY = src.accelY;
|
||||||
|
accelZ = src.accelZ;
|
||||||
|
outputAccelX = accelX;
|
||||||
|
outputAccelY = accelY;
|
||||||
|
outputAccelZ = accelZ;
|
||||||
|
|
||||||
|
elapsed = src.elapsed;
|
||||||
|
previousAxis = src.previousAxis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void populate(int X, int Y, int Z,
|
||||||
|
int aX, int aY, int aZ,
|
||||||
|
double elapsedDelta, SixAxis prevAxis = null)
|
||||||
{
|
{
|
||||||
gyroYaw = -X / 256;
|
gyroYaw = -X / 256;
|
||||||
gyroPitch = Y / 256;
|
gyroPitch = Y / 256;
|
||||||
@ -68,12 +103,13 @@ namespace DS4Windows
|
|||||||
public class DS4SixAxis
|
public class DS4SixAxis
|
||||||
{
|
{
|
||||||
public event EventHandler<SixAxisEventArgs> SixAccelMoved = null;
|
public event EventHandler<SixAxisEventArgs> SixAccelMoved = null;
|
||||||
|
private SixAxis sPrev = null, now = null;
|
||||||
|
|
||||||
private int lastGyroYaw, lastGyroPitch, lastGyroRoll,
|
public DS4SixAxis()
|
||||||
lastAX, lastAY, lastAZ;
|
{
|
||||||
|
sPrev = new SixAxis(0, 0, 0, 0, 0, 0, 0.0);
|
||||||
private double lastElapsedDelta;
|
now = new SixAxis(0, 0, 0, 0, 0, 0, 0.0);
|
||||||
private byte[] previousPacket = new byte[8];
|
}
|
||||||
|
|
||||||
public void handleSixaxis(byte[] gyro, byte[] accel, DS4State state,
|
public void handleSixaxis(byte[] gyro, byte[] accel, DS4State state,
|
||||||
double elapsedDelta)
|
double elapsedDelta)
|
||||||
@ -90,25 +126,14 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
if (SixAccelMoved != null)
|
if (SixAccelMoved != null)
|
||||||
{
|
{
|
||||||
SixAxis sPrev = null, now = null;
|
sPrev.copy(now);
|
||||||
sPrev = new SixAxis(lastGyroYaw, lastGyroPitch, lastGyroRoll,
|
now.populate(currentYaw, currentPitch, currentRoll,
|
||||||
lastAX, lastAY, lastAZ, lastElapsedDelta);
|
|
||||||
|
|
||||||
now = new SixAxis(currentYaw, currentPitch, currentRoll,
|
|
||||||
AccelX, AccelY, AccelZ, elapsedDelta, sPrev);
|
AccelX, AccelY, AccelZ, elapsedDelta, sPrev);
|
||||||
|
|
||||||
args = new SixAxisEventArgs(state.ReportTimeStamp, now);
|
args = new SixAxisEventArgs(state.ReportTimeStamp, now);
|
||||||
state.Motion = now;
|
state.Motion = now;
|
||||||
SixAccelMoved(this, args);
|
SixAccelMoved(this, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastGyroYaw = currentYaw;
|
|
||||||
lastGyroPitch = currentPitch;
|
|
||||||
lastGyroRoll = currentRoll;
|
|
||||||
lastAX = AccelX;
|
|
||||||
lastAY = AccelY;
|
|
||||||
lastAZ = AccelZ;
|
|
||||||
lastElapsedDelta = elapsedDelta;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user