From 473958ba1a26f26169ee0969d06c5af6897ba9c2 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 27 Jul 2017 05:41:44 -0500 Subject: [PATCH] Correct touchpad X coordinate. Change DS4State. --- DS4Windows/DS4Library/DS4Device.cs | 9 +++++---- DS4Windows/DS4Library/DS4State.cs | 8 ++++---- DS4Windows/DS4Library/DS4Touchpad.cs | 8 ++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 74a973a..ce117e6 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -847,8 +847,9 @@ namespace DS4Windows cState.Touch2Identifier = (byte)(inputReport[4 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset] & 0x7f); cState.Touch1Finger = cState.Touch1 || cState.Touch2; // >= 1 touch detected cState.Touch2Fingers = cState.Touch1 && cState.Touch2; // 2 touches detected - cState.TouchLeft = (inputReport[1 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset] + ((inputReport[2 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset] & 0xF) * 255) >= 1920 * 2 / 5) ? false : true; - cState.TouchRight = (inputReport[1 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset] + ((inputReport[2 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset] & 0xF) * 255) < 1920 * 2 / 5) ? false : true; + int touchX = (((inputReport[2 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset] & 0xF) << 8) | inputReport[1 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset]); + cState.TouchLeft = touchX >= 1920 * 2 / 5 ? false : true; + cState.TouchRight = touchX < 1920 * 2 / 5 ? false : true; // Even when idling there is still a touch packet indicating no touch 1 or 2 touchpad.handleTouchpad(inputReport, cState, touchOffset); } @@ -872,9 +873,9 @@ namespace DS4Windows deltaTimeCurrent = tempDelta * 16u / 3u; } - cState.elapsedNanoSec = deltaTimeCurrent; + cState.elapsedMicroSec = deltaTimeCurrent; timeStampPrevious = tempStamp; - elapsedDeltaTime = 0.000001 * deltaTimeCurrent; // Convert from nanoseconds to seconds + elapsedDeltaTime = 0.000001 * deltaTimeCurrent; // Convert from microseconds to seconds // Store Gyro and Accel values Array.Copy(inputReport, 13, gyro, 0, 6); diff --git a/DS4Windows/DS4Library/DS4State.cs b/DS4Windows/DS4Library/DS4State.cs index ac55dc8..70c987e 100644 --- a/DS4Windows/DS4Library/DS4State.cs +++ b/DS4Windows/DS4Library/DS4State.cs @@ -23,7 +23,7 @@ namespace DS4Windows public double LYUnit; public double RXUnit; public double RYUnit; - public uint elapsedNanoSec = 0; + public uint elapsedMicroSec = 0; public SixAxis Motion = null; public static readonly int DEFAULT_AXISDIR_VALUE = 127; @@ -47,7 +47,7 @@ namespace DS4Windows LYUnit = 0.0; RXUnit = 0.0; RYUnit = 0.0; - elapsedNanoSec = 0; + elapsedMicroSec = 0; Motion = new SixAxis(0, 0, 0, 0, 0, 0, 0.0); } @@ -95,7 +95,7 @@ namespace DS4Windows LYUnit = state.LYUnit; RXUnit = state.RXUnit; RYUnit = state.RYUnit; - elapsedNanoSec = state.elapsedNanoSec; + elapsedMicroSec = state.elapsedMicroSec; Motion = state.Motion; } @@ -148,7 +148,7 @@ namespace DS4Windows state.LYUnit = LYUnit; state.RXUnit = RXUnit; state.RYUnit = RYUnit; - state.elapsedNanoSec = elapsedNanoSec; + state.elapsedMicroSec = elapsedMicroSec; state.Motion = Motion; } diff --git a/DS4Windows/DS4Library/DS4Touchpad.cs b/DS4Windows/DS4Library/DS4Touchpad.cs index 21f673e..5d8f1ef 100644 --- a/DS4Windows/DS4Library/DS4Touchpad.cs +++ b/DS4Windows/DS4Library/DS4Touchpad.cs @@ -92,10 +92,10 @@ namespace DS4Windows byte touchID1 = (byte)(data[0 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F); byte touchID2 = (byte)(data[4 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F); - int currentX1 = data[1 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] + ((data[2 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF) * 255); - int currentY1 = ((data[2 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF0) >> 4) + (data[3 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] * 16); - int currentX2 = data[5 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] + ((data[6 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF) * 255); - int currentY2 = ((data[6 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF0) >> 4) + (data[7 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] * 16); + int currentX1 = ((data[2 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x0F) << 8) | data[1 + TOUCHPAD_DATA_OFFSET + touchPacketOffset]; + int currentY1 = (data[3 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] << 4) | ((data[2 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF0) >> 4); + int currentX2 = ((data[6 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x0F) << 8) | data[5 + TOUCHPAD_DATA_OFFSET + touchPacketOffset]; + int currentY2 = (data[7 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] << 4) | ((data[6 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF0) >> 4); TouchpadEventArgs args; if (sensors.Touch1 || sensors.Touch2)