Merge pull request #4 from Ryochan7/jay

Update to Version 1.4.84
This commit is contained in:
Yuki-nyan 2017-07-10 00:15:46 +01:00 committed by GitHub
commit 48545207b4
29 changed files with 9479 additions and 3857 deletions

View File

@ -1,15 +1,18 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Media; using System.Media;
using System.Threading.Tasks;
using static DS4Windows.Global; using static DS4Windows.Global;
using System.Threading;
namespace DS4Windows namespace DS4Windows
{ {
public class ControlService public class ControlService
{ {
public X360Device x360Bus; public X360Device x360Bus = null;
public const int DS4_CONTROLLER_COUNT = 4; public const int DS4_CONTROLLER_COUNT = 4;
public DS4Device[] DS4Controllers = new DS4Device[DS4_CONTROLLER_COUNT]; public DS4Device[] DS4Controllers = new DS4Device[DS4_CONTROLLER_COUNT];
public Mouse[] touchPad = new Mouse[DS4_CONTROLLER_COUNT]; public Mouse[] touchPad = new Mouse[DS4_CONTROLLER_COUNT];
@ -37,7 +40,17 @@ namespace DS4Windows
public ControlService() public ControlService()
{ {
//sp.Stream = Properties.Resources.EE; //sp.Stream = Properties.Resources.EE;
x360Bus = new X360Device(); // Cause thread affinity to not be tied to main GUI thread
Thread x360Thread = new Thread(() => { x360Bus = new X360Device(); });
x360Thread.IsBackground = true;
x360Thread.Priority = ThreadPriority.Normal;
x360Thread.Name = "SCP Virtual Bus Thread";
x360Thread.Start();
while (!x360Thread.ThreadState.HasFlag(ThreadState.Stopped))
{
Thread.SpinWait(500);
}
AddtoDS4List(); AddtoDS4List();
for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++) for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
@ -87,7 +100,7 @@ namespace DS4Windows
{ {
if (DS4Devices.isExclusiveMode && !device.isExclusive()) if (DS4Devices.isExclusiveMode && !device.isExclusive())
{ {
await System.Threading.Tasks.Task.Delay(5); await Task.Delay(5);
string message = Properties.Resources.CouldNotOpenDS4.Replace("*Mac address*", device.getMacAddress()) + " " + string message = Properties.Resources.CouldNotOpenDS4.Replace("*Mac address*", device.getMacAddress()) + " " +
Properties.Resources.QuitOtherPrograms; Properties.Resources.QuitOtherPrograms;
LogDebug(message, true); LogDebug(message, true);
@ -127,12 +140,16 @@ namespace DS4Windows
WarnExclusiveModeFailure(device); WarnExclusiveModeFailure(device);
DS4Controllers[i] = device; DS4Controllers[i] = device;
device.setUiContext(SynchronizationContext.Current);
device.Removal += this.On_DS4Removal; device.Removal += this.On_DS4Removal;
device.Removal += DS4Devices.On_Removal; device.Removal += DS4Devices.On_Removal;
device.SyncChange += this.On_SyncChange;
device.SyncChange += DS4Devices.UpdateSerial;
device.SerialChange += this.On_SerialChange;
touchPad[i] = new Mouse(i, device); touchPad[i] = new Mouse(i, device);
device.LightBarColor = getMainColor(i); device.LightBarColor = getMainColor(i);
if (!getDInputOnly(i)) if (!getDInputOnly(i) && device.isSynced())
{ {
int xinputIndex = x360Bus.FirstController + i; int xinputIndex = x360Bus.FirstController + i;
LogDebug("Plugging in X360 Controller #" + xinputIndex); LogDebug("Plugging in X360 Controller #" + xinputIndex);
@ -151,12 +168,13 @@ namespace DS4Windows
device.Report += this.On_Report; device.Report += this.On_Report;
TouchPadOn(i, device); TouchPadOn(i, device);
CheckProfileOptions(i, device, true);
device.StartUpdate(); device.StartUpdate();
//string filename = ProfilePath[ind]; //string filename = ProfilePath[ind];
//ind++; //ind++;
if (showlog) if (showlog)
{ {
if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[i] + ".xml")) if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[i] + ".xml"))
{ {
string prolog = Properties.Resources.UsingProfile.Replace("*number*", (i + 1).ToString()).Replace("*Profile name*", ProfilePath[i]); string prolog = Properties.Resources.UsingProfile.Replace("*number*", (i + 1).ToString()).Replace("*Profile name*", ProfilePath[i]);
LogDebug(prolog); LogDebug(prolog);
@ -228,14 +246,15 @@ namespace DS4Windows
DS4LightBar.forcelight[i] = false; DS4LightBar.forcelight[i] = false;
DS4LightBar.forcedFlash[i] = 0; DS4LightBar.forcedFlash[i] = 0;
DS4LightBar.defaultLight = true; DS4LightBar.defaultLight = true;
DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]); DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i],
ExposedState[i], touchPad[i]);
tempDevice.IsRemoved = true; tempDevice.IsRemoved = true;
System.Threading.Thread.Sleep(50); System.Threading.Thread.Sleep(50);
} }
CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change. CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change.
x360Bus.Unplug(i); x360Bus.Unplug(i);
useDInputOnly[i] = false; useDInputOnly[i] = true;
anyUnplugged = true; anyUnplugged = true;
DS4Controllers[i] = null; DS4Controllers[i] = null;
touchPad[i] = null; touchPad[i] = null;
@ -262,28 +281,10 @@ namespace DS4Windows
return true; return true;
} }
public bool HotPlug() public bool HotPlug(SynchronizationContext uiContext)
{ {
if (running) if (running)
{ {
// Do first run check for Quick Charge checks. Needed so old device will
// be removed before performing another controller scan
if (getQuickCharge())
{
for (int i = 0, devlen = DS4Controllers.Length; i < devlen; i++)
{
DS4Device device = DS4Controllers[i];
if (device != null)
{
if (device.getConnectionType() == ConnectionType.BT && device.isCharging())
{
device.StopUpdate();
device.DisconnectBT(true);
}
}
}
}
DS4Devices.findControllers(); DS4Devices.findControllers();
IEnumerable<DS4Device> devices = DS4Devices.getDS4Controllers(); IEnumerable<DS4Device> devices = DS4Devices.getDS4Controllers();
//foreach (DS4Device device in devices) //foreach (DS4Device device in devices)
@ -316,33 +317,38 @@ namespace DS4Windows
LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")"); LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
WarnExclusiveModeFailure(device); WarnExclusiveModeFailure(device);
DS4Controllers[Index] = device; DS4Controllers[Index] = device;
device.setUiContext(uiContext);
device.Removal += this.On_DS4Removal; device.Removal += this.On_DS4Removal;
device.Removal += DS4Devices.On_Removal; device.Removal += DS4Devices.On_Removal;
device.SyncChange += this.On_SyncChange;
device.SyncChange += DS4Devices.UpdateSerial;
device.SerialChange += this.On_SerialChange;
touchPad[Index] = new Mouse(Index, device); touchPad[Index] = new Mouse(Index, device);
device.LightBarColor = getMainColor(Index); device.LightBarColor = getMainColor(Index);
device.Report += this.On_Report; device.Report += this.On_Report;
if (!getDInputOnly(Index)) if (!getDInputOnly(Index) && device.isSynced())
{ {
int xinputIndex = x360Bus.FirstController + i; int xinputIndex = x360Bus.FirstController + Index;
LogDebug("Plugging in X360 Controller #" + xinputIndex); LogDebug("Plugging in X360 Controller #" + xinputIndex);
bool xinputResult = x360Bus.Plugin(i); bool xinputResult = x360Bus.Plugin(Index);
if (xinputResult) if (xinputResult)
{ {
LogDebug("X360 Controller # " + xinputIndex + " connected"); LogDebug("X360 Controller # " + xinputIndex + " connected");
useDInputOnly[i] = false; useDInputOnly[Index] = false;
} }
else else
{ {
LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode"); LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
useDInputOnly[i] = true; useDInputOnly[Index] = true;
} }
} }
TouchPadOn(Index, device); TouchPadOn(Index, device);
CheckProfileOptions(Index, device);
device.StartUpdate(); device.StartUpdate();
//string filename = Path.GetFileName(ProfilePath[Index]); //string filename = Path.GetFileName(ProfilePath[Index]);
if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml")) if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml"))
{ {
string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", ProfilePath[Index]); string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", ProfilePath[Index]);
LogDebug(prolog); LogDebug(prolog);
@ -364,6 +370,56 @@ namespace DS4Windows
return true; return true;
} }
private void CheckProfileOptions(int ind, DS4Device device, bool startUp=false)
{
device.setIdleTimeout(getIdleDisconnectTimeout(ind));
device.setBTPollRate(getBTPollRate(ind));
if (!startUp)
{
CheckLauchProfileOption(ind, device);
}
}
private void CheckLauchProfileOption(int ind, DS4Device device)
{
string programPath = LaunchProgram[ind];
if (programPath != string.Empty)
{
System.Diagnostics.Process[] localAll = System.Diagnostics.Process.GetProcesses();
bool procFound = false;
for (int procInd = 0, procsLen = localAll.Length; !procFound && procInd < procsLen; procInd++)
{
try
{
string temp = localAll[procInd].MainModule.FileName;
if (temp == programPath)
{
procFound = true;
}
}
// Ignore any process for which this information
// is not exposed
catch { }
}
if (!procFound)
{
Task processTask = new Task(() =>
{
System.Diagnostics.Process tempProcess = new System.Diagnostics.Process();
tempProcess.StartInfo.FileName = programPath;
tempProcess.StartInfo.WorkingDirectory = new FileInfo(programPath).Directory.ToString();
//tempProcess.StartInfo.UseShellExecute = false;
try { tempProcess.Start(); }
catch { }
});
processTask.Start();
}
}
}
public void TouchPadOn(int ind, DS4Device device) public void TouchPadOn(int ind, DS4Device device)
{ {
ITouchpadBehaviour tPad = touchPad[ind]; ITouchpadBehaviour tPad = touchPad[ind];
@ -373,10 +429,11 @@ namespace DS4Windows
device.Touchpad.TouchesMoved += tPad.touchesMoved; device.Touchpad.TouchesMoved += tPad.touchesMoved;
device.Touchpad.TouchesEnded += tPad.touchesEnded; device.Touchpad.TouchesEnded += tPad.touchesEnded;
device.Touchpad.TouchUnchanged += tPad.touchUnchanged; 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; device.SixAxis.SixAccelMoved += tPad.sixaxisMoved;
//LogDebug("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString()); //LogDebug("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
//Log.LogToTray("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString()); //Log.LogToTray("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
//ControllerStatusChanged(this);
} }
public string getDS4ControllerInfo(int index) public string getDS4ControllerInfo(int index)
@ -490,6 +547,77 @@ namespace DS4Windows
return Properties.Resources.NoneText; return Properties.Resources.NoneText;
} }
protected void On_SerialChange(object sender, EventArgs e)
{
DS4Device device = (DS4Device)sender;
int ind = -1;
for (int i = 0, arlength = DS4_CONTROLLER_COUNT; ind == -1 && i < arlength; i++)
{
DS4Device tempDev = DS4Controllers[i];
if (tempDev != null && device == tempDev)
ind = i;
}
if (ind >= 0)
{
OnDeviceSerialChange(this, ind, device.getMacAddress());
}
}
protected void On_SyncChange(object sender, EventArgs e)
{
DS4Device device = (DS4Device)sender;
int ind = -1;
for (int i = 0, arlength = DS4_CONTROLLER_COUNT; ind == -1 && i < arlength; i++)
{
DS4Device tempDev = DS4Controllers[i];
if (tempDev != null && device == tempDev)
ind = i;
}
if (ind >= 0)
{
bool synced = device.isSynced();
if (!synced)
{
if (!useDInputOnly[ind])
{
bool unplugResult = x360Bus.Unplug(ind);
int xinputIndex = x360Bus.FirstController + ind;
if (unplugResult)
{
LogDebug("X360 Controller # " + xinputIndex + " unplugged");
useDInputOnly[ind] = true;
}
else
{
LogDebug("X360 Controller # " + xinputIndex + " failed to unplug");
}
}
}
else
{
if (!getDInputOnly(ind))
{
int xinputIndex = x360Bus.FirstController + ind;
LogDebug("Plugging in X360 Controller #" + xinputIndex);
bool xinputResult = x360Bus.Plugin(ind);
if (xinputResult)
{
LogDebug("X360 Controller # " + xinputIndex + " connected");
useDInputOnly[ind] = false;
}
else
{
LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
useDInputOnly[ind] = true;
}
}
}
}
}
//Called when DS4 is disconnected or timed out //Called when DS4 is disconnected or timed out
protected virtual void On_DS4Removal(object sender, EventArgs e) protected virtual void On_DS4Removal(object sender, EventArgs e)
{ {
@ -516,7 +644,20 @@ namespace DS4Windows
if (removingStatus) if (removingStatus)
{ {
CurrentState[ind].Battery = PreviousState[ind].Battery = 0; // Reset for the next connection's initial status change. CurrentState[ind].Battery = PreviousState[ind].Battery = 0; // Reset for the next connection's initial status change.
x360Bus.Unplug(ind); if (!useDInputOnly[ind])
{
bool unplugResult = x360Bus.Unplug(ind);
int xinputIndex = x360Bus.FirstController + ind;
if (unplugResult)
{
LogDebug("X360 Controller # " + xinputIndex + " unplugged");
}
else
{
LogDebug("X360 Controller # " + xinputIndex + " failed to unplug");
}
}
string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind + 1).ToString()); string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind + 1).ToString());
if (device.getBattery() <= 20 && if (device.getBattery() <= 20 &&
device.getConnectionType() == ConnectionType.BT && !device.isCharging()) device.getConnectionType() == ConnectionType.BT && !device.isCharging())
@ -526,23 +667,36 @@ namespace DS4Windows
LogDebug(removed); LogDebug(removed);
Log.LogToTray(removed); Log.LogToTray(removed);
System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME); /*Stopwatch sw = new Stopwatch();
sw.Start();
while (sw.ElapsedMilliseconds < XINPUT_UNPLUG_SETTLE_TIME)
{
// Use SpinWait to keep control of current thread. Using Sleep could potentially
// cause other events to get run out of order
System.Threading.Thread.SpinWait(500);
}
sw.Stop();
*/
device.IsRemoved = true; device.IsRemoved = true;
device.Synced = false;
DS4Controllers[ind] = null; DS4Controllers[ind] = null;
touchPad[ind] = null; touchPad[ind] = null;
lag[ind] = false; lag[ind] = false;
inWarnMonitor[ind] = false; inWarnMonitor[ind] = false;
useDInputOnly[ind] = false; useDInputOnly[ind] = true;
System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
OnControllerRemoved(this, ind); OnControllerRemoved(this, ind);
//ControllerStatusChanged(this);
} }
} }
} }
public bool[] lag = { false, false, false, false }; public bool[] lag = { false, false, false, false };
public bool[] inWarnMonitor = { false, false, false, false }; public bool[] inWarnMonitor = { false, false, false, false };
private byte[] currentBattery = { 0, 0, 0, 0 };
private bool[] charging = { 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) protected virtual void On_Report(object sender, EventArgs e)
{ {
DS4Device device = (DS4Device)sender; DS4Device device = (DS4Device)sender;
@ -569,9 +723,21 @@ namespace DS4Windows
{ {
int flashWhenLateAt = getFlashWhenLateAt(); int flashWhenLateAt = getFlashWhenLateAt();
if (!lag[ind] && device.Latency >= flashWhenLateAt) if (!lag[ind] && device.Latency >= flashWhenLateAt)
LagFlashWarning(ind, true); {
lag[ind] = true;
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
{
LagFlashWarning(ind, true);
}), null);
}
else if (lag[ind] && device.Latency < flashWhenLateAt) else if (lag[ind] && device.Latency < flashWhenLateAt)
LagFlashWarning(ind, false); {
lag[ind] = false;
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
{
LagFlashWarning(ind, false);
}), null);
}
} }
else else
{ {
@ -589,12 +755,19 @@ namespace DS4Windows
if (!device.firstReport && device.IsAlive()) if (!device.firstReport && device.IsAlive())
{ {
device.firstReport = true; device.firstReport = true;
OnDeviceStatusChanged(this, ind); device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
{
OnDeviceStatusChanged(this, ind);
}), null);
} }
else if (pState.Battery != cState.Battery) else if (pState.Battery != cState.Battery || device.oldCharging != device.isCharging())
{ {
OnBatteryStatusChange(this, ind, cState.Battery); byte tempBattery = currentBattery[ind] = cState.Battery;
//ControllerStatusChanged(this); bool tempCharging = charging[ind] = device.isCharging();
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
{
OnBatteryStatusChange(this, ind, tempBattery, tempCharging);
}), null);
} }
if (getEnableTouchToggle(ind)) if (getEnableTouchToggle(ind))
@ -612,9 +785,6 @@ namespace DS4Windows
cState = MappedState[ind]; cState = MappedState[ind];
} }
// Update the GUI/whatever.
DS4LightBar.updateLightBar(device, ind, cState, ExposedState[ind], touchPad[ind]);
if (!useDInputOnly[ind]) if (!useDInputOnly[ind])
{ {
x360Bus.Parse(cState, processingData[ind].Report, ind); x360Bus.Parse(cState, processingData[ind].Report, ind);
@ -622,8 +792,8 @@ namespace DS4Windows
// pull back any possible rumble data coming from Xinput consumers. // pull back any possible rumble data coming from Xinput consumers.
if (x360Bus.Report(processingData[ind].Report, processingData[ind].Rumble)) if (x360Bus.Report(processingData[ind].Report, processingData[ind].Rumble))
{ {
Byte Big = (Byte)(processingData[ind].Rumble[3]); byte Big = processingData[ind].Rumble[3];
Byte Small = (Byte)(processingData[ind].Rumble[4]); byte Small = processingData[ind].Rumble[4];
if (processingData[ind].Rumble[1] == 0x08) if (processingData[ind].Rumble[1] == 0x08)
{ {
@ -634,8 +804,9 @@ namespace DS4Windows
// Output any synthetic events. // Output any synthetic events.
Mapping.Commit(ind); Mapping.Commit(ind);
// Pull settings updates.
device.setIdleTimeout(getIdleDisconnectTimeout(ind)); // Update the GUI/whatever.
DS4LightBar.updateLightBar(device, ind, cState, ExposedState[ind], touchPad[ind]);
} }
} }
@ -685,7 +856,7 @@ namespace DS4Windows
} }
else if (Mapping.getBoolButtonMapping(cState.Square)) else if (Mapping.getBoolButtonMapping(cState.Square))
{ {
result = "Triangle"; result = "Square";
} }
else if (Mapping.getBoolButtonMapping(cState.L1)) else if (Mapping.getBoolButtonMapping(cState.L1))
{ {
@ -725,7 +896,7 @@ namespace DS4Windows
} }
else if (Mapping.getBoolButtonMapping(cState.DpadRight)) else if (Mapping.getBoolButtonMapping(cState.DpadRight))
{ {
result = "DpadRight"; result = "Right";
} }
else if (Mapping.getBoolButtonMapping(cState.Share)) else if (Mapping.getBoolButtonMapping(cState.Share))
{ {

View File

@ -34,11 +34,6 @@ namespace DS4Windows
public static void updateLightBar(DS4Device device, int deviceNum, DS4State cState, public static void updateLightBar(DS4Device device, int deviceNum, DS4State cState,
DS4StateExposed eState, Mouse tp) DS4StateExposed eState, Mouse tp)
{ {
/*
* TODO: Remove more property usage and use explicit getter methods instead.
* Testing in proper optimized release builds shows that it is
* still necessary to reduce lag.
*/
DS4Color color; DS4Color color;
if (!defaultLight && !forcelight[deviceNum]) if (!defaultLight && !forcelight[deviceNum])
{ {
@ -48,7 +43,7 @@ namespace DS4Windows
{ {
DS4Color fullColor = getCustomColor(deviceNum); DS4Color fullColor = getCustomColor(deviceNum);
DS4Color lowColor = getLowColor(deviceNum); DS4Color lowColor = getLowColor(deviceNum);
color = getTransitionedColor(lowColor, fullColor, device.Battery); color = getTransitionedColor(lowColor, fullColor, device.getBattery());
} }
else else
color = getCustomColor(deviceNum); color = getCustomColor(deviceNum);
@ -75,7 +70,7 @@ namespace DS4Windows
counters[deviceNum] = 0; counters[deviceNum] = 0;
if (getLedAsBatteryIndicator(deviceNum)) if (getLedAsBatteryIndicator(deviceNum))
color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(2.55 * device.getBattery())); color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(device.getBattery() * 2.55));
else else
color = HuetoRGB((float)counters[deviceNum] % 360, 255); color = HuetoRGB((float)counters[deviceNum] % 360, 255);
@ -87,7 +82,7 @@ namespace DS4Windows
DS4Color fullColor = getMainColor(deviceNum); DS4Color fullColor = getMainColor(deviceNum);
DS4Color lowColor = getLowColor(deviceNum); DS4Color lowColor = getLowColor(deviceNum);
color = getTransitionedColor(lowColor, fullColor, (uint)device.getBattery()); color = getTransitionedColor(lowColor, fullColor, device.getBattery());
} }
} }
else else
@ -158,7 +153,7 @@ namespace DS4Windows
double botratio = timeratio.TotalMilliseconds; double botratio = timeratio.TotalMilliseconds;
double topratio = TimeSpan.FromSeconds(idleDisconnectTimeout).TotalMilliseconds; double topratio = TimeSpan.FromSeconds(idleDisconnectTimeout).TotalMilliseconds;
double ratio = 100.0 * (botratio / topratio); double ratio = 100.0 * (botratio / topratio);
if (ratio >= 50.0 && ratio <= 100.0) if (ratio >= 50.0 && ratio < 100.0)
color = getTransitionedColor(color, new DS4Color(0, 0, 0), (uint)((ratio - 50) * 2)); color = getTransitionedColor(color, new DS4Color(0, 0, 0), (uint)((ratio - 50) * 2));
else if (ratio >= 100.0) else if (ratio >= 100.0)
color = getTransitionedColor(color, new DS4Color(0, 0, 0), 100.0); color = getTransitionedColor(color, new DS4Color(0, 0, 0), 100.0);

View File

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

View File

@ -82,8 +82,8 @@ namespace DS4Windows
public static DateTime[] oldnowAction = { DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue }; public static DateTime[] oldnowAction = { DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue };
public static int[] untriggerindex = { -1, -1, -1, -1 }; public static int[] untriggerindex = { -1, -1, -1, -1 };
public static DateTime[] oldnowKeyAct = { DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue }; public static DateTime[] oldnowKeyAct = { DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue };
private static bool tappedOnce = false, firstTouch = false, secondtouchbegin = false; //private static bool tappedOnce = false, firstTouch = false, secondtouchbegin = false;
private static DateTime pastTime, firstTap, TimeofEnd; //private static DateTime pastTime, firstTap, TimeofEnd;
private static DS4Controls[] shiftTriggerMapping = { DS4Controls.None, DS4Controls.Cross, DS4Controls.Circle, DS4Controls.Square, private static DS4Controls[] shiftTriggerMapping = { DS4Controls.None, DS4Controls.Cross, DS4Controls.Circle, DS4Controls.Square,
DS4Controls.Triangle, DS4Controls.Options, DS4Controls.Share, DS4Controls.DpadUp, DS4Controls.DpadDown, DS4Controls.Triangle, DS4Controls.Options, DS4Controls.Share, DS4Controls.DpadUp, DS4Controls.DpadDown,
DS4Controls.DpadLeft, DS4Controls.DpadRight, DS4Controls.PS, DS4Controls.L1, DS4Controls.R1, DS4Controls.L2, DS4Controls.DpadLeft, DS4Controls.DpadRight, DS4Controls.PS, DS4Controls.L1, DS4Controls.R1, DS4Controls.L2,
@ -126,15 +126,23 @@ namespace DS4Windows
32 // DS4Controls.GyroZNeg 32 // DS4Controls.GyroZNeg
}; };
//special macros // Define here to save some time processing.
// It is enough to feel a difference during gameplay.
private static int[] rsOutCurveModeArray = { 0, 0, 0, 0 };
private static int[] lsOutCurveModeArray = { 0, 0, 0, 0 };
static bool tempBool = false;
// Special macros
static bool altTabDone = true; static bool altTabDone = true;
static DateTime altTabNow = DateTime.UtcNow, oldAltTabNow = DateTime.UtcNow - TimeSpan.FromSeconds(1); static DateTime altTabNow = DateTime.UtcNow, oldAltTabNow = DateTime.UtcNow - TimeSpan.FromSeconds(1);
//mouse // Mouse
public static int mcounter = 34; public static int mcounter = 34;
public static int mouseaccel = 0; public static int mouseaccel = 0;
public static int prevmouseaccel = 0; public static int prevmouseaccel = 0;
private static double horizontalRemainder = 0.0, verticalRemainder = 0.0; private static double horizontalRemainder = 0.0, verticalRemainder = 0.0;
private const int MOUSESPEEDFACTOR = 40;
private const double MOUSESTICKOFFSET = 0.03;
public static void Commit(int device) public static void Commit(int device)
{ {
@ -386,7 +394,7 @@ namespace DS4Windows
return value1 * percent + value2 * (1 - percent); return value1 * percent + value2 * (1 - percent);
} }
static double Clamp(double min, double value, double max) /*static double Clamp(double min, double value, double max)
{ {
if (value > max) if (value > max)
return max; return max;
@ -395,14 +403,24 @@ namespace DS4Windows
else else
return value; return value;
} }
*/
private static int ClampInt(int min, int value, int max) private static int ClampInt(int min, int value, int max)
{ {
return (value < min) ? min : (value > max) ? max : value; return (value < min) ? min : (value > max) ? max : value;
} }
private static double[] tempDoubleArray = { 0.0, 0.0, 0.0, 0.0 };
public static DS4State SetCurveAndDeadzone(int device, DS4State cState) public static DS4State SetCurveAndDeadzone(int device, DS4State cState)
{ {
double rotation = tempDoubleArray[device] = getLSRotation(device);
if (rotation != 0.0)
cState.rotateLSCoordinates(rotation);
double rotationRS = tempDoubleArray[device] = getRSRotation(device);
if (rotationRS != 0.0)
cState.rotateRSCoordinates(rotationRS);
DS4State dState = new DS4State(cState); DS4State dState = new DS4State(cState);
int x; int x;
int y; int y;
@ -514,8 +532,8 @@ namespace DS4Windows
if (lsSquared > lsDeadzoneSquared) if (lsSquared > lsDeadzoneSquared)
{ {
double currentX = Clamp(maxZoneXNegValue, dState.LX, maxZoneXPosValue); double currentX = Global.Clamp(maxZoneXNegValue, dState.LX, maxZoneXPosValue);
double currentY = Clamp(maxZoneYNegValue, dState.LY, maxZoneYPosValue); double currentY = Global.Clamp(maxZoneYNegValue, dState.LY, maxZoneYPosValue);
//currentX = (byte)((dState.LX >= 127.5f) ? Math.Min(dState.LX, maxZoneX) : Math.Max(dState.LX, maxZoneX)); //currentX = (byte)((dState.LX >= 127.5f) ? Math.Min(dState.LX, maxZoneX) : Math.Max(dState.LX, maxZoneX));
//currentY = (byte)((dState.LY >= 127.5f) ? Math.Min(dState.LY, maxZoneY) : Math.Max(dState.LY, maxZoneY)); //currentY = (byte)((dState.LY >= 127.5f) ? Math.Min(dState.LY, maxZoneY) : Math.Max(dState.LY, maxZoneY));
tempOutputX = ((currentX - 127.5f - tempLsXDead) / (double)(maxZoneX - tempLsXDead)); tempOutputX = ((currentX - 127.5f - tempLsXDead) / (double)(maxZoneX - tempLsXDead));
@ -524,8 +542,8 @@ namespace DS4Windows
} }
else else
{ {
double currentX = Clamp(maxZoneXNegValue, dState.LX, maxZoneXPosValue); double currentX = Global.Clamp(maxZoneXNegValue, dState.LX, maxZoneXPosValue);
double currentY = Clamp(maxZoneYNegValue, dState.LY, maxZoneYPosValue); double currentY = Global.Clamp(maxZoneYNegValue, dState.LY, maxZoneYPosValue);
tempOutputX = (currentX - 127.5f) / (double)(maxZoneX); tempOutputX = (currentX - 127.5f) / (double)(maxZoneX);
tempOutputY = (currentY - 127.5f) / (double)(maxZoneY); tempOutputY = (currentY - 127.5f) / (double)(maxZoneY);
} }
@ -592,8 +610,8 @@ namespace DS4Windows
if (rsSquared > rsDeadzoneSquared) if (rsSquared > rsDeadzoneSquared)
{ {
double currentX = Clamp(maxZoneXNegValue, dState.RX, maxZoneXPosValue); double currentX = Global.Clamp(maxZoneXNegValue, dState.RX, maxZoneXPosValue);
double currentY = Clamp(maxZoneYNegValue, dState.RY, maxZoneYPosValue); double currentY = Global.Clamp(maxZoneYNegValue, dState.RY, maxZoneYPosValue);
tempOutputX = ((currentX - 127.5f - tempRsXDead) / (double)(maxZoneX - tempRsXDead)); tempOutputX = ((currentX - 127.5f - tempRsXDead) / (double)(maxZoneX - tempRsXDead));
tempOutputY = ((currentY - 127.5f - tempRsYDead) / (double)(maxZoneY - tempRsYDead)); tempOutputY = ((currentY - 127.5f - tempRsYDead) / (double)(maxZoneY - tempRsYDead));
@ -603,8 +621,8 @@ namespace DS4Windows
} }
else else
{ {
double currentX = Clamp(maxZoneXNegValue, dState.RX, maxZoneXPosValue); double currentX = Global.Clamp(maxZoneXNegValue, dState.RX, maxZoneXPosValue);
double currentY = Clamp(maxZoneYNegValue, dState.RY, maxZoneYPosValue); double currentY = Global.Clamp(maxZoneYNegValue, dState.RY, maxZoneYPosValue);
tempOutputX = (currentX - 127.5f) / (double)(maxZoneX); tempOutputX = (currentX - 127.5f) / (double)(maxZoneX);
tempOutputY = (currentY - 127.5f) / (double)(maxZoneY); tempOutputY = (currentY - 127.5f) / (double)(maxZoneY);
@ -653,7 +671,7 @@ namespace DS4Windows
{ {
if (cState.L2 > l2Deadzone) if (cState.L2 > l2Deadzone)
{ {
double current = Clamp(0, dState.L2, maxValue); double current = Global.Clamp(0, dState.L2, maxValue);
tempL2Output = ((current - l2Deadzone) / (double)(maxValue - l2Deadzone)); tempL2Output = ((current - l2Deadzone) / (double)(maxValue - l2Deadzone));
} }
else else
@ -691,7 +709,7 @@ namespace DS4Windows
{ {
if (cState.R2 > r2Deadzone) if (cState.R2 > r2Deadzone)
{ {
double current = Clamp(0, dState.R2, maxValue); double current = Global.Clamp(0, dState.R2, maxValue);
tempR2Output = ((current - r2Deadzone) / (double)(maxValue - r2Deadzone)); tempR2Output = ((current - r2Deadzone) / (double)(maxValue - r2Deadzone));
} }
else else
@ -718,24 +736,144 @@ namespace DS4Windows
double lsSens = getLSSens(device); double lsSens = getLSSens(device);
if (lsSens != 1.0) if (lsSens != 1.0)
{ {
dState.LX = (byte)Clamp(0, lsSens * (dState.LX - 127.5f) + 127.5f, 255); dState.LX = (byte)Global.Clamp(0, lsSens * (dState.LX - 127.5f) + 127.5f, 255);
dState.LY = (byte)Clamp(0, lsSens * (dState.LY - 127.5f) + 127.5f, 255); dState.LY = (byte)Global.Clamp(0, lsSens * (dState.LY - 127.5f) + 127.5f, 255);
} }
double rsSens = getRSSens(device); double rsSens = getRSSens(device);
if (rsSens != 1.0) if (rsSens != 1.0)
{ {
dState.RX = (byte)Clamp(0, rsSens * (dState.RX - 127.5f) + 127.5f, 255); dState.RX = (byte)Global.Clamp(0, rsSens * (dState.RX - 127.5f) + 127.5f, 255);
dState.RY = (byte)Clamp(0, rsSens * (dState.RY - 127.5f) + 127.5f, 255); dState.RY = (byte)Global.Clamp(0, rsSens * (dState.RY - 127.5f) + 127.5f, 255);
} }
double l2Sens = getL2Sens(device); double l2Sens = getL2Sens(device);
if (l2Sens != 1.0) if (l2Sens != 1.0)
dState.L2 = (byte)Clamp(0, l2Sens * dState.L2, 255); dState.L2 = (byte)Global.Clamp(0, l2Sens * dState.L2, 255);
double r2Sens = getR2Sens(device); double r2Sens = getR2Sens(device);
if (r2Sens != 1.0) if (r2Sens != 1.0)
dState.R2 = (byte)Clamp(0, r2Sens * dState.R2, 255); dState.R2 = (byte)Global.Clamp(0, r2Sens * dState.R2, 255);
int lsOutCurveMode = lsOutCurveModeArray[device] = getLsOutCurveMode(device);
if (lsOutCurveMode != 0)
{
double tempX = (dState.LX - 127.5f) / 127.5;
double tempY = (dState.LY - 127.5f) / 127.5;
double signX = tempX >= 0.0 ? 1.0 : -1.0;
double signY = tempY >= 0.0 ? 1.0 : -1.0;
if (lsOutCurveMode == 1)
{
double absX = Math.Abs(tempX);
double absY = Math.Abs(tempY);
double outputX = 0.0;
double outputY = 0.0;
if (absX <= 0.4)
{
outputX = 0.38 * absX;
}
else if (absX <= 0.75)
{
outputX = absX - 0.248;
}
else if (absX > 0.75)
{
outputX = (absX * 1.992) - 0.992;
}
if (absY <= 0.4)
{
outputY = 0.38 * absY;
}
else if (absY <= 0.75)
{
outputY = absY - 0.248;
}
else if (absY > 0.75)
{
outputY = (absY * 1.992) - 0.992;
}
dState.LX = (byte)(outputX * signX * 127.5f + 127.5f);
dState.LY = (byte)(outputY * signY * 127.5f + 127.5f);
}
else if (lsOutCurveMode == 2)
{
double outputX = tempX * tempX;
double outputY = tempY * tempY;
dState.LX = (byte)(outputX * signX * 127.5f + 127.5f);
dState.LY = (byte)(outputY * signY * 127.5f + 127.5f);
}
else if (lsOutCurveMode == 3)
{
double outputX = tempX * tempX * tempX;
double outputY = tempY * tempY * tempY;
dState.LX = (byte)(outputX * 127.5f + 127.5f);
dState.LY = (byte)(outputY * 127.5f + 127.5f);
}
}
int rsOutCurveMode = rsOutCurveModeArray[device] = getRsOutCurveMode(device);
if (rsOutCurveMode != 0)
{
double tempX = (dState.RX - 127.5f) / 127.5;
double tempY = (dState.RY - 127.5f) / 127.5;
double signX = tempX >= 0.0 ? 1.0 : -1.0;
double signY = tempY >= 0.0 ? 1.0 : -1.0;
if (rsOutCurveMode == 1)
{
double absX = Math.Abs(tempX);
double absY = Math.Abs(tempY);
double outputX = 0.0;
double outputY = 0.0;
if (absX <= 0.4)
{
outputX = 0.38 * absX;
}
else if (absX <= 0.75)
{
outputX = absX - 0.248;
}
else if (absX > 0.75)
{
outputX = (absX * 1.992) - 0.992;
}
if (absY <= 0.4)
{
outputY = 0.38 * absY;
}
else if (absY <= 0.75)
{
outputY = absY - 0.248;
}
else if (absY > 0.75)
{
outputY = (absY * 1.992) - 0.992;
}
dState.RX = (byte)(outputX * signX * 127.5f + 127.5f);
dState.RY = (byte)(outputY * signY * 127.5f + 127.5f);
}
else if (rsOutCurveMode == 2)
{
double outputX = tempX * tempX;
double outputY = tempY * tempY;
dState.RX = (byte)(outputX * signX * 127.5f + 127.5f);
dState.RY = (byte)(outputY * signY * 127.5f + 127.5f);
}
else if (rsOutCurveMode == 3)
{
double outputX = tempX * tempX * tempX;
double outputY = tempY * tempY * tempY;
dState.RX = (byte)(outputX * 127.5f + 127.5f);
dState.RY = (byte)(outputY * 127.5f + 127.5f);
}
}
return dState; return dState;
} }
@ -1041,7 +1179,7 @@ namespace DS4Windows
{ {
if (tempMouseDeltaY == 0) if (tempMouseDeltaY == 0)
{ {
tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 0); tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 0, ctrl);
tempMouseDeltaY = -Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY)); tempMouseDeltaY = -Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY));
} }
@ -1051,7 +1189,7 @@ namespace DS4Windows
{ {
if (tempMouseDeltaY == 0) if (tempMouseDeltaY == 0)
{ {
tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 1); tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 1, ctrl);
tempMouseDeltaY = Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY)); tempMouseDeltaY = Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY));
} }
@ -1061,7 +1199,7 @@ namespace DS4Windows
{ {
if (tempMouseDeltaX == 0) if (tempMouseDeltaX == 0)
{ {
tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 2); tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 2, ctrl);
tempMouseDeltaX = -Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX)); tempMouseDeltaX = -Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX));
} }
@ -1071,7 +1209,7 @@ namespace DS4Windows
{ {
if (tempMouseDeltaX == 0) if (tempMouseDeltaX == 0)
{ {
tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 3); tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 3, ctrl);
tempMouseDeltaX = Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX)); tempMouseDeltaX = Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX));
} }
@ -1609,13 +1747,19 @@ namespace DS4Windows
actionFound = true; actionFound = true;
DS4Device d = ctrl.DS4Controllers[device]; DS4Device d = ctrl.DS4Controllers[device];
if (!d.isCharging()) bool synced = tempBool = d.isSynced();
if (synced && !d.isCharging())
{ {
ConnectionType deviceConn = d.getConnectionType(); ConnectionType deviceConn = d.getConnectionType();
bool exclusive = tempBool = d.isExclusive();
if (deviceConn == ConnectionType.BT) if (deviceConn == ConnectionType.BT)
{ {
d.DisconnectBT(); d.DisconnectBT();
} }
else if (deviceConn == ConnectionType.SONYWA && exclusive)
{
d.DisconnectDongle();
}
//foreach (DS4Controls dc in action.trigger) //foreach (DS4Controls dc in action.trigger)
for (int i = 0, arlen = action.trigger.Count; i < arlen; i++) for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
@ -1717,6 +1861,11 @@ namespace DS4Windows
{ {
actionFound = true; actionFound = true;
bool tappedOnce = action.tappedOnce, firstTouch = action.firstTouch,
secondtouchbegin = action.secondtouchbegin;
//DateTime pastTime = action.pastTime, firstTap = action.firstTap,
// TimeofEnd = action.TimeofEnd;
/*if (getCustomButton(device, action.trigger[0]) != X360Controls.Unbound) /*if (getCustomButton(device, action.trigger[0]) != X360Controls.Unbound)
getCustomButtons(device)[action.trigger[0]] = X360Controls.Unbound; getCustomButtons(device)[action.trigger[0]] = X360Controls.Unbound;
if (getCustomMacro(device, action.trigger[0]) != "0") if (getCustomMacro(device, action.trigger[0]) != "0")
@ -1732,7 +1881,7 @@ namespace DS4Windows
// button is assigned // button is assigned
if (previousFieldMapping == null) 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); bool activeCur = getBoolMapping2(device, action.trigger[0], cState, eState, tp, fieldMapping);
@ -1740,31 +1889,38 @@ namespace DS4Windows
if (activeCur && !activePrev) if (activeCur && !activePrev)
{ {
// pressed down // pressed down
pastTime = DateTime.UtcNow; action.pastTime = DateTime.UtcNow;
if (pastTime <= (firstTap + TimeSpan.FromMilliseconds(150))) if (action.pastTime <= (action.firstTap + TimeSpan.FromMilliseconds(150)))
{ {
tappedOnce = false; action.tappedOnce = tappedOnce = false;
secondtouchbegin = true; action.secondtouchbegin = secondtouchbegin = true;
//tappedOnce = false;
//secondtouchbegin = true;
} }
else else
firstTouch = true; action.firstTouch = firstTouch = true;
//firstTouch = true;
} }
else if (!activeCur && activePrev) else if (!activeCur && activePrev)
{ {
// released // released
if (secondtouchbegin) if (secondtouchbegin)
{ {
firstTouch = false; action.firstTouch = firstTouch = false;
secondtouchbegin = false; action.secondtouchbegin = secondtouchbegin = false;
//firstTouch = false;
//secondtouchbegin = false;
} }
else if (firstTouch) else if (firstTouch)
{ {
firstTouch = false; action.firstTouch = firstTouch = false;
if (DateTime.UtcNow <= (pastTime + TimeSpan.FromMilliseconds(200)) && !tappedOnce) //firstTouch = false;
if (DateTime.UtcNow <= (action.pastTime + TimeSpan.FromMilliseconds(200)) && !tappedOnce)
{ {
tappedOnce = true; action.tappedOnce = tappedOnce = true;
firstTap = DateTime.UtcNow; //tappedOnce = true;
TimeofEnd = DateTime.UtcNow; action.firstTap = DateTime.UtcNow;
action.TimeofEnd = DateTime.UtcNow;
} }
} }
} }
@ -1788,15 +1944,18 @@ namespace DS4Windows
case 4: macro = "91/164/71/71/164/91"; break; case 4: macro = "91/164/71/71/164/91"; break;
} }
} }
if ((DateTime.UtcNow - TimeofEnd) > TimeSpan.FromMilliseconds(150))
if ((DateTime.UtcNow - action.TimeofEnd) > TimeSpan.FromMilliseconds(150))
{ {
if (macro != "") if (macro != "")
PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None); PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
tappedOnce = false; tappedOnce = false;
action.tappedOnce = false;
} }
//if it fails the method resets, and tries again with a new tester value (gives tap a delay so tap and hold can work) //if it fails the method resets, and tries again with a new tester value (gives tap a delay so tap and hold can work)
} }
else if (firstTouch && (DateTime.UtcNow - pastTime) > TimeSpan.FromMilliseconds(1000)) //helddown else if (firstTouch && (DateTime.UtcNow - action.pastTime) > TimeSpan.FromMilliseconds(1000)) //helddown
{ {
if (action.typeID == SpecialAction.ActionTypeId.MultiAction) if (action.typeID == SpecialAction.ActionTypeId.MultiAction)
{ {
@ -1813,9 +1972,12 @@ namespace DS4Windows
case 4: macro = "91/164/71/71/164/91"; break; case 4: macro = "91/164/71/71/164/91"; break;
} }
} }
if (macro != "") if (macro != "")
PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None); PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
firstTouch = false; firstTouch = false;
action.firstTouch = false;
} }
else if (secondtouchbegin) //if double tap else if (secondtouchbegin) //if double tap
{ {
@ -1834,9 +1996,12 @@ namespace DS4Windows
case 4: macro = "91/164/71/71/164/91"; break; case 4: macro = "91/164/71/71/164/91"; break;
} }
} }
if (macro != "") if (macro != "")
PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None); PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
secondtouchbegin = false; secondtouchbegin = false;
action.secondtouchbegin = false;
} }
} }
else else
@ -1890,6 +2055,7 @@ namespace DS4Windows
} }
} }
} }
untriggeraction[device] = null; untriggeraction[device] = null;
LoadProfile(device, false, ctrl); LoadProfile(device, false, ctrl);
} }
@ -2153,7 +2319,7 @@ namespace DS4Windows
} }
private static double getMouseMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, private static double getMouseMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState,
DS4StateFieldMapping fieldMapping, int mnum) DS4StateFieldMapping fieldMapping, int mnum, ControlService ctrl)
{ {
int controlnum = DS4ControltoInt(control); int controlnum = DS4ControltoInt(control);
@ -2172,6 +2338,10 @@ namespace DS4Windows
int controlNum = (int)control; int controlNum = (int)control;
DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum]; DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum];
//long timeElapsed = ctrl.DS4Controllers[device].getLastTimeElapsed();
double timeElapsed = ctrl.DS4Controllers[device].lastTimeElapsedDouble;
//double mouseOffset = 0.025;
double tempMouseOffsetX = 0.0, tempMouseOffsetY = 0.0;
if (controlType == DS4StateFieldMapping.ControlType.Button) if (controlType == DS4StateFieldMapping.ControlType.Button)
{ {
@ -2183,37 +2353,126 @@ namespace DS4Windows
switch (control) switch (control)
{ {
case DS4Controls.LXNeg: case DS4Controls.LXNeg:
{
if (cState.LX < 127 - deadzoneL) if (cState.LX < 127 - deadzoneL)
value = -(cState.LX - 127 - deadzoneL) / 2550d * speed; {
double diff = -(cState.LX - 127 - deadzoneL) / (double)(0 - 127 - deadzoneL);
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.LSAngleRad)) * MOUSESTICKOFFSET;
//tempMouseOffsetX = MOUSESTICKOFFSET;
tempMouseOffsetX = cState.LXUnit * MOUSESTICKOFFSET;
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + (tempMouseOffsetX * -1.0);
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
//value = -(cState.LX - 127 - deadzoneL) / 2550d * speed;
}
break; break;
}
case DS4Controls.LXPos: case DS4Controls.LXPos:
{
if (cState.LX > 127 + deadzoneL) if (cState.LX > 127 + deadzoneL)
value = (cState.LX - 127 + deadzoneL) / 2550d * speed; {
double diff = (cState.LX - 127 + deadzoneL) / (double)(255 - 127 + deadzoneL);
tempMouseOffsetX = cState.LXUnit * MOUSESTICKOFFSET;
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.LSAngleRad)) * MOUSESTICKOFFSET;
//tempMouseOffsetX = MOUSESTICKOFFSET;
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + tempMouseOffsetX;
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
//value = (cState.LX - 127 + deadzoneL) / 2550d * speed;
}
break; break;
}
case DS4Controls.RXNeg: case DS4Controls.RXNeg:
{
if (cState.RX < 127 - deadzoneR) if (cState.RX < 127 - deadzoneR)
value = -(cState.RX - 127 - deadzoneR) / 2550d * speed; {
double diff = -(cState.RX - 127 - deadzoneR) / (double)(0 - 127 - deadzoneR);
tempMouseOffsetX = cState.RXUnit * MOUSESTICKOFFSET;
//tempMouseOffsetX = MOUSESTICKOFFSET;
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.RSAngleRad)) * MOUSESTICKOFFSET;
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + (tempMouseOffsetX * -1.0);
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
//value = -(cState.RX - 127 - deadzoneR) / 2550d * speed;
}
break; break;
}
case DS4Controls.RXPos: case DS4Controls.RXPos:
{
if (cState.RX > 127 + deadzoneR) if (cState.RX > 127 + deadzoneR)
value = (cState.RX - 127 + deadzoneR) / 2550d * speed; {
double diff = (cState.RX - 127 + deadzoneR) / (double)(255 - 127 + deadzoneR);
tempMouseOffsetX = cState.RXUnit * MOUSESTICKOFFSET;
//tempMouseOffsetX = MOUSESTICKOFFSET;
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.RSAngleRad)) * MOUSESTICKOFFSET;
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + tempMouseOffsetX;
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
//value = (cState.RX - 127 + deadzoneR) / 2550d * speed;
}
break; break;
}
case DS4Controls.LYNeg: case DS4Controls.LYNeg:
{
if (cState.LY < 127 - deadzoneL) if (cState.LY < 127 - deadzoneL)
value = -(cState.LY - 127 - deadzoneL) / 2550d * speed; {
double diff = -(cState.LY - 127 - deadzoneL) / (double)(0 - 127 - deadzoneL);
tempMouseOffsetY = cState.LYUnit * MOUSESTICKOFFSET;
//tempMouseOffsetY = MOUSESTICKOFFSET;
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.LSAngleRad)) * MOUSESTICKOFFSET;
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + (tempMouseOffsetY * -1.0);
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
//value = -(cState.LY - 127 - deadzoneL) / 2550d * speed;
}
break; break;
}
case DS4Controls.LYPos: case DS4Controls.LYPos:
{
if (cState.LY > 127 + deadzoneL) if (cState.LY > 127 + deadzoneL)
value = (cState.LY - 127 + deadzoneL) / 2550d * speed; {
double diff = (cState.LY - 127 + deadzoneL) / (double)(255 - 127 + deadzoneL);
tempMouseOffsetY = cState.LYUnit * MOUSESTICKOFFSET;
//tempMouseOffsetY = MOUSESTICKOFFSET;
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.LSAngleRad)) * MOUSESTICKOFFSET;
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + tempMouseOffsetY;
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
//value = (cState.LY - 127 + deadzoneL) / 2550d * speed;
}
break; break;
}
case DS4Controls.RYNeg: case DS4Controls.RYNeg:
{
if (cState.RY < 127 - deadzoneR) if (cState.RY < 127 - deadzoneR)
value = -(cState.RY - 127 - deadzoneR) / 2550d * speed; {
double diff = -(cState.RY - 127 - deadzoneR) / (double)(0 - 127 - deadzoneR);
tempMouseOffsetY = cState.RYUnit * MOUSESTICKOFFSET;
//tempMouseOffsetY = MOUSESTICKOFFSET;
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.RSAngleRad)) * MOUSESTICKOFFSET;
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + (tempMouseOffsetY * -1.0);
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
//value = -(cState.RY - 127 - deadzoneR) / 2550d * speed;
}
break; break;
}
case DS4Controls.RYPos: case DS4Controls.RYPos:
{
if (cState.RY > 127 + deadzoneR) if (cState.RY > 127 + deadzoneR)
value = (cState.RY - 127 + deadzoneR) / 2550d * speed; {
double diff = (cState.RY - 127 + deadzoneR) / (double)(255 - 127 + deadzoneR);
tempMouseOffsetY = cState.RYUnit * MOUSESTICKOFFSET;
//tempMouseOffsetY = MOUSESTICKOFFSET;
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.RSAngleRad)) * MOUSESTICKOFFSET;
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + tempMouseOffsetY;
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
//value = (cState.RY - 127 + deadzoneR) / 2550d * speed;
}
break; break;
}
default: break; default: break;
} }
} }
@ -2295,8 +2554,13 @@ namespace DS4Windows
horizontalRemainder = 0.0; horizontalRemainder = 0.0;
} }
mouseX = (int)rawMouseX; //double mouseXTemp = rawMouseX - (Math.IEEERemainder(rawMouseX * 1000.0, 1.0) / 1000.0);
horizontalRemainder = rawMouseX - mouseX; double mouseXTemp = rawMouseX - (remainderCutoff(rawMouseX * 1000.0, 1.0) / 1000.0);
//double mouseXTemp = rawMouseX - (rawMouseX * 1000.0 - (1.0 * (int)(rawMouseX * 1000.0 / 1.0)));
mouseX = (int)mouseXTemp;
horizontalRemainder = mouseXTemp - mouseX;
//mouseX = (int)rawMouseX;
//horizontalRemainder = rawMouseX - mouseX;
if ((rawMouseY > 0.0 && verticalRemainder > 0.0) || (rawMouseY < 0.0 && verticalRemainder < 0.0)) if ((rawMouseY > 0.0 && verticalRemainder > 0.0) || (rawMouseY < 0.0 && verticalRemainder < 0.0))
{ {
@ -2307,8 +2571,17 @@ namespace DS4Windows
verticalRemainder = 0.0; verticalRemainder = 0.0;
} }
mouseY = (int)rawMouseY; //double mouseYTemp = rawMouseY - (Math.IEEERemainder(rawMouseY * 1000.0, 1.0) / 1000.0);
verticalRemainder = rawMouseY - mouseY; double mouseYTemp = rawMouseY - (remainderCutoff(rawMouseY * 1000.0, 1.0) / 1000.0);
mouseY = (int)mouseYTemp;
verticalRemainder = mouseYTemp - mouseY;
//mouseY = (int)rawMouseY;
//verticalRemainder = rawMouseY - mouseY;
}
private static double remainderCutoff(double dividend, double divisor)
{
return dividend - (divisor * (int)(dividend / divisor));
} }
public static bool compare(byte b1, byte b2) public static bool compare(byte b1, byte b2)

View File

@ -13,10 +13,14 @@ namespace DS4Windows
private readonly MouseWheel wheel; private readonly MouseWheel wheel;
private bool tappedOnce = false, secondtouchbegin = false; private bool tappedOnce = false, secondtouchbegin = false;
public bool swipeLeft, swipeRight, swipeUp, swipeDown; public bool swipeLeft, swipeRight, swipeUp, swipeDown;
public bool priorSwipeLeft, priorSwipeRight, priorSwipeUp, priorSwipeDown;
public byte swipeLeftB, swipeRightB, swipeUpB, swipeDownB, swipedB; public byte swipeLeftB, swipeRightB, swipeUpB, swipeDownB, swipedB;
public byte priorSwipeLeftB, priorSwipeRightB, priorSwipeUpB, priorSwipeDownB, priorSwipedB;
public bool slideleft, slideright; public bool slideleft, slideright;
public bool priorSlideLeft, priorSlideright;
// touch area stuff // touch area stuff
public bool leftDown, rightDown, upperDown, multiDown; public bool leftDown, rightDown, upperDown, multiDown;
public bool priorLeftDown, priorRightDown, priorUpperDown, priorMultiDown;
protected DS4Controls pushed = DS4Controls.None; protected DS4Controls pushed = DS4Controls.None;
protected Mapping.Click clicked = Mapping.Click.None; protected Mapping.Click clicked = Mapping.Click.None;
@ -28,19 +32,38 @@ namespace DS4Windows
wheel = new MouseWheel(deviceNum); wheel = new MouseWheel(deviceNum);
} }
bool triggeractivated = false;
bool useReverseRatchet = false;
public virtual void sixaxisMoved(object sender, SixAxisEventArgs arg) public virtual void sixaxisMoved(object sender, SixAxisEventArgs arg)
{ {
if (Global.UseSAforMouse[deviceNum] && Global.GyroSensitivity[deviceNum] > 0) if (Global.isUsingSAforMouse(deviceNum) && Global.getGyroSensitivity(deviceNum) > 0)
{ {
bool triggeractivated = true; triggeractivated = true;
useReverseRatchet = Global.getGyroTriggerTurns(deviceNum);
int i = 0; int i = 0;
string[] ss = Global.SATriggers[deviceNum].Split(','); string[] ss = Global.getSATriggers(deviceNum).Split(',');
if (!string.IsNullOrEmpty(ss[0])) if (!string.IsNullOrEmpty(ss[0]))
foreach (string s in ss) {
string s = string.Empty;
for (int index = 0, arlen = ss.Length; triggeractivated && index < arlen; index++)
//foreach (string s in ss)
{
s = ss[index];
if (!(int.TryParse(s, out i) && getDS4ControlsByName(i))) if (!(int.TryParse(s, out i) && getDS4ControlsByName(i)))
{
triggeractivated = false; triggeractivated = false;
if (triggeractivated) }
}
}
if (useReverseRatchet && triggeractivated)
cursor.sixaxisMoved(arg); cursor.sixaxisMoved(arg);
else if (!useReverseRatchet && !triggeractivated)
cursor.sixaxisMoved(arg);
else
cursor.mouseRemainderReset();
dev.getCurrentState(s); dev.getCurrentState(s);
} }
} }
@ -64,8 +87,8 @@ namespace DS4Windows
case 11: return s.DpadRight; case 11: return s.DpadRight;
case 12: return s.L3; case 12: return s.L3;
case 13: return s.R3; case 13: return s.R3;
case 14: return s.Touch1; case 14: return s.Touch1Finger;
case 15: return s.Touch2; case 15: return s.Touch2Fingers;
case 16: return s.Options; case 16: return s.Options;
case 17: return s.Share; case 17: return s.Share;
case 18: return s.PS; case 18: return s.PS;
@ -91,6 +114,7 @@ namespace DS4Windows
if (arg.touches[0].hwY - firstTouch.hwY > 300) swipeDown = true; if (arg.touches[0].hwY - firstTouch.hwY > 300) swipeDown = true;
if (arg.touches[0].hwY - firstTouch.hwY < -300) swipeUp = 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)); 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)); 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)); swipeLeftB = (byte)Math.Min(255, Math.Max(0, firstTouch.hwX - arg.touches[0].hwX));
@ -98,14 +122,17 @@ namespace DS4Windows
} }
if (Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 50 && arg.touches.Length == 2) if (Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 50 && arg.touches.Length == 2)
{
if (arg.touches[0].hwX - firstTouch.hwX > 200 && !slideleft) if (arg.touches[0].hwX - firstTouch.hwX > 200 && !slideleft)
slideright = true; slideright = true;
else if (firstTouch.hwX - arg.touches[0].hwX > 200 && !slideright) else if (firstTouch.hwX - arg.touches[0].hwX > 200 && !slideright)
slideleft = true; slideleft = true;
}
dev.getCurrentState(s); dev.getCurrentState(s);
synthesizeMouseButtons(); synthesizeMouseButtons();
} }
public virtual void touchesBegan(object sender, TouchpadEventArgs arg) public virtual void touchesBegan(object sender, TouchpadEventArgs arg)
{ {
if (!Global.UseTPforControls[deviceNum]) if (!Global.UseTPforControls[deviceNum])
@ -127,6 +154,7 @@ namespace DS4Windows
dev.getCurrentState(s); dev.getCurrentState(s);
synthesizeMouseButtons(); synthesizeMouseButtons();
} }
public virtual void touchesEnded(object sender, TouchpadEventArgs arg) public virtual void touchesEnded(object sender, TouchpadEventArgs arg)
{ {
slideright = slideleft = false; slideright = slideleft = false;
@ -143,7 +171,9 @@ namespace DS4Windows
DateTime test = arg.timeStamp; DateTime test = arg.timeStamp;
if (test <= (pastTime + TimeSpan.FromMilliseconds((double)tapSensitivity * 2)) && !arg.touchButtonPressed && !tappedOnce) 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 (Math.Abs(firstTouch.hwX - arg.touches[0].hwX) < 10 && Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 10)
{
if (Global.DoubleTap[deviceNum]) if (Global.DoubleTap[deviceNum])
{ {
tappedOnce = true; tappedOnce = true;
@ -152,6 +182,8 @@ namespace DS4Windows
} }
else else
Mapping.MapClick(deviceNum, Mapping.Click.Left); //this way no delay if disabled Mapping.MapClick(deviceNum, Mapping.Click.Left); //this way no delay if disabled
}
}
} }
dev.getCurrentState(s); dev.getCurrentState(s);
@ -191,8 +223,10 @@ namespace DS4Windows
if (Global.GetDS4Action(deviceNum, DS4Controls.TouchUpper, false) == null && upperDown) if (Global.GetDS4Action(deviceNum, DS4Controls.TouchUpper, false) == null && upperDown)
Mapping.MapClick(deviceNum, Mapping.Click.Middle); Mapping.MapClick(deviceNum, Mapping.Click.Middle);
if (Global.GetDS4Action(deviceNum, DS4Controls.TouchRight, false) == null && rightDown) if (Global.GetDS4Action(deviceNum, DS4Controls.TouchRight, false) == null && rightDown)
Mapping.MapClick(deviceNum, Mapping.Click.Left); Mapping.MapClick(deviceNum, Mapping.Click.Left);
if (Global.GetDS4Action(deviceNum, DS4Controls.TouchMulti, false) == null && multiDown) if (Global.GetDS4Action(deviceNum, DS4Controls.TouchMulti, false) == null && multiDown)
Mapping.MapClick(deviceNum, Mapping.Click.Right); Mapping.MapClick(deviceNum, Mapping.Click.Right);
@ -254,6 +288,19 @@ namespace DS4Windows
synthesizeMouseButtons(); 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() public DS4State getDS4State()
{ {
return s; return s;

View File

@ -18,27 +18,157 @@ namespace DS4Windows
private Direction horizontalDirection = Direction.Neutral, verticalDirection = Direction.Neutral; private Direction horizontalDirection = Direction.Neutral, verticalDirection = Direction.Neutral;
private Direction hDirection = Direction.Neutral, vDirection = Direction.Neutral; private Direction hDirection = Direction.Neutral, vDirection = Direction.Neutral;
private double GYRO_MOUSE_COEFFICIENT = 0.0095;
private int GYRO_MOUSE_DEADZONE = 12;
private double GYRO_MOUSE_OFFSET = 0.1463;
private double GYRO_SMOOTH_MOUSE_OFFSET = 0.14698;
private const int SMOOTH_BUFFER_LEN = 3;
private double[] xSmoothBuffer = new double[SMOOTH_BUFFER_LEN];
private double[] ySmoothBuffer = new double[SMOOTH_BUFFER_LEN];
private int smoothBufferTail = 0;
double coefficient = 0.0;
double verticalScale = 0.0;
bool gyroSmooth = false;
//double gyroSmoothWeight = 0.0;
public virtual void sixaxisMoved(SixAxisEventArgs arg) public virtual void sixaxisMoved(SixAxisEventArgs arg)
{ {
int deltaX = 0, deltaY = 0; int deltaX = 0, deltaY = 0;
deltaX = -arg.sixAxis.accelX; deltaX = -arg.sixAxis.gyroXFull;
deltaY = -arg.sixAxis.accelY; deltaY = -arg.sixAxis.gyroYFull;
//Console.WriteLine(arg.sixAxis.deltaX); //Console.WriteLine(arg.sixAxis.deltaX);
double coefficient = Global.GyroSensitivity[deviceNumber] / 100f; gyroSmooth = Global.getGyroSmoothing(deviceNumber);
//Collect rounding errors instead of losing motion. double gyroSmoothWeight = 0.0;
double xMotion = coefficient * deltaX;
xMotion += hRemainder;
int xAction = (int)xMotion;
hRemainder += xMotion - xAction;
hRemainder -= (int)hRemainder;
double yMotion = coefficient * deltaY;
yMotion += vRemainder;
int yAction = (int)yMotion;
vRemainder += yMotion - yAction;
vRemainder -= (int)vRemainder;
int gyroInvert = Global.GyroInvert[deviceNumber]; coefficient = (Global.getGyroSensitivity(deviceNumber) * 0.01) * GYRO_MOUSE_COEFFICIENT;
double offset = GYRO_MOUSE_OFFSET;
if (gyroSmooth)
{
gyroSmoothWeight = Global.getGyroSmoothingWeight(deviceNumber);
if (gyroSmoothWeight > 0.0)
{
offset = GYRO_SMOOTH_MOUSE_OFFSET;
}
}
double tempAngle = System.Math.Atan2(-deltaY, deltaX);
double normX = System.Math.Abs(System.Math.Cos(tempAngle));
double normY = System.Math.Abs(System.Math.Sin(tempAngle));
int signX = System.Math.Sign(deltaX);
int signY = System.Math.Sign(deltaY);
if ((hRemainder > 0) != (deltaX > 0))
{
hRemainder = 0.0;
}
if ((vRemainder > 0) != (deltaY > 0))
{
vRemainder = 0.0;
}
int deadzone = GYRO_MOUSE_DEADZONE;
//int deadzone = 0;
int deadzoneX = (int)System.Math.Abs(normX * deadzone);
int deadzoneY = (int)System.Math.Abs(normY * deadzone);
if (System.Math.Abs(deltaX) > deadzoneX)
{
deltaX -= signX * deadzoneX;
}
else
{
deltaX = 0;
}
if (System.Math.Abs(deltaY) > deadzoneY)
{
deltaY -= signY * deadzoneY;
}
else
{
deltaY = 0;
}
double xMotion = deltaX != 0 ? coefficient * deltaX + (normX * (offset * signX)) : 0;
int xAction = 0;
if (xMotion != 0.0)
{
xMotion += hRemainder;
//xAction = (int)xMotion;
//hRemainder = xMotion - xAction;
}
else
{
//hRemainder = 0.0;
}
//hRemainder -= (int)hRemainder;
verticalScale = Global.getGyroSensVerticalScale(deviceNumber) * 0.01;
double yMotion = deltaY != 0 ? (coefficient * verticalScale) * deltaY + (normY * (offset * signY)) : 0;
int yAction = 0;
if (yMotion != 0.0)
{
yMotion += vRemainder;
//yAction = (int)yMotion;
//vRemainder = yMotion - yAction;
}
else
{
//vRemainder = 0.0;
}
if (gyroSmooth)
{
int iIndex = smoothBufferTail % SMOOTH_BUFFER_LEN;
xSmoothBuffer[iIndex] = xMotion;
ySmoothBuffer[iIndex] = yMotion;
smoothBufferTail = iIndex + 1;
double currentWeight = 1.0;
double finalWeight = 0.0;
double x_out = 0.0, y_out = 0.0;
for (int i = 0; i < SMOOTH_BUFFER_LEN; i++)
{
int idx = System.Math.Abs(smoothBufferTail - i - 1) % SMOOTH_BUFFER_LEN;
x_out += xSmoothBuffer[idx] * currentWeight;
y_out += ySmoothBuffer[idx] * currentWeight;
finalWeight += currentWeight;
currentWeight *= gyroSmoothWeight;
}
x_out /= finalWeight;
xMotion = x_out;
y_out /= finalWeight;
yMotion = y_out;
}
if (xMotion != 0.0)
{
xAction = (int)xMotion;
hRemainder = xMotion - xAction;
}
else
{
hRemainder = 0.0;
}
if (yMotion != 0.0)
{
yAction = (int)yMotion;
vRemainder = yMotion - yAction;
}
else
{
vRemainder = 0.0;
}
//vRemainder -= (int)vRemainder;
int gyroInvert = Global.getGyroInvert(deviceNumber);
if (gyroInvert == 2 || gyroInvert == 3) if (gyroInvert == 2 || gyroInvert == 3)
xAction *= -1; xAction *= -1;
@ -52,6 +182,15 @@ namespace DS4Windows
vDirection = yMotion > 0.0 ? Direction.Positive : yMotion < 0.0 ? Direction.Negative : Direction.Neutral; vDirection = yMotion > 0.0 ? Direction.Positive : yMotion < 0.0 ? Direction.Negative : Direction.Neutral;
} }
public void mouseRemainderReset()
{
hRemainder = vRemainder = 0.0;
int iIndex = smoothBufferTail % SMOOTH_BUFFER_LEN;
xSmoothBuffer[iIndex] = 0.0;
ySmoothBuffer[iIndex] = 0.0;
smoothBufferTail = iIndex + 1;
}
public void touchesBegan(TouchpadEventArgs arg) public void touchesBegan(TouchpadEventArgs arg)
{ {
if (arg.touches.Length == 1) if (arg.touches.Length == 1)

File diff suppressed because it is too large Load Diff

View File

@ -160,7 +160,7 @@ namespace DS4Windows
if (Byte.TryParse(WindowsEnumerator.WindowText(EditWindows[3].hWnd), out red)) if (Byte.TryParse(WindowsEnumerator.WindowText(EditWindows[3].hWnd), out red))
if (Byte.TryParse(WindowsEnumerator.WindowText(EditWindows[4].hWnd), out green)) if (Byte.TryParse(WindowsEnumerator.WindowText(EditWindows[4].hWnd), out green))
if (Byte.TryParse(WindowsEnumerator.WindowText(EditWindows[5].hWnd), out blue)) if (Byte.TryParse(WindowsEnumerator.WindowText(EditWindows[5].hWnd), out blue))
OnUpdateColor(Color.FromArgb(red, green, blue), EventArgs.Empty); OnUpdateColor?.Invoke(Color.FromArgb(red, green, blue), EventArgs.Empty);
} }
} }
// Always call the base class hook procedure. // Always call the base class hook procedure.

View File

@ -33,7 +33,6 @@
this.lvDebug = new System.Windows.Forms.ListView(); this.lvDebug = new System.Windows.Forms.ListView();
this.chTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chData = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chData = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.tmrUpdate = new System.Windows.Forms.Timer(this.components);
this.pnlButton = new System.Windows.Forms.Panel(); this.pnlButton = new System.Windows.Forms.Panel();
this.llbHelp = new System.Windows.Forms.LinkLabel(); this.llbHelp = new System.Windows.Forms.LinkLabel();
this.lbTest = new System.Windows.Forms.Label(); this.lbTest = new System.Windows.Forms.Label();
@ -207,11 +206,6 @@
// //
resources.ApplyResources(this.chData, "chData"); resources.ApplyResources(this.chData, "chData");
// //
// tmrUpdate
//
this.tmrUpdate.Interval = 1;
this.tmrUpdate.Tick += new System.EventHandler(this.ControllerStatusChange);
//
// pnlButton // pnlButton
// //
this.pnlButton.BackColor = System.Drawing.SystemColors.Control; this.pnlButton.BackColor = System.Drawing.SystemColors.Control;
@ -442,7 +436,7 @@
// //
resources.ApplyResources(this.bnEditC3, "bnEditC3"); resources.ApplyResources(this.bnEditC3, "bnEditC3");
this.bnEditC3.Name = "bnEditC3"; this.bnEditC3.Name = "bnEditC3";
this.bnEditC3.Tag = "2"; this.bnEditC3.Tag = "";
this.bnEditC3.UseVisualStyleBackColor = true; this.bnEditC3.UseVisualStyleBackColor = true;
this.bnEditC3.Click += new System.EventHandler(this.editButtons_Click); this.bnEditC3.Click += new System.EventHandler(this.editButtons_Click);
// //
@ -450,7 +444,7 @@
// //
resources.ApplyResources(this.bnEditC4, "bnEditC4"); resources.ApplyResources(this.bnEditC4, "bnEditC4");
this.bnEditC4.Name = "bnEditC4"; this.bnEditC4.Name = "bnEditC4";
this.bnEditC4.Tag = "3"; this.bnEditC4.Tag = "";
this.bnEditC4.UseVisualStyleBackColor = true; this.bnEditC4.UseVisualStyleBackColor = true;
this.bnEditC4.Click += new System.EventHandler(this.editButtons_Click); this.bnEditC4.Click += new System.EventHandler(this.editButtons_Click);
// //
@ -483,7 +477,7 @@
// //
resources.ApplyResources(this.bnEditC2, "bnEditC2"); resources.ApplyResources(this.bnEditC2, "bnEditC2");
this.bnEditC2.Name = "bnEditC2"; this.bnEditC2.Name = "bnEditC2";
this.bnEditC2.Tag = "1"; this.bnEditC2.Tag = "";
this.bnEditC2.UseVisualStyleBackColor = true; this.bnEditC2.UseVisualStyleBackColor = true;
this.bnEditC2.Click += new System.EventHandler(this.editButtons_Click); this.bnEditC2.Click += new System.EventHandler(this.editButtons_Click);
// //
@ -509,7 +503,7 @@
// //
resources.ApplyResources(this.bnEditC1, "bnEditC1"); resources.ApplyResources(this.bnEditC1, "bnEditC1");
this.bnEditC1.Name = "bnEditC1"; this.bnEditC1.Name = "bnEditC1";
this.bnEditC1.Tag = "0"; this.bnEditC1.Tag = "";
this.bnEditC1.UseVisualStyleBackColor = true; this.bnEditC1.UseVisualStyleBackColor = true;
this.bnEditC1.Click += new System.EventHandler(this.editButtons_Click); this.bnEditC1.Click += new System.EventHandler(this.editButtons_Click);
// //
@ -823,8 +817,8 @@
// //
// tSBImportProfile // tSBImportProfile
// //
resources.ApplyResources(this.tSBImportProfile, "tSBImportProfile");
this.tSBImportProfile.Image = global::DS4Windows.Properties.Resources.import; this.tSBImportProfile.Image = global::DS4Windows.Properties.Resources.import;
resources.ApplyResources(this.tSBImportProfile, "tSBImportProfile");
this.tSBImportProfile.Name = "tSBImportProfile"; this.tSBImportProfile.Name = "tSBImportProfile";
this.tSBImportProfile.Click += new System.EventHandler(this.tSBImportProfile_Click); this.tSBImportProfile.Click += new System.EventHandler(this.tSBImportProfile_Click);
// //
@ -1265,7 +1259,6 @@
private System.Windows.Forms.ListView lvDebug; private System.Windows.Forms.ListView lvDebug;
private System.Windows.Forms.ColumnHeader chTime; private System.Windows.Forms.ColumnHeader chTime;
private System.Windows.Forms.ColumnHeader chData; private System.Windows.Forms.ColumnHeader chData;
private System.Windows.Forms.Timer tmrUpdate;
private System.Windows.Forms.Panel pnlButton; private System.Windows.Forms.Panel pnlButton;
private System.Windows.Forms.Button btnStartStop; private System.Windows.Forms.Button btnStartStop;
private System.Windows.Forms.Button btnClear; private System.Windows.Forms.Button btnClear;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -22,31 +22,37 @@ namespace DS4Windows
int ind = tLPTranslators.Controls.IndexOf(ctrls[0]) + 1; int ind = tLPTranslators.Controls.IndexOf(ctrls[0]) + 1;
((Label)tLPTranslators.Controls[ind]).ForeColor = Color.DarkGreen; ((Label)tLPTranslators.Controls[ind]).ForeColor = Color.DarkGreen;
} }
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
string version = fvi.FileVersion; string version = fvi.FileVersion;
lbAbout.Text += version + ")"; lbAbout.Text += version + ")";
if (tPCredits.HasChildren) if (tPCredits.HasChildren)
foreach (System.Windows.Forms.Control ctrl in tPCredits.Controls) {
foreach (Control ctrl in tPCredits.Controls)
{ {
if (ctrl.HasChildren) if (ctrl.HasChildren)
foreach (System.Windows.Forms.Control ctrl2 in ctrl.Controls) {
foreach (Control ctrl2 in ctrl.Controls)
ctrl2.MouseHover += Items_MouseHover; ctrl2.MouseHover += Items_MouseHover;
}
ctrl.MouseHover += Items_MouseHover; ctrl.MouseHover += Items_MouseHover;
} }
}
tPCredits.MouseHover += Items_MouseHover; tPCredits.MouseHover += Items_MouseHover;
lbLinkText.Text = string.Empty; lbLinkText.Text = string.Empty;
} }
private void Items_MouseHover(object sender, EventArgs e) private void Items_MouseHover(object sender, EventArgs e)
{ {
switch (((System.Windows.Forms.Control)sender).Name) switch (((Control)sender).Name)
{ {
//if (File.Exists(appdatapath + "\\Auto Profiles.xml"))
case "linkJays2Kings": lbLinkText.Text = "http://ds4windows.com"; break; case "linkJays2Kings": lbLinkText.Text = "http://ds4windows.com"; break;
case "linkElectro": lbLinkText.Text = "https://code.google.com/r/brianfundakowskifeldman-ds4windows/"; break; case "linkElectro": lbLinkText.Text = "https://code.google.com/r/brianfundakowskifeldman-ds4windows/"; break;
case "linkInhexSTER": lbLinkText.Text = "https://code.google.com/p/ds4-tool/"; break; case "linkInhexSTER": lbLinkText.Text = "https://code.google.com/p/ds4-tool/"; break;
case "linkJhebbel": lbLinkText.Text = "http://dsdcs.com/index.php/portfolio/software-development/4-ds4windows"; break; case "linkJhebbel": lbLinkText.Text = "http://dsdcs.com/index.php/portfolio/software-development/4-ds4windows"; break;
case "linkSourceCode": lbLinkText.Text = "https://github.com/Jays2Kings/DS4Windows"; break; case "linkSourceCode": lbLinkText.Text = "https://github.com/Ryochan7/DS4Windows"; break;
case "linkBoganhobo": lbLinkText.Text = "https://github.com/boganhobo"; break; case "linkBoganhobo": lbLinkText.Text = "https://github.com/boganhobo"; break;
case "linkChamilsaan": lbLinkText.Text = "https://github.com/Chamilsaan"; break; case "linkChamilsaan": lbLinkText.Text = "https://github.com/Chamilsaan"; break;
case "linkKiliansch": lbLinkText.Text = "https://github.com/kiliansch"; break; case "linkKiliansch": lbLinkText.Text = "https://github.com/kiliansch"; break;
@ -82,12 +88,14 @@ namespace DS4Windows
private void linkDonate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) private void linkDonate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{ {
Process.Start("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2FTZ9BZEHSQ8Q&lc=US&item_name=DS4Windows&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"); //Process.Start("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2FTZ9BZEHSQ8Q&lc=US&item_name=DS4Windows&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted");
Process.Start("https://paypal.me/ryochan7");
} }
private void linkSourceCode_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) private void linkSourceCode_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{ {
Process.Start("https://github.com/Jays2Kings/DS4Windows"); //Process.Start("https://github.com/Jays2Kings/DS4Windows");
Process.Start("https://github.com/Ryochan7/DS4Windows");
} }
private void linkBoganhobo_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) private void linkBoganhobo_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

File diff suppressed because it is too large Load Diff

View File

@ -114,6 +114,8 @@
this.bnSwipeRight = new System.Windows.Forms.Button(); this.bnSwipeRight = new System.Windows.Forms.Button();
this.lbSwipeRight = new System.Windows.Forms.Label(); this.lbSwipeRight = new System.Windows.Forms.Label();
this.gBOther = new System.Windows.Forms.GroupBox(); this.gBOther = new System.Windows.Forms.GroupBox();
this.btPollRateLabel = new System.Windows.Forms.Label();
this.btPollRateComboBox = new System.Windows.Forms.ComboBox();
this.enableTouchToggleCheckbox = new System.Windows.Forms.CheckBox(); this.enableTouchToggleCheckbox = new System.Windows.Forms.CheckBox();
this.cBDinput = new System.Windows.Forms.CheckBox(); this.cBDinput = new System.Windows.Forms.CheckBox();
this.pBProgram = new System.Windows.Forms.PictureBox(); this.pBProgram = new System.Windows.Forms.PictureBox();
@ -250,13 +252,6 @@
this.lbActionsTip = new System.Windows.Forms.Label(); this.lbActionsTip = new System.Windows.Forms.Label();
this.tCSens = new System.Windows.Forms.TabControl(); this.tCSens = new System.Windows.Forms.TabControl();
this.tPDeadzone = new System.Windows.Forms.TabPage(); this.tPDeadzone = new System.Windows.Forms.TabPage();
this.tPCurve = new System.Windows.Forms.TabPage();
this.nUDLSCurve = new System.Windows.Forms.NumericUpDown();
this.nUDRSCurve = new System.Windows.Forms.NumericUpDown();
this.lbRSCurve = new System.Windows.Forms.Label();
this.lbRSCurvePercent = new System.Windows.Forms.Label();
this.lbLSCurvePercent = new System.Windows.Forms.Label();
this.lbLSCurve = new System.Windows.Forms.Label();
this.antiDeadzoneTabPage = new System.Windows.Forms.TabPage(); this.antiDeadzoneTabPage = new System.Windows.Forms.TabPage();
this.nUDR2AntiDead = new System.Windows.Forms.NumericUpDown(); this.nUDR2AntiDead = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
@ -275,11 +270,31 @@
this.label6 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label();
this.nUDLSMaxZone = new System.Windows.Forms.NumericUpDown(); this.nUDLSMaxZone = new System.Windows.Forms.NumericUpDown();
this.label5 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label();
this.tPCurve = new System.Windows.Forms.TabPage();
this.nUDLSCurve = new System.Windows.Forms.NumericUpDown();
this.nUDRSCurve = new System.Windows.Forms.NumericUpDown();
this.lbRSCurve = new System.Windows.Forms.Label();
this.lbRSCurvePercent = new System.Windows.Forms.Label();
this.lbLSCurvePercent = new System.Windows.Forms.Label();
this.lbLSCurve = new System.Windows.Forms.Label();
this.tPOutCurve = new System.Windows.Forms.TabPage();
this.rsOutCurveComboBox = new System.Windows.Forms.ComboBox();
this.lsOutCurveComboBox = new System.Windows.Forms.ComboBox();
this.label10 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.fLPSettings = new System.Windows.Forms.FlowLayoutPanel(); this.fLPSettings = new System.Windows.Forms.FlowLayoutPanel();
this.gBGyro = new System.Windows.Forms.GroupBox(); this.gBGyro = new System.Windows.Forms.GroupBox();
this.rBSAControls = new System.Windows.Forms.RadioButton(); this.rBSAControls = new System.Windows.Forms.RadioButton();
this.rBSAMouse = new System.Windows.Forms.RadioButton(); this.rBSAMouse = new System.Windows.Forms.RadioButton();
this.pnlSAMouse = new System.Windows.Forms.Panel(); this.pnlSAMouse = new System.Windows.Forms.Panel();
this.lbGyroSmooth = new System.Windows.Forms.Label();
this.cBGyroSmooth = new System.Windows.Forms.CheckBox();
this.lbSmoothWeight = new System.Windows.Forms.Label();
this.nUDGyroSmoothWeight = new System.Windows.Forms.NumericUpDown();
this.label12 = new System.Windows.Forms.Label();
this.nUDGyroMouseVertScale = new System.Windows.Forms.NumericUpDown();
this.label11 = new System.Windows.Forms.Label();
this.gyroTriggerBehavior = new System.Windows.Forms.CheckBox();
this.cBGyroInvertY = new System.Windows.Forms.CheckBox(); this.cBGyroInvertY = new System.Windows.Forms.CheckBox();
this.cBGyroInvertX = new System.Windows.Forms.CheckBox(); this.cBGyroInvertX = new System.Windows.Forms.CheckBox();
this.lbGyroInvert = new System.Windows.Forms.Label(); this.lbGyroInvert = new System.Windows.Forms.Label();
@ -322,6 +337,11 @@
this.pSToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pSToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.alwaysOnToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.alwaysOnToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.advColorDialog = new DS4Windows.AdvancedColorDialog(); this.advColorDialog = new DS4Windows.AdvancedColorDialog();
this.tpRotation = new System.Windows.Forms.TabPage();
this.label13 = new System.Windows.Forms.Label();
this.nUDLSRotation = new System.Windows.Forms.NumericUpDown();
this.label14 = new System.Windows.Forms.Label();
this.nUDRSRotation = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.nUDRainbow)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDRainbow)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tBBlueBar)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.tBBlueBar)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tBGreenBar)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.tBGreenBar)).BeginInit();
@ -378,9 +398,6 @@
this.fLPActionButtons.SuspendLayout(); this.fLPActionButtons.SuspendLayout();
this.tCSens.SuspendLayout(); this.tCSens.SuspendLayout();
this.tPDeadzone.SuspendLayout(); this.tPDeadzone.SuspendLayout();
this.tPCurve.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDLSCurve)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRSCurve)).BeginInit();
this.antiDeadzoneTabPage.SuspendLayout(); this.antiDeadzoneTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDR2AntiDead)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDR2AntiDead)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDL2AntiDead)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDL2AntiDead)).BeginInit();
@ -391,9 +408,15 @@
((System.ComponentModel.ISupportInitialize)(this.nUDL2Maxzone)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDL2Maxzone)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRSMaxZone)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDRSMaxZone)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDLSMaxZone)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDLSMaxZone)).BeginInit();
this.tPCurve.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDLSCurve)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRSCurve)).BeginInit();
this.tPOutCurve.SuspendLayout();
this.fLPSettings.SuspendLayout(); this.fLPSettings.SuspendLayout();
this.gBGyro.SuspendLayout(); this.gBGyro.SuspendLayout();
this.pnlSAMouse.SuspendLayout(); this.pnlSAMouse.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDGyroSmoothWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDGyroMouseVertScale)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDGyroSensitivity)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDGyroSensitivity)).BeginInit();
this.gBSensitivity.SuspendLayout(); this.gBSensitivity.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDL2S)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDL2S)).BeginInit();
@ -403,6 +426,9 @@
((System.ComponentModel.ISupportInitialize)(this.nUDSXS)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDSXS)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDSZS)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDSZS)).BeginInit();
this.cMGyroTriggers.SuspendLayout(); this.cMGyroTriggers.SuspendLayout();
this.tpRotation.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDLSRotation)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRSRotation)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// lowColorChooserButton // lowColorChooserButton
@ -1162,6 +1188,8 @@
// gBOther // gBOther
// //
this.gBOther.BackColor = System.Drawing.Color.WhiteSmoke; this.gBOther.BackColor = System.Drawing.Color.WhiteSmoke;
this.gBOther.Controls.Add(this.btPollRateLabel);
this.gBOther.Controls.Add(this.btPollRateComboBox);
this.gBOther.Controls.Add(this.enableTouchToggleCheckbox); this.gBOther.Controls.Add(this.enableTouchToggleCheckbox);
this.gBOther.Controls.Add(this.cBDinput); this.gBOther.Controls.Add(this.cBDinput);
this.gBOther.Controls.Add(this.pBProgram); this.gBOther.Controls.Add(this.pBProgram);
@ -1181,6 +1209,38 @@
this.gBOther.Name = "gBOther"; this.gBOther.Name = "gBOther";
this.gBOther.TabStop = false; this.gBOther.TabStop = false;
// //
// btPollRateLabel
//
resources.ApplyResources(this.btPollRateLabel, "btPollRateLabel");
this.btPollRateLabel.Name = "btPollRateLabel";
//
// btPollRateComboBox
//
this.btPollRateComboBox.BackColor = System.Drawing.SystemColors.Window;
this.btPollRateComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.btPollRateComboBox.FormattingEnabled = true;
this.btPollRateComboBox.Items.AddRange(new object[] {
resources.GetString("btPollRateComboBox.Items"),
resources.GetString("btPollRateComboBox.Items1"),
resources.GetString("btPollRateComboBox.Items2"),
resources.GetString("btPollRateComboBox.Items3"),
resources.GetString("btPollRateComboBox.Items4"),
resources.GetString("btPollRateComboBox.Items5"),
resources.GetString("btPollRateComboBox.Items6"),
resources.GetString("btPollRateComboBox.Items7"),
resources.GetString("btPollRateComboBox.Items8"),
resources.GetString("btPollRateComboBox.Items9"),
resources.GetString("btPollRateComboBox.Items10"),
resources.GetString("btPollRateComboBox.Items11"),
resources.GetString("btPollRateComboBox.Items12"),
resources.GetString("btPollRateComboBox.Items13"),
resources.GetString("btPollRateComboBox.Items14"),
resources.GetString("btPollRateComboBox.Items15"),
resources.GetString("btPollRateComboBox.Items16")});
resources.ApplyResources(this.btPollRateComboBox, "btPollRateComboBox");
this.btPollRateComboBox.Name = "btPollRateComboBox";
this.btPollRateComboBox.SelectedIndexChanged += new System.EventHandler(this.btPollRateComboBox_SelectedIndexChanged);
//
// enableTouchToggleCheckbox // enableTouchToggleCheckbox
// //
resources.ApplyResources(this.enableTouchToggleCheckbox, "enableTouchToggleCheckbox"); resources.ApplyResources(this.enableTouchToggleCheckbox, "enableTouchToggleCheckbox");
@ -2520,7 +2580,6 @@
this.lVActions.ShowItemToolTips = true; this.lVActions.ShowItemToolTips = true;
this.lVActions.UseCompatibleStateImageBehavior = false; this.lVActions.UseCompatibleStateImageBehavior = false;
this.lVActions.View = System.Windows.Forms.View.Details; this.lVActions.View = System.Windows.Forms.View.Details;
this.lVActions.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.lVActions_ItemCheck);
// //
// cHName // cHName
// //
@ -2578,9 +2637,11 @@
// tCSens // tCSens
// //
this.tCSens.Controls.Add(this.tPDeadzone); this.tCSens.Controls.Add(this.tPDeadzone);
this.tCSens.Controls.Add(this.tPCurve);
this.tCSens.Controls.Add(this.antiDeadzoneTabPage); this.tCSens.Controls.Add(this.antiDeadzoneTabPage);
this.tCSens.Controls.Add(this.maxZoneTabPage); this.tCSens.Controls.Add(this.maxZoneTabPage);
this.tCSens.Controls.Add(this.tPCurve);
this.tCSens.Controls.Add(this.tPOutCurve);
this.tCSens.Controls.Add(this.tpRotation);
resources.ApplyResources(this.tCSens, "tCSens"); resources.ApplyResources(this.tCSens, "tCSens");
this.tCSens.Name = "tCSens"; this.tCSens.Name = "tCSens";
this.tCSens.SelectedIndex = 0; this.tCSens.SelectedIndex = 0;
@ -2603,60 +2664,6 @@
resources.ApplyResources(this.tPDeadzone, "tPDeadzone"); resources.ApplyResources(this.tPDeadzone, "tPDeadzone");
this.tPDeadzone.Name = "tPDeadzone"; this.tPDeadzone.Name = "tPDeadzone";
// //
// tPCurve
//
this.tPCurve.BackColor = System.Drawing.Color.WhiteSmoke;
this.tPCurve.Controls.Add(this.nUDLSCurve);
this.tPCurve.Controls.Add(this.nUDRSCurve);
this.tPCurve.Controls.Add(this.lbRSCurve);
this.tPCurve.Controls.Add(this.lbRSCurvePercent);
this.tPCurve.Controls.Add(this.lbLSCurvePercent);
this.tPCurve.Controls.Add(this.lbLSCurve);
resources.ApplyResources(this.tPCurve, "tPCurve");
this.tPCurve.Name = "tPCurve";
//
// nUDLSCurve
//
this.nUDLSCurve.Increment = new decimal(new int[] {
10,
0,
0,
0});
resources.ApplyResources(this.nUDLSCurve, "nUDLSCurve");
this.nUDLSCurve.Name = "nUDLSCurve";
this.nUDLSCurve.ValueChanged += new System.EventHandler(this.nUDLSCurve_ValueChanged);
//
// nUDRSCurve
//
this.nUDRSCurve.Increment = new decimal(new int[] {
10,
0,
0,
0});
resources.ApplyResources(this.nUDRSCurve, "nUDRSCurve");
this.nUDRSCurve.Name = "nUDRSCurve";
this.nUDRSCurve.ValueChanged += new System.EventHandler(this.nUDRSCurve_ValueChanged);
//
// lbRSCurve
//
resources.ApplyResources(this.lbRSCurve, "lbRSCurve");
this.lbRSCurve.Name = "lbRSCurve";
//
// lbRSCurvePercent
//
resources.ApplyResources(this.lbRSCurvePercent, "lbRSCurvePercent");
this.lbRSCurvePercent.Name = "lbRSCurvePercent";
//
// lbLSCurvePercent
//
resources.ApplyResources(this.lbLSCurvePercent, "lbLSCurvePercent");
this.lbLSCurvePercent.Name = "lbLSCurvePercent";
//
// lbLSCurve
//
resources.ApplyResources(this.lbLSCurve, "lbLSCurve");
this.lbLSCurve.Name = "lbLSCurve";
//
// antiDeadzoneTabPage // antiDeadzoneTabPage
// //
this.antiDeadzoneTabPage.Controls.Add(this.nUDR2AntiDead); this.antiDeadzoneTabPage.Controls.Add(this.nUDR2AntiDead);
@ -2881,6 +2888,108 @@
resources.ApplyResources(this.label5, "label5"); resources.ApplyResources(this.label5, "label5");
this.label5.Name = "label5"; this.label5.Name = "label5";
// //
// tPCurve
//
this.tPCurve.BackColor = System.Drawing.Color.WhiteSmoke;
this.tPCurve.Controls.Add(this.nUDLSCurve);
this.tPCurve.Controls.Add(this.nUDRSCurve);
this.tPCurve.Controls.Add(this.lbRSCurve);
this.tPCurve.Controls.Add(this.lbRSCurvePercent);
this.tPCurve.Controls.Add(this.lbLSCurvePercent);
this.tPCurve.Controls.Add(this.lbLSCurve);
resources.ApplyResources(this.tPCurve, "tPCurve");
this.tPCurve.Name = "tPCurve";
//
// nUDLSCurve
//
this.nUDLSCurve.Increment = new decimal(new int[] {
10,
0,
0,
0});
resources.ApplyResources(this.nUDLSCurve, "nUDLSCurve");
this.nUDLSCurve.Name = "nUDLSCurve";
this.nUDLSCurve.ValueChanged += new System.EventHandler(this.nUDLSCurve_ValueChanged);
//
// nUDRSCurve
//
this.nUDRSCurve.Increment = new decimal(new int[] {
10,
0,
0,
0});
resources.ApplyResources(this.nUDRSCurve, "nUDRSCurve");
this.nUDRSCurve.Name = "nUDRSCurve";
this.nUDRSCurve.ValueChanged += new System.EventHandler(this.nUDRSCurve_ValueChanged);
//
// lbRSCurve
//
resources.ApplyResources(this.lbRSCurve, "lbRSCurve");
this.lbRSCurve.Name = "lbRSCurve";
//
// lbRSCurvePercent
//
resources.ApplyResources(this.lbRSCurvePercent, "lbRSCurvePercent");
this.lbRSCurvePercent.Name = "lbRSCurvePercent";
//
// lbLSCurvePercent
//
resources.ApplyResources(this.lbLSCurvePercent, "lbLSCurvePercent");
this.lbLSCurvePercent.Name = "lbLSCurvePercent";
//
// lbLSCurve
//
resources.ApplyResources(this.lbLSCurve, "lbLSCurve");
this.lbLSCurve.Name = "lbLSCurve";
//
// tPOutCurve
//
this.tPOutCurve.Controls.Add(this.rsOutCurveComboBox);
this.tPOutCurve.Controls.Add(this.lsOutCurveComboBox);
this.tPOutCurve.Controls.Add(this.label10);
this.tPOutCurve.Controls.Add(this.label9);
resources.ApplyResources(this.tPOutCurve, "tPOutCurve");
this.tPOutCurve.Name = "tPOutCurve";
this.tPOutCurve.UseVisualStyleBackColor = true;
//
// rsOutCurveComboBox
//
this.rsOutCurveComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.rsOutCurveComboBox.DropDownWidth = 100;
this.rsOutCurveComboBox.FormattingEnabled = true;
this.rsOutCurveComboBox.Items.AddRange(new object[] {
resources.GetString("rsOutCurveComboBox.Items"),
resources.GetString("rsOutCurveComboBox.Items1"),
resources.GetString("rsOutCurveComboBox.Items2"),
resources.GetString("rsOutCurveComboBox.Items3")});
resources.ApplyResources(this.rsOutCurveComboBox, "rsOutCurveComboBox");
this.rsOutCurveComboBox.Name = "rsOutCurveComboBox";
this.rsOutCurveComboBox.SelectedIndexChanged += new System.EventHandler(this.rsOutCurveComboBox_SelectedIndexChanged);
//
// lsOutCurveComboBox
//
this.lsOutCurveComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.lsOutCurveComboBox.DropDownWidth = 100;
this.lsOutCurveComboBox.FormattingEnabled = true;
this.lsOutCurveComboBox.Items.AddRange(new object[] {
resources.GetString("lsOutCurveComboBox.Items"),
resources.GetString("lsOutCurveComboBox.Items1"),
resources.GetString("lsOutCurveComboBox.Items2"),
resources.GetString("lsOutCurveComboBox.Items3")});
resources.ApplyResources(this.lsOutCurveComboBox, "lsOutCurveComboBox");
this.lsOutCurveComboBox.Name = "lsOutCurveComboBox";
this.lsOutCurveComboBox.SelectedIndexChanged += new System.EventHandler(this.lsOutCurveComboBox_SelectedIndexChanged);
//
// label10
//
resources.ApplyResources(this.label10, "label10");
this.label10.Name = "label10";
//
// label9
//
resources.ApplyResources(this.label9, "label9");
this.label9.Name = "label9";
//
// fLPSettings // fLPSettings
// //
resources.ApplyResources(this.fLPSettings, "fLPSettings"); resources.ApplyResources(this.fLPSettings, "fLPSettings");
@ -2922,6 +3031,14 @@
// //
// pnlSAMouse // pnlSAMouse
// //
this.pnlSAMouse.Controls.Add(this.lbGyroSmooth);
this.pnlSAMouse.Controls.Add(this.cBGyroSmooth);
this.pnlSAMouse.Controls.Add(this.lbSmoothWeight);
this.pnlSAMouse.Controls.Add(this.nUDGyroSmoothWeight);
this.pnlSAMouse.Controls.Add(this.label12);
this.pnlSAMouse.Controls.Add(this.nUDGyroMouseVertScale);
this.pnlSAMouse.Controls.Add(this.label11);
this.pnlSAMouse.Controls.Add(this.gyroTriggerBehavior);
this.pnlSAMouse.Controls.Add(this.cBGyroInvertY); this.pnlSAMouse.Controls.Add(this.cBGyroInvertY);
this.pnlSAMouse.Controls.Add(this.cBGyroInvertX); this.pnlSAMouse.Controls.Add(this.cBGyroInvertX);
this.pnlSAMouse.Controls.Add(this.lbGyroInvert); this.pnlSAMouse.Controls.Add(this.lbGyroInvert);
@ -2932,6 +3049,80 @@
resources.ApplyResources(this.pnlSAMouse, "pnlSAMouse"); resources.ApplyResources(this.pnlSAMouse, "pnlSAMouse");
this.pnlSAMouse.Name = "pnlSAMouse"; this.pnlSAMouse.Name = "pnlSAMouse";
// //
// lbGyroSmooth
//
resources.ApplyResources(this.lbGyroSmooth, "lbGyroSmooth");
this.lbGyroSmooth.Name = "lbGyroSmooth";
//
// cBGyroSmooth
//
resources.ApplyResources(this.cBGyroSmooth, "cBGyroSmooth");
this.cBGyroSmooth.Name = "cBGyroSmooth";
this.cBGyroSmooth.UseVisualStyleBackColor = true;
this.cBGyroSmooth.CheckedChanged += new System.EventHandler(this.cBGyroSmooth_CheckedChanged);
//
// lbSmoothWeight
//
resources.ApplyResources(this.lbSmoothWeight, "lbSmoothWeight");
this.lbSmoothWeight.Name = "lbSmoothWeight";
//
// nUDGyroSmoothWeight
//
this.nUDGyroSmoothWeight.DecimalPlaces = 3;
resources.ApplyResources(this.nUDGyroSmoothWeight, "nUDGyroSmoothWeight");
this.nUDGyroSmoothWeight.Maximum = new decimal(new int[] {
1,
0,
0,
0});
this.nUDGyroSmoothWeight.Name = "nUDGyroSmoothWeight";
this.nUDGyroSmoothWeight.Value = new decimal(new int[] {
5,
0,
0,
65536});
this.nUDGyroSmoothWeight.ValueChanged += new System.EventHandler(this.nUDGyroSmoothWeight_ValueChanged);
//
// label12
//
resources.ApplyResources(this.label12, "label12");
this.label12.Name = "label12";
//
// nUDGyroMouseVertScale
//
this.nUDGyroMouseVertScale.Increment = new decimal(new int[] {
1,
0,
0,
65536});
resources.ApplyResources(this.nUDGyroMouseVertScale, "nUDGyroMouseVertScale");
this.nUDGyroMouseVertScale.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.nUDGyroMouseVertScale.Name = "nUDGyroMouseVertScale";
this.nUDGyroMouseVertScale.Value = new decimal(new int[] {
100,
0,
0,
0});
this.nUDGyroMouseVertScale.ValueChanged += new System.EventHandler(this.nUDGyroMouseVertScale_ValueChanged);
//
// label11
//
resources.ApplyResources(this.label11, "label11");
this.label11.Name = "label11";
//
// gyroTriggerBehavior
//
resources.ApplyResources(this.gyroTriggerBehavior, "gyroTriggerBehavior");
this.gyroTriggerBehavior.Checked = true;
this.gyroTriggerBehavior.CheckState = System.Windows.Forms.CheckState.Checked;
this.gyroTriggerBehavior.Name = "gyroTriggerBehavior";
this.gyroTriggerBehavior.UseVisualStyleBackColor = true;
this.gyroTriggerBehavior.CheckedChanged += new System.EventHandler(this.gyroTriggerBehavior_CheckedChanged);
//
// cBGyroInvertY // cBGyroInvertY
// //
resources.ApplyResources(this.cBGyroInvertY, "cBGyroInvertY"); resources.ApplyResources(this.cBGyroInvertY, "cBGyroInvertY");
@ -3033,7 +3224,7 @@
0, 0,
0, 0,
0}); 0});
this.nUDL2S.ValueChanged += new System.EventHandler(this.nUDSens_ValueChanged); this.nUDL2S.ValueChanged += new System.EventHandler(this.nUDL2Sens_ValueChanged);
// //
// nUDLSS // nUDLSS
// //
@ -3060,7 +3251,7 @@
0, 0,
0, 0,
0}); 0});
this.nUDLSS.ValueChanged += new System.EventHandler(this.nUDSens_ValueChanged); this.nUDLSS.ValueChanged += new System.EventHandler(this.nUDLSSens_ValueChanged);
// //
// lbSixaxisXS // lbSixaxisXS
// //
@ -3092,7 +3283,7 @@
0, 0,
0, 0,
0}); 0});
this.nUDR2S.ValueChanged += new System.EventHandler(this.nUDSens_ValueChanged); this.nUDR2S.ValueChanged += new System.EventHandler(this.nUDR2Sens_ValueChanged);
// //
// lbSixaxisZS // lbSixaxisZS
// //
@ -3124,7 +3315,7 @@
0, 0,
0, 0,
0}); 0});
this.nUDRSS.ValueChanged += new System.EventHandler(this.nUDSens_ValueChanged); this.nUDRSS.ValueChanged += new System.EventHandler(this.nUDRSSens_ValueChanged);
// //
// lbR2LS // lbR2LS
// //
@ -3156,7 +3347,7 @@
0, 0,
0, 0,
0}); 0});
this.nUDSXS.ValueChanged += new System.EventHandler(this.nUDSens_ValueChanged); this.nUDSXS.ValueChanged += new System.EventHandler(this.nUDSXSens_ValueChanged);
// //
// lbRSS // lbRSS
// //
@ -3193,7 +3384,7 @@
0, 0,
0, 0,
0}); 0});
this.nUDSZS.ValueChanged += new System.EventHandler(this.nUDSens_ValueChanged); this.nUDSZS.ValueChanged += new System.EventHandler(this.nUDSZSens_ValueChanged);
// //
// cMGyroTriggers // cMGyroTriggers
// //
@ -3384,6 +3575,58 @@
resources.ApplyResources(this.alwaysOnToolStripMenuItem, "alwaysOnToolStripMenuItem"); resources.ApplyResources(this.alwaysOnToolStripMenuItem, "alwaysOnToolStripMenuItem");
this.alwaysOnToolStripMenuItem.CheckedChanged += new System.EventHandler(this.SATrigger_CheckedChanged); this.alwaysOnToolStripMenuItem.CheckedChanged += new System.EventHandler(this.SATrigger_CheckedChanged);
// //
// tpRotation
//
this.tpRotation.Controls.Add(this.nUDRSRotation);
this.tpRotation.Controls.Add(this.label14);
this.tpRotation.Controls.Add(this.nUDLSRotation);
this.tpRotation.Controls.Add(this.label13);
resources.ApplyResources(this.tpRotation, "tpRotation");
this.tpRotation.Name = "tpRotation";
this.tpRotation.UseVisualStyleBackColor = true;
//
// label13
//
resources.ApplyResources(this.label13, "label13");
this.label13.Name = "label13";
//
// nUDLSRotation
//
resources.ApplyResources(this.nUDLSRotation, "nUDLSRotation");
this.nUDLSRotation.Maximum = new decimal(new int[] {
180,
0,
0,
0});
this.nUDLSRotation.Minimum = new decimal(new int[] {
180,
0,
0,
-2147483648});
this.nUDLSRotation.Name = "nUDLSRotation";
this.nUDLSRotation.ValueChanged += new System.EventHandler(this.nUDLSRotation_ValueChanged);
//
// label14
//
resources.ApplyResources(this.label14, "label14");
this.label14.Name = "label14";
//
// nUDRSRotation
//
resources.ApplyResources(this.nUDRSRotation, "nUDRSRotation");
this.nUDRSRotation.Maximum = new decimal(new int[] {
180,
0,
0,
0});
this.nUDRSRotation.Minimum = new decimal(new int[] {
180,
0,
0,
-2147483648});
this.nUDRSRotation.Name = "nUDRSRotation";
this.nUDRSRotation.ValueChanged += new System.EventHandler(this.nUDRSRotation_ValueChanged);
//
// Options // Options
// //
resources.ApplyResources(this, "$this"); resources.ApplyResources(this, "$this");
@ -3462,10 +3705,6 @@
this.tCSens.ResumeLayout(false); this.tCSens.ResumeLayout(false);
this.tPDeadzone.ResumeLayout(false); this.tPDeadzone.ResumeLayout(false);
this.tPDeadzone.PerformLayout(); this.tPDeadzone.PerformLayout();
this.tPCurve.ResumeLayout(false);
this.tPCurve.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDLSCurve)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRSCurve)).EndInit();
this.antiDeadzoneTabPage.ResumeLayout(false); this.antiDeadzoneTabPage.ResumeLayout(false);
this.antiDeadzoneTabPage.PerformLayout(); this.antiDeadzoneTabPage.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDR2AntiDead)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDR2AntiDead)).EndInit();
@ -3478,11 +3717,19 @@
((System.ComponentModel.ISupportInitialize)(this.nUDL2Maxzone)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDL2Maxzone)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRSMaxZone)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDRSMaxZone)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDLSMaxZone)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDLSMaxZone)).EndInit();
this.tPCurve.ResumeLayout(false);
this.tPCurve.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDLSCurve)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRSCurve)).EndInit();
this.tPOutCurve.ResumeLayout(false);
this.tPOutCurve.PerformLayout();
this.fLPSettings.ResumeLayout(false); this.fLPSettings.ResumeLayout(false);
this.gBGyro.ResumeLayout(false); this.gBGyro.ResumeLayout(false);
this.gBGyro.PerformLayout(); this.gBGyro.PerformLayout();
this.pnlSAMouse.ResumeLayout(false); this.pnlSAMouse.ResumeLayout(false);
this.pnlSAMouse.PerformLayout(); this.pnlSAMouse.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDGyroSmoothWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDGyroMouseVertScale)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDGyroSensitivity)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDGyroSensitivity)).EndInit();
this.gBSensitivity.ResumeLayout(false); this.gBSensitivity.ResumeLayout(false);
this.gBSensitivity.PerformLayout(); this.gBSensitivity.PerformLayout();
@ -3493,6 +3740,10 @@
((System.ComponentModel.ISupportInitialize)(this.nUDSXS)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDSXS)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDSZS)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDSZS)).EndInit();
this.cMGyroTriggers.ResumeLayout(false); this.cMGyroTriggers.ResumeLayout(false);
this.tpRotation.ResumeLayout(false);
this.tpRotation.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDLSRotation)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRSRotation)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@ -3793,5 +4044,25 @@
private System.Windows.Forms.NumericUpDown nUDL2Maxzone; private System.Windows.Forms.NumericUpDown nUDL2Maxzone;
private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label btPollRateLabel;
private System.Windows.Forms.ComboBox btPollRateComboBox;
private System.Windows.Forms.TabPage tPOutCurve;
private System.Windows.Forms.ComboBox rsOutCurveComboBox;
private System.Windows.Forms.ComboBox lsOutCurveComboBox;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.CheckBox gyroTriggerBehavior;
private System.Windows.Forms.NumericUpDown nUDGyroMouseVertScale;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Label lbSmoothWeight;
private System.Windows.Forms.NumericUpDown nUDGyroSmoothWeight;
private System.Windows.Forms.CheckBox cBGyroSmooth;
private System.Windows.Forms.Label lbGyroSmooth;
private System.Windows.Forms.TabPage tpRotation;
private System.Windows.Forms.NumericUpDown nUDRSRotation;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.NumericUpDown nUDLSRotation;
private System.Windows.Forms.Label label13;
} }
} }

View File

@ -3,10 +3,7 @@ using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection;
using System.Xml;
using static DS4Windows.Global; using static DS4Windows.Global;
using System.Runtime.InteropServices;
namespace DS4Windows namespace DS4Windows
{ {
@ -82,19 +79,19 @@ namespace DS4Windows
b.Text = ""; b.Text = "";
} }
foreach (System.Windows.Forms.Control control in Controls) foreach (Control control in Controls)
{ {
if (control.HasChildren) if (control.HasChildren)
{ {
foreach (System.Windows.Forms.Control ctrl in control.Controls) foreach (Control ctrl in control.Controls)
{ {
if (ctrl.HasChildren) if (ctrl.HasChildren)
{ {
foreach (System.Windows.Forms.Control ctrl2 in ctrl.Controls) foreach (Control ctrl2 in ctrl.Controls)
{ {
if (ctrl2.HasChildren) if (ctrl2.HasChildren)
{ {
foreach (System.Windows.Forms.Control ctrl3 in ctrl2.Controls) foreach (Control ctrl3 in ctrl2.Controls)
ctrl3.MouseHover += Items_MouseHover; ctrl3.MouseHover += Items_MouseHover;
} }
@ -272,6 +269,8 @@ namespace DS4Windows
if (device < 4) if (device < 4)
nUDSixaxis.Value = deviceNum + 1; nUDSixaxis.Value = deviceNum + 1;
lVActions.ItemCheck -= this.lVActions_ItemCheck;
if (filename != "") if (filename != "")
{ {
if (device == 4) //if temp device is called if (device == 4) //if temp device is called
@ -313,10 +312,11 @@ namespace DS4Windows
DS4Color cColor = ChargingColor[device]; DS4Color cColor = ChargingColor[device];
btnChargingColor.BackColor = Color.FromArgb(cColor.red, cColor.green, cColor.blue); btnChargingColor.BackColor = Color.FromArgb(cColor.red, cColor.green, cColor.blue);
if (FlashType[device] > cBFlashType.Items.Count - 1) byte tempFlashType = FlashType[device];
if (tempFlashType > cBFlashType.Items.Count - 1)
cBFlashType.SelectedIndex = 0; cBFlashType.SelectedIndex = 0;
else else
cBFlashType.SelectedIndex = FlashType[device]; cBFlashType.SelectedIndex = tempFlashType;
DS4Color fColor = FlashColor[device]; DS4Color fColor = FlashColor[device];
if (fColor.Equals(new DS4Color { red = 0, green = 0, blue = 0 })) if (fColor.Equals(new DS4Color { red = 0, green = 0, blue = 0 }))
@ -352,10 +352,15 @@ namespace DS4Windows
full = HuetoRGB(reg.GetHue(), reg.GetBrightness(), reg); full = HuetoRGB(reg.GetHue(), reg.GetBrightness(), reg);
lowColorChooserButton.BackColor = Color.FromArgb((alphacolor > 205 ? 255 : (alphacolor + 50)), full); lowColorChooserButton.BackColor = Color.FromArgb((alphacolor > 205 ? 255 : (alphacolor + 50)), full);
nUDRainbow.Value = (decimal)Rainbow[device]; nUDRainbow.Value = (decimal)Rainbow[device];
if (ChargingType[device] > cBWhileCharging.Items.Count - 1) int tempWhileCharging = ChargingType[device];
if (tempWhileCharging > cBWhileCharging.Items.Count - 1)
cBWhileCharging.SelectedIndex = 0; cBWhileCharging.SelectedIndex = 0;
else else
cBWhileCharging.SelectedIndex = ChargingType[device]; cBWhileCharging.SelectedIndex = tempWhileCharging;
btPollRateComboBox.SelectedIndex = getBTPollRate(device);
lsOutCurveComboBox.SelectedIndex = getLsOutCurveMode(device);
rsOutCurveComboBox.SelectedIndex = getRsOutCurveMode(device);
try try
{ {
@ -459,6 +464,24 @@ namespace DS4Windows
nUDRSMaxZone.Value = 1; nUDRSMaxZone.Value = 1;
} }
try
{
nUDLSRotation.Value = (decimal)(LSRotation[device] * 180.0 / Math.PI);
}
catch
{
nUDLSRotation.Value = 0.0m;
}
try
{
nUDRSRotation.Value = (decimal)(RSRotation[device] * 180.0 / Math.PI);
}
catch
{
nUDRSRotation.Value = 0.0m;
}
try try
{ {
nUDSX.Value = (decimal)SXDeadzone[device]; nUDSX.Value = (decimal)SXDeadzone[device];
@ -569,16 +592,24 @@ namespace DS4Windows
} }
} }
nUDGyroSensitivity.Value = GyroSensitivity[device]; nUDGyroSensitivity.Value = GyroSensitivity[device];
gyroTriggerBehavior.Checked = GyroTriggerTurns[device];
nUDGyroMouseVertScale.Value = GyroSensVerticalScale[device];
int invert = GyroInvert[device]; int invert = GyroInvert[device];
cBGyroInvertX.Checked = invert == 2 || invert == 3; cBGyroInvertX.Checked = invert == 2 || invert == 3;
cBGyroInvertY.Checked = invert == 1 || invert == 3; cBGyroInvertY.Checked = invert == 1 || invert == 3;
if (s.Count > 0) if (s.Count > 0)
btnGyroTriggers.Text = string.Join(", ", s); btnGyroTriggers.Text = string.Join(", ", s);
cBGyroSmooth.Checked = nUDGyroSmoothWeight.Enabled = GyroSmoothing[device];
nUDGyroSmoothWeight.Value = (decimal)(GyroSmoothingWeight[device]);
} }
else else
{ {
cBFlashType.SelectedIndex = 0; cBFlashType.SelectedIndex = 0;
cBWhileCharging.SelectedIndex = 0; cBWhileCharging.SelectedIndex = 0;
btPollRateComboBox.SelectedIndex = 0;
lsOutCurveComboBox.SelectedIndex = 0;
rsOutCurveComboBox.SelectedIndex = 0;
rBTPMouse.Checked = true; rBTPMouse.Checked = true;
rBSAControls.Checked = true; rBSAControls.Checked = true;
ToggleRainbow(false); ToggleRainbow(false);
@ -586,6 +617,7 @@ namespace DS4Windows
cbStartTouchpadOff.Checked = false; cbStartTouchpadOff.Checked = false;
rBSAControls.Checked = true; rBSAControls.Checked = true;
rBTPMouse.Checked = true; rBTPMouse.Checked = true;
switch (device) switch (device)
{ {
case 0: tBRedBar.Value = 0; tBGreenBar.Value = 0; tBBlueBar.Value = 255; break; case 0: tBRedBar.Value = 0; tBGreenBar.Value = 0; tBBlueBar.Value = 255; break;
@ -631,6 +663,8 @@ namespace DS4Windows
nUDRSAntiDead.Value = 0; nUDRSAntiDead.Value = 0;
nUDLSMaxZone.Value = 1; nUDLSMaxZone.Value = 1;
nUDRSMaxZone.Value = 1; nUDRSMaxZone.Value = 1;
nUDLSRotation.Value = 0;
nUDRSRotation.Value = 0;
nUDSX.Value = .25m; nUDSX.Value = .25m;
nUDSZ.Value = .25m; nUDSZ.Value = .25m;
@ -652,70 +686,22 @@ namespace DS4Windows
cBControllerInput.Checked = DS4Mapping; cBControllerInput.Checked = DS4Mapping;
((ToolStripMenuItem)cMGyroTriggers.Items[cMGyroTriggers.Items.Count - 1]).Checked = true; ((ToolStripMenuItem)cMGyroTriggers.Items[cMGyroTriggers.Items.Count - 1]).Checked = true;
nUDGyroSensitivity.Value = 100; nUDGyroSensitivity.Value = 100;
nUDGyroMouseVertScale.Value = 100;
gyroTriggerBehavior.Checked = true;
cBGyroInvertX.Checked = false; cBGyroInvertX.Checked = false;
cBGyroInvertY.Checked = false; cBGyroInvertY.Checked = false;
cBGyroSmooth.Checked = false;
nUDGyroSmoothWeight.Value = 0.5m;
Set(); Set();
} }
UpdateLists(); UpdateLists();
LoadActions(string.IsNullOrEmpty(filename)); LoadActions(string.IsNullOrEmpty(filename));
lVActions.ItemCheck += new ItemCheckEventHandler(this.lVActions_ItemCheck);
loading = false; loading = false;
saving = false; saving = false;
} }
/* TODO: Possibly remove. Currently not used. */
/*private string getDS4ControlsByName(DS4Controls key)
{
switch (key)
{
case DS4Controls.Share: return "bnShare";
case DS4Controls.L3: return "bnL3";
case DS4Controls.R3: return "bnR3";
case DS4Controls.Options: return "bnOptions";
case DS4Controls.DpadUp: return "bnUp";
case DS4Controls.DpadRight: return "bnRight";
case DS4Controls.DpadDown: return "bnDown";
case DS4Controls.DpadLeft: return "bnLeft";
case DS4Controls.L1: return "bnL1";
case DS4Controls.R1: return "bnR1";
case DS4Controls.Triangle: return "bnTriangle";
case DS4Controls.Circle: return "bnCircle";
case DS4Controls.Cross: return "bnCross";
case DS4Controls.Square: return "bnSquare";
case DS4Controls.PS: return "bnPS";
case DS4Controls.LXNeg: return "bnLSLeft";
case DS4Controls.LYNeg: return "bnLSUp";
case DS4Controls.RXNeg: return "bnRSLeft";
case DS4Controls.RYNeg: return "bnRSUp";
case DS4Controls.LXPos: return "bnLSRight";
case DS4Controls.LYPos: return "bnLSDown";
case DS4Controls.RXPos: return "bnRSRight";
case DS4Controls.RYPos: return "bnRSDown";
case DS4Controls.L2: return "bnL2";
case DS4Controls.R2: return "bnR2";
case DS4Controls.TouchLeft: return "bnTouchLeft";
case DS4Controls.TouchMulti: return "bnTouchMulti";
case DS4Controls.TouchUpper: return "bnTouchUpper";
case DS4Controls.TouchRight: return "bnTouchRight";
case DS4Controls.GyroXPos: return "bnGyroXP";
case DS4Controls.GyroXNeg: return "bnGyroXN";
case DS4Controls.GyroZPos: return "bnGyroZP";
case DS4Controls.GyroZNeg: return "bnGyroZN";
case DS4Controls.SwipeUp: return "bnSwipeUp";
case DS4Controls.SwipeDown: return "bnSwipeDown";
case DS4Controls.SwipeLeft: return "bnSwipeLeft";
case DS4Controls.SwipeRight: return "bnSwipeRight";
}
return "";
}
*/
public void LoadActions(bool newp) public void LoadActions(bool newp)
{ {
lVActions.Items.Clear(); lVActions.Items.Clear();
@ -768,7 +754,7 @@ namespace DS4Windows
} }
} }
public double Clamp(double min, double value, double max) /*public double Clamp(double min, double value, double max)
{ {
if (value > max) if (value > max)
return max; return max;
@ -777,6 +763,7 @@ namespace DS4Windows
else else
return value; return value;
} }
*/
void EnableReadings(bool on) void EnableReadings(bool on)
{ {
@ -798,7 +785,8 @@ namespace DS4Windows
// MEMS gyro data is all calibrated to roughly -1G..1G for values -0x2000..0x1fff // MEMS gyro data is all calibrated to roughly -1G..1G for values -0x2000..0x1fff
// Enough additional acceleration and we are no longer mostly measuring Earth's gravity... // Enough additional acceleration and we are no longer mostly measuring Earth's gravity...
// We should try to indicate setpoints of the calibration when exposing this measurement.... // We should try to indicate setpoints of the calibration when exposing this measurement....
DS4Device ds = Program.rootHub.DS4Controllers[(int)nUDSixaxis.Value - 1]; int tempDeviceNum = (int)nUDSixaxis.Value - 1;
DS4Device ds = Program.rootHub.DS4Controllers[tempDeviceNum];
if (ds == null) if (ds == null)
{ {
EnableReadings(false); EnableReadings(false);
@ -809,23 +797,26 @@ namespace DS4Windows
else else
{ {
EnableReadings(true); EnableReadings(true);
SetDynamicTrackBarValue(tBsixaxisGyroX, (Program.rootHub.ExposedState[(int)nUDSixaxis.Value - 1].GyroX + tBsixaxisGyroX.Value * 2) / 3); SetDynamicTrackBarValue(tBsixaxisGyroX, (Program.rootHub.ExposedState[tempDeviceNum].GyroX + tBsixaxisGyroX.Value * 2) / 3);
SetDynamicTrackBarValue(tBsixaxisGyroY, (Program.rootHub.ExposedState[(int)nUDSixaxis.Value - 1].GyroY + tBsixaxisGyroY.Value * 2) / 3); SetDynamicTrackBarValue(tBsixaxisGyroY, (Program.rootHub.ExposedState[tempDeviceNum].GyroY + tBsixaxisGyroY.Value * 2) / 3);
SetDynamicTrackBarValue(tBsixaxisGyroZ, (Program.rootHub.ExposedState[(int)nUDSixaxis.Value - 1].GyroZ + tBsixaxisGyroZ.Value * 2) / 3); SetDynamicTrackBarValue(tBsixaxisGyroZ, (Program.rootHub.ExposedState[tempDeviceNum].GyroZ + tBsixaxisGyroZ.Value * 2) / 3);
SetDynamicTrackBarValue(tBsixaxisAccelX, (int)(Program.rootHub.ExposedState[(int)nUDSixaxis.Value - 1].AccelX + tBsixaxisAccelX.Value * 2) / 3); SetDynamicTrackBarValue(tBsixaxisAccelX, (int)(Program.rootHub.ExposedState[tempDeviceNum].AccelX + tBsixaxisAccelX.Value * 2) / 3);
SetDynamicTrackBarValue(tBsixaxisAccelY, (int)(Program.rootHub.ExposedState[(int)nUDSixaxis.Value - 1].AccelY + tBsixaxisAccelY.Value * 2) / 3); SetDynamicTrackBarValue(tBsixaxisAccelY, (int)(Program.rootHub.ExposedState[tempDeviceNum].AccelY + tBsixaxisAccelY.Value * 2) / 3);
SetDynamicTrackBarValue(tBsixaxisAccelZ, (int)(Program.rootHub.ExposedState[(int)nUDSixaxis.Value - 1].AccelZ + tBsixaxisAccelZ.Value * 2) / 3); SetDynamicTrackBarValue(tBsixaxisAccelZ, (int)(Program.rootHub.ExposedState[tempDeviceNum].AccelZ + tBsixaxisAccelZ.Value * 2) / 3);
int x = Program.rootHub.getDS4State((int)nUDSixaxis.Value - 1).LX; int x = Program.rootHub.getDS4State(tempDeviceNum).LX;
int y = Program.rootHub.getDS4State((int)nUDSixaxis.Value - 1).LY; int y = Program.rootHub.getDS4State(tempDeviceNum).LY;
btnLSTrackS.Visible = nUDLSS.Value != 1;
if (nUDLSCurve.Value > 0) double tempLSS = (double)nUDLSS.Value;
btnLSTrackS.Visible = tempLSS != 1;
double tempLSCurve = (double)nUDLSCurve.Value;
if (tempLSCurve > 0.0)
{ {
float max = x + y; float max = x + y;
double curvex; double curvex;
double curvey; double curvey;
double multimax = TValue(382.5, max, (double)nUDLSCurve.Value); double multimax = TValue(382.5, max, tempLSCurve);
double multimin = TValue(127.5, max, (double)nUDLSCurve.Value); double multimin = TValue(127.5, max, tempLSCurve);
if ((x > 127.5f && y > 127.5f) || (x < 127.5f && y < 127.5f)) if ((x > 127.5f && y > 127.5f) || (x < 127.5f && y < 127.5f))
{ {
curvex = (x > 127.5f ? Math.Min(x, (x / max) * multimax) : Math.Max(x, (x / max) * multimin)); curvex = (x > 127.5f ? Math.Min(x, (x / max) * multimax) : Math.Max(x, (x / max) * multimin));
@ -849,27 +840,28 @@ namespace DS4Windows
else else
{ {
btnLSTrack.Location = new Point((int)(dpix * x / 2.09), (int)(dpiy * y / 2.09)); btnLSTrack.Location = new Point((int)(dpix * x / 2.09), (int)(dpiy * y / 2.09));
btnLSTrackS.Visible = nUDLSS.Value != 1; btnLSTrackS.Visible = tempLSS != 1;
} }
if (nUDLSS.Value != 1) if (tempLSS != 1)
{ {
btnLSTrackS.Location = new Point((int)((float)nUDLSS.Value * (btnLSTrack.Location.X - pnlLSTrack.Size.Width / 2f) + pnlLSTrack.Size.Width / 2f), btnLSTrackS.Location = new Point((int)(tempLSS * (btnLSTrack.Location.X - pnlLSTrack.Size.Width / 2f) + pnlLSTrack.Size.Width / 2f),
(int)((float)nUDLSS.Value * (btnLSTrack.Location.Y - pnlLSTrack.Size.Height / 2f) + pnlLSTrack.Size.Height / 2f)); (int)(tempLSS * (btnLSTrack.Location.Y - pnlLSTrack.Size.Height / 2f) + pnlLSTrack.Size.Height / 2f));
} }
x = Program.rootHub.getDS4State(tempDeviceNum).RX;
y = Program.rootHub.getDS4State(tempDeviceNum).RY;
x = Program.rootHub.getDS4State((int)nUDSixaxis.Value - 1).RX; double tempRSS = (double)nUDRSS.Value;
y = Program.rootHub.getDS4State((int)nUDSixaxis.Value - 1).RY; btnRSTrackS.Visible = tempRSS != 1;
btnRSTrackS.Visible = nUDRSS.Value != 1; double tempRSCurve = (double)nUDRSCurve.Value;
if (tempRSCurve > 0.0)
if (nUDRSCurve.Value > 0)
{ {
float max = x + y; float max = x + y;
double curvex; double curvex;
double curvey; double curvey;
double multimax = TValue(382.5, max, (double)nUDRSCurve.Value); double multimax = TValue(382.5, max, tempRSCurve);
double multimin = TValue(127.5, max, (double)nUDRSCurve.Value); double multimin = TValue(127.5, max, tempRSCurve);
if ((x > 127.5f && y > 127.5f) || (x < 127.5f && y < 127.5f)) if ((x > 127.5f && y > 127.5f) || (x < 127.5f && y < 127.5f))
{ {
curvex = (x > 127.5f ? Math.Min(x, (x / max) * multimax) : Math.Max(x, (x / max) * multimin)); curvex = (x > 127.5f ? Math.Min(x, (x / max) * multimax) : Math.Max(x, (x / max) * multimin));
@ -893,46 +885,56 @@ namespace DS4Windows
else else
{ {
btnRSTrack.Location = new Point((int)(dpix * x / 2.09), (int)(dpiy * y / 2.09)); btnRSTrack.Location = new Point((int)(dpix * x / 2.09), (int)(dpiy * y / 2.09));
btnRSTrackS.Visible = nUDRSS.Value != 1; btnRSTrackS.Visible = tempRSS != 1;
} }
if (nUDRSS.Value != 1) if (tempRSS != 1)
btnRSTrackS.Location = new Point((int)((float)nUDRSS.Value * (btnRSTrack.Location.X - pnlRSTrack.Size.Width / 2f) + pnlRSTrack.Size.Width / 2f), {
(int)((float)nUDRSS.Value * (btnRSTrack.Location.Y - pnlRSTrack.Size.Height / 2f) + pnlRSTrack.Size.Height / 2f)); btnRSTrackS.Location = new Point((int)(tempRSS * (btnRSTrack.Location.X - pnlRSTrack.Size.Width / 2f) + pnlRSTrack.Size.Width / 2f),
(int)(tempRSS * (btnRSTrack.Location.Y - pnlRSTrack.Size.Height / 2f) + pnlRSTrack.Size.Height / 2f));
}
x = -Program.rootHub.ExposedState[(int)nUDSixaxis.Value - 1].GyroX + 127; x = -Program.rootHub.ExposedState[tempDeviceNum].GyroX + 127;
y = Program.rootHub.ExposedState[(int)nUDSixaxis.Value - 1].GyroZ + 127; y = Program.rootHub.ExposedState[tempDeviceNum].GyroZ + 127;
btnSATrack.Location = new Point((int)(dpix * Clamp(0, x / 2.09, pnlSATrack.Size.Width)), (int)(dpiy * Clamp(0, y / 2.09, pnlSATrack.Size.Height))); btnSATrack.Location = new Point((int)(dpix * Global.Clamp(0, x / 2.09, pnlSATrack.Size.Width)), (int)(dpiy * Global.Clamp(0, y / 2.09, pnlSATrack.Size.Height)));
btnSATrackS.Visible = nUDSXS.Value != 1 || nUDSZS.Value != 1;
if (nUDSXS.Value != 1 || nUDSZS.Value != 1)
btnSATrackS.Location = new Point((int)((float)nUDSXS.Value * (btnSATrack.Location.X - pnlSATrack.Size.Width / 2f) + pnlSATrack.Size.Width / 2f),
(int)((float)nUDSZS.Value * (btnSATrack.Location.Y - pnlSATrack.Size.Height / 2f) + pnlSATrack.Size.Height / 2f));
tBL2.Value = Program.rootHub.getDS4State((int)nUDSixaxis.Value - 1).L2; double tempSXS = (double)nUDSXS.Value;
double tempSZS = (double)nUDSZS.Value;
btnSATrackS.Visible = tempSXS != 1 || tempSZS != 1;
if (tempSXS != 1 || tempSZS != 1)
{
btnSATrackS.Location = new Point((int)(tempSXS * (btnSATrack.Location.X - pnlSATrack.Size.Width / 2f) + pnlSATrack.Size.Width / 2f),
(int)(tempSZS * (btnSATrack.Location.Y - pnlSATrack.Size.Height / 2f) + pnlSATrack.Size.Height / 2f));
}
double tempL2 = (double)nUDL2.Value;
double tempL2S = (double)nUDL2S.Value;
tBL2.Value = Program.rootHub.getDS4State(tempDeviceNum).L2;
lbL2Track.Location = new Point(tBL2.Location.X - (int)(dpix * 25), lbL2Track.Location = new Point(tBL2.Location.X - (int)(dpix * 25),
Math.Max((int)(((tBL2.Location.Y + tBL2.Size.Height) - (tBL2.Value * (float)nUDL2S.Value) / (tBL2.Size.Height * .0209f / Math.Pow(dpix, 2))) - dpix * 20), Math.Max((int)(((tBL2.Location.Y + tBL2.Size.Height) - (tBL2.Value * tempL2S) / (tBL2.Size.Height * .0209f / Math.Pow(dpix, 2))) - dpix * 20),
(int)(1 * ((tBL2.Location.Y + tBL2.Size.Height) - 255 / (tBL2.Size.Height * .0209f / Math.Pow(dpix, 2))) - dpix * 20))); (int)(1 * ((tBL2.Location.Y + tBL2.Size.Height) - 255 / (tBL2.Size.Height * .0209f / Math.Pow(dpix, 2))) - dpix * 20)));
if (tBL2.Value * (float)nUDL2S.Value >= 255) if (tBL2.Value * tempL2S >= 255)
lbL2Track.ForeColor = Color.Green; lbL2Track.ForeColor = Color.Green;
else if (tBL2.Value * (float)nUDL2S.Value < (double)nUDL2.Value * 255) else if (tBL2.Value * tempL2S < tempL2 * 255)
lbL2Track.ForeColor = Color.Red; lbL2Track.ForeColor = Color.Red;
else else
lbL2Track.ForeColor = Color.Black; lbL2Track.ForeColor = Color.Black;
tBR2.Value = Program.rootHub.getDS4State((int)nUDSixaxis.Value - 1).R2; double tempR2 = (double)nUDR2.Value;
double tempR2S = (double)nUDR2S.Value;
tBR2.Value = Program.rootHub.getDS4State(tempDeviceNum).R2;
lbR2Track.Location = new Point(tBR2.Location.X + (int)(dpix * 25), lbR2Track.Location = new Point(tBR2.Location.X + (int)(dpix * 25),
Math.Max((int)(1 * ((tBR2.Location.Y + tBR2.Size.Height) - (tBR2.Value * (float)nUDR2S.Value) / (tBR2.Size.Height * .0209f / Math.Pow(dpix, 2))) - dpix * 20), Math.Max((int)(1 * ((tBR2.Location.Y + tBR2.Size.Height) - (tBR2.Value * tempR2S) / (tBR2.Size.Height * .0209f / Math.Pow(dpix, 2))) - dpix * 20),
(int)(1 * ((tBR2.Location.Y + tBR2.Size.Height) - 255 / (tBR2.Size.Height * .0209f / Math.Pow(dpix, 2))) - dpix * 20))); (int)(1 * ((tBR2.Location.Y + tBR2.Size.Height) - 255 / (tBR2.Size.Height * .0209f / Math.Pow(dpix, 2))) - dpix * 20)));
if (tBR2.Value * (float)nUDR2S.Value >= 255) if (tBR2.Value * tempR2S >= 255)
lbR2Track.ForeColor = Color.Green; lbR2Track.ForeColor = Color.Green;
else if (tBR2.Value * (float)nUDR2S.Value < (double)nUDR2.Value * 255) else if (tBR2.Value * tempR2S < tempR2 * 255)
lbR2Track.ForeColor = Color.Red; lbR2Track.ForeColor = Color.Red;
else else
lbR2Track.ForeColor = Color.Black; lbR2Track.ForeColor = Color.Black;
double latency = ds.Latency; double latency = ds.Latency;
int warnInterval = ds.getWarnInterval(); int warnInterval = ds.getWarnInterval();
lbInputDelay.Text = Properties.Resources.InputDelay.Replace("*number*", latency.ToString()); lbInputDelay.Text = Properties.Resources.InputDelay.Replace("*number*", latency.ToString());
@ -964,7 +966,8 @@ namespace DS4Windows
{ {
if (Form.ActiveForm == root && cBControllerInput.Checked && tCControls.SelectedIndex < 1) if (Form.ActiveForm == root && cBControllerInput.Checked && tCControls.SelectedIndex < 1)
{ {
switch (Program.rootHub.GetInputkeys((int)nUDSixaxis.Value - 1)) int tempDeviceNum = (int)nUDSixaxis.Value - 1;
switch (Program.rootHub.GetInputkeys(tempDeviceNum))
{ {
case ("nothing"): break; case ("nothing"): break;
case ("Cross"): Show_ControlsBn(bnCross, e); break; case ("Cross"): Show_ControlsBn(bnCross, e); break;
@ -1265,7 +1268,6 @@ namespace DS4Windows
pBHoveredButton.Size = new Size((int)(pBHoveredButton.Image.Size.Width * (dpix / 1.25f)), (int)(pBHoveredButton.Image.Size.Height * (dpix / 1.25f))); pBHoveredButton.Size = new Size((int)(pBHoveredButton.Image.Size.Width * (dpix / 1.25f)), (int)(pBHoveredButton.Image.Size.Height * (dpix / 1.25f)));
} }
private void button_MouseLeave(object sender, EventArgs e) private void button_MouseLeave(object sender, EventArgs e)
{ {
pBHoveredButton.Image = null; pBHoveredButton.Image = null;
@ -1296,6 +1298,9 @@ namespace DS4Windows
else else
FlashColor[device] = new DS4Color(Color.Black); FlashColor[device] = new DS4Color(Color.Black);
BTPollRate[device] = btPollRateComboBox.SelectedIndex;
lsOutCurveMode[device] = lsOutCurveComboBox.SelectedIndex;
rsOutCurveMode[device] = rsOutCurveComboBox.SelectedIndex;
L2Deadzone[device] = (byte)Math.Round((nUDL2.Value * 255), 0); L2Deadzone[device] = (byte)Math.Round((nUDL2.Value * 255), 0);
R2Deadzone[device] = (byte)Math.Round((nUDR2.Value * 255), 0); R2Deadzone[device] = (byte)Math.Round((nUDR2.Value * 255), 0);
L2AntiDeadzone[device] = (int)(nUDL2AntiDead.Value * 100); L2AntiDeadzone[device] = (int)(nUDL2AntiDead.Value * 100);
@ -1313,6 +1318,10 @@ namespace DS4Windows
LSDeadzone[device] = (int)Math.Round((nUDLS.Value * 127), 0); LSDeadzone[device] = (int)Math.Round((nUDLS.Value * 127), 0);
LSAntiDeadzone[device] = (int)(nUDLSAntiDead.Value * 100); LSAntiDeadzone[device] = (int)(nUDLSAntiDead.Value * 100);
RSAntiDeadzone[device] = (int)(nUDRSAntiDead.Value * 100); RSAntiDeadzone[device] = (int)(nUDRSAntiDead.Value * 100);
LSMaxzone[device] = (int)(nUDLSMaxZone.Value * 100);
RSMaxzone[device] = (int)(nUDRSMaxZone.Value * 100);
LSRotation[device] = (double)nUDLSRotation.Value * Math.PI / 180.0;
RSRotation[device] = (double)nUDRSRotation.Value * Math.PI / 180.0;
ButtonMouseSensitivity[device] = (int)numUDMouseSens.Value; ButtonMouseSensitivity[device] = (int)numUDMouseSens.Value;
FlashAt[device] = (int)nUDflashLED.Value; FlashAt[device] = (int)nUDflashLED.Value;
SXDeadzone[device] = (double)nUDSX.Value; SXDeadzone[device] = (double)nUDSX.Value;
@ -1335,12 +1344,18 @@ namespace DS4Windows
ProfileActions[device] = pactions; ProfileActions[device] = pactions;
calculateProfileActionCount(device); calculateProfileActionCount(device);
calculateProfileActionDicts(device); calculateProfileActionDicts(device);
cacheProfileCustomsFlags(device);
pnlTPMouse.Visible = rBTPMouse.Checked; pnlTPMouse.Visible = rBTPMouse.Checked;
pnlSAMouse.Visible = rBSAMouse.Checked; pnlSAMouse.Visible = rBSAMouse.Checked;
fLPTiltControls.Visible = rBSAControls.Checked; fLPTiltControls.Visible = rBSAControls.Checked;
fLPTouchSwipe.Visible = rBTPControls.Checked; fLPTouchSwipe.Visible = rBTPControls.Checked;
GyroSensitivity[device] = (int)Math.Round(nUDGyroSensitivity.Value, 0); GyroSensitivity[device] = (int)Math.Round(nUDGyroSensitivity.Value, 0);
GyroTriggerTurns[device] = gyroTriggerBehavior.Checked;
GyroSensVerticalScale[device] = (int)nUDGyroMouseVertScale.Value;
GyroSmoothing[device] = cBGyroSmooth.Checked;
GyroSmoothingWeight[device] = (double)nUDGyroSmoothWeight.Value;
int invert = 0; int invert = 0;
if (cBGyroInvertX.Checked) if (cBGyroInvertX.Checked)
invert += 2; invert += 2;
@ -1351,7 +1366,7 @@ namespace DS4Windows
GyroInvert[device] = invert; GyroInvert[device] = invert;
List<int> ints = new List<int>(); List<int> ints = new List<int>();
for (int i = 0; i < cMGyroTriggers.Items.Count - 1; i++) for (int i = 0, trigLen = cMGyroTriggers.Items.Count - 1; i < trigLen; i++)
{ {
if (((ToolStripMenuItem)cMGyroTriggers.Items[i]).Checked) if (((ToolStripMenuItem)cMGyroTriggers.Items[i]).Checked)
ints.Add(i); ints.Add(i);
@ -1391,15 +1406,15 @@ namespace DS4Windows
UpdateDS4CSetting(device, ctrl.Name, shift, tag.Key, tag.Value, kt, sTrigger); UpdateDS4CSetting(device, ctrl.Name, shift, tag.Key, tag.Value, kt, sTrigger);
} }
public void ChangeButtonText(KeyValuePair<object, string> tag, Control ctrl, bool SC) public void ChangeButtonText(KeyValuePair<object, string> tag, Control ctrl, bool SC)
{ {
if (ctrl is Button) if (ctrl is Button)
{ {
DS4KeyType kt = DS4KeyType.None; DS4KeyType kt = DS4KeyType.None;
if (SC) kt |= DS4KeyType.ScanCode; if (SC) kt |= DS4KeyType.ScanCode;
UpdateDS4CSetting(device, ctrl.Name, false, tag.Key, tag.Value, kt); UpdateDS4CSetting(device, ctrl.Name, false, tag.Key, tag.Value, kt);
} }
} }
/*public void Toggle_Bn(bool SC, bool TG, bool MC, bool MR) /*public void Toggle_Bn(bool SC, bool TG, bool MC, bool MR)
{ {
@ -1431,7 +1446,6 @@ namespace DS4Windows
} }
}*/ }*/
private void btnLightbar_Click(object sender, EventArgs e) private void btnLightbar_Click(object sender, EventArgs e)
{ {
advColorDialog.Color = Color.FromArgb(tBRedBar.Value, tBGreenBar.Value, tBBlueBar.Value); advColorDialog.Color = Color.FromArgb(tBRedBar.Value, tBGreenBar.Value, tBBlueBar.Value);
@ -1470,7 +1484,6 @@ namespace DS4Windows
DS4LightBar.forcelight[device] = false; DS4LightBar.forcelight[device] = false;
} }
private void btnChargingColor_Click(object sender, EventArgs e) private void btnChargingColor_Click(object sender, EventArgs e)
{ {
Color chargingBackColor = btnChargingColor.BackColor; Color chargingBackColor = btnChargingColor.BackColor;
@ -1563,6 +1576,7 @@ namespace DS4Windows
else if (300 <= hue && hue < 360) { R = C; B = X; } else if (300 <= hue && hue < 360) { R = C; B = X; }
return Color.FromArgb((int)((R + m) * 255), (int)((G + m) * 255), (int)((B + m) * 255)); return Color.FromArgb((int)((R + m) * 255), (int)((G + m) * 255), (int)((B + m) * 255));
} }
private void rumbleBoostBar_ValueChanged(object sender, EventArgs e) private void rumbleBoostBar_ValueChanged(object sender, EventArgs e)
{ {
if (!loading) if (!loading)
@ -1578,17 +1592,18 @@ namespace DS4Windows
private void btnRumbleHeavyTest_Click(object sender, EventArgs e) private void btnRumbleHeavyTest_Click(object sender, EventArgs e)
{ {
DS4Device d = Program.rootHub.DS4Controllers[(int)nUDSixaxis.Value - 1]; int tempDeviceNum = (int)nUDSixaxis.Value - 1;
DS4Device d = Program.rootHub.DS4Controllers[tempDeviceNum];
if (d != null) if (d != null)
{ {
if (((Button)sender).Text == Properties.Resources.TestHText) if (((Button)sender).Text == Properties.Resources.TestHText)
{ {
Program.rootHub.setRumble((byte)Math.Min(255, (255 * nUDRumbleBoost.Value / 100)), d.RightLightFastRumble, (int)nUDSixaxis.Value - 1); Program.rootHub.setRumble((byte)Math.Min(255, (255 * nUDRumbleBoost.Value / 100)), d.RightLightFastRumble, tempDeviceNum);
((Button)sender).Text = Properties.Resources.StopHText; ((Button)sender).Text = Properties.Resources.StopHText;
} }
else else
{ {
Program.rootHub.setRumble(0, d.RightLightFastRumble, (int)nUDSixaxis.Value - 1); Program.rootHub.setRumble(0, d.RightLightFastRumble, tempDeviceNum);
((Button)sender).Text = Properties.Resources.TestHText; ((Button)sender).Text = Properties.Resources.TestHText;
} }
} }
@ -1596,17 +1611,18 @@ namespace DS4Windows
private void btnRumbleLightTest_Click(object sender, EventArgs e) private void btnRumbleLightTest_Click(object sender, EventArgs e)
{ {
DS4Device d = Program.rootHub.DS4Controllers[(int)nUDSixaxis.Value - 1]; int tempDeviceNum = (int)nUDSixaxis.Value - 1;
DS4Device d = Program.rootHub.DS4Controllers[tempDeviceNum];
if (d != null) if (d != null)
{ {
if (((Button)sender).Text == Properties.Resources.TestLText) if (((Button)sender).Text == Properties.Resources.TestLText)
{ {
Program.rootHub.setRumble(d.LeftHeavySlowRumble, (byte)Math.Min(255, (255 * nUDRumbleBoost.Value / 100)), (int)nUDSixaxis.Value - 1); Program.rootHub.setRumble(d.LeftHeavySlowRumble, (byte)Math.Min(255, (255 * nUDRumbleBoost.Value / 100)), tempDeviceNum);
((Button)sender).Text = Properties.Resources.StopLText; ((Button)sender).Text = Properties.Resources.StopLText;
} }
else else
{ {
Program.rootHub.setRumble(d.LeftHeavySlowRumble, 0, (int)nUDSixaxis.Value - 1); Program.rootHub.setRumble(d.LeftHeavySlowRumble, 0, tempDeviceNum);
((Button)sender).Text = Properties.Resources.TestLText; ((Button)sender).Text = Properties.Resources.TestLText;
} }
} }
@ -1654,8 +1670,6 @@ namespace DS4Windows
private void nUDIdleDisconnect_ValueChanged(object sender, EventArgs e) private void nUDIdleDisconnect_ValueChanged(object sender, EventArgs e)
{ {
IdleDisconnectTimeout[device] = (int)(nUDIdleDisconnect.Value * 60); IdleDisconnectTimeout[device] = (int)(nUDIdleDisconnect.Value * 60);
//if (nUDIdleDisconnect.Value == 0)
//cBIdleDisconnect.Checked = false;
} }
private void cBIdleDisconnect_CheckedChanged(object sender, EventArgs e) private void cBIdleDisconnect_CheckedChanged(object sender, EventArgs e)
@ -1683,9 +1697,31 @@ namespace DS4Windows
if (btnRumbleHeavyTest.Text == Properties.Resources.StopText) if (btnRumbleHeavyTest.Text == Properties.Resources.StopText)
Program.rootHub.setRumble(0, 0, (int)nUDSixaxis.Value - 1); Program.rootHub.setRumble(0, 0, (int)nUDSixaxis.Value - 1);
if (saving)
{
if (device < 4)
{
DS4Device tempDev = Program.rootHub.DS4Controllers[device];
if (tempDev != null)
{
int discon = getIdleDisconnectTimeout(device);
int btCurrentIndex = btPollRateComboBox.SelectedIndex;
tempDev.queueEvent(() =>
{
tempDev.setIdleTimeout(discon);
if (btCurrentIndex >= 0)
{
tempDev.setBTPollRate(btCurrentIndex);
}
});
}
}
}
inputtimer.Stop(); inputtimer.Stop();
sixaxisTimer.Stop(); sixaxisTimer.Stop();
root.OptionsClosed(); root.OptionsClosed();
lVActions.ItemCheck -= this.lVActions_ItemCheck;
Visible = false; Visible = false;
e.Cancel = true; e.Cancel = true;
} }
@ -1882,8 +1918,9 @@ namespace DS4Windows
private void numUDRainbow_ValueChanged(object sender, EventArgs e) private void numUDRainbow_ValueChanged(object sender, EventArgs e)
{ {
Rainbow[device]= (double)nUDRainbow.Value; double tempRainbow = (double)nUDRainbow.Value;
if ((double)nUDRainbow.Value <= 0.5) Rainbow[device] = tempRainbow;
if (tempRainbow <= 0.5)
{ {
btnRainbow.Image = greyscale; btnRainbow.Image = greyscale;
ToggleRainbow(false); ToggleRainbow(false);
@ -2068,7 +2105,6 @@ namespace DS4Windows
private void numUDMouseSens_ValueChanged(object sender, EventArgs e) private void numUDMouseSens_ValueChanged(object sender, EventArgs e)
{ {
ButtonMouseSensitivity[device] = (int)numUDMouseSens.Value; ButtonMouseSensitivity[device] = (int)numUDMouseSens.Value;
//ButtonMouseSensitivity(device, (int)numUDMouseSens.Value);
} }
private void LightBar_MouseDown(object sender, MouseEventArgs e) private void LightBar_MouseDown(object sender, MouseEventArgs e)
@ -2151,7 +2187,7 @@ namespace DS4Windows
private void btnBrowse_Click(object sender, EventArgs e) private void btnBrowse_Click(object sender, EventArgs e)
{ {
if( openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) if (openFileDialog1.ShowDialog() == DialogResult.OK)
{ {
cBLaunchProgram.Checked = true; cBLaunchProgram.Checked = true;
LaunchProgram[device] = openFileDialog1.FileName; LaunchProgram[device] = openFileDialog1.FileName;
@ -2236,6 +2272,12 @@ namespace DS4Windows
case "bnSwipeDown": root.lbLastMessage.Text = Properties.Resources.RightClickPresets; break; case "bnSwipeDown": root.lbLastMessage.Text = Properties.Resources.RightClickPresets; break;
case "bnL3": root.lbLastMessage.Text = Properties.Resources.RightClickPresets; break; case "bnL3": root.lbLastMessage.Text = Properties.Resources.RightClickPresets; break;
case "bnR3": root.lbLastMessage.Text = Properties.Resources.RightClickPresets; break; case "bnR3": root.lbLastMessage.Text = Properties.Resources.RightClickPresets; break;
case "btPollRateLabel": root.lbLastMessage.Text = Properties.Resources.BTPollRate; break;
case "btPollRateComboBox": root.lbLastMessage.Text = Properties.Resources.BTPollRate; break;
case "nUDSixaxis": root.lbLastMessage.Text = Properties.Resources.UseControllerForMapping; break;
case "cBControllerInput": root.lbLastMessage.Text = Properties.Resources.UseControllerForMapping; break;
case "lbUseController": root.lbLastMessage.Text = Properties.Resources.UseControllerForMapping; break;
case "gyroTriggerBehavior": root.lbLastMessage.Text = Properties.Resources.GyroTriggerBehavior; break;
default: root.lbLastMessage.Text = Properties.Resources.HoverOverItems; break; default: root.lbLastMessage.Text = Properties.Resources.HoverOverItems; break;
} }
@ -2269,7 +2311,7 @@ namespace DS4Windows
private void cBControllerInput_CheckedChanged(object sender, EventArgs e) private void cBControllerInput_CheckedChanged(object sender, EventArgs e)
{ {
DS4Mapping=cBControllerInput.Checked; DS4Mapping = cBControllerInput.Checked;
} }
private void btnAddAction_Click(object sender, EventArgs e) private void btnAddAction_Click(object sender, EventArgs e)
@ -2668,19 +2710,6 @@ namespace DS4Windows
lbControlName.Text = lbControlTip.Text; lbControlName.Text = lbControlTip.Text;
} }
private void nUDSens_ValueChanged(object sender, EventArgs e)
{
if (!loading)
{
L2Sens[device] = (double)nUDL2S.Value;
R2Sens[device] = (double)nUDR2S.Value;
LSSens[device] = (double)nUDLSS.Value;
RSSens[device] = (double)nUDRSS.Value;
SXSens[device] = (double)nUDSXS.Value;
SZSens[device] = (double)nUDSZS.Value;
}
}
private void nUDLSAntiDead_ValueChanged(object sender, EventArgs e) private void nUDLSAntiDead_ValueChanged(object sender, EventArgs e)
{ {
LSAntiDeadzone[device] = (int)(nUDLSAntiDead.Value * 100); LSAntiDeadzone[device] = (int)(nUDLSAntiDead.Value * 100);
@ -2744,6 +2773,126 @@ namespace DS4Windows
R2Maxzone[device] = (int)(nUDR2Maxzone.Value * 100); R2Maxzone[device] = (int)(nUDR2Maxzone.Value * 100);
} }
private void btPollRateComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
int currentIndex = btPollRateComboBox.SelectedIndex;
BTPollRate[device] = currentIndex;
}
private void nUDL2Sens_ValueChanged(object sender, EventArgs e)
{
if (!loading)
{
L2Sens[device] = (double)nUDL2S.Value;
}
}
private void nUDLSSens_ValueChanged(object sender, EventArgs e)
{
if (!loading)
{
LSSens[device] = (double)nUDLSS.Value;
}
}
private void nUDR2Sens_ValueChanged(object sender, EventArgs e)
{
if (!loading)
{
R2Sens[device] = (double)nUDR2S.Value;
}
}
private void nUDRSSens_ValueChanged(object sender, EventArgs e)
{
if (!loading)
{
RSSens[device] = (double)nUDRSS.Value;
}
}
private void nUDSXSens_ValueChanged(object sender, EventArgs e)
{
if (!loading)
{
SXSens[device] = (double)nUDSXS.Value;
}
}
private void nUDSZSens_ValueChanged(object sender, EventArgs e)
{
if (!loading)
{
SZSens[device] = (double)nUDSZS.Value;
}
}
private void lsOutCurveComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (!loading)
{
lsOutCurveMode[device] = lsOutCurveComboBox.SelectedIndex;
}
}
private void rsOutCurveComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (!loading)
{
rsOutCurveMode[device] = rsOutCurveComboBox.SelectedIndex;
}
}
private void gyroTriggerBehavior_CheckedChanged(object sender, EventArgs e)
{
if (!loading)
{
GyroTriggerTurns[device] = gyroTriggerBehavior.Checked;
}
}
private void nUDGyroMouseVertScale_ValueChanged(object sender, EventArgs e)
{
if (!loading)
{
GyroSensVerticalScale[device] = (int)nUDGyroMouseVertScale.Value;
}
}
private void nUDGyroSmoothWeight_ValueChanged(object sender, EventArgs e)
{
if (!loading)
{
GyroSmoothingWeight[device] = (double)nUDGyroSmoothWeight.Value;
}
}
private void cBGyroSmooth_CheckedChanged(object sender, EventArgs e)
{
bool value = cBGyroSmooth.Checked;
nUDGyroSmoothWeight.Enabled = value;
if (!loading)
{
GyroSmoothing[device] = value;
}
}
private void nUDLSRotation_ValueChanged(object sender, EventArgs e)
{
if (!loading)
{
LSRotation[device] = (double)nUDLSRotation.Value * Math.PI / 180.0;
}
}
private void nUDRSRotation_ValueChanged(object sender, EventArgs e)
{
if (!loading)
{
RSRotation[device] = (double)nUDRSRotation.Value * Math.PI / 180.0;
}
}
private void Options_Resize(object sender, EventArgs e) private void Options_Resize(object sender, EventArgs e)
{ {
fLPSettings.AutoScroll = false; fLPSettings.AutoScroll = false;
@ -2816,7 +2965,6 @@ namespace DS4Windows
{ {
GyroSensitivity[device] = (int)Math.Round(nUDGyroSensitivity.Value, 0); GyroSensitivity[device] = (int)Math.Round(nUDGyroSensitivity.Value, 0);
} }
private void cBFlashType_SelectedIndexChanged(object sender, EventArgs e) private void cBFlashType_SelectedIndexChanged(object sender, EventArgs e)
{ {

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
@ -36,10 +30,13 @@ namespace DS4Windows
openPresets.Filter = Properties.Resources.TextDocs + "|*.txt"; openPresets.Filter = Properties.Resources.TextDocs + "|*.txt";
savePresets.Filter = Properties.Resources.TextDocs + "|*.txt"; savePresets.Filter = Properties.Resources.TextDocs + "|*.txt";
if (op != null) if (op != null)
if (kbm.macrorepeat) {
cBStyle.SelectedIndex = 1; if (kbm.macrorepeat)
else cBStyle.SelectedIndex = 1;
cBStyle.SelectedIndex = 0; else
cBStyle.SelectedIndex = 0;
}
AddtoDS4List(); AddtoDS4List();
ds4.Tick += ds4_Tick; ds4.Tick += ds4_Tick;
ds4.Interval = 1; ds4.Interval = 1;
@ -59,9 +56,11 @@ namespace DS4Windows
cBStyle.SelectedIndex = 1; cBStyle.SelectedIndex = 1;
else else
cBStyle.SelectedIndex = 0; cBStyle.SelectedIndex = 0;
AddtoDS4List(); AddtoDS4List();
if (button > -1) if (button > -1)
sAButton = button; sAButton = button;
ds4.Tick += ds4_Tick; ds4.Tick += ds4_Tick;
ds4.Interval = 1; ds4.Interval = 1;
lbRecordTip.Visible = false; lbRecordTip.Visible = false;
@ -294,6 +293,7 @@ namespace DS4Windows
case DS4Controls.RYPos: return "RS Down"; case DS4Controls.RYPos: return "RS Down";
case DS4Controls.RYNeg: return "RS Up"; case DS4Controls.RYNeg: return "RS Up";
} }
return "None"; return "None";
} }
@ -306,6 +306,7 @@ namespace DS4Windows
{ {
if (cBRecordDelays.Checked) if (cBRecordDelays.Checked)
sw.Start(); sw.Start();
btnRumble.Visible = cBRecordDelays.Checked; btnRumble.Visible = cBRecordDelays.Checked;
btnLightbar.Visible = cBRecordDelays.Checked; btnLightbar.Visible = cBRecordDelays.Checked;
pBLtouch.Visible = cBRecordDelays.Checked; pBLtouch.Visible = cBRecordDelays.Checked;
@ -315,6 +316,7 @@ namespace DS4Windows
ds4.Start(); ds4.Start();
if (!recordAfter) if (!recordAfter)
macros.Clear(); macros.Clear();
lVMacros.Items.Clear(); lVMacros.Items.Clear();
btnRecord.Text = Properties.Resources.StopText; btnRecord.Text = Properties.Resources.StopText;
EnableControls(false); EnableControls(false);
@ -333,21 +335,28 @@ namespace DS4Windows
recordAfter = false; recordAfter = false;
LoadMacro(); LoadMacro();
} }
if (btn4th.Text.Contains(Properties.Resources.UpText)) if (btn4th.Text.Contains(Properties.Resources.UpText))
btn4th_Click(sender, e); btn4th_Click(sender, e);
if (btn5th.Text.Contains(Properties.Resources.UpText)) if (btn5th.Text.Contains(Properties.Resources.UpText))
btn5th_Click(sender, e); btn5th_Click(sender, e);
if (cBRecordDelays.Checked) if (cBRecordDelays.Checked)
{ {
if (btnRumble.Text.Contains("Stop")) if (btnRumble.Text.Contains("Stop"))
btnRumble_Click(sender, e); btnRumble_Click(sender, e);
if (btnLightbar.Text.Contains("Reset")) if (btnLightbar.Text.Contains("Reset"))
btnLightbar_Click(sender, e); btnLightbar_Click(sender, e);
} }
if (cBRecordDelays.Checked) if (cBRecordDelays.Checked)
sw.Reset(); sw.Reset();
if (cBRecordDelays.Checked) if (cBRecordDelays.Checked)
lbDelayTip.Visible = true; lbDelayTip.Visible = true;
btnRecord.Text = Properties.Resources.RecordText; btnRecord.Text = Properties.Resources.RecordText;
EnableControls(true); EnableControls(true);
} }
@ -371,17 +380,22 @@ namespace DS4Windows
int value = WhichKey(e, 0); int value = WhichKey(e, 0);
int count = 0; int count = 0;
if (recordAfter) if (recordAfter)
{
foreach (int i in macrosAfter) foreach (int i in macrosAfter)
{ {
if (i == value) if (i == value)
count++; count++;
} }
else
foreach (int i in macros)
{
if (i == value)
count++;
} }
else
{
foreach (int i in macros)
{
if (i == value)
count++;
}
}
if (macros.Count == 0 || (recordAfter && macrosAfter.Count == 0)) if (macros.Count == 0 || (recordAfter && macrosAfter.Count == 0))
{ {
AddMacroValue(value); AddMacroValue(value);
@ -401,19 +415,25 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add(((Keys)value).ToString(), 0); lVMacros.Items.Add(((Keys)value).ToString(), 0);
} }
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible(); lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
} }
else if (e.KeyValue == 27) else if (e.KeyValue == 27)
{
Close(); Close();
}
else if (e.KeyCode == Keys.Delete) else if (e.KeyCode == Keys.Delete)
{
if (lVMacros.SelectedIndices.Count > 0 && lVMacros.SelectedIndices[0] > -1) if (lVMacros.SelectedIndices.Count > 0 && lVMacros.SelectedIndices[0] > -1)
{ {
macros.RemoveAt(lVMacros.SelectedIndices[0]); macros.RemoveAt(lVMacros.SelectedIndices[0]);
lVMacros.Items.Remove(lVMacros.SelectedItems[0]); lVMacros.Items.Remove(lVMacros.SelectedItems[0]);
} }
}
} }
private int WhichKey(KeyEventArgs e, int keystate) private int WhichKey(KeyEventArgs e, int keystate)
@ -425,55 +445,75 @@ namespace DS4Windows
if (recordAfter) if (recordAfter)
{ {
for (int i = macrosAfter.Count - 1; i >= 0; i--) for (int i = macrosAfter.Count - 1; i >= 0; i--)
{
if (macrosAfter[i] == 160) if (macrosAfter[i] == 160)
return 160; return 160;
else if (macrosAfter[i] == 161) else if (macrosAfter[i] == 161)
return 161; return 161;
}
} }
else else
{
for (int i = macros.Count - 1; i >= 0; i--) for (int i = macros.Count - 1; i >= 0; i--)
{
if (macros[i] == 160) if (macros[i] == 160)
return 160; return 160;
else if (macros[i] == 161) else if (macros[i] == 161)
return 161; return 161;
}
}
} }
else if (e.KeyCode == Keys.ControlKey) else if (e.KeyCode == Keys.ControlKey)
{ {
if (recordAfter) if (recordAfter)
{ {
for (int i = macrosAfter.Count - 1; i >= 0; i--) for (int i = macrosAfter.Count - 1; i >= 0; i--)
{
if (macrosAfter[i] == 162) if (macrosAfter[i] == 162)
return 162; return 162;
else if (macrosAfter[i] == 163) else if (macrosAfter[i] == 163)
return 163; return 163;
}
} }
else else
for (int i = macros.Count - 1; i >= 0; i--) {
if (macros[i] == 162) for (int i = macros.Count - 1; i >= 0; i--)
return 162; {
else if (macros[i] == 163) if (macros[i] == 162)
return 163; return 162;
else if (macros[i] == 163)
return 163;
}
}
} }
else if (e.KeyCode == Keys.Menu) else if (e.KeyCode == Keys.Menu)
{ {
if (recordAfter) if (recordAfter)
{ {
for (int i = macrosAfter.Count - 1; i >= 0; i--) for (int i = macrosAfter.Count - 1; i >= 0; i--)
{
if (macrosAfter[i] == 164) if (macrosAfter[i] == 164)
return 164; return 164;
else if (macrosAfter[i] == 165) else if (macrosAfter[i] == 165)
return 165; return 165;
}
} }
else else
{
for (int i = macros.Count - 1; i >= 0; i--) for (int i = macros.Count - 1; i >= 0; i--)
{
if (macros[i] == 164) if (macros[i] == 164)
return 164; return 164;
else if (macros[i] == 165) else if (macros[i] == 165)
return 165; return 165;
}
}
} }
return e.KeyValue; return e.KeyValue;
} }
else else
{
if (e.KeyCode == Keys.ShiftKey) if (e.KeyCode == Keys.ShiftKey)
{ {
if (Convert.ToBoolean(GetAsyncKeyState(Keys.LShiftKey))) if (Convert.ToBoolean(GetAsyncKeyState(Keys.LShiftKey)))
@ -495,8 +535,9 @@ namespace DS4Windows
return 164; return 164;
if (Convert.ToBoolean(GetAsyncKeyState(Keys.RMenu))) if (Convert.ToBoolean(GetAsyncKeyState(Keys.RMenu)))
return 165; return 165;
} }
}
return e.KeyValue; return e.KeyValue;
} }
@ -512,6 +553,7 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add(((Keys)value).ToString(), 1); lVMacros.Items.Add(((Keys)value).ToString(), 1);
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible(); lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
@ -524,13 +566,14 @@ namespace DS4Windows
int value; int value;
switch (e.Button) switch (e.Button)
{ {
case System.Windows.Forms.MouseButtons.Left: value = 256; break; case MouseButtons.Left: value = 256; break;
case System.Windows.Forms.MouseButtons.Right: value = 257; break; case MouseButtons.Right: value = 257; break;
case System.Windows.Forms.MouseButtons.Middle: value = 258; break; case MouseButtons.Middle: value = 258; break;
case System.Windows.Forms.MouseButtons.XButton1: value = 259; break; case MouseButtons.XButton1: value = 259; break;
case System.Windows.Forms.MouseButtons.XButton2: value = 260; break; case MouseButtons.XButton2: value = 260; break;
default: value = 0; break; default: value = 0; break;
} }
if (macros.Count == 0 || (recordAfter && macrosAfter.Count == 0)) if (macros.Count == 0 || (recordAfter && macrosAfter.Count == 0))
{ {
AddMacroValue(value); AddMacroValue(value);
@ -550,13 +593,17 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add(e.Button.ToString() + " Mouse Button", 0); lVMacros.Items.Add(e.Button.ToString() + " Mouse Button", 0);
} }
if (e.Button == System.Windows.Forms.MouseButtons.XButton1)
if (e.Button == MouseButtons.XButton1)
lVMacros.Items[lVMacros.Items.Count - 1].Text = "4th Mouse Button"; lVMacros.Items[lVMacros.Items.Count - 1].Text = "4th Mouse Button";
if (e.Button == System.Windows.Forms.MouseButtons.XButton2)
if (e.Button == MouseButtons.XButton2)
lVMacros.Items[lVMacros.Items.Count - 1].Text = "5th Mouse Button"; lVMacros.Items[lVMacros.Items.Count - 1].Text = "5th Mouse Button";
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible(); lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
} }
} }
@ -568,11 +615,11 @@ namespace DS4Windows
int value; int value;
switch (e.Button) switch (e.Button)
{ {
case System.Windows.Forms.MouseButtons.Left: value = 256; break; case MouseButtons.Left: value = 256; break;
case System.Windows.Forms.MouseButtons.Right: value = 257; break; case MouseButtons.Right: value = 257; break;
case System.Windows.Forms.MouseButtons.Middle: value = 258; break; case MouseButtons.Middle: value = 258; break;
case System.Windows.Forms.MouseButtons.XButton1: value = 259; break; case MouseButtons.XButton1: value = 259; break;
case System.Windows.Forms.MouseButtons.XButton2: value = 260; break; case MouseButtons.XButton2: value = 260; break;
default: value = 0; break; default: value = 0; break;
} }
@ -583,12 +630,16 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add(e.Button.ToString() + " Mouse Button", 1); lVMacros.Items.Add(e.Button.ToString() + " Mouse Button", 1);
if (e.Button == System.Windows.Forms.MouseButtons.XButton1)
if (e.Button == MouseButtons.XButton1)
lVMacros.Items[lVMacros.Items.Count - 1].Text = "4th Mouse Button"; lVMacros.Items[lVMacros.Items.Count - 1].Text = "4th Mouse Button";
if (e.Button == System.Windows.Forms.MouseButtons.XButton2)
if (e.Button == MouseButtons.XButton2)
lVMacros.Items[lVMacros.Items.Count - 1].Text = "5th Mouse Button"; lVMacros.Items[lVMacros.Items.Count - 1].Text = "5th Mouse Button";
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible(); lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
} }
} }
@ -617,9 +668,11 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add("4th Mouse Button", 0); lVMacros.Items.Add("4th Mouse Button", 0);
} }
btn4th.Text = Properties.Resources.FourthMouseUp; btn4th.Text = Properties.Resources.FourthMouseUp;
} }
else else
@ -631,10 +684,12 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add("4th Mouse Button", 1); lVMacros.Items.Add("4th Mouse Button", 1);
btn4th.Text = Properties.Resources.FourthMouseDown; btn4th.Text = Properties.Resources.FourthMouseDown;
} }
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible(); lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
} }
@ -662,9 +717,11 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add("5th Mouse Button", 0); lVMacros.Items.Add("5th Mouse Button", 0);
} }
btn5th.Text = Properties.Resources.FifthMouseUp; btn5th.Text = Properties.Resources.FifthMouseUp;
} }
else else
@ -676,10 +733,12 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add("5th Mouse Button", 1); lVMacros.Items.Add("5th Mouse Button", 1);
btn5th.Text = Properties.Resources.FifthMouseDown; btn5th.Text = Properties.Resources.FifthMouseDown;
} }
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible(); lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
} }
@ -708,9 +767,11 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add("Rumble 255,255 (100%)", 0); lVMacros.Items.Add("Rumble 255,255 (100%)", 0);
} }
btnRumble.Text = "Stop Rumble"; btnRumble.Text = "Stop Rumble";
} }
else else
@ -723,10 +784,12 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add("Stop Rumble", 1); lVMacros.Items.Add("Stop Rumble", 1);
btnRumble.Text = "Add Rumble"; btnRumble.Text = "Add Rumble";
} }
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible(); lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
} }
@ -754,9 +817,11 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add("Lightbar Color: 255,255,255", 0); lVMacros.Items.Add("Lightbar Color: 255,255,255", 0);
} }
btnLightbar.Text = "Reset Lightbar Color"; btnLightbar.Text = "Reset Lightbar Color";
} }
else else
@ -769,10 +834,12 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add("Reset Lightbar", 1); lVMacros.Items.Add("Reset Lightbar", 1);
btnLightbar.Text = "Change Lightbar Color"; btnLightbar.Text = "Change Lightbar Color";
} }
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible(); lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
} }
@ -787,6 +854,7 @@ namespace DS4Windows
case 1: sA.btnHoldT.Text = macros.Count > 0 ? Properties.Resources.MacroRecorded : Properties.Resources.SelectMacro; break; case 1: sA.btnHoldT.Text = macros.Count > 0 ? Properties.Resources.MacroRecorded : Properties.Resources.SelectMacro; break;
case 2: sA.btnDTapT.Text = macros.Count > 0 ? Properties.Resources.MacroRecorded : Properties.Resources.SelectMacro; break; case 2: sA.btnDTapT.Text = macros.Count > 0 ? Properties.Resources.MacroRecorded : Properties.Resources.SelectMacro; break;
} }
saved = true; saved = true;
Close(); Close();
} }
@ -797,6 +865,7 @@ namespace DS4Windows
{ {
macronames.Add(lvi.Text); macronames.Add(lvi.Text);
} }
string macro = string.Join(", ", macronames.ToArray()); string macro = string.Join(", ", macronames.ToArray());
if (kbm != null) if (kbm != null)
{ {
@ -823,10 +892,12 @@ namespace DS4Windows
else else
Close(); Close();
} }
else MessageBox.Show(Properties.Resources.NoMacroRecorded, "DS4Windows", MessageBoxButtons.OK, MessageBoxIcon.Warning); else
{
MessageBox.Show(Properties.Resources.NoMacroRecorded, "DS4Windows", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
} }
private void btnSaveP_Click(object sender, EventArgs e) private void btnSaveP_Click(object sender, EventArgs e)
{ {
if (macros.Count > 0) if (macros.Count > 0)
@ -839,13 +910,16 @@ namespace DS4Windows
savePresets.InitialDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + @"\Macros\"; savePresets.InitialDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + @"\Macros\";
else else
savePresets.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + @"\Macros\"; savePresets.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + @"\Macros\";
if (!Directory.Exists(savePresets.InitialDirectory)) if (!Directory.Exists(savePresets.InitialDirectory))
{ {
Directory.CreateDirectory(savePresets.InitialDirectory); Directory.CreateDirectory(savePresets.InitialDirectory);
//savePresets.InitialDirectory = path; //savePresets.InitialDirectory = path;
} }
Console.WriteLine(savePresets.InitialDirectory); Console.WriteLine(savePresets.InitialDirectory);
if (savePresets.ShowDialog() == System.Windows.Forms.DialogResult.OK) if (savePresets.ShowDialog() == DialogResult.OK)
{
if ((stream = savePresets.OpenFile()) != null) if ((stream = savePresets.OpenFile()) != null)
{ {
string macro = string.Join("/", macros.ToArray()); string macro = string.Join("/", macros.ToArray());
@ -853,8 +927,12 @@ namespace DS4Windows
sw.Write(macro); sw.Write(macro);
sw.Close(); sw.Close();
} }
}
}
else
{
MessageBox.Show(Properties.Resources.NoMacroRecorded, "DS4Windows", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} }
else MessageBox.Show(Properties.Resources.NoMacroRecorded, "DS4Windows", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} }
private void btnLoadP_Click(object sender, EventArgs e) private void btnLoadP_Click(object sender, EventArgs e)
@ -880,7 +958,8 @@ namespace DS4Windows
openPresets.InitialDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + @"\Macros\"; openPresets.InitialDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + @"\Macros\";
else else
openPresets.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + @"\Macros\"; openPresets.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + @"\Macros\";
if (openPresets.ShowDialog() == System.Windows.Forms.DialogResult.OK)
if (openPresets.ShowDialog() == DialogResult.OK)
{ {
string file = openPresets.FileName; string file = openPresets.FileName;
macros.Clear(); macros.Clear();
@ -893,6 +972,7 @@ namespace DS4Windows
if (int.TryParse(s, out temp)) if (int.TryParse(s, out temp))
macros.Add(temp); macros.Add(temp);
} }
LoadMacro(); LoadMacro();
sr.Close(); sr.Close();
} }
@ -911,7 +991,6 @@ namespace DS4Windows
void LoadMacro() void LoadMacro()
{ {
if (macros.Count > 0) if (macros.Count > 0)
{ {
bool[] keydown = new bool[286]; bool[] keydown = new bool[286];
@ -945,7 +1024,9 @@ namespace DS4Windows
lVMacros.Items.Add("Stop Rumble", 1); lVMacros.Items.Add("Stop Rumble", 1);
} }
else if (i >= 300) //ints over 300 used to delay else if (i >= 300) //ints over 300 used to delay
{
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", (i - 300).ToString()).Replace("*ms*", "ms"), 2); lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", (i - 300).ToString()).Replace("*ms*", "ms"), 2);
}
else if (!keydown[i]) else if (!keydown[i])
{ {
//anything above 255 is not a keyvalue //anything above 255 is not a keyvalue
@ -1018,6 +1099,7 @@ namespace DS4Windows
keydown[i] = false; keydown[i] = false;
} }
} }
for (int i = 0; i < keydown.Length; i++) for (int i = 0; i < keydown.Length; i++)
{ {
if (keydown[i]) if (keydown[i])
@ -1059,13 +1141,15 @@ namespace DS4Windows
} }
} }
private void RecordBox_FormClosing(object sender, FormClosingEventArgs e) private void RecordBox_FormClosing(object sender, FormClosingEventArgs e)
{ {
if (!saved && macros.Count > 0) if (!saved && macros.Count > 0)
if (MessageBox.Show(Properties.Resources.SaveRecordedMacro, "DS4Windows", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) {
if (MessageBox.Show(Properties.Resources.SaveRecordedMacro, "DS4Windows", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
btnSave_Click(null, null); btnSave_Click(null, null);
}
Program.rootHub.recordingMacro = false;
} }
protected override bool IsInputKey(Keys keyData) protected override bool IsInputKey(Keys keyData)
@ -1091,8 +1175,10 @@ namespace DS4Windows
case Keys.Shift | Keys.MediaNextTrack: case Keys.Shift | Keys.MediaNextTrack:
return true; return true;
} }
return base.IsInputKey(keyData); return base.IsInputKey(keyData);
} }
protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyDown(KeyEventArgs e)
{ {
base.OnKeyDown(e); base.OnKeyDown(e);
@ -1116,11 +1202,14 @@ namespace DS4Windows
break; break;
} }
} }
private int selection; private int selection;
private bool changingDelay = false; private bool changingDelay = false;
private void lVMacros_MouseDoubleClick(object sender, MouseEventArgs e) private void lVMacros_MouseDoubleClick(object sender, MouseEventArgs e)
{ {
if (lVMacros.SelectedIndices[0] >= 0) if (lVMacros.SelectedIndices[0] >= 0)
{
if (lVMacros.SelectedItems[0].ImageIndex == 2) if (lVMacros.SelectedItems[0].ImageIndex == 2)
{ {
TextBox tb = new TextBox(); TextBox tb = new TextBox();
@ -1154,7 +1243,7 @@ namespace DS4Windows
} }
else if (macros[lVMacros.SelectedIndices[0]] > 1000000 && macros[lVMacros.SelectedIndices[0]] != 1000000000) else if (macros[lVMacros.SelectedIndices[0]] > 1000000 && macros[lVMacros.SelectedIndices[0]] != 1000000000)
{ {
lVMacros.MouseHover -= lVMacros_MouseHover; lVMacros.MouseHover -= lVMacros_MouseHover;
string r = macros[lVMacros.SelectedIndices[0]].ToString().Substring(1); string r = macros[lVMacros.SelectedIndices[0]].ToString().Substring(1);
byte heavy = (byte)(int.Parse(r[0].ToString()) * 100 + int.Parse(r[1].ToString()) * 10 + int.Parse(r[2].ToString())); byte heavy = (byte)(int.Parse(r[0].ToString()) * 100 + int.Parse(r[1].ToString()) * 10 + int.Parse(r[2].ToString()));
@ -1183,6 +1272,7 @@ namespace DS4Windows
tb2.TextChanged += tb_TextChanged; tb2.TextChanged += tb_TextChanged;
tb1.Focus(); tb1.Focus();
} }
}
} }
void tb_TextChanged(object sender, EventArgs e) void tb_TextChanged(object sender, EventArgs e)
@ -1191,8 +1281,10 @@ namespace DS4Windows
//if (changingDelay) //if (changingDelay)
{ {
for (int i = tb.Text.Length - 1; i >= 0; i--) for (int i = tb.Text.Length - 1; i >= 0; i--)
{
if (!char.IsDigit(tb.Text[i])) if (!char.IsDigit(tb.Text[i]))
tb.Text = tb.Text.Remove(i, 1); tb.Text = tb.Text.Remove(i, 1);
}
} }
} }
@ -1206,6 +1298,7 @@ namespace DS4Windows
if (e.KeyCode == Keys.Enter) if (e.KeyCode == Keys.Enter)
SaveMacroChange((TextBox)sender); SaveMacroChange((TextBox)sender);
} }
private void SaveMacroChange(TextBox tb) private void SaveMacroChange(TextBox tb)
{ {
int i, j; int i, j;
@ -1237,6 +1330,7 @@ namespace DS4Windows
} }
} }
} }
lVMacros.MouseHover += lVMacros_MouseHover; lVMacros.MouseHover += lVMacros_MouseHover;
} }
@ -1260,6 +1354,7 @@ namespace DS4Windows
private void lVMacros_SelectedIndexChanged(object sender, EventArgs e) private void lVMacros_SelectedIndexChanged(object sender, EventArgs e)
{ {
if (btnRecord.Text != Properties.Resources.StopText) if (btnRecord.Text != Properties.Resources.StopText)
{
if (lVMacros.SelectedIndices.Count > 0 && lVMacros.SelectedIndices[0] > -1) if (lVMacros.SelectedIndices.Count > 0 && lVMacros.SelectedIndices[0] > -1)
{ {
recordAfter = true; recordAfter = true;
@ -1271,7 +1366,7 @@ namespace DS4Windows
recordAfter = false; recordAfter = false;
btnRecord.Text = "Record"; btnRecord.Text = "Record";
} }
}
} }
} }
} }

View File

@ -77,7 +77,7 @@ namespace DS4Windows
try try
{ {
string[] ss = value.Split(','); string[] ss = value.Split(',');
return byte.TryParse(ss[0], out ds4color.red) &&byte.TryParse(ss[1], out ds4color.green) && byte.TryParse(ss[2], out ds4color.blue); return byte.TryParse(ss[0], out ds4color.red) && byte.TryParse(ss[1], out ds4color.green) && byte.TryParse(ss[2], out ds4color.blue);
} }
catch { return false; } catch { return false; }
} }
@ -115,7 +115,7 @@ namespace DS4Windows
private const int BT_OUTPUT_REPORT_LENGTH = 78; private const int BT_OUTPUT_REPORT_LENGTH = 78;
private const int BT_INPUT_REPORT_LENGTH = 547; private const int BT_INPUT_REPORT_LENGTH = 547;
// Use large value for worst case scenario // Use large value for worst case scenario
private const int READ_STREAM_TIMEOUT = 100; private const int READ_STREAM_TIMEOUT = 1000;
// Isolated BT report can have latency as high as 15 ms // Isolated BT report can have latency as high as 15 ms
// due to hardware. // due to hardware.
private const int WARN_INTERVAL_BT = 20; private const int WARN_INTERVAL_BT = 20;
@ -124,6 +124,7 @@ namespace DS4Windows
// and when a USB cable is connected // and when a USB cable is connected
private const int BATTERY_MAX = 8; private const int BATTERY_MAX = 8;
private const int BATTERY_MAX_USB = 11; private const int BATTERY_MAX_USB = 11;
public const string blankSerial = "00:00:00:00:00:00";
private HidDevice hDevice; private HidDevice hDevice;
private string Mac; private string Mac;
private DS4State cState = new DS4State(); private DS4State cState = new DS4State();
@ -132,7 +133,7 @@ namespace DS4Windows
private byte[] accel = new byte[6]; private byte[] accel = new byte[6];
private byte[] gyro = new byte[6]; private byte[] gyro = new byte[6];
private byte[] inputReport; private byte[] inputReport;
private byte[] inputReport2; //private byte[] inputReport2;
private byte[] btInputReport = null; private byte[] btInputReport = null;
private byte[] outputReportBuffer, outputReport; private byte[] outputReportBuffer, outputReport;
private readonly DS4Touchpad touchpad = null; private readonly DS4Touchpad touchpad = null;
@ -158,8 +159,12 @@ namespace DS4Windows
private bool exitOutputThread = false; private bool exitOutputThread = false;
private bool exitInputThread = false; private bool exitInputThread = false;
private object exitLocker = new object(); private object exitLocker = new object();
public event EventHandler<EventArgs> Report = null; public event EventHandler<EventArgs> Report = null;
public event EventHandler<EventArgs> Removal = null; public event EventHandler<EventArgs> Removal = null;
public event EventHandler<EventArgs> SyncChange = null;
public event EventHandler<EventArgs> SerialChange = null;
public event EventHandler<EventArgs> PublishRemoval = null;
public HidDevice HidDevice => hDevice; public HidDevice HidDevice => hDevice;
public bool IsExclusive => HidDevice.IsExclusive; public bool IsExclusive => HidDevice.IsExclusive;
@ -259,6 +264,12 @@ namespace DS4Windows
return lastTimeElapsed; return lastTimeElapsed;
} }
public double lastTimeElapsedDouble = 0.0;
public double getLastTimeElapsedDouble()
{
return lastTimeElapsedDouble;
}
public byte RightLightFastRumble public byte RightLightFastRumble
{ {
get { return rightLightFastRumble; } get { return rightLightFastRumble; }
@ -330,6 +341,34 @@ namespace DS4Windows
return ledFlashOff; return ledFlashOff;
} }
// Specify the poll rate interval used for the DS4 hardware when
// connected via Bluetooth
private int btPollRate = 0;
public int BTPollRate
{
get { return btPollRate; }
set
{
if (btPollRate != value && value >= 0 && value <= 16)
{
btPollRate = value;
}
}
}
public int getBTPollRate()
{
return btPollRate;
}
public void setBTPollRate(int value)
{
if (btPollRate != value && value >= 0 && value <= 16)
{
btPollRate = value;
}
}
public DS4Touchpad Touchpad { get { return touchpad; } } public DS4Touchpad Touchpad { get { return touchpad; } }
public DS4SixAxis SixAxis { get { return sixAxis; } } public DS4SixAxis SixAxis { get { return sixAxis; } }
@ -352,6 +391,21 @@ namespace DS4Windows
} }
private SynchronizationContext uiContext = null; private SynchronizationContext uiContext = null;
public SynchronizationContext getUiContext()
{
return uiContext;
}
public void setUiContext(SynchronizationContext uiContext)
{
this.uiContext = uiContext;
}
private Queue<Action> eventQueue = new Queue<Action>();
private object eventQueueLock = new object();
private Thread timeoutCheckThread = null;
private bool timeoutExecuted = false;
private bool timeoutEvent = false;
public DS4Device(HidDevice hidDevice) public DS4Device(HidDevice hidDevice)
{ {
@ -361,18 +415,20 @@ namespace DS4Windows
if (conType == ConnectionType.USB || conType == ConnectionType.SONYWA) if (conType == ConnectionType.USB || conType == ConnectionType.SONYWA)
{ {
inputReport = new byte[64]; inputReport = new byte[64];
inputReport2 = new byte[64]; //inputReport2 = new byte[64];
outputReport = new byte[hDevice.Capabilities.OutputReportByteLength]; outputReport = new byte[hDevice.Capabilities.OutputReportByteLength];
outputReportBuffer = new byte[hDevice.Capabilities.OutputReportByteLength]; outputReportBuffer = new byte[hDevice.Capabilities.OutputReportByteLength];
if (conType == ConnectionType.USB) if (conType == ConnectionType.USB)
{ {
warnInterval = WARN_INTERVAL_USB; warnInterval = WARN_INTERVAL_USB;
synced = true;
} }
else else
{ {
warnInterval = WARN_INTERVAL_BT; warnInterval = WARN_INTERVAL_BT;
audio = new DS4Audio(); audio = new DS4Audio();
micAudio = new DS4Audio(DS4Library.CoreAudio.DataFlow.Render); micAudio = new DS4Audio(DS4Library.CoreAudio.DataFlow.Capture);
synced = isValidSerial();
} }
} }
else else
@ -382,11 +438,28 @@ namespace DS4Windows
outputReport = new byte[BT_OUTPUT_REPORT_LENGTH]; outputReport = new byte[BT_OUTPUT_REPORT_LENGTH];
outputReportBuffer = new byte[BT_OUTPUT_REPORT_LENGTH]; outputReportBuffer = new byte[BT_OUTPUT_REPORT_LENGTH];
warnInterval = WARN_INTERVAL_BT; warnInterval = WARN_INTERVAL_BT;
synced = isValidSerial();
} }
touchpad = new DS4Touchpad(); touchpad = new DS4Touchpad();
sixAxis = new DS4SixAxis(); sixAxis = new DS4SixAxis();
uiContext = SynchronizationContext.Current; }
private void timeoutTestThread()
{
while (!timeoutExecuted)
{
if (timeoutEvent)
{
timeoutExecuted = true;
this.sendOutputReport(true); // Kick Windows into noticing the disconnection.
}
else
{
timeoutEvent = true;
Thread.Sleep(READ_STREAM_TIMEOUT);
}
}
} }
public void StartUpdate() public void StartUpdate()
@ -410,6 +483,10 @@ namespace DS4Windows
ds4Output.Name = "DS4 Output thread: " + Mac; ds4Output.Name = "DS4 Output thread: " + Mac;
ds4Output.IsBackground = true; ds4Output.IsBackground = true;
ds4Output.Start(); ds4Output.Start();
timeoutCheckThread = new Thread(timeoutTestThread);
timeoutCheckThread.IsBackground = true;
timeoutCheckThread.Start();
} }
ds4Input = new Thread(performDs4Input); ds4Input = new Thread(performDs4Input);
@ -479,7 +556,8 @@ namespace DS4Windows
} }
else else
{ {
return hDevice.WriteAsyncOutputReportViaInterrupt(outputReport); return hDevice.WriteOutputReportViaInterrupt(outputReport, READ_STREAM_TIMEOUT);
//return hDevice.WriteAsyncOutputReportViaInterrupt(outputReport);
} }
} }
@ -503,7 +581,7 @@ namespace DS4Windows
if (lastError != thisError) if (lastError != thisError)
{ {
Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> encountered write failure: " + thisError); Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> encountered write failure: " + thisError);
Log.LogToGui(Mac.ToString() + " encountered write failure: " + thisError, true); //Log.LogToGui(Mac.ToString() + " encountered write failure: " + thisError, true);
lastError = thisError; lastError = thisError;
} }
} }
@ -539,42 +617,87 @@ namespace DS4Windows
} }
private byte priorInputReport30 = 0xff; private byte priorInputReport30 = 0xff;
public double Latency = 0;
private bool synced = false;
public bool Synced
{
get { return synced; }
set
{
if (synced != value)
{
synced = value;
}
}
}
public bool isSynced()
{
return synced;
}
public double Latency = 0.0;
public string error; public string error;
public bool firstReport = false; public bool firstReport = false;
public bool oldCharging = false;
double curTimeDouble = 0.0;
double oldTimeDouble = 0.0;
DateTime utcNow = DateTime.UtcNow;
bool ds4InactiveFrame = true;
bool idleInput = true;
private void performDs4Input() private void performDs4Input()
{ {
firstActive = DateTime.UtcNow; firstActive = DateTime.UtcNow;
NativeMethods.HidD_SetNumInputBuffers(hDevice.safeReadHandle.DangerousGetHandle(), 2); NativeMethods.HidD_SetNumInputBuffers(hDevice.safeReadHandle.DangerousGetHandle(), 2);
List<long> Latency = new List<long>(100); Queue<long> latencyQueue = new Queue<long>(51); // Set capacity at max + 1 to avoid any resizing
int tempLatencyCount = 0;
long oldtime = 0; long oldtime = 0;
string currerror = string.Empty;
long curtime = 0;
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
sw.Start(); sw.Start();
timeoutEvent = false;
ds4InactiveFrame = true;
idleInput = true;
int maxBatteryValue = 0;
int tempBattery = 0;
while (!exitInputThread) while (!exitInputThread)
{ {
string currerror = string.Empty; oldCharging = charging;
long curtime = sw.ElapsedMilliseconds; currerror = string.Empty;
this.lastTimeElapsed = curtime - oldtime; curTimeDouble = sw.Elapsed.TotalMilliseconds;
Latency.Add(this.lastTimeElapsed); curtime = sw.ElapsedMilliseconds;
if (tempLatencyCount >= 50)
{
latencyQueue.Dequeue();
tempLatencyCount--;
}
lastTimeElapsed = curtime - oldtime;
lastTimeElapsedDouble = (curTimeDouble - oldTimeDouble);
latencyQueue.Enqueue(this.lastTimeElapsed);
tempLatencyCount++;
oldtime = curtime; oldtime = curtime;
oldTimeDouble = curTimeDouble;
if (Latency.Count > 100) Latency = latencyQueue.Average();
Latency.RemoveAt(0);
this.Latency = Latency.Average();
if (conType == ConnectionType.BT) if (conType == ConnectionType.BT)
{ {
//HidDevice.ReadStatus res = hDevice.ReadFile(btInputReport); //HidDevice.ReadStatus res = hDevice.ReadFile(btInputReport);
HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(btInputReport, READ_STREAM_TIMEOUT); //HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(btInputReport, READ_STREAM_TIMEOUT);
HidDevice.ReadStatus res = hDevice.ReadWithFileStream(btInputReport);
timeoutEvent = false;
//HidDevice.ReadStatus res = hDevice.ReadFileOverlapped(btInputReport, READ_STREAM_TIMEOUT);
if (res == HidDevice.ReadStatus.Success) if (res == HidDevice.ReadStatus.Success)
{ {
Array.Copy(btInputReport, 2, inputReport, 0, inputReport.Length); Array.Copy(btInputReport, 2, inputReport, 0, inputReport.Length);
} }
else else
{ {
if (res == HidDevice.ReadStatus.WaitTimedOut) if (res == HidDevice.ReadStatus.WaitTimedOut)
{ {
Log.LogToGui(Mac.ToString() + " disconnected due to timeout", true); Log.LogToGui(Mac.ToString() + " disconnected due to timeout", true);
@ -583,7 +706,7 @@ namespace DS4Windows
{ {
int winError = Marshal.GetLastWin32Error(); int winError = Marshal.GetLastWin32Error();
Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + winError); Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + winError);
Log.LogToGui(Mac.ToString() + " disconnected due to read failure: " + winError, true); //Log.LogToGui(Mac.ToString() + " disconnected due to read failure: " + winError, true);
} }
sendOutputReport(true); // Kick Windows into noticing the disconnection. sendOutputReport(true); // Kick Windows into noticing the disconnection.
@ -594,15 +717,20 @@ namespace DS4Windows
Removal?.Invoke(this, EventArgs.Empty); Removal?.Invoke(this, EventArgs.Empty);
}), null); }), null);
return; //System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
//Removal?.Invoke(this, EventArgs.Empty);
timeoutExecuted = true;
return;
} }
} }
else else
{ {
//HidDevice.ReadStatus res = hDevice.ReadFile(inputReport); //HidDevice.ReadStatus res = hDevice.ReadFile(inputReport);
//Array.Clear(inputReport, 0, inputReport.Length); //Array.Clear(inputReport, 0, inputReport.Length);
HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(inputReport, READ_STREAM_TIMEOUT); //HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(inputReport, READ_STREAM_TIMEOUT);
HidDevice.ReadStatus res = hDevice.ReadWithFileStream(inputReport);
//HidDevice.ReadStatus res = hDevice.ReadFileOverlapped(inputReport, READ_STREAM_TIMEOUT);
if (res != HidDevice.ReadStatus.Success) if (res != HidDevice.ReadStatus.Success)
{ {
if (res == HidDevice.ReadStatus.WaitTimedOut) if (res == HidDevice.ReadStatus.WaitTimedOut)
@ -613,7 +741,7 @@ namespace DS4Windows
{ {
int winError = Marshal.GetLastWin32Error(); int winError = Marshal.GetLastWin32Error();
Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + winError); Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + winError);
Log.LogToGui(Mac.ToString() + " disconnected due to read failure: " + winError, true); //Log.LogToGui(Mac.ToString() + " disconnected due to read failure: " + winError, true);
} }
StopOutputUpdate(); StopOutputUpdate();
@ -623,6 +751,10 @@ namespace DS4Windows
Removal?.Invoke(this, EventArgs.Empty); Removal?.Invoke(this, EventArgs.Empty);
}), null); }), null);
//System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
//Removal?.Invoke(this, EventArgs.Empty);
timeoutExecuted = true;
return; return;
} }
else else
@ -632,12 +764,12 @@ namespace DS4Windows
} }
if (conType == ConnectionType.BT && btInputReport[0] != 0x11) if (conType == ConnectionType.BT && btInputReport[0] != 0x11)
{ {
//Received incorrect report, skip it //Received incorrect report, skip it
continue; continue;
} }
DateTime utcNow = System.DateTime.UtcNow; // timestamp with UTC in case system time zone changes utcNow = DateTime.UtcNow; // timestamp with UTC in case system time zone changes
resetHapticState(); resetHapticState();
cState.ReportTimeStamp = utcNow; cState.ReportTimeStamp = utcNow;
cState.LX = inputReport[1]; cState.LX = inputReport[1];
@ -678,21 +810,17 @@ namespace DS4Windows
cState.L1 = (inputReport[6] & (1 << 0)) != 0; cState.L1 = (inputReport[6] & (1 << 0)) != 0;
cState.PS = (inputReport[7] & (1 << 0)) != 0; cState.PS = (inputReport[7] & (1 << 0)) != 0;
cState.TouchButton = (inputReport[7] & (1 << 2 - 1)) != 0; cState.TouchButton = (inputReport[7] & 0x02) != 0;
cState.FrameCounter = (byte)(inputReport[7] >> 2); cState.FrameCounter = (byte)(inputReport[7] >> 2);
// Store Gyro and Accel values
Array.Copy(inputReport, 14, accel, 0, 6);
Array.Copy(inputReport, 20, gyro, 0, 6);
sixAxis.handleSixaxis(gyro, accel, cState);
try try
{ {
charging = (inputReport[30] & 0x10) != 0; charging = (inputReport[30] & 0x10) != 0;
int maxBatteryValue = charging ? BATTERY_MAX_USB : BATTERY_MAX; maxBatteryValue = charging ? BATTERY_MAX_USB : BATTERY_MAX;
int tempBattery = (inputReport[30] & 0x0f) * 100 / maxBatteryValue; tempBattery = (inputReport[30] & 0x0f) * 100 / maxBatteryValue;
battery = Math.Min((byte)tempBattery, (byte)100); battery = Math.Min((byte)tempBattery, (byte)100);
cState.Battery = (byte)battery; cState.Battery = (byte)battery;
//System.Diagnostics.Debug.WriteLine("CURRENT BATTERY: " + (inputReport[30] & 0x0f) + " | " + tempBattery + " | " + battery);
if (inputReport[30] != priorInputReport30) if (inputReport[30] != priorInputReport30)
{ {
priorInputReport30 = inputReport[30]; priorInputReport30 = inputReport[30];
@ -710,10 +838,12 @@ namespace DS4Windows
//for (int touches = inputReport[-1 + DS4Touchpad.TOUCHPAD_DATA_OFFSET - 1], touchOffset = 0; touches > 0; touches--, touchOffset += 9) //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.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.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.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.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; 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 // Even when idling there is still a touch packet indicating no touch 1 or 2
@ -722,6 +852,11 @@ namespace DS4Windows
} }
catch { currerror = "Index out of bounds: touchpad"; } catch { currerror = "Index out of bounds: touchpad"; }
// Store Gyro and Accel values
Array.Copy(inputReport, 13, gyro, 0, 6);
Array.Copy(inputReport, 19, accel, 0, 6);
sixAxis.handleSixaxis(gyro, accel, cState);
/* Debug output of incoming HID data: /* Debug output of incoming HID data:
if (cState.L2 == 0xff && cState.R2 == 0xff) if (cState.L2 == 0xff && cState.R2 == 0xff)
{ {
@ -729,28 +864,49 @@ namespace DS4Windows
for (int i = 0; i < inputReport.Length; i++) for (int i = 0; i < inputReport.Length; i++)
Console.Write(" " + inputReport[i].ToString("x2")); Console.Write(" " + inputReport[i].ToString("x2"));
Console.WriteLine(); Console.WriteLine();
} */ }
*/
bool ds4Idle = cState.FrameCounter == pState.FrameCounter; if (conType == ConnectionType.SONYWA)
if (!ds4Idle) {
bool controllerSynced = inputReport[31] == 0;
if (controllerSynced != synced)
{
synced = controllerSynced;
SyncChange?.Invoke(this, EventArgs.Empty);
}
}
ds4InactiveFrame = cState.FrameCounter == pState.FrameCounter;
if (!ds4InactiveFrame)
{ {
isRemoved = false; isRemoved = false;
} }
if (conType == ConnectionType.USB) if (conType == ConnectionType.USB)
{ {
lastActive = utcNow; if (idleTimeout == 0)
{
lastActive = utcNow;
}
else
{
idleInput = isDS4Idle();
if (!idleInput)
{
lastActive = utcNow;
}
}
} }
else else
{ {
bool shouldDisconnect = false; bool shouldDisconnect = false;
int idleTime = idleTimeout; if (!isRemoved && idleTimeout > 0)
if (!isRemoved && idleTime > 0)
{ {
bool idleInput = isDS4Idle(); idleInput = isDS4Idle();
if (idleInput) if (idleInput)
{ {
DateTime timeout = lastActive + TimeSpan.FromSeconds(idleTime); DateTime timeout = lastActive + TimeSpan.FromSeconds(idleTimeout);
if (!charging) if (!charging)
shouldDisconnect = utcNow >= timeout; shouldDisconnect = utcNow >= timeout;
} }
@ -771,7 +927,10 @@ namespace DS4Windows
if (conType == ConnectionType.BT) if (conType == ConnectionType.BT)
{ {
if (DisconnectBT(true)) if (DisconnectBT(true))
{
timeoutExecuted = true;
return; // all done return; // all done
}
} }
else if (conType == ConnectionType.SONYWA) else if (conType == ConnectionType.SONYWA)
{ {
@ -780,6 +939,16 @@ namespace DS4Windows
} }
} }
if (conType == ConnectionType.BT && oldCharging != charging)
{
if (Global.getQuickCharge() && charging)
{
DisconnectBT(true);
timeoutExecuted = true;
return;
}
}
if (Report != null) if (Report != null)
Report(this, EventArgs.Empty); Report(this, EventArgs.Empty);
@ -790,14 +959,25 @@ namespace DS4Windows
} }
sendOutputReport(syncWriteReport); sendOutputReport(syncWriteReport);
if (!string.IsNullOrEmpty(error))
error = string.Empty;
if (!string.IsNullOrEmpty(currerror)) if (!string.IsNullOrEmpty(currerror))
error = currerror; error = currerror;
else if (!string.IsNullOrEmpty(error))
error = string.Empty;
cState.CopyTo(pState); cState.CopyTo(pState);
lock (eventQueueLock)
{
Action tempAct = null;
for (int actInd = 0, actLen = eventQueue.Count; actInd < actLen; actInd++)
{
tempAct = eventQueue.Dequeue();
tempAct.Invoke();
}
}
} }
timeoutExecuted = true;
} }
public void FlushHID() public void FlushHID()
@ -813,31 +993,36 @@ namespace DS4Windows
if (conType == ConnectionType.BT) if (conType == ConnectionType.BT)
{ {
outputReportBuffer[0] = 0x11; outputReportBuffer[0] = 0x11;
outputReportBuffer[1] = 0x80; //outputReportBuffer[1] = 0x80;
outputReportBuffer[3] = 0xff; //outputReportBuffer[1] = 0x84;
outputReportBuffer[6] = rightLightFastRumble; //fast motor outputReportBuffer[1] = (byte)(0x80 | btPollRate); // input report rate
outputReportBuffer[7] = leftHeavySlowRumble; //slow motor // enable lightbar, rumble, flash
outputReportBuffer[8] = LightBarColor.red; //red outputReportBuffer[3] = 0xf7;
outputReportBuffer[9] = LightBarColor.green; //green outputReportBuffer[6] = rightLightFastRumble; // fast motor
outputReportBuffer[10] = LightBarColor.blue; //blue outputReportBuffer[7] = leftHeavySlowRumble; // slow motor
outputReportBuffer[11] = ledFlashOn; //flash on duration outputReportBuffer[8] = ligtBarColor.red; // red
outputReportBuffer[12] = ledFlashOff; //flash off duration outputReportBuffer[9] = ligtBarColor.green; // green
outputReportBuffer[10] = ligtBarColor.blue; // blue
outputReportBuffer[11] = ledFlashOn; // flash on duration
outputReportBuffer[12] = ledFlashOff; // flash off duration
} }
else else
{ {
outputReportBuffer[0] = 0x05; outputReportBuffer[0] = 0x05;
outputReportBuffer[1] = 0xff; // enable lightbar, rumble, flash
outputReportBuffer[4] = rightLightFastRumble; //fast motor outputReportBuffer[1] = 0xf7;
outputReportBuffer[5] = leftHeavySlowRumble; //slow motor outputReportBuffer[4] = rightLightFastRumble; // fast motor
outputReportBuffer[6] = LightBarColor.red; //red outputReportBuffer[5] = leftHeavySlowRumble; // slow motor
outputReportBuffer[7] = LightBarColor.green; //green outputReportBuffer[6] = ligtBarColor.red; // red
outputReportBuffer[8] = LightBarColor.blue; //blue outputReportBuffer[7] = ligtBarColor.green; // green
outputReportBuffer[9] = ledFlashOn; //flash on duration outputReportBuffer[8] = ligtBarColor.blue; // blue
outputReportBuffer[10] = ledFlashOff; //flash off duration outputReportBuffer[9] = ledFlashOn; // flash on duration
outputReportBuffer[10] = ledFlashOff; // flash off duration
if (conType == ConnectionType.SONYWA) if (conType == ConnectionType.SONYWA)
{ {
// Headphone volume levels // Headphone volume levels
outputReportBuffer[19] = outputReportBuffer[20] = Convert.ToByte(audio.getVolume()); outputReportBuffer[19] = outputReportBuffer[20] =
Convert.ToByte(audio.getVolume());
// Microphone volume level // Microphone volume level
outputReportBuffer[21] = Convert.ToByte(micAudio.getVolume()); outputReportBuffer[21] = Convert.ToByte(micAudio.getVolume());
} }
@ -857,7 +1042,7 @@ namespace DS4Windows
{ {
int winError = Marshal.GetLastWin32Error(); int winError = Marshal.GetLastWin32Error();
Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> encountered synchronous write failure: " + winError); Console.WriteLine(Mac.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> encountered synchronous write failure: " + winError);
Log.LogToGui(Mac.ToString() + " encountered synchronous write failure: " + winError, true); //Log.LogToGui(Mac.ToString() + " encountered synchronous write failure: " + winError, true);
quitOutputThread = true; quitOutputThread = true;
} }
} }
@ -941,6 +1126,8 @@ namespace DS4Windows
{ {
Removal?.Invoke(this, EventArgs.Empty); Removal?.Invoke(this, EventArgs.Empty);
}), null); }), null);
//System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
} }
} }
@ -972,6 +1159,9 @@ namespace DS4Windows
{ {
Removal?.Invoke(this, EventArgs.Empty); Removal?.Invoke(this, EventArgs.Empty);
}), null); }), null);
//System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
//Removal?.Invoke(this, EventArgs.Empty);
} }
else if (result && !remove) else if (result && !remove)
{ {
@ -1058,9 +1248,10 @@ namespace DS4Windows
// Use the "most recently set" haptic state for each of light bar/motor. // Use the "most recently set" haptic state for each of light bar/motor.
private void setHapticState() private void setHapticState()
{ {
DS4Color lightBarColor = LightBarColor; DS4Color lightBarColor = ligtBarColor;
byte lightBarFlashDurationOn = LightBarOnDuration, lightBarFlashDurationOff = LightBarOffDuration; byte lightBarFlashDurationOn = ledFlashOn, lightBarFlashDurationOff = ledFlashOff;
byte rumbleMotorStrengthLeftHeavySlow = LeftHeavySlowRumble, rumbleMotorStrengthRightLightFast = rightLightFastRumble; byte rumbleMotorStrengthLeftHeavySlow = leftHeavySlowRumble,
rumbleMotorStrengthRightLightFast = rightLightFastRumble;
int hapticLen = hapticState.Length; int hapticLen = hapticState.Length;
for (int i=0; i < hapticLen; i++) for (int i=0; i < hapticLen; i++)
{ {
@ -1082,11 +1273,11 @@ namespace DS4Windows
} }
} }
LightBarColor = lightBarColor; ligtBarColor = lightBarColor;
LightBarOnDuration = lightBarFlashDurationOn; ledFlashOn = lightBarFlashDurationOn;
LightBarOffDuration = lightBarFlashDurationOff; ledFlashOff = lightBarFlashDurationOff;
LeftHeavySlowRumble = rumbleMotorStrengthLeftHeavySlow; leftHeavySlowRumble = rumbleMotorStrengthLeftHeavySlow;
RightLightFastRumble = rumbleMotorStrengthRightLightFast; rightLightFastRumble = rumbleMotorStrengthRightLightFast;
} }
public void pushHapticState(DS4HapticState hs) public void pushHapticState(DS4HapticState hs)
@ -1103,7 +1294,7 @@ namespace DS4Windows
} }
override override
public String ToString() public string ToString()
{ {
return Mac; return Mac;
} }
@ -1117,5 +1308,34 @@ namespace DS4Windows
{ {
this.Report = null; this.Report = null;
} }
public void queueEvent(Action act)
{
lock (eventQueueLock)
{
eventQueue.Enqueue(act);
}
}
public void updateSerial()
{
hDevice.resetSerial();
string tempMac = hDevice.readSerial();
if (tempMac != Mac)
{
Mac = tempMac;
SerialChange?.Invoke(this, EventArgs.Empty);
}
}
public bool isValidSerial()
{
return !Mac.Equals(blankSerial);
}
public static bool isValidSerial(string test)
{
return !test.Equals(blankSerial);
}
} }
} }

View File

@ -10,7 +10,9 @@ namespace DS4Windows
public class DS4Devices public class DS4Devices
{ {
private static Dictionary<string, DS4Device> Devices = new Dictionary<string, DS4Device>(); private static Dictionary<string, DS4Device> Devices = new Dictionary<string, DS4Device>();
private static HashSet<String> DevicePaths = new HashSet<String>(); private static HashSet<string> DevicePaths = new HashSet<string>();
// Keep instance of opened exclusive mode devices not in use (Charging while using BT connection)
private static List<HidDevice> DisabledDevices = new List<HidDevice>();
public static bool isExclusiveMode = false; public static bool isExclusiveMode = false;
private static string devicePathToInstanceId(string devicePath) private static string devicePathToInstanceId(string devicePath)
@ -27,7 +29,7 @@ namespace DS4Windows
return deviceInstanceId; return deviceInstanceId;
} }
// enumerates ds4 controllers in the system // Enumerates ds4 controllers in the system
public static void findControllers() public static void findControllers()
{ {
lock (Devices) lock (Devices)
@ -39,6 +41,8 @@ namespace DS4Windows
hDevices = hDevices.OrderBy<HidDevice, ConnectionType>((HidDevice d) => { return DS4Device.HidConnectionType(d); }); hDevices = hDevices.OrderBy<HidDevice, ConnectionType>((HidDevice d) => { return DS4Device.HidConnectionType(d); });
List<HidDevice> tempList = hDevices.ToList(); List<HidDevice> tempList = hDevices.ToList();
purgeHiddenExclusiveDevices();
tempList.AddRange(DisabledDevices);
int devCount = tempList.Count(); int devCount = tempList.Count();
string devicePlural = "device" + (devCount == 0 || devCount > 1 ? "s" : ""); string devicePlural = "device" + (devCount == 0 || devCount > 1 ? "s" : "");
//Log.LogToGui("Found " + devCount + " possible " + devicePlural + ". Examining " + devicePlural + ".", false); //Log.LogToGui("Found " + devCount + " possible " + devicePlural + ". Examining " + devicePlural + ".", false);
@ -98,9 +102,21 @@ namespace DS4Windows
if (hDevice.IsOpen) if (hDevice.IsOpen)
{ {
string serial = hDevice.readSerial(); string serial = hDevice.readSerial();
bool validSerial = !serial.Equals("00:00:00:00:00:00"); bool validSerial = !serial.Equals(DS4Device.blankSerial);
if (Devices.ContainsKey(serial)) if (Devices.ContainsKey(serial))
continue; // happens when the BT endpoint already is open and the USB is plugged into the same host {
// happens when the BT endpoint already is open and the USB is plugged into the same host
if (isExclusiveMode && hDevice.IsExclusive &&
!DisabledDevices.Contains(hDevice))
{
// Grab reference to exclusively opened HidDevice so device
// stays hidden to other processes
DisabledDevices.Add(hDevice);
//DevicePaths.Add(hDevice.DevicePath);
}
continue;
}
else else
{ {
DS4Device ds4Device = new DS4Device(hDevice); DS4Device ds4Device = new DS4Device(hDevice);
@ -129,7 +145,7 @@ namespace DS4Windows
} }
} }
//returns DS4 controllers that were found and are running // Returns DS4 controllers that were found and are running
public static IEnumerable<DS4Device> getDS4Controllers() public static IEnumerable<DS4Device> getDS4Controllers()
{ {
lock (Devices) lock (Devices)
@ -156,23 +172,87 @@ namespace DS4Windows
Devices.Clear(); Devices.Clear();
DevicePaths.Clear(); DevicePaths.Clear();
DisabledDevices.Clear();
} }
} }
//called when devices is diconnected, timed out or has input reading failure // Called when devices is diconnected, timed out or has input reading failure
public static void On_Removal(object sender, EventArgs e) public static void On_Removal(object sender, EventArgs e)
{ {
lock (Devices) lock (Devices)
{ {
DS4Device device = (DS4Device)sender; DS4Device device = (DS4Device)sender;
device.HidDevice.CloseDevice(); if (device != null)
Devices.Remove(device.MacAddress); {
DevicePaths.Remove(device.HidDevice.DevicePath); device.HidDevice.CloseDevice();
Devices.Remove(device.MacAddress);
DevicePaths.Remove(device.HidDevice.DevicePath);
//purgeHiddenExclusiveDevices();
}
}
}
public static void UpdateSerial(object sender, EventArgs e)
{
lock (Devices)
{
DS4Device device = (DS4Device)sender;
if (device != null)
{
string serial = device.getMacAddress();
if (Devices.ContainsKey(serial))
{
Devices.Remove(serial);
device.updateSerial();
serial = device.getMacAddress();
Devices.Add(serial, device);
}
}
}
}
private static void purgeHiddenExclusiveDevices()
{
int disabledDevCount = DisabledDevices.Count;
if (disabledDevCount > 0)
{
List<HidDevice> disabledDevList = new List<HidDevice>();
for (int i = 0, arlen = disabledDevCount; i < arlen; i++)
{
HidDevice tempDev = DisabledDevices.ElementAt(i);
if (tempDev != null)
{
if (tempDev.IsOpen && tempDev.IsConnected)
{
disabledDevList.Add(tempDev);
}
else if (tempDev.IsOpen)
{
if (!tempDev.IsConnected)
{
try
{
tempDev.CloseDevice();
}
catch { }
}
if (DevicePaths.Contains(tempDev.DevicePath))
{
DevicePaths.Remove(tempDev.DevicePath);
}
}
}
}
DisabledDevices.Clear();
DisabledDevices.AddRange(disabledDevList);
} }
} }
public static void reEnableDevice(string deviceInstanceId) public static void reEnableDevice(string deviceInstanceId)
{ {
Stopwatch sw = new Stopwatch();
bool success; bool success;
Guid hidGuid = new Guid(); Guid hidGuid = new Guid();
NativeMethods.HidD_GetHidGuid(ref hidGuid); NativeMethods.HidD_GetHidGuid(ref hidGuid);
@ -207,7 +287,14 @@ namespace DS4Windows
throw new Exception("Error disabling device, error code = " + Marshal.GetLastWin32Error()); throw new Exception("Error disabling device, error code = " + Marshal.GetLastWin32Error());
} }
System.Threading.Thread.Sleep(50); sw.Start();
while (sw.ElapsedMilliseconds < 50)
{
// Use SpinWait to keep control of current thread. Using Sleep could potentially
// cause other events to get run out of order
System.Threading.Thread.SpinWait(100);
}
sw.Stop();
propChangeParams.stateChange = NativeMethods.DICS_ENABLE; propChangeParams.stateChange = NativeMethods.DICS_ENABLE;
success = NativeMethods.SetupDiSetClassInstallParams(deviceInfoSet, ref deviceInfoData, ref propChangeParams, Marshal.SizeOf(propChangeParams)); success = NativeMethods.SetupDiSetClassInstallParams(deviceInfoSet, ref deviceInfoData, ref propChangeParams, Marshal.SizeOf(propChangeParams));

View File

@ -5,45 +5,54 @@ namespace DS4Windows
public class SixAxisEventArgs : EventArgs public class SixAxisEventArgs : EventArgs
{ {
public readonly SixAxis sixAxis; public readonly SixAxis sixAxis;
public readonly System.DateTime timeStamp; public readonly DateTime timeStamp;
public SixAxisEventArgs(System.DateTime utcTimestamp, SixAxis sa) public SixAxisEventArgs(DateTime utcTimestamp, SixAxis sa)
{ {
sixAxis = sa; sixAxis = sa;
this.timeStamp = utcTimestamp; timeStamp = utcTimestamp;
} }
} }
public class SixAxis public class SixAxis
{ {
public readonly int gyroX, gyroY, gyroZ, deltaX, deltaY, deltaZ, accelX, accelY, accelZ; public readonly int gyroX, gyroY, gyroZ, deltaX, deltaY, deltaZ, accelX, accelY, accelZ;
public readonly int gyroXFull, gyroYFull, gyroZFull;
public readonly int accelXFull, accelYFull, accelZFull;
public readonly byte touchID; public readonly byte touchID;
public readonly SixAxis previousAxis; public readonly SixAxis previousAxis;
public SixAxis(int X, int Y, int Z, int aX, int aY, int aZ, SixAxis prevAxis = null) public SixAxis(int X, int Y, int Z, int aX, int aY, int aZ, SixAxis prevAxis = null)
{ {
gyroX = X; gyroX = X / 256;
gyroY = Y; gyroY = Y / 256;
gyroZ = Z; gyroZ = Z / 256;
accelX = aX; gyroXFull = X;
accelY = aY; gyroYFull = Y;
accelZ = aZ; gyroZFull = Z;
accelX = aX / 64;
accelY = aY / 64;
accelZ = aZ / 64;
accelXFull = aX;
accelYFull = aY;
accelZFull = aZ;
previousAxis = prevAxis; previousAxis = prevAxis;
if (previousAxis != null) if (previousAxis != null)
{ {
deltaX = X - previousAxis.gyroX; deltaX = gyroX - previousAxis.gyroX;
deltaY = Y - previousAxis.gyroY; deltaY = gyroY - previousAxis.gyroY;
deltaZ = Z - previousAxis.gyroZ; deltaZ = gyroZ - previousAxis.gyroZ;
} }
} }
} }
public class DS4SixAxis public class DS4SixAxis
{ {
public event EventHandler<SixAxisEventArgs> SixAxisMoved = null; // deltaX/deltaY are set because one or both fingers were already down on a prior sensor reading //public event EventHandler<SixAxisEventArgs> SixAxisMoved = null; // deltaX/deltaY are set because one or both fingers were already down on a prior sensor reading
public event EventHandler<SixAxisEventArgs> SixAccelMoved = 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<SixAxisEventArgs> SixAccelMoved = null; // no status change for the touchpad itself... but other sensors may have changed, or you may just want to do some processing
internal int lastGyroX, lastGyroY, lastGyroZ, lastAX, lastAY, lastAZ; // tracks 0, 1 or 2 touches; we maintain touch 1 and 2 separately internal int lastGyroX, lastGyroY, lastGyroZ, lastAX, lastAY, lastAZ; // tracks 0, 1 or 2 touches; we maintain touch 1 and 2 separately
internal byte[] previousPacket = new byte[8]; internal byte[] previousPacket = new byte[8];
public void handleSixaxis(byte[] gyro, byte[] accel, DS4State state) public void handleSixaxis(byte[] gyro, byte[] accel, DS4State state)
{ {
@ -56,12 +65,14 @@ namespace DS4Windows
}*/ }*/
/* byte touchID1 = (byte)(data[0 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F); /* byte touchID1 = (byte)(data[0 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F);
byte touchID2 = (byte)(data[4 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F);*/ byte touchID2 = (byte)(data[4 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F);*/
int currentX = (short)((ushort)(gyro[0] << 8) | gyro[1]) / 64;
int currentY = (short)((ushort)(gyro[2] << 8) | gyro[3]) / 64; int currentX = (short)((ushort)(gyro[3] << 8) | gyro[2]); // Gyro Pitch
int currentZ = (short)((ushort)(gyro[4] << 8) | gyro[5]) / 64; int currentY = (short)((ushort)(gyro[1] << 8) | gyro[0]); // Gyro Yaw
int AccelX = (short)((ushort)(accel[2] << 8) | accel[3]) / 256; int currentZ = (short)((ushort)(gyro[5] << 8) | gyro[4]); // Gyro Roll
int AccelY = (short)((ushort)(accel[0] << 8) | accel[1]) / 256; int AccelX = (short)((ushort)(accel[1] << 8) | accel[0]); // Accel Pitch
int AccelZ = (short)((ushort)(accel[4] << 8) | accel[5]) / 256; int AccelY = (short)((ushort)(accel[3] << 8) | accel[2]); // Accel Roll
int AccelZ = (short)((ushort)(accel[5] << 8) | accel[4]); // Accel Yaw
SixAxisEventArgs args; SixAxisEventArgs args;
//if (sensors.Touch1 || sensors.Touch2) //if (sensors.Touch1 || sensors.Touch2)
{ {

View File

@ -8,7 +8,7 @@ namespace DS4Windows
public bool Square, Triangle, Circle, Cross; public bool Square, Triangle, Circle, Cross;
public bool DpadUp, DpadDown, DpadLeft, DpadRight; public bool DpadUp, DpadDown, DpadLeft, DpadRight;
public bool L1, L3, R1, R3; 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 Touch1Identifier, Touch2Identifier;
public byte LX, RX, LY, RY, L2, R2; public byte LX, RX, LY, RY, L2, R2;
public byte FrameCounter; // 0, 1, 2...62, 63, 0.... public byte FrameCounter; // 0, 1, 2...62, 63, 0....
@ -16,6 +16,12 @@ namespace DS4Windows
public byte Battery; // 0 for charging, 10/20/30/40/50/60/70/80/90/100 for percentage of full public byte Battery; // 0 for charging, 10/20/30/40/50/60/70/80/90/100 for percentage of full
public double LSAngle; // Calculated bearing of the LS X,Y coordinates public double LSAngle; // Calculated bearing of the LS X,Y coordinates
public double RSAngle; // Calculated bearing of the RS X,Y coordinates public double RSAngle; // Calculated bearing of the RS X,Y coordinates
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;
public static readonly int DEFAULT_AXISDIR_VALUE = 127; public static readonly int DEFAULT_AXISDIR_VALUE = 127;
public DS4State() public DS4State()
@ -23,14 +29,21 @@ namespace DS4Windows
Square = Triangle = Circle = Cross = false; Square = Triangle = Circle = Cross = false;
DpadUp = DpadDown = DpadLeft = DpadRight = false; DpadUp = DpadDown = DpadLeft = DpadRight = false;
L1 = L3 = R1 = R3 = false; L1 = L3 = R1 = R3 = false;
Share = Options = PS = Touch1 = Touch2 = TouchButton = TouchRight = TouchLeft = false; Share = Options = PS = Touch1 = Touch2 = TouchButton = TouchRight = TouchLeft = false;
Touch1Finger = Touch2Fingers = false;
LX = RX = LY = RY = 127; LX = RX = LY = RY = 127;
L2 = R2 = 0; L2 = R2 = 0;
FrameCounter = 255; // only actually has 6 bits, so this is a null indicator FrameCounter = 255; // only actually has 6 bits, so this is a null indicator
TouchPacketCounter = 255; // 8 bits, no great junk value TouchPacketCounter = 255; // 8 bits, no great junk value
Battery = 0; Battery = 0;
LSAngle = 0.0; LSAngle = 0.0;
LSAngleRad = 0.0;
RSAngle = 0.0; RSAngle = 0.0;
RSAngleRad = 0.0;
LXUnit = 0.0;
LYUnit = 0.0;
RXUnit = 0.0;
RYUnit = 0.0;
} }
public DS4State(DS4State state) public DS4State(DS4State state)
@ -61,6 +74,8 @@ namespace DS4Windows
Touch2Identifier = state.Touch2Identifier; Touch2Identifier = state.Touch2Identifier;
TouchButton = state.TouchButton; TouchButton = state.TouchButton;
TouchPacketCounter = state.TouchPacketCounter; TouchPacketCounter = state.TouchPacketCounter;
Touch1Finger = state.Touch1Finger;
Touch2Fingers = state.Touch2Fingers;
LX = state.LX; LX = state.LX;
RX = state.RX; RX = state.RX;
LY = state.LY; LY = state.LY;
@ -68,7 +83,13 @@ namespace DS4Windows
FrameCounter = state.FrameCounter; FrameCounter = state.FrameCounter;
Battery = state.Battery; Battery = state.Battery;
LSAngle = state.LSAngle; LSAngle = state.LSAngle;
LSAngleRad = state.LSAngleRad;
RSAngle = state.RSAngle; RSAngle = state.RSAngle;
RSAngleRad = state.RSAngleRad;
LXUnit = state.LXUnit;
LYUnit = state.LYUnit;
RXUnit = state.RXUnit;
RYUnit = state.RYUnit;
} }
public DS4State Clone() public DS4State Clone()
@ -104,6 +125,8 @@ namespace DS4Windows
state.TouchRight = TouchRight; state.TouchRight = TouchRight;
state.TouchButton = TouchButton; state.TouchButton = TouchButton;
state.TouchPacketCounter = TouchPacketCounter; state.TouchPacketCounter = TouchPacketCounter;
state.Touch1Finger = Touch1Finger;
state.Touch2Fingers = Touch2Fingers;
state.LX = LX; state.LX = LX;
state.RX = RX; state.RX = RX;
state.LY = LY; state.LY = LY;
@ -111,18 +134,50 @@ namespace DS4Windows
state.FrameCounter = FrameCounter; state.FrameCounter = FrameCounter;
state.Battery = Battery; state.Battery = Battery;
state.LSAngle = LSAngle; state.LSAngle = LSAngle;
state.LSAngleRad = LSAngleRad;
state.RSAngle = RSAngle; state.RSAngle = RSAngle;
state.RSAngleRad = RSAngleRad;
state.LXUnit = LXUnit;
state.LYUnit = LYUnit;
state.RXUnit = RXUnit;
state.RYUnit = RYUnit;
} }
public void calculateStickAngles() public void calculateStickAngles()
{ {
double lsangle = Math.Atan2((LX - 127), -(LY - 127)); double lsangle = Math.Atan2((LX - 127), -(LY - 127));
LSAngleRad = lsangle;
lsangle = (lsangle >= 0 ? lsangle : (2 * Math.PI + lsangle)) * 180 / Math.PI; lsangle = (lsangle >= 0 ? lsangle : (2 * Math.PI + lsangle)) * 180 / Math.PI;
LSAngle = lsangle; LSAngle = lsangle;
LXUnit = Math.Abs(Math.Cos(LSAngleRad));
LYUnit = Math.Abs(Math.Sin(LSAngleRad));
double rsangle = Math.Atan2((RX - 127), -(RY - 127)); double rsangle = Math.Atan2((RX - 127), -(RY - 127));
RSAngleRad = rsangle;
rsangle = (rsangle >= 0 ? rsangle : (2 * Math.PI + rsangle)) * 180 / Math.PI; rsangle = (rsangle >= 0 ? rsangle : (2 * Math.PI + rsangle)) * 180 / Math.PI;
RSAngle = rsangle; RSAngle = rsangle;
RXUnit = Math.Abs(Math.Cos(RSAngleRad));
RYUnit = Math.Abs(Math.Sin(LSAngleRad));
}
public void rotateLSCoordinates(double rotation)
{
double sinAngle = Math.Sin(rotation), cosAngle = Math.Cos(rotation);
double tempLX = LX - 127.5, tempLY = LY - 127.5;
Byte tempx = (Byte)(tempLX * cosAngle - tempLY * sinAngle + 127.5);
Byte tempy = (Byte)(tempLX * sinAngle + tempLY * cosAngle + 127.5);
LX = tempx;
LY = tempy;
}
public void rotateRSCoordinates(double rotation)
{
double sinAngle = Math.Sin(rotation), cosAngle = Math.Cos(rotation);
double tempRX = RX - 127.5, tempRY = RY - 127.5;
Byte tempx = (Byte)(tempRX * cosAngle - tempRY * sinAngle + 127.5);
Byte tempy = (Byte)(tempRX * sinAngle + tempRY * cosAngle + 127.5);
RX = tempx;
RY = tempy;
} }
} }
} }

View File

@ -34,6 +34,8 @@ namespace DS4Windows
bool Touch1 { get { return _state.Touch1; } } bool Touch1 { get { return _state.Touch1; } }
bool Touch2 { get { return _state.Touch2; } } bool Touch2 { get { return _state.Touch2; } }
bool TouchButton { get { return _state.TouchButton; } } 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 LX { get { return _state.LX; } }
byte RX { get { return _state.RX; } } byte RX { get { return _state.RX; } }
byte LY { get { return _state.LY; } } byte LY { get { return _state.LY; } }
@ -58,38 +60,59 @@ namespace DS4Windows
/// <summary> Yaw leftward/counter-clockwise/turn to port or larboard side </summary> /// <summary> Yaw leftward/counter-clockwise/turn to port or larboard side </summary>
/// <remarks> Add double the previous result to this delta and divide by three.</remarks> /// <remarks> Add double the previous result to this delta and divide by three.</remarks>
public int AccelX { get { return (short)((ushort)(accel[2] << 8) | accel[3]) / 256; } } //public int AccelX { get { return (short)((ushort)(accel[2] << 8) | accel[3]) / 256; } }
//public int AccelX { get { return (short)((ushort)(accel[1] << 8) | accel[0]) / 64; } }
public int AccelX { get { return (short)((ushort)(gyro[3] << 8) | gyro[2]) / 256; } }
/// <summary> Pitch upward/backward </summary> /// <summary> Pitch upward/backward </summary>
/// <remarks> Add double the previous result to this delta and divide by three.</remarks> /// <remarks> Add double the previous result to this delta and divide by three.</remarks>
public int AccelY { get { return (short)((ushort)(accel[0] << 8) | accel[1] ) / 256; } } //public int AccelY { get { return (short)((ushort)(accel[0] << 8) | accel[1] ) / 256; } }
//public int AccelY { get { return (short)((ushort)(accel[3] << 8) | accel[2]) / 64; } }
public int AccelY { get { return (short)((ushort)(gyro[1] << 8) | gyro[0]) / 256; } }
/// <summary> roll left/L side of controller down/starboard raising up </summary> /// <summary> roll left/L side of controller down/starboard raising up </summary>
/// <remarks> Add double the previous result to this delta and divide by three.</remarks> /// <remarks> Add double the previous result to this delta and divide by three.</remarks>
public int AccelZ { get { return (short)((ushort)(accel[4] << 8) | accel[5]) / 256; } } //public int AccelZ { get { return (short)((ushort)(accel[4] << 8) | accel[5]) / 256; } }
//public int AccelZ { get { return (short)((ushort)(accel[5] << 8) | accel[4]) / 64; } }
public int AccelZ { get { return (short)((ushort)(gyro[5] << 8) | gyro[4]) / 256; } }
/// <summary> R side of controller upward </summary> /// <summary> R side of controller upward </summary>
/// <remarks> Add double the previous result to this delta and divide by three.</remarks> /// <remarks> Add double the previous result to this delta and divide by three.</remarks>
public int GyroX { get { return (short)((ushort)(gyro[0] << 8) | gyro[1]) / 64; } } //public int GyroX { get { return (short)((ushort)(gyro[0] << 8) | gyro[1]) / 64; } }
//public int GyroX { get { return (short)((ushort)(gyro[3] << 8) | gyro[2]) / 256; } }
public int GyroX { get { return (short)((ushort)(accel[1] << 8) | accel[0]) / 64; } }
public int getGyroX() public int getGyroX()
{ {
return (short)((ushort)(gyro[0] << 8) | gyro[1]) / 64; //return (short)((ushort)(gyro[0] << 8) | gyro[1]) / 64;
//return (short)((ushort)(gyro[3] << 8) | gyro[2]) / 256;
return (short)((ushort)(accel[1] << 8) | accel[0]) / 64;
} }
/// <summary> touchpad and button face side of controller upward </summary> /// <summary> touchpad and button face side of controller upward </summary>
/// <remarks> Add double the previous result to this delta and divide by three.</remarks> /// <remarks> Add double the previous result to this delta and divide by three.</remarks>
public int GyroY { get { return (short)((ushort)(gyro[2] << 8) | gyro[3]) / 64; } } //public int GyroY { get { return (short)((ushort)(gyro[2] << 8) | gyro[3]) / 64; } }
//public int GyroY { get { return (short)((ushort)(gyro[1] << 8) | gyro[0]) / 256; } }
public int GyroY { get { return (short)((ushort)(accel[3] << 8) | accel[2]) / 64; } }
public int getGyroY() public int getGyroY()
{ {
return (short)((ushort)(gyro[2] << 8) | gyro[3]) / 64; //return (short)((ushort)(gyro[2] << 8) | gyro[3]) / 64;
//return (short)((ushort)(gyro[1] << 8) | gyro[0]) / 256;
return (short)((ushort)(accel[3] << 8) | accel[2]) / 64;
} }
/// <summary> Audio/expansion ports upward and light bar/shoulders/bumpers/USB port downward </summary> /// <summary> Audio/expansion ports upward and light bar/shoulders/bumpers/USB port downward </summary>
/// <remarks> Add double the previous result to this delta and divide by three.</remarks> /// <remarks> Add double the previous result to this delta and divide by three.</remarks>
public int GyroZ { get { return (short)((ushort)(gyro[4] << 8) | gyro[5]) / 64; } } //public int GyroZ { get { return (short)((ushort)(gyro[4] << 8) | gyro[5]) / 64; } }
//public int GyroZ { get { return (short)((ushort)(gyro[5] << 8) | gyro[4]) / 256; } }
public int GyroZ { get { return (short)((ushort)(accel[5] << 8) | accel[4]) / 64; } }
public int getGyroZ() public int getGyroZ()
{ {
return (short)((ushort)(gyro[4] << 8) | gyro[5]) / 64; //return (short)((ushort)(gyro[4] << 8) | gyro[5]) / 64;
//return (short)((ushort)(gyro[5] << 8) | gyro[4]) / 256;
return (short)((ushort)(accel[5] << 8) | accel[4]) / 64;
} }
} }
} }

View File

@ -5,9 +5,9 @@ namespace DS4Windows
public class TouchpadEventArgs : EventArgs public class TouchpadEventArgs : EventArgs
{ {
public readonly Touch[] touches = null; public readonly Touch[] touches = null;
public readonly System.DateTime timeStamp; public readonly DateTime timeStamp;
public readonly bool touchButtonPressed; 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) if (t1 != null)
{ {
@ -20,8 +20,9 @@ namespace DS4Windows
touches = new Touch[1]; touches = new Touch[1];
touches[0] = t0; touches[0] = t0;
} }
touchButtonPressed = tButtonDown; touchButtonPressed = tButtonDown;
this.timeStamp = utcTimestamp; timeStamp = utcTimestamp;
} }
} }
@ -30,7 +31,7 @@ namespace DS4Windows
public readonly int hwX, hwY, deltaX, deltaY; public readonly int hwX, hwY, deltaX, deltaY;
public readonly byte touchID; public readonly byte touchID;
public readonly Touch previousTouch; 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; hwX = X;
hwY = Y; 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> TouchButtonDown = null; // touchpad pushed down until the button clicks
public event EventHandler<TouchpadEventArgs> TouchButtonUp = null; // touchpad button released 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> 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; public readonly static int TOUCHPAD_DATA_OFFSET = 35;
internal int lastTouchPadX1, lastTouchPadY1, internal int lastTouchPadX1, lastTouchPadY1,
@ -65,18 +67,21 @@ namespace DS4Windows
private bool PacketChanged(byte[] data, int touchPacketOffset) private bool PacketChanged(byte[] data, int touchPacketOffset)
{ {
bool changed = false; 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]; byte oldValue = previousPacket[i];
previousPacket[i] = data[i + TOUCHPAD_DATA_OFFSET + touchPacketOffset]; previousPacket[i] = data[i + TOUCHPAD_DATA_OFFSET + touchPacketOffset];
if (previousPacket[i] != oldValue) if (previousPacket[i] != oldValue)
changed = true; changed = true;
} }
return changed; return changed;
} }
public void handleTouchpad(byte[] data, DS4State sensors, int touchPacketOffset = 0) public void handleTouchpad(byte[] data, DS4State sensors, int touchPacketOffset = 0)
{ {
PreTouchProcess?.Invoke(this, EventArgs.Empty);
bool touchPadIsDown = sensors.TouchButton; bool touchPadIsDown = sensors.TouchButton;
if (!PacketChanged(data, touchPacketOffset) && touchPadIsDown == lastTouchPadIsDown) if (!PacketChanged(data, touchPacketOffset) && touchPadIsDown == lastTouchPadIsDown)
{ {
@ -84,6 +89,7 @@ namespace DS4Windows
TouchUnchanged(this, EventArgs.Empty); TouchUnchanged(this, EventArgs.Empty);
return; return;
} }
byte touchID1 = (byte)(data[0 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F); byte touchID1 = (byte)(data[0 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F);
byte touchID2 = (byte)(data[4 + 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 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); t0 = new Touch(currentX2, currentY2, touchID2, tPrev);
t1 = null; t1 = null;
} }
args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0, t1); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0, t1);
TouchesMoved(this, args); TouchesMoved(this, args);
@ -169,6 +176,7 @@ namespace DS4Windows
lastTouchPadX2 = currentX2; lastTouchPadX2 = currentX2;
lastTouchPadY2 = currentY2; lastTouchPadY2 = currentY2;
} }
lastTouchPadIsDown = touchPadIsDown; lastTouchPadIsDown = touchPadIsDown;
} }
else else

View File

@ -242,6 +242,25 @@ namespace DS4Windows
} }
} }
public ReadStatus ReadWithFileStream(byte[] inputBuffer)
{
try
{
if (fileStream.Read(inputBuffer, 0, inputBuffer.Length) > 0)
{
return ReadStatus.Success;
}
else
{
return ReadStatus.NoDataRead;
}
}
catch (Exception)
{
return ReadStatus.ReadError;
}
}
public ReadStatus ReadWithFileStream(byte[] inputBuffer, int timeout) public ReadStatus ReadWithFileStream(byte[] inputBuffer, int timeout)
{ {
try try
@ -452,6 +471,11 @@ namespace DS4Windows
return NativeMethods.HidD_GetFeature(safeReadHandle.DangerousGetHandle(), inputBuffer, inputBuffer.Length); return NativeMethods.HidD_GetFeature(safeReadHandle.DangerousGetHandle(), inputBuffer, inputBuffer.Length);
} }
public void resetSerial()
{
serial = null;
}
public string readSerial() public string readSerial()
{ {
if (serial != null) if (serial != null)

View File

@ -15,15 +15,14 @@ namespace DS4Windows
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd); static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
// Add "global\" in front of the EventName, then only one instance is allowed on the // Add "global\" in front of the EventName, then only one instance is allowed on the
// whole system, including other users. But the application can not be brought // whole system, including other users. But the application can not be brought
// into view, of course. // into view, of course.
private static String SingleAppComEventName = "{a52b5b20-d9ee-4f32-8518-307fa14aa0c6}"; private static string SingleAppComEventName = "{a52b5b20-d9ee-4f32-8518-307fa14aa0c6}";
static Mutex mutex = new Mutex(true, "{FI329DM2-DS4W-J2K2-HYES-92H21B3WJARG}"); //static Mutex mutex = new Mutex(true, "{FI329DM2-DS4W-J2K2-HYES-92H21B3WJARG}");
private static BackgroundWorker singleAppComThread = null; private static BackgroundWorker singleAppComThread = null;
private static EventWaitHandle threadComEvent = null; private static EventWaitHandle threadComEvent = null;
private static bool exitComThread = false;
public static ControlService rootHub; public static ControlService rootHub;
/// <summary> /// <summary>
@ -72,11 +71,13 @@ namespace DS4Windows
return; return;
} }
} }
System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.LowLatency; System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.LowLatency;
try try
{ {
Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.High; Process.GetCurrentProcess().PriorityClass =
ProcessPriorityClass.High;
} }
catch catch
{ {
@ -94,20 +95,20 @@ namespace DS4Windows
catch { /* don't care about errors */ } catch { /* don't care about errors */ }
// Create the Event handle // Create the Event handle
threadComEvent = new EventWaitHandle(false, EventResetMode.AutoReset, SingleAppComEventName); threadComEvent = new EventWaitHandle(false, EventResetMode.ManualReset, SingleAppComEventName);
CreateInterAppComThread(); CreateInterAppComThread();
if (mutex.WaitOne(TimeSpan.Zero, true)) //if (mutex.WaitOne(TimeSpan.Zero, true))
{ //{
rootHub = new ControlService(); rootHub = new ControlService();
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new DS4Form(args)); Application.Run(new DS4Form(args));
mutex.ReleaseMutex(); //mutex.ReleaseMutex();
} //}
// End the communication thread. exitComThread = true;
singleAppComThread.CancelAsync(); threadComEvent.Set(); // signal the other instance.
while (singleAppComThread.IsBusy) while (singleAppComThread.IsBusy)
Thread.Sleep(50); Thread.Sleep(50);
threadComEvent.Close(); threadComEvent.Close();
@ -116,8 +117,8 @@ namespace DS4Windows
static private void CreateInterAppComThread() static private void CreateInterAppComThread()
{ {
singleAppComThread = new BackgroundWorker(); singleAppComThread = new BackgroundWorker();
singleAppComThread.WorkerReportsProgress = false; //singleAppComThread.WorkerReportsProgress = false;
singleAppComThread.WorkerSupportsCancellation = true; //singleAppComThread.WorkerSupportsCancellation = true;
singleAppComThread.DoWork += new DoWorkEventHandler(singleAppComThread_DoWork); singleAppComThread.DoWork += new DoWorkEventHandler(singleAppComThread_DoWork);
singleAppComThread.RunWorkerAsync(); singleAppComThread.RunWorkerAsync();
} }
@ -126,16 +127,18 @@ namespace DS4Windows
{ {
BackgroundWorker worker = sender as BackgroundWorker; BackgroundWorker worker = sender as BackgroundWorker;
WaitHandle[] waitHandles = new WaitHandle[] { threadComEvent }; WaitHandle[] waitHandles = new WaitHandle[] { threadComEvent };
Thread.CurrentThread.Priority = ThreadPriority.Lowest;
while (!worker.CancellationPending) while (!exitComThread)
{ {
// check every second for a signal. // check every second for a signal.
if (WaitHandle.WaitAny(waitHandles, 1000) == 0) if (WaitHandle.WaitAny(waitHandles) == 0)
{ {
threadComEvent.Reset();
// The user tried to start another instance. We can't allow that, // The user tried to start another instance. We can't allow that,
// so bring the other instance back into view and enable that one. // so bring the other instance back into view and enable that one.
// That form is created in another thread, so we need some thread sync magic. // That form is created in another thread, so we need some thread sync magic.
if (Application.OpenForms.Count > 0) if (!exitComThread && Application.OpenForms.Count > 0)
{ {
Form mainForm = Application.OpenForms[0]; Form mainForm = Application.OpenForms[0];
mainForm.Invoke(new SetFormVisableDelegate(ThreadFormVisable), mainForm); mainForm.Invoke(new SetFormVisableDelegate(ThreadFormVisable), mainForm);
@ -144,7 +147,6 @@ namespace DS4Windows
} }
} }
/// <summary> /// <summary>
/// When this method is called using a Invoke then this runs in the thread /// When this method is called using a Invoke then this runs in the thread
/// that created the form, which is nice. /// that created the form, which is nice.
@ -169,6 +171,7 @@ namespace DS4Windows
SetForegroundWindow(wp.form.Handle); SetForegroundWindow(wp.form.Handle);
} }
} }
SetForegroundWindow(frm.Handle); SetForegroundWindow(frm.Handle);
} }
} }

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.70")] [assembly: AssemblyVersion("1.4.84")]
[assembly: AssemblyFileVersion("1.4.70")] [assembly: AssemblyFileVersion("1.4.84")]

View File

@ -211,6 +211,15 @@ namespace DS4Windows.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Determines the poll rate used for the DS4 hardware when connected via Bluetooth.
/// </summary>
internal static string BTPollRate {
get {
return ResourceManager.GetString("BTPollRate", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Cannot move files to new location, Please rename the DS4Tool folder to &quot;DS4Windows&quot;. /// Looks up a localized string similar to Cannot move files to new location, Please rename the DS4Tool folder to &quot;DS4Windows&quot;.
/// </summary> /// </summary>
@ -265,6 +274,15 @@ namespace DS4Windows.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to This will disconnect all your connected controllers. Proceed?.
/// </summary>
internal static string CloseConfirm {
get {
return ResourceManager.GetString("CloseConfirm", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Close DS4Windows?. /// Looks up a localized string similar to Close DS4Windows?.
/// </summary> /// </summary>
@ -301,6 +319,15 @@ namespace DS4Windows.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Confirm....
/// </summary>
internal static string Confirm {
get {
return ResourceManager.GetString("Confirm", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Connecting.... /// Looks up a localized string similar to Connecting....
/// </summary> /// </summary>
@ -918,6 +945,15 @@ namespace DS4Windows.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Check to have gyro active while trigger is active. Uncheck to disable gyro while trigger is active..
/// </summary>
internal static string GyroTriggerBehavior {
get {
return ResourceManager.GetString("GyroTriggerBehavior", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to GyroX, Left and Right Tilt. /// Looks up a localized string similar to GyroX, Left and Right Tilt.
/// </summary> /// </summary>
@ -1112,7 +1148,7 @@ namespace DS4Windows.Properties {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Also dim light by idle timeout if on. /// Looks up a localized string similar to Also dim light by idle timeout if enabled when DS4 is fully charged.
/// </summary> /// </summary>
internal static string LightByBatteryTip { internal static string LightByBatteryTip {
get { get {

View File

@ -614,7 +614,7 @@
<value>Use Sixaxis to help calculate touchpad movement</value> <value>Use Sixaxis to help calculate touchpad movement</value>
</data> </data>
<data name="LightByBatteryTip" xml:space="preserve"> <data name="LightByBatteryTip" xml:space="preserve">
<value>Also dim light by idle timeout if on</value> <value>Also dim light by idle timeout if enabled when DS4 is fully charged</value>
</data> </data>
<data name="Macro" xml:space="preserve"> <data name="Macro" xml:space="preserve">
<value>Macro</value> <value>Macro</value>
@ -781,4 +781,16 @@
<data name="UACTask" xml:space="preserve"> <data name="UACTask" xml:space="preserve">
<value>You need to run DS4Windows as the Administrator in order to activate this mode.</value> <value>You need to run DS4Windows as the Administrator in order to activate this mode.</value>
</data> </data>
<data name="BTPollRate" xml:space="preserve">
<value>Determines the poll rate used for the DS4 hardware when connected via Bluetooth</value>
</data>
<data name="GyroTriggerBehavior" xml:space="preserve">
<value>Check to have gyro active while trigger is active. Uncheck to disable gyro while trigger is active.</value>
</data>
<data name="CloseConfirm" xml:space="preserve">
<value>This will disconnect all your connected controllers. Proceed?</value>
</data>
<data name="Confirm" xml:space="preserve">
<value>Confirm...</value>
</data>
</root> </root>

View File

@ -2,9 +2,9 @@
Like those other ds4tools, but sexier. Like those other ds4tools, but sexier.
DS4Windows is a portable program that allows you to get the best experience while using a DualShock 4 on your PC. By emulating a Xbox 360 controller, many more games are accessible. DS4Windows is a portable program that allows you to get the best DualShock 4 experience on your PC. By emulating a Xbox 360 controller, many more games are accessible.
You can find the latest and older versions [here](https://github.com/Jays2Kings/DS4Windows/releases). You can find the latest and older versions [here](https://github.com/Ryochan7/DS4Windows/releases).
## Requirements ## Requirements