2015-11-28 06:47:26 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace DS4Windows
|
|
|
|
|
{
|
|
|
|
|
public class SixAxisEventArgs : EventArgs
|
|
|
|
|
{
|
|
|
|
|
public readonly SixAxis sixAxis;
|
2017-06-22 03:07:21 +02:00
|
|
|
|
public readonly DateTime timeStamp;
|
|
|
|
|
public SixAxisEventArgs(DateTime utcTimestamp, SixAxis sa)
|
2015-11-28 06:47:26 +01:00
|
|
|
|
{
|
|
|
|
|
sixAxis = sa;
|
2017-06-22 03:07:21 +02:00
|
|
|
|
timeStamp = utcTimestamp;
|
2015-11-28 06:47:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SixAxis
|
|
|
|
|
{
|
2017-07-20 07:57:14 +02:00
|
|
|
|
public int gyroYaw, gyroPitch, gyroRoll, accelX, accelY, accelZ;
|
2017-08-09 03:19:17 +02:00
|
|
|
|
public int outputAccelX, outputAccelY, outputAccelZ;
|
2017-07-12 15:04:37 +02:00
|
|
|
|
public readonly int gyroYawFull, gyroPitchFull, gyroRollFull;
|
2017-08-09 03:19:17 +02:00
|
|
|
|
public readonly int accelXFull, accelYFull, accelZFull;
|
2015-11-28 06:47:26 +01:00
|
|
|
|
public readonly byte touchID;
|
2017-07-16 09:22:21 +02:00
|
|
|
|
public readonly double elapsed;
|
|
|
|
|
public readonly SixAxis previousAxis = null;
|
2017-08-09 03:19:17 +02:00
|
|
|
|
|
2017-07-18 21:21:03 +02:00
|
|
|
|
public SixAxis(int X, int Y, int Z, int aX, int aY, int aZ,
|
|
|
|
|
double milliseconds, SixAxis prevAxis = null)
|
2015-11-28 06:47:26 +01:00
|
|
|
|
{
|
2017-07-17 02:42:43 +02:00
|
|
|
|
gyroYaw = -X / 256;
|
|
|
|
|
gyroPitch = Y / 256;
|
|
|
|
|
gyroRoll = -Z / 256;
|
2017-07-13 14:27:25 +02:00
|
|
|
|
gyroYawFull = -X;
|
2017-07-12 15:04:37 +02:00
|
|
|
|
gyroPitchFull = Y;
|
2017-07-13 14:27:25 +02:00
|
|
|
|
gyroRollFull = -Z;
|
2017-06-27 12:16:10 +02:00
|
|
|
|
|
2017-07-17 02:42:43 +02:00
|
|
|
|
// Put accel ranges between 0 - 128 abs
|
2017-07-16 14:11:58 +02:00
|
|
|
|
accelX = -aX / 64;
|
|
|
|
|
accelY = -aY / 64;
|
2017-06-22 03:07:21 +02:00
|
|
|
|
accelZ = aZ / 64;
|
2017-08-09 03:19:17 +02:00
|
|
|
|
outputAccelX = accelX;
|
|
|
|
|
outputAccelY = accelY;
|
|
|
|
|
outputAccelZ = accelZ;
|
2017-07-17 02:42:43 +02:00
|
|
|
|
|
2017-07-16 14:11:58 +02:00
|
|
|
|
accelXFull = -aX;
|
|
|
|
|
accelYFull = -aY;
|
2017-06-27 12:16:10 +02:00
|
|
|
|
accelZFull = aZ;
|
2017-07-16 09:22:21 +02:00
|
|
|
|
elapsed = milliseconds;
|
2017-06-27 12:16:10 +02:00
|
|
|
|
|
2015-11-28 06:47:26 +01:00
|
|
|
|
previousAxis = prevAxis;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class DS4SixAxis
|
|
|
|
|
{
|
2017-07-17 02:42:43 +02:00
|
|
|
|
public event EventHandler<SixAxisEventArgs> SixAccelMoved = null;
|
|
|
|
|
|
|
|
|
|
internal int lastGyroYaw, lastGyroPitch, lastGyroRoll,
|
2017-07-18 22:37:01 +02:00
|
|
|
|
lastAX, lastAY, lastAZ;
|
2015-11-28 06:47:26 +01:00
|
|
|
|
|
2017-07-16 09:22:21 +02:00
|
|
|
|
internal double lastMilliseconds;
|
2015-11-28 06:47:26 +01:00
|
|
|
|
internal byte[] previousPacket = new byte[8];
|
|
|
|
|
|
2017-07-16 09:22:21 +02:00
|
|
|
|
public void handleSixaxis(byte[] gyro, byte[] accel, DS4State state, double milliseconds)
|
2015-11-28 06:47:26 +01:00
|
|
|
|
{
|
2017-07-18 22:37:01 +02:00
|
|
|
|
int currentYaw = (short)((ushort)(gyro[3] << 8) | gyro[2]);
|
|
|
|
|
int currentPitch = (short)((ushort)(gyro[1] << 8) | gyro[0]);
|
|
|
|
|
int currentRoll = (short)((ushort)(gyro[5] << 8) | gyro[4]);
|
2017-07-12 15:04:37 +02:00
|
|
|
|
int AccelX = (short)((ushort)(accel[1] << 8) | accel[0]);
|
|
|
|
|
int AccelY = (short)((ushort)(accel[3] << 8) | accel[2]);
|
|
|
|
|
int AccelZ = (short)((ushort)(accel[5] << 8) | accel[4]);
|
2017-06-22 03:07:21 +02:00
|
|
|
|
|
2017-07-16 09:22:21 +02:00
|
|
|
|
SixAxisEventArgs args = null;
|
2015-11-28 06:47:26 +01:00
|
|
|
|
if (AccelX != 0 || AccelY != 0 || AccelZ != 0)
|
|
|
|
|
{
|
|
|
|
|
if (SixAccelMoved != null)
|
|
|
|
|
{
|
2017-07-16 09:22:21 +02:00
|
|
|
|
SixAxis sPrev = null, now = null;
|
2017-07-17 02:42:43 +02:00
|
|
|
|
sPrev = new SixAxis(lastGyroYaw, lastGyroPitch, lastGyroRoll,
|
|
|
|
|
lastAX, lastAY, lastAZ, lastMilliseconds);
|
|
|
|
|
|
|
|
|
|
now = new SixAxis(currentYaw, currentPitch, currentRoll,
|
|
|
|
|
AccelX, AccelY, AccelZ, milliseconds, sPrev);
|
|
|
|
|
|
2015-11-28 06:47:26 +01:00
|
|
|
|
args = new SixAxisEventArgs(state.ReportTimeStamp, now);
|
2017-07-16 10:30:49 +02:00
|
|
|
|
state.Motion = now;
|
2015-11-28 06:47:26 +01:00
|
|
|
|
SixAccelMoved(this, args);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-17 02:42:43 +02:00
|
|
|
|
lastGyroYaw = currentYaw;
|
|
|
|
|
lastGyroPitch = currentPitch;
|
|
|
|
|
lastGyroRoll = currentRoll;
|
2015-11-28 06:47:26 +01:00
|
|
|
|
lastAX = AccelX;
|
|
|
|
|
lastAY = AccelY;
|
|
|
|
|
lastAZ = AccelZ;
|
2017-07-16 09:22:21 +02:00
|
|
|
|
lastMilliseconds = milliseconds;
|
2015-11-28 06:47:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|