mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2025-02-18 08:56:20 +01:00
More minor gyro changes
This commit is contained in:
parent
dba2b1bbb3
commit
9972e85e13
@ -21,7 +21,7 @@ namespace DS4Windows
|
|||||||
private double GYRO_MOUSE_COEFFICIENT = 0.0095;
|
private double GYRO_MOUSE_COEFFICIENT = 0.0095;
|
||||||
private int GYRO_MOUSE_DEADZONE = 12;
|
private int GYRO_MOUSE_DEADZONE = 12;
|
||||||
private double GYRO_MOUSE_OFFSET = 0.1463;
|
private double GYRO_MOUSE_OFFSET = 0.1463;
|
||||||
private double GYRO_SMOOTH_MOUSE_OFFSET = 0.14695;
|
private double GYRO_SMOOTH_MOUSE_OFFSET = 0.14696;
|
||||||
|
|
||||||
private const int SMOOTH_BUFFER_LEN = 3;
|
private const int SMOOTH_BUFFER_LEN = 3;
|
||||||
private double[] xSmoothBuffer = new double[SMOOTH_BUFFER_LEN];
|
private double[] xSmoothBuffer = new double[SMOOTH_BUFFER_LEN];
|
||||||
|
@ -15,7 +15,7 @@ namespace DS4Windows
|
|||||||
|
|
||||||
public class SixAxis
|
public class SixAxis
|
||||||
{
|
{
|
||||||
public readonly int gyroX, gyroY, gyroZ, deltaX, deltaY, deltaZ, accelX, accelY, accelZ;
|
public readonly int gyroYaw, gyroPitch, gyroRoll, deltaX, deltaY, deltaZ, accelX, accelY, accelZ;
|
||||||
public readonly int gyroYawFull, gyroPitchFull, gyroRollFull;
|
public readonly int gyroYawFull, gyroPitchFull, gyroRollFull;
|
||||||
public readonly int accelXFull, accelYFull, accelZFull;
|
public readonly int accelXFull, accelYFull, accelZFull;
|
||||||
public readonly byte touchID;
|
public readonly byte touchID;
|
||||||
@ -23,16 +23,18 @@ namespace DS4Windows
|
|||||||
public readonly SixAxis previousAxis = null;
|
public readonly SixAxis previousAxis = null;
|
||||||
public SixAxis(int X, int Y, int Z, int aX, int aY, int aZ, double milliseconds, SixAxis prevAxis = null)
|
public SixAxis(int X, int Y, int Z, int aX, int aY, int aZ, double milliseconds, SixAxis prevAxis = null)
|
||||||
{
|
{
|
||||||
gyroX = -X / 256;
|
gyroYaw = -X / 256;
|
||||||
gyroY = Y / 256;
|
gyroPitch = Y / 256;
|
||||||
gyroZ = -Z / 256;
|
gyroRoll = -Z / 256;
|
||||||
gyroYawFull = -X;
|
gyroYawFull = -X;
|
||||||
gyroPitchFull = Y;
|
gyroPitchFull = Y;
|
||||||
gyroRollFull = -Z;
|
gyroRollFull = -Z;
|
||||||
|
|
||||||
|
// Put accel ranges between 0 - 128 abs
|
||||||
accelX = -aX / 64;
|
accelX = -aX / 64;
|
||||||
accelY = -aY / 64;
|
accelY = -aY / 64;
|
||||||
accelZ = aZ / 64;
|
accelZ = aZ / 64;
|
||||||
|
|
||||||
accelXFull = -aX;
|
accelXFull = -aX;
|
||||||
accelYFull = -aY;
|
accelYFull = -aY;
|
||||||
accelZFull = aZ;
|
accelZFull = aZ;
|
||||||
@ -41,26 +43,29 @@ namespace DS4Windows
|
|||||||
previousAxis = prevAxis;
|
previousAxis = prevAxis;
|
||||||
if (previousAxis != null)
|
if (previousAxis != null)
|
||||||
{
|
{
|
||||||
deltaX = gyroX - previousAxis.gyroX;
|
deltaX = gyroYaw - previousAxis.gyroYaw;
|
||||||
deltaY = gyroY - previousAxis.gyroY;
|
deltaY = gyroPitch - previousAxis.gyroPitch;
|
||||||
deltaZ = gyroZ - previousAxis.gyroZ;
|
deltaZ = gyroRoll - previousAxis.gyroRoll;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DS4SixAxis
|
public class DS4SixAxis
|
||||||
{
|
{
|
||||||
public event EventHandler<SixAxisEventArgs> SixAccelMoved = null; // no status change for the touchpad itself... but other sensors may have changed, or you may just want to do some processing
|
// no status change for the touchpad itself... but other sensors may have changed, or you may just want to do some processing
|
||||||
|
public event EventHandler<SixAxisEventArgs> SixAccelMoved = null;
|
||||||
|
|
||||||
|
internal int lastGyroYaw, lastGyroPitch, lastGyroRoll,
|
||||||
|
lastAX, lastAY, lastAZ; // tracks 0, 1 or 2 touches; we maintain touch 1 and 2 separately
|
||||||
|
|
||||||
internal int lastGyroX, lastGyroY, lastGyroZ, lastAX, lastAY, lastAZ; // tracks 0, 1 or 2 touches; we maintain touch 1 and 2 separately
|
|
||||||
internal double lastMilliseconds;
|
internal double lastMilliseconds;
|
||||||
internal byte[] previousPacket = new byte[8];
|
internal byte[] previousPacket = new byte[8];
|
||||||
|
|
||||||
public void handleSixaxis(byte[] gyro, byte[] accel, DS4State state, double milliseconds)
|
public void handleSixaxis(byte[] gyro, byte[] accel, DS4State state, double milliseconds)
|
||||||
{
|
{
|
||||||
int currentX = (short)((ushort)(gyro[3] << 8) | gyro[2]); // Gyro Yaw
|
int currentYaw = (short)((ushort)(gyro[3] << 8) | gyro[2]); // Gyro Yaw
|
||||||
int currentY = (short)((ushort)(gyro[1] << 8) | gyro[0]); // Gyro Pitch
|
int currentPitch = (short)((ushort)(gyro[1] << 8) | gyro[0]); // Gyro Pitch
|
||||||
int currentZ = (short)((ushort)(gyro[5] << 8) | gyro[4]); // Gyro Roll
|
int currentRoll = (short)((ushort)(gyro[5] << 8) | gyro[4]); // Gyro Roll
|
||||||
int AccelX = (short)((ushort)(accel[1] << 8) | accel[0]);
|
int AccelX = (short)((ushort)(accel[1] << 8) | accel[0]);
|
||||||
int AccelY = (short)((ushort)(accel[3] << 8) | accel[2]);
|
int AccelY = (short)((ushort)(accel[3] << 8) | accel[2]);
|
||||||
int AccelZ = (short)((ushort)(accel[5] << 8) | accel[4]);
|
int AccelZ = (short)((ushort)(accel[5] << 8) | accel[4]);
|
||||||
@ -71,16 +76,20 @@ namespace DS4Windows
|
|||||||
if (SixAccelMoved != null)
|
if (SixAccelMoved != null)
|
||||||
{
|
{
|
||||||
SixAxis sPrev = null, now = null;
|
SixAxis sPrev = null, now = null;
|
||||||
sPrev = new SixAxis(lastGyroX, lastGyroY, lastGyroZ, lastAX, lastAY, lastAZ, lastMilliseconds);
|
sPrev = new SixAxis(lastGyroYaw, lastGyroPitch, lastGyroRoll,
|
||||||
now = new SixAxis(currentX, currentY, currentZ, AccelX, AccelY, AccelZ, milliseconds, sPrev);
|
lastAX, lastAY, lastAZ, lastMilliseconds);
|
||||||
|
|
||||||
|
now = new SixAxis(currentYaw, currentPitch, currentRoll,
|
||||||
|
AccelX, AccelY, AccelZ, milliseconds, 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastGyroX = currentX;
|
lastGyroYaw = currentYaw;
|
||||||
lastGyroY = currentY;
|
lastGyroPitch = currentPitch;
|
||||||
lastGyroZ = currentZ;
|
lastGyroRoll = currentRoll;
|
||||||
lastAX = AccelX;
|
lastAX = AccelX;
|
||||||
lastAY = AccelY;
|
lastAY = AccelY;
|
||||||
lastAZ = AccelZ;
|
lastAZ = AccelZ;
|
||||||
|
@ -43,9 +43,9 @@ namespace DS4Windows
|
|||||||
byte R2 { get { return _state.R2; } }
|
byte R2 { get { return _state.R2; } }
|
||||||
int Battery { get { return _state.Battery; } }
|
int Battery { get { return _state.Battery; } }
|
||||||
|
|
||||||
public int GyroYaw { get { return _state.Motion.gyroX; } }
|
public int GyroYaw { get { return _state.Motion.gyroYaw; } }
|
||||||
public int GyroPitch { get { return _state.Motion.gyroY; } }
|
public int GyroPitch { get { return _state.Motion.gyroPitch; } }
|
||||||
public int GyroRoll { get { return _state.Motion.gyroZ; } }
|
public int GyroRoll { get { return _state.Motion.gyroRoll; } }
|
||||||
|
|
||||||
public int AccelX { get { return _state.Motion.accelX; } }
|
public int AccelX { get { return _state.Motion.accelX; } }
|
||||||
public int getAccelX()
|
public int getAccelX()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user