Make sure multi-action button can work with touchpad area button

This commit is contained in:
Travis Nickles 2017-06-05 01:31:29 -07:00
parent 2583361e46
commit ce0ac4f04a
7 changed files with 66 additions and 22 deletions

View File

@ -433,6 +433,8 @@ namespace DS4Windows
device.Touchpad.TouchesMoved += tPad.touchesMoved;
device.Touchpad.TouchesEnded += tPad.touchesEnded;
device.Touchpad.TouchUnchanged += tPad.touchUnchanged;
//device.Touchpad.PreTouchProcess += delegate { touchPad[ind].populatePriorButtonStates(); };
device.Touchpad.PreTouchProcess += (sender, args) => { touchPad[ind].populatePriorButtonStates(); };
device.SixAxis.SixAccelMoved += tPad.sixaxisMoved;
//LogDebug("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
//Log.LogToTray("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
@ -642,7 +644,7 @@ namespace DS4Windows
public bool[] lag = { false, false, false, false };
public bool[] inWarnMonitor = { false, false, false, false };
//Called every time a new input report has arrived
// Called every time a new input report has arrived
protected virtual void On_Report(object sender, EventArgs e)
{
DS4Device device = (DS4Device)sender;

View File

@ -52,7 +52,7 @@ namespace DS4Windows
ControlType.SwipeDir, // DS4Controls.SwipeDown
};
public DS4StateFieldMapping(DS4State cState, DS4StateExposed exposeState, Mouse tp)
public DS4StateFieldMapping(DS4State cState, DS4StateExposed exposeState, Mouse tp, bool priorMouse=false)
{
axisdirs[(int)DS4Controls.LXNeg] = cState.LX;
axisdirs[(int)DS4Controls.LXPos] = cState.LX;
@ -85,10 +85,10 @@ namespace DS4Windows
buttons[(int)DS4Controls.DpadDown] = cState.DpadDown;
buttons[(int)DS4Controls.DpadLeft] = cState.DpadLeft;
buttons[(int)DS4Controls.TouchLeft] = tp != null ? tp.leftDown : false;
buttons[(int)DS4Controls.TouchRight] = tp != null ? tp.rightDown : false;
buttons[(int)DS4Controls.TouchUpper] = tp != null ? tp.upperDown : false;
buttons[(int)DS4Controls.TouchMulti] = tp != null ? tp.multiDown : false;
buttons[(int)DS4Controls.TouchLeft] = tp != null ? (!priorMouse ? tp.leftDown : tp.priorLeftDown) : false;
buttons[(int)DS4Controls.TouchRight] = tp != null ? (!priorMouse ? tp.rightDown : tp.priorRightDown) : false;
buttons[(int)DS4Controls.TouchUpper] = tp != null ? (!priorMouse ? tp.upperDown : tp.priorUpperDown) : false;
buttons[(int)DS4Controls.TouchMulti] = tp != null ? (!priorMouse ? tp.multiDown : tp.priorMultiDown) : false;
int gyroX = exposeState.getGyroX();
gryodirs[(int)DS4Controls.GyroXPos] = gyroX > 0 ? gyroX : 0;
@ -98,15 +98,15 @@ namespace DS4Windows
gryodirs[(int)DS4Controls.GyroZPos] = gyroZ > 0 ? gyroZ : 0;
gryodirs[(int)DS4Controls.GyroZNeg] = gyroZ < 0 ? gyroZ : 0;
swipedirs[(int)DS4Controls.SwipeLeft] = tp != null ? tp.swipeLeftB : (byte)0;
swipedirs[(int)DS4Controls.SwipeRight] = tp != null ? tp.swipeRightB : (byte)0;
swipedirs[(int)DS4Controls.SwipeUp] = tp != null ? tp.swipeUpB : (byte)0;
swipedirs[(int)DS4Controls.SwipeDown] = tp != null ? tp.swipeDownB : (byte)0;
swipedirs[(int)DS4Controls.SwipeLeft] = tp != null ? (!priorMouse ? tp.swipeLeftB : tp.priorSwipeLeftB): (byte)0;
swipedirs[(int)DS4Controls.SwipeRight] = tp != null ? (!priorMouse ? tp.swipeRightB : tp.priorSwipeRightB) : (byte)0;
swipedirs[(int)DS4Controls.SwipeUp] = tp != null ? (!priorMouse ? tp.swipeUpB : tp.priorSwipeUpB) : (byte)0;
swipedirs[(int)DS4Controls.SwipeDown] = tp != null ? (!priorMouse ? tp.swipeDownB : tp.priorSwipeDownB) : (byte)0;
swipedirbools[(int)DS4Controls.SwipeLeft] = tp != null ? tp.swipeLeft : false;
swipedirbools[(int)DS4Controls.SwipeRight] = tp != null ? tp.swipeRight : false;
swipedirbools[(int)DS4Controls.SwipeUp] = tp != null ? tp.swipeUp : false;
swipedirbools[(int)DS4Controls.SwipeDown] = tp != null ? tp.swipeDown : false;
swipedirbools[(int)DS4Controls.SwipeLeft] = tp != null ? (!priorMouse ? tp.swipeLeft : tp.priorSwipeLeft) : false;
swipedirbools[(int)DS4Controls.SwipeRight] = tp != null ? (!priorMouse ? tp.swipeRight : tp.priorSwipeRight) : false;
swipedirbools[(int)DS4Controls.SwipeUp] = tp != null ? (!priorMouse ? tp.swipeUp : tp.priorSwipeUp) : false;
swipedirbools[(int)DS4Controls.SwipeDown] = tp != null ? (!priorMouse ? tp.swipeDown : tp.priorSwipeDown) : false;
}
public void populateState(DS4State state)

View File

@ -1740,7 +1740,7 @@ namespace DS4Windows
// button is assigned
if (previousFieldMapping == null)
{
previousFieldMapping = new DS4StateFieldMapping(tempPrevState, eState, tp);
previousFieldMapping = new DS4StateFieldMapping(tempPrevState, eState, tp, true);
}
bool activeCur = getBoolMapping2(device, action.trigger[0], cState, eState, tp, fieldMapping);

View File

@ -13,10 +13,14 @@ namespace DS4Windows
private readonly MouseWheel wheel;
private bool tappedOnce = false, secondtouchbegin = false;
public bool swipeLeft, swipeRight, swipeUp, swipeDown;
public bool priorSwipeLeft, priorSwipeRight, priorSwipeUp, priorSwipeDown;
public byte swipeLeftB, swipeRightB, swipeUpB, swipeDownB, swipedB;
public byte priorSwipeLeftB, priorSwipeRightB, priorSwipeUpB, priorSwipeDownB, priorSwipedB;
public bool slideleft, slideright;
public bool priorSlideLeft, priorSlideright;
// touch area stuff
public bool leftDown, rightDown, upperDown, multiDown;
public bool priorLeftDown, priorRightDown, priorUpperDown, priorMultiDown;
protected DS4Controls pushed = DS4Controls.None;
protected Mapping.Click clicked = Mapping.Click.None;
@ -36,11 +40,17 @@ namespace DS4Windows
int i = 0;
string[] ss = Global.SATriggers[deviceNum].Split(',');
if (!string.IsNullOrEmpty(ss[0]))
{
foreach (string s in ss)
{
if (!(int.TryParse(s, out i) && getDS4ControlsByName(i)))
triggeractivated = false;
}
}
if (triggeractivated)
cursor.sixaxisMoved(arg);
dev.getCurrentState(s);
}
}
@ -91,6 +101,7 @@ namespace DS4Windows
if (arg.touches[0].hwY - firstTouch.hwY > 300) swipeDown = true;
if (arg.touches[0].hwY - firstTouch.hwY < -300) swipeUp = true;
}
swipeUpB = (byte)Math.Min(255, Math.Max(0, (firstTouch.hwY - arg.touches[0].hwY) * 1.5f));
swipeDownB = (byte)Math.Min(255, Math.Max(0, (arg.touches[0].hwY - firstTouch.hwY) * 1.5f));
swipeLeftB = (byte)Math.Min(255, Math.Max(0, firstTouch.hwX - arg.touches[0].hwX));
@ -98,14 +109,17 @@ namespace DS4Windows
}
if (Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 50 && arg.touches.Length == 2)
{
if (arg.touches[0].hwX - firstTouch.hwX > 200 && !slideleft)
slideright = true;
else if (firstTouch.hwX - arg.touches[0].hwX > 200 && !slideright)
slideleft = true;
}
dev.getCurrentState(s);
synthesizeMouseButtons();
}
public virtual void touchesBegan(object sender, TouchpadEventArgs arg)
{
if (!Global.UseTPforControls[deviceNum])
@ -127,6 +141,7 @@ namespace DS4Windows
dev.getCurrentState(s);
synthesizeMouseButtons();
}
public virtual void touchesEnded(object sender, TouchpadEventArgs arg)
{
slideright = slideleft = false;
@ -143,7 +158,9 @@ namespace DS4Windows
DateTime test = arg.timeStamp;
if (test <= (pastTime + TimeSpan.FromMilliseconds((double)tapSensitivity * 2)) && !arg.touchButtonPressed && !tappedOnce)
{
if (Math.Abs(firstTouch.hwX - arg.touches[0].hwX) < 10 && Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 10)
{
if (Global.DoubleTap[deviceNum])
{
tappedOnce = true;
@ -152,6 +169,8 @@ namespace DS4Windows
}
else
Mapping.MapClick(deviceNum, Mapping.Click.Left); //this way no delay if disabled
}
}
}
dev.getCurrentState(s);
@ -191,8 +210,10 @@ namespace DS4Windows
if (Global.GetDS4Action(deviceNum, DS4Controls.TouchUpper, false) == null && upperDown)
Mapping.MapClick(deviceNum, Mapping.Click.Middle);
if (Global.GetDS4Action(deviceNum, DS4Controls.TouchRight, false) == null && rightDown)
Mapping.MapClick(deviceNum, Mapping.Click.Left);
if (Global.GetDS4Action(deviceNum, DS4Controls.TouchMulti, false) == null && multiDown)
Mapping.MapClick(deviceNum, Mapping.Click.Right);
@ -254,6 +275,19 @@ namespace DS4Windows
synthesizeMouseButtons();
}
public void populatePriorButtonStates()
{
priorUpperDown = upperDown;
priorLeftDown = leftDown;
priorRightDown = rightDown;
priorMultiDown = multiDown;
priorSwipeLeft = swipeLeft; priorSwipeRight = swipeRight;
priorSwipeUp = swipeUp; priorSwipeDown = swipeDown;
priorSwipeLeftB = swipeLeftB; priorSwipeRightB = swipeRightB; priorSwipeUpB = swipeUpB;
priorSwipeDownB = swipeDownB; priorSwipedB = swipedB;
}
public DS4State getDS4State()
{
return s;

View File

@ -1183,7 +1183,7 @@ namespace DS4Windows
}
}
string tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
//string tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
int Index = args.getIndex();
if (Index >= 0 && Index < ControlService.DS4_CONTROLLER_COUNT)
{

View File

@ -23,7 +23,7 @@ namespace DS4Windows
Square = Triangle = Circle = Cross = false;
DpadUp = DpadDown = DpadLeft = DpadRight = false;
L1 = L3 = R1 = R3 = false;
Share = Options = PS = Touch1 = Touch2 = TouchButton = TouchRight = TouchLeft = false;
Share = Options = PS = Touch1 = Touch2 = TouchButton = TouchRight = TouchLeft = false;
LX = RX = LY = RY = 127;
L2 = R2 = 0;
FrameCounter = 255; // only actually has 6 bits, so this is a null indicator

View File

@ -5,9 +5,9 @@ namespace DS4Windows
public class TouchpadEventArgs : EventArgs
{
public readonly Touch[] touches = null;
public readonly System.DateTime timeStamp;
public readonly DateTime timeStamp;
public readonly bool touchButtonPressed;
public TouchpadEventArgs(System.DateTime utcTimestamp, bool tButtonDown, Touch t0, Touch t1 = null)
public TouchpadEventArgs(DateTime utcTimestamp, bool tButtonDown, Touch t0, Touch t1 = null)
{
if (t1 != null)
{
@ -20,8 +20,9 @@ namespace DS4Windows
touches = new Touch[1];
touches[0] = t0;
}
touchButtonPressed = tButtonDown;
this.timeStamp = utcTimestamp;
timeStamp = utcTimestamp;
}
}
@ -30,7 +31,7 @@ namespace DS4Windows
public readonly int hwX, hwY, deltaX, deltaY;
public readonly byte touchID;
public readonly Touch previousTouch;
public Touch(int X, int Y, byte tID, Touch prevTouch = null)
public Touch(int X, int Y, byte tID, Touch prevTouch = null)
{
hwX = X;
hwY = Y;
@ -52,6 +53,7 @@ namespace DS4Windows
public event EventHandler<TouchpadEventArgs> TouchButtonDown = null; // touchpad pushed down until the button clicks
public event EventHandler<TouchpadEventArgs> TouchButtonUp = null; // touchpad button released
public event EventHandler<EventArgs> TouchUnchanged = null; // no status change for the touchpad itself... but other sensors may have changed, or you may just want to do some processing
public event EventHandler<EventArgs> PreTouchProcess = null; // used to publish that a touch packet is about to be processed
public readonly static int TOUCHPAD_DATA_OFFSET = 35;
internal int lastTouchPadX1, lastTouchPadY1,
@ -65,18 +67,21 @@ namespace DS4Windows
private bool PacketChanged(byte[] data, int touchPacketOffset)
{
bool changed = false;
for (int i = 0; i < previousPacket.Length; i++)
for (int i = 0, arLen = previousPacket.Length; i < arLen; i++)
{
byte oldValue = previousPacket[i];
previousPacket[i] = data[i + TOUCHPAD_DATA_OFFSET + touchPacketOffset];
if (previousPacket[i] != oldValue)
changed = true;
}
return changed;
}
public void handleTouchpad(byte[] data, DS4State sensors, int touchPacketOffset = 0)
{
PreTouchProcess?.Invoke(this, EventArgs.Empty);
bool touchPadIsDown = sensors.TouchButton;
if (!PacketChanged(data, touchPacketOffset) && touchPadIsDown == lastTouchPadIsDown)
{
@ -84,6 +89,7 @@ namespace DS4Windows
TouchUnchanged(this, EventArgs.Empty);
return;
}
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);
@ -131,6 +137,7 @@ namespace DS4Windows
t0 = new Touch(currentX2, currentY2, touchID2, tPrev);
t1 = null;
}
args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0, t1);
TouchesMoved(this, args);
@ -169,6 +176,7 @@ namespace DS4Windows
lastTouchPadX2 = currentX2;
lastTouchPadY2 = currentY2;
}
lastTouchPadIsDown = touchPadIsDown;
}
else