2014-03-28 02:50:40 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
2015-02-08 22:51:52 +01:00
|
|
|
|
namespace DS4Windows
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{
|
|
|
|
|
public class DS4State
|
|
|
|
|
{
|
2018-05-06 09:10:49 +02:00
|
|
|
|
public uint PacketCounter;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
public DateTime ReportTimeStamp;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
public bool Square, Triangle, Circle, Cross;
|
|
|
|
|
public bool DpadUp, DpadDown, DpadLeft, DpadRight;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
public bool L1, L2Btn, L3, R1, R2Btn, R3;
|
2017-07-13 14:27:25 +02:00
|
|
|
|
public bool Share, Options, PS, Touch1, Touch2, TouchButton, TouchRight,
|
|
|
|
|
TouchLeft, Touch1Finger, Touch2Fingers;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
public byte Touch1Identifier, Touch2Identifier;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
public byte LX, RX, LY, RY, L2, R2;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
public byte FrameCounter; // 0, 1, 2...62, 63, 0....
|
|
|
|
|
public byte TouchPacketCounter; // we break these out automatically
|
|
|
|
|
public byte Battery; // 0 for charging, 10/20/30/40/50/60/70/80/90/100 for percentage of full
|
2017-04-21 05:09:08 +02:00
|
|
|
|
public double LSAngle; // Calculated bearing of the LS X,Y coordinates
|
|
|
|
|
public double RSAngle; // Calculated bearing of the RS X,Y coordinates
|
2017-06-11 02:48:34 +02:00
|
|
|
|
public double LSAngleRad; // Calculated bearing of the LS X,Y coordinates (in radians)
|
|
|
|
|
public double RSAngleRad; // Calculated bearing of the RS X,Y coordinates (in radians)
|
|
|
|
|
public double LXUnit;
|
|
|
|
|
public double LYUnit;
|
|
|
|
|
public double RXUnit;
|
|
|
|
|
public double RYUnit;
|
2018-01-03 10:55:40 +01:00
|
|
|
|
public double elapsedTime = 0.0;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
public ulong totalMicroSec = 0;
|
2017-07-16 10:30:49 +02:00
|
|
|
|
public SixAxis Motion = null;
|
2017-04-26 05:07:02 +02:00
|
|
|
|
public static readonly int DEFAULT_AXISDIR_VALUE = 127;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
|
2018-05-06 09:10:49 +02:00
|
|
|
|
public struct TrackPadTouch
|
|
|
|
|
{
|
|
|
|
|
public bool IsActive;
|
|
|
|
|
public byte Id;
|
|
|
|
|
public short X;
|
|
|
|
|
public short Y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TrackPadTouch TrackPadTouch0;
|
|
|
|
|
public TrackPadTouch TrackPadTouch1;
|
|
|
|
|
|
2014-03-28 02:50:40 +01:00
|
|
|
|
public DS4State()
|
|
|
|
|
{
|
2018-05-06 09:10:49 +02:00
|
|
|
|
PacketCounter = 0;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
Square = Triangle = Circle = Cross = false;
|
|
|
|
|
DpadUp = DpadDown = DpadLeft = DpadRight = false;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
L1 = L2Btn = L3 = R1 = R2Btn = R3 = false;
|
2017-06-05 10:31:29 +02:00
|
|
|
|
Share = Options = PS = Touch1 = Touch2 = TouchButton = TouchRight = TouchLeft = false;
|
2017-06-22 12:24:51 +02:00
|
|
|
|
Touch1Finger = Touch2Fingers = false;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
LX = RX = LY = RY = 127;
|
|
|
|
|
L2 = R2 = 0;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
FrameCounter = 255; // only actually has 6 bits, so this is a null indicator
|
|
|
|
|
TouchPacketCounter = 255; // 8 bits, no great junk value
|
2014-03-28 02:50:40 +01:00
|
|
|
|
Battery = 0;
|
2017-04-16 11:54:34 +02:00
|
|
|
|
LSAngle = 0.0;
|
2017-06-11 02:48:34 +02:00
|
|
|
|
LSAngleRad = 0.0;
|
2017-04-16 11:54:34 +02:00
|
|
|
|
RSAngle = 0.0;
|
2017-06-11 02:48:34 +02:00
|
|
|
|
RSAngleRad = 0.0;
|
|
|
|
|
LXUnit = 0.0;
|
|
|
|
|
LYUnit = 0.0;
|
|
|
|
|
RXUnit = 0.0;
|
|
|
|
|
RYUnit = 0.0;
|
2018-01-03 10:55:40 +01:00
|
|
|
|
elapsedTime = 0.0;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
totalMicroSec = 0;
|
2017-07-16 14:11:58 +02:00
|
|
|
|
Motion = new SixAxis(0, 0, 0, 0, 0, 0, 0.0);
|
2018-05-06 09:10:49 +02:00
|
|
|
|
TrackPadTouch0.IsActive = false;
|
|
|
|
|
TrackPadTouch1.IsActive = false;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DS4State(DS4State state)
|
|
|
|
|
{
|
2018-05-06 09:10:49 +02:00
|
|
|
|
PacketCounter = state.PacketCounter;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
ReportTimeStamp = state.ReportTimeStamp;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
Square = state.Square;
|
|
|
|
|
Triangle = state.Triangle;
|
|
|
|
|
Circle = state.Circle;
|
|
|
|
|
Cross = state.Cross;
|
|
|
|
|
DpadUp = state.DpadUp;
|
|
|
|
|
DpadDown = state.DpadDown;
|
|
|
|
|
DpadLeft = state.DpadLeft;
|
|
|
|
|
DpadRight = state.DpadRight;
|
|
|
|
|
L1 = state.L1;
|
|
|
|
|
L2 = state.L2;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
L2Btn = state.L2Btn;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
L3 = state.L3;
|
|
|
|
|
R1 = state.R1;
|
|
|
|
|
R2 = state.R2;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
R2Btn = state.R2Btn;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
R3 = state.R3;
|
|
|
|
|
Share = state.Share;
|
|
|
|
|
Options = state.Options;
|
|
|
|
|
PS = state.PS;
|
|
|
|
|
Touch1 = state.Touch1;
|
2014-04-27 21:32:09 +02:00
|
|
|
|
TouchRight = state.TouchRight;
|
|
|
|
|
TouchLeft = state.TouchLeft;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
Touch1Identifier = state.Touch1Identifier;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
Touch2 = state.Touch2;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
Touch2Identifier = state.Touch2Identifier;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
TouchButton = state.TouchButton;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
TouchPacketCounter = state.TouchPacketCounter;
|
2017-06-22 12:24:51 +02:00
|
|
|
|
Touch1Finger = state.Touch1Finger;
|
|
|
|
|
Touch2Fingers = state.Touch2Fingers;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
LX = state.LX;
|
|
|
|
|
RX = state.RX;
|
|
|
|
|
LY = state.LY;
|
|
|
|
|
RY = state.RY;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
FrameCounter = state.FrameCounter;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
Battery = state.Battery;
|
2017-04-16 11:54:34 +02:00
|
|
|
|
LSAngle = state.LSAngle;
|
2017-06-11 02:48:34 +02:00
|
|
|
|
LSAngleRad = state.LSAngleRad;
|
2017-04-16 11:54:34 +02:00
|
|
|
|
RSAngle = state.RSAngle;
|
2017-06-11 02:48:34 +02:00
|
|
|
|
RSAngleRad = state.RSAngleRad;
|
|
|
|
|
LXUnit = state.LXUnit;
|
|
|
|
|
LYUnit = state.LYUnit;
|
|
|
|
|
RXUnit = state.RXUnit;
|
|
|
|
|
RYUnit = state.RYUnit;
|
2018-01-03 10:55:40 +01:00
|
|
|
|
elapsedTime = state.elapsedTime;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
totalMicroSec = state.totalMicroSec;
|
2017-07-16 10:30:49 +02:00
|
|
|
|
Motion = state.Motion;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
TrackPadTouch0 = state.TrackPadTouch0;
|
|
|
|
|
TrackPadTouch1 = state.TrackPadTouch1;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DS4State Clone()
|
|
|
|
|
{
|
|
|
|
|
return new DS4State(this);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-27 21:32:09 +02:00
|
|
|
|
public void CopyTo(DS4State state)
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{
|
2018-05-06 09:10:49 +02:00
|
|
|
|
state.PacketCounter = PacketCounter;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
state.ReportTimeStamp = ReportTimeStamp;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
state.Square = Square;
|
|
|
|
|
state.Triangle = Triangle;
|
|
|
|
|
state.Circle = Circle;
|
|
|
|
|
state.Cross = Cross;
|
|
|
|
|
state.DpadUp = DpadUp;
|
|
|
|
|
state.DpadDown = DpadDown;
|
|
|
|
|
state.DpadLeft = DpadLeft;
|
|
|
|
|
state.DpadRight = DpadRight;
|
|
|
|
|
state.L1 = L1;
|
|
|
|
|
state.L2 = L2;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
state.L2Btn = L2Btn;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
state.L3 = L3;
|
|
|
|
|
state.R1 = R1;
|
|
|
|
|
state.R2 = R2;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
state.R2Btn = R2Btn;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
state.R3 = R3;
|
|
|
|
|
state.Share = Share;
|
|
|
|
|
state.Options = Options;
|
|
|
|
|
state.PS = PS;
|
|
|
|
|
state.Touch1 = Touch1;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
state.Touch1Identifier = Touch1Identifier;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
state.Touch2 = Touch2;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
state.Touch2Identifier = Touch2Identifier;
|
2014-04-27 21:32:09 +02:00
|
|
|
|
state.TouchLeft = TouchLeft;
|
|
|
|
|
state.TouchRight = TouchRight;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
state.TouchButton = TouchButton;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
state.TouchPacketCounter = TouchPacketCounter;
|
2017-06-22 12:24:51 +02:00
|
|
|
|
state.Touch1Finger = Touch1Finger;
|
|
|
|
|
state.Touch2Fingers = Touch2Fingers;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
state.LX = LX;
|
|
|
|
|
state.RX = RX;
|
|
|
|
|
state.LY = LY;
|
|
|
|
|
state.RY = RY;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
state.FrameCounter = FrameCounter;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
state.Battery = Battery;
|
2017-04-16 11:54:34 +02:00
|
|
|
|
state.LSAngle = LSAngle;
|
2017-06-11 02:48:34 +02:00
|
|
|
|
state.LSAngleRad = LSAngleRad;
|
2017-04-16 11:54:34 +02:00
|
|
|
|
state.RSAngle = RSAngle;
|
2017-06-11 02:48:34 +02:00
|
|
|
|
state.RSAngleRad = RSAngleRad;
|
|
|
|
|
state.LXUnit = LXUnit;
|
|
|
|
|
state.LYUnit = LYUnit;
|
|
|
|
|
state.RXUnit = RXUnit;
|
|
|
|
|
state.RYUnit = RYUnit;
|
2018-01-03 10:55:40 +01:00
|
|
|
|
state.elapsedTime = elapsedTime;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
state.totalMicroSec = totalMicroSec;
|
2017-07-16 10:30:49 +02:00
|
|
|
|
state.Motion = Motion;
|
2018-05-06 09:10:49 +02:00
|
|
|
|
state.TrackPadTouch0 = TrackPadTouch0;
|
|
|
|
|
state.TrackPadTouch1 = TrackPadTouch1;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 11:54:34 +02:00
|
|
|
|
public void calculateStickAngles()
|
|
|
|
|
{
|
2018-06-05 23:12:11 +02:00
|
|
|
|
double lsangle = Math.Atan2(-(LY - 127), (LX - 127));
|
2017-06-11 02:48:34 +02:00
|
|
|
|
LSAngleRad = lsangle;
|
2017-04-16 11:54:34 +02:00
|
|
|
|
lsangle = (lsangle >= 0 ? lsangle : (2 * Math.PI + lsangle)) * 180 / Math.PI;
|
|
|
|
|
LSAngle = lsangle;
|
2017-06-11 02:48:34 +02:00
|
|
|
|
LXUnit = Math.Abs(Math.Cos(LSAngleRad));
|
|
|
|
|
LYUnit = Math.Abs(Math.Sin(LSAngleRad));
|
2017-04-16 11:54:34 +02:00
|
|
|
|
|
2018-06-05 23:12:11 +02:00
|
|
|
|
double rsangle = Math.Atan2(-(RY - 127), (RX - 127));
|
2017-06-11 02:48:34 +02:00
|
|
|
|
RSAngleRad = rsangle;
|
2017-04-16 11:54:34 +02:00
|
|
|
|
rsangle = (rsangle >= 0 ? rsangle : (2 * Math.PI + rsangle)) * 180 / Math.PI;
|
|
|
|
|
RSAngle = rsangle;
|
2017-06-11 02:48:34 +02:00
|
|
|
|
RXUnit = Math.Abs(Math.Cos(RSAngleRad));
|
2018-06-05 22:46:33 +02:00
|
|
|
|
RYUnit = Math.Abs(Math.Sin(RSAngleRad));
|
2017-04-16 11:54:34 +02:00
|
|
|
|
}
|
2017-06-30 10:42:19 +02:00
|
|
|
|
|
|
|
|
|
public void rotateLSCoordinates(double rotation)
|
|
|
|
|
{
|
|
|
|
|
double sinAngle = Math.Sin(rotation), cosAngle = Math.Cos(rotation);
|
|
|
|
|
double tempLX = LX - 127.5, tempLY = LY - 127.5;
|
2017-07-20 11:25:15 +02:00
|
|
|
|
LX = (Byte)(Global.Clamp(-127.5, (tempLX * cosAngle - tempLY * sinAngle), 127.5) + 127.5);
|
|
|
|
|
LY = (Byte)(Global.Clamp(-127.5, (tempLX * sinAngle + tempLY * cosAngle), 127.5) + 127.5);
|
2017-06-30 10:42:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void rotateRSCoordinates(double rotation)
|
|
|
|
|
{
|
|
|
|
|
double sinAngle = Math.Sin(rotation), cosAngle = Math.Cos(rotation);
|
|
|
|
|
double tempRX = RX - 127.5, tempRY = RY - 127.5;
|
2017-07-20 11:25:15 +02:00
|
|
|
|
RX = (Byte)(Global.Clamp(-127.5, (tempRX * cosAngle - tempRY * sinAngle), 127.5) + 127.5);
|
|
|
|
|
RY = (Byte)(Global.Clamp(-127.5, (tempRX * sinAngle + tempRY * cosAngle), 127.5) + 127.5);
|
2017-06-30 10:42:19 +02:00
|
|
|
|
}
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|