From cfa2bea4be9c2d03dca9713eaddbde7b46121e12 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Tue, 10 Jul 2018 00:46:25 -0500 Subject: [PATCH] Minor tweak for skipping calibration that .NET likes better Related to issue #330. --- DS4Windows/DS4Library/DS4Device.cs | 10 ++++++---- DS4Windows/DS4Library/DS4Sixaxis.cs | 9 +++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 9765dd9..daae783 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -150,7 +150,6 @@ namespace DS4Windows public DateTime lastActive = DateTime.UtcNow; public DateTime firstActive = DateTime.UtcNow; private bool charging; - private bool isNacon = false; private bool outputRumble = false; private int warnInterval = WARN_INTERVAL_USB; public int getWarnInterval() @@ -414,6 +413,7 @@ namespace DS4Windows hDevice = hidDevice; conType = HidConnectionType(hDevice); Mac = hDevice.readSerial(); + bool runCalib = true; if (conType == ConnectionType.USB || conType == ConnectionType.SONYWA) { inputReport = new byte[64]; @@ -431,7 +431,7 @@ namespace DS4Windows else if (tempAttr.VendorId == 0x146B) { - isNacon = true; + runCalib = false; } synced = true; @@ -457,7 +457,8 @@ namespace DS4Windows touchpad = new DS4Touchpad(); sixAxis = new DS4SixAxis(); Crc32Algorithm.InitializeTable(DefaultPolynomial); - refreshCalibration(); + if (runCalib) + refreshCalibration(); if (!hDevice.IsFileStreamOpen()) { @@ -977,7 +978,8 @@ namespace DS4Windows pbAccel[i-6] = pbInput[i]; } } - sixAxis.handleSixaxis(gyro, accel, cState, elapsedDeltaTime, isNacon); + + sixAxis.handleSixaxis(gyro, accel, cState, elapsedDeltaTime); /* Debug output of incoming HID data: if (cState.L2 == 0xff && cState.R2 == 0xff) diff --git a/DS4Windows/DS4Library/DS4Sixaxis.cs b/DS4Windows/DS4Library/DS4Sixaxis.cs index c44e4a2..62353b5 100644 --- a/DS4Windows/DS4Library/DS4Sixaxis.cs +++ b/DS4Windows/DS4Library/DS4Sixaxis.cs @@ -115,6 +115,7 @@ namespace DS4Windows private CalibData[] calibrationData = new CalibData[6] { new CalibData(), new CalibData(), new CalibData(), new CalibData(), new CalibData(), new CalibData() }; + private bool calibrationDone = false; public DS4SixAxis() { @@ -187,6 +188,8 @@ namespace DS4Windows calibrationData[5].bias = accelZPlus - accelRange / 2; calibrationData[5].sensNumer = 2 * SixAxis.ACC_RES_PER_G; calibrationData[5].sensDenom = accelRange; + + calibrationDone = true; } private void applyCalibs(ref int yaw, ref int pitch, ref int roll, @@ -218,7 +221,7 @@ namespace DS4Windows } public void handleSixaxis(byte[] gyro, byte[] accel, DS4State state, - double elapsedDelta, bool disableCalibs) + double elapsedDelta) { int currentYaw = (short)((ushort)(gyro[3] << 8) | gyro[2]); int currentPitch = (short)((ushort)(gyro[1] << 8) | gyro[0]); @@ -227,10 +230,8 @@ namespace DS4Windows int AccelY = (short)((ushort)(accel[3] << 8) | accel[2]); int AccelZ = (short)((ushort)(accel[5] << 8) | accel[4]); - if (!disableCalibs) - { + if (calibrationDone) applyCalibs(ref currentYaw, ref currentPitch, ref currentRoll, ref AccelX, ref AccelY, ref AccelZ); - } SixAxisEventArgs args = null; if (AccelX != 0 || AccelY != 0 || AccelZ != 0)