From 44aef8b90d656b60d01edc5e15920ace1ee86602 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 22 Jun 2017 03:24:51 -0700 Subject: [PATCH] Fixed distinction between one finger touchpad touch and two finger touch Touch 2 being active does not necessarily mean two fingers are currently on the touchpad --- DS4Windows/DS4Control/Mouse.cs | 4 ++-- DS4Windows/DS4Library/DS4Device.cs | 6 ++++-- DS4Windows/DS4Library/DS4State.cs | 7 ++++++- DS4Windows/DS4Library/DS4StateExposed.cs | 2 ++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/DS4Windows/DS4Control/Mouse.cs b/DS4Windows/DS4Control/Mouse.cs index 6544258..9e62e41 100644 --- a/DS4Windows/DS4Control/Mouse.cs +++ b/DS4Windows/DS4Control/Mouse.cs @@ -82,8 +82,8 @@ namespace DS4Windows case 11: return s.DpadRight; case 12: return s.L3; case 13: return s.R3; - case 14: return s.Touch1; - case 15: return s.Touch2; + case 14: return s.Touch1Finger; + case 15: return s.Touch2Fingers; case 16: return s.Options; case 17: return s.Share; case 18: return s.PS; diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 45d3d14..820a520 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -838,10 +838,12 @@ namespace DS4Windows //for (int touches = inputReport[-1 + DS4Touchpad.TOUCHPAD_DATA_OFFSET - 1], touchOffset = 0; touches > 0; touches--, touchOffset += 9) { cState.TouchPacketCounter = inputReport[-1 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset]; - cState.Touch1 = (inputReport[0 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset] >> 7) != 0 ? false : true; // >= 1 touch detected + cState.Touch1 = (inputReport[0 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset] >> 7) != 0 ? false : true; // finger 1 detected cState.Touch1Identifier = (byte)(inputReport[0 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset] & 0x7f); - cState.Touch2 = (inputReport[4 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset] >> 7) != 0 ? false : true; // 2 touches detected + cState.Touch2 = (inputReport[4 + DS4Touchpad.TOUCHPAD_DATA_OFFSET + touchOffset] >> 7) != 0 ? false : true; // finger 2 detected 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; // Even when idling there is still a touch packet indicating no touch 1 or 2 diff --git a/DS4Windows/DS4Library/DS4State.cs b/DS4Windows/DS4Library/DS4State.cs index d62810b..54e18ba 100644 --- a/DS4Windows/DS4Library/DS4State.cs +++ b/DS4Windows/DS4Library/DS4State.cs @@ -8,7 +8,7 @@ namespace DS4Windows public bool Square, Triangle, Circle, Cross; public bool DpadUp, DpadDown, DpadLeft, DpadRight; public bool L1, L3, R1, R3; - public bool Share, Options, PS, Touch1, Touch2, TouchButton, TouchRight, TouchLeft; + public bool Share, Options, PS, Touch1, Touch2, TouchButton, TouchRight, TouchLeft, Touch1Finger, Touch2Fingers; public byte Touch1Identifier, Touch2Identifier; public byte LX, RX, LY, RY, L2, R2; public byte FrameCounter; // 0, 1, 2...62, 63, 0.... @@ -30,6 +30,7 @@ namespace DS4Windows DpadUp = DpadDown = DpadLeft = DpadRight = false; L1 = L3 = R1 = R3 = false; Share = Options = PS = Touch1 = Touch2 = TouchButton = TouchRight = TouchLeft = false; + Touch1Finger = Touch2Fingers = false; LX = RX = LY = RY = 127; L2 = R2 = 0; FrameCounter = 255; // only actually has 6 bits, so this is a null indicator @@ -73,6 +74,8 @@ namespace DS4Windows Touch2Identifier = state.Touch2Identifier; TouchButton = state.TouchButton; TouchPacketCounter = state.TouchPacketCounter; + Touch1Finger = state.Touch1Finger; + Touch2Fingers = state.Touch2Fingers; LX = state.LX; RX = state.RX; LY = state.LY; @@ -122,6 +125,8 @@ namespace DS4Windows state.TouchRight = TouchRight; state.TouchButton = TouchButton; state.TouchPacketCounter = TouchPacketCounter; + state.Touch1Finger = Touch1Finger; + state.Touch2Fingers = Touch2Fingers; state.LX = LX; state.RX = RX; state.LY = LY; diff --git a/DS4Windows/DS4Library/DS4StateExposed.cs b/DS4Windows/DS4Library/DS4StateExposed.cs index 2826bf6..924cc4a 100644 --- a/DS4Windows/DS4Library/DS4StateExposed.cs +++ b/DS4Windows/DS4Library/DS4StateExposed.cs @@ -34,6 +34,8 @@ namespace DS4Windows bool Touch1 { get { return _state.Touch1; } } bool Touch2 { get { return _state.Touch2; } } bool TouchButton { get { return _state.TouchButton; } } + bool Touch1Finger { get { return _state.Touch1Finger; } } + bool Touch2Fingers { get { return _state.Touch2Fingers; } } byte LX { get { return _state.LX; } } byte RX { get { return _state.RX; } } byte LY { get { return _state.LY; } }