From 887a4fbdbd15a644348b41e05d7bfb2cb196ad26 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sun, 16 Jul 2017 03:30:49 -0500 Subject: [PATCH] Make imu data part of the DS4State --- DS4Windows/DS4Control/ControlService.cs | 2 +- DS4Windows/DS4Library/DS4Device.cs | 7 ++--- DS4Windows/DS4Library/DS4Sixaxis.cs | 1 + DS4Windows/DS4Library/DS4State.cs | 4 +++ DS4Windows/DS4Library/DS4StateExposed.cs | 33 +++++++----------------- 5 files changed, 20 insertions(+), 27 deletions(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 9999089..b304c0c 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -747,7 +747,7 @@ namespace DS4Windows } } - device.getExposedState(ExposedState[ind], CurrentState[ind]); + device.getCurrentState(CurrentState[ind]); DS4State cState = CurrentState[ind]; device.getPreviousState(PreviousState[ind]); DS4State pState = PreviousState[ind]; diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 1f1f623..dee478e 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -1196,12 +1196,13 @@ namespace DS4Windows return pState.Clone(); } - public void getExposedState(DS4StateExposed expState, DS4State state) + /*public void getExposedState(DS4StateExposed expState, DS4State state) { cState.CopyTo(state); - expState.setAccel(accel); - expState.setGyro(gyro); + //expState.setAccel(accel); + //expState.setGyro(gyro); } + */ public void getCurrentState(DS4State state) { diff --git a/DS4Windows/DS4Library/DS4Sixaxis.cs b/DS4Windows/DS4Library/DS4Sixaxis.cs index c9201e9..705c43b 100644 --- a/DS4Windows/DS4Library/DS4Sixaxis.cs +++ b/DS4Windows/DS4Library/DS4Sixaxis.cs @@ -74,6 +74,7 @@ namespace DS4Windows sPrev = new SixAxis(lastGyroX, lastGyroY, lastGyroZ, lastAX, lastAY, lastAZ, lastMilliseconds); now = new SixAxis(currentX, currentY, currentZ, AccelX, AccelY, AccelZ, milliseconds, sPrev); args = new SixAxisEventArgs(state.ReportTimeStamp, now); + state.Motion = now; SixAccelMoved(this, args); } diff --git a/DS4Windows/DS4Library/DS4State.cs b/DS4Windows/DS4Library/DS4State.cs index 4b75b5f..73ccb6a 100644 --- a/DS4Windows/DS4Library/DS4State.cs +++ b/DS4Windows/DS4Library/DS4State.cs @@ -23,6 +23,7 @@ namespace DS4Windows public double LYUnit; public double RXUnit; public double RYUnit; + public SixAxis Motion = null; public static readonly int DEFAULT_AXISDIR_VALUE = 127; public DS4State() @@ -45,6 +46,7 @@ namespace DS4Windows LYUnit = 0.0; RXUnit = 0.0; RYUnit = 0.0; + Motion = null; } public DS4State(DS4State state) @@ -91,6 +93,7 @@ namespace DS4Windows LYUnit = state.LYUnit; RXUnit = state.RXUnit; RYUnit = state.RYUnit; + Motion = state.Motion; } public DS4State Clone() @@ -142,6 +145,7 @@ namespace DS4Windows state.LYUnit = LYUnit; state.RXUnit = RXUnit; state.RYUnit = RYUnit; + state.Motion = Motion; } public void calculateStickAngles() diff --git a/DS4Windows/DS4Library/DS4StateExposed.cs b/DS4Windows/DS4Library/DS4StateExposed.cs index bc9e1a0..d5ef8b8 100644 --- a/DS4Windows/DS4Library/DS4StateExposed.cs +++ b/DS4Windows/DS4Library/DS4StateExposed.cs @@ -4,13 +4,12 @@ namespace DS4Windows public class DS4StateExposed { private DS4State _state; - private byte[] accel = new byte[] { 0, 0, 0, 0, 0, 0 }, - gyro = new byte[] { 0, 0, 0, 0, 0, 0 }; public DS4StateExposed() { _state = new DS4State(); } + public DS4StateExposed(DS4State state) { _state = state; @@ -44,38 +43,26 @@ namespace DS4Windows byte R2 { get { return _state.R2; } } int Battery { get { return _state.Battery; } } - public byte[] Accel { set { accel = value; } } - public void setAccel(byte[] value) - { - accel = value; - } + public int GyroYaw { get { return -_state.Motion.gyroX; } } + public int GyroPitch { get { return _state.Motion.gyroY; } } + public int GyroRoll { get { return -_state.Motion.gyroZ; } } - public byte[] Gyro { set { gyro = value; } } - public void setGyro(byte[] value) - { - gyro = value; - } - - public int GyroYaw { get { return -(short)((ushort)(gyro[3] << 8) | gyro[2]) / 256; } } - public int GyroPitch { get { return (short)((ushort)(gyro[1] << 8) | gyro[0]) / 256; } } - public int GyroRoll { get { return -(short)((ushort)(gyro[5] << 8) | gyro[4]) / 256; } } - - public int AccelX { get { return (short)((ushort)(accel[1] << 8) | accel[0]) / 64; } } + public int AccelX { get { return _state.Motion.accelX; } } public int getAccelX() { - return (short)((ushort)(accel[1] << 8) | accel[0]) / 64; + return _state.Motion.accelX; } - public int AccelY { get { return (short)((ushort)(accel[3] << 8) | accel[2]) / 64; } } + public int AccelY { get { return _state.Motion.accelY; } } public int getAccelY() { - return (short)((ushort)(accel[3] << 8) | accel[2]) / 64; + return _state.Motion.accelY; } - public int AccelZ { get { return (short)((ushort)(accel[5] << 8) | accel[4]) / 64; } } + public int AccelZ { get { return _state.Motion.accelZ; } } public int getAccelZ() { - return (short)((ushort)(accel[5] << 8) | accel[4]) / 64; + return _state.Motion.accelZ; } } }