Merge branch 'jay' into vigem-udpserver

# Conflicts:
#	DS4Windows/DS4Control/ControlService.cs
This commit is contained in:
Travis Nickles 2018-08-24 15:27:36 -05:00
commit d0a60155ec
6 changed files with 89 additions and 67 deletions

View File

@ -421,6 +421,7 @@ namespace DS4Windows
} }
} }
private SynchronizationContext uiContext = null;
public bool Start(object tempui, bool showlog = true) public bool Start(object tempui, bool showlog = true)
{ {
startViGEm(); startViGEm();
@ -433,6 +434,7 @@ namespace DS4Windows
LogDebug("Connection to ViGEm established"); LogDebug("Connection to ViGEm established");
DS4Devices.isExclusiveMode = getUseExclusiveMode(); DS4Devices.isExclusiveMode = getUseExclusiveMode();
uiContext = tempui as SynchronizationContext;
if (showlog) if (showlog)
{ {
LogDebug(Properties.Resources.SearchingController); LogDebug(Properties.Resources.SearchingController);
@ -466,7 +468,6 @@ namespace DS4Windows
task.Start(); task.Start();
DS4Controllers[i] = device; DS4Controllers[i] = device;
device.setUiContext(tempui as SynchronizationContext);
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 += this.On_SyncChange;
@ -653,7 +654,7 @@ namespace DS4Windows
return true; return true;
} }
public bool HotPlug(SynchronizationContext uiContext) public bool HotPlug()
{ {
if (running) if (running)
{ {
@ -690,7 +691,6 @@ namespace DS4Windows
Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); }); Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); });
task.Start(); task.Start();
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 += this.On_SyncChange;
@ -1142,7 +1142,7 @@ namespace DS4Windows
string devError = tempStrings[ind] = device.error; string devError = tempStrings[ind] = device.error;
if (!string.IsNullOrEmpty(devError)) if (!string.IsNullOrEmpty(devError))
{ {
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) uiContext?.Post(new SendOrPostCallback(delegate (object state)
{ {
LogDebug(devError); LogDebug(devError);
}), null); }), null);
@ -1154,7 +1154,7 @@ namespace DS4Windows
if (!lag[ind] && device.Latency >= flashWhenLateAt) if (!lag[ind] && device.Latency >= flashWhenLateAt)
{ {
lag[ind] = true; lag[ind] = true;
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) uiContext?.Post(new SendOrPostCallback(delegate (object state)
{ {
LagFlashWarning(ind, true); LagFlashWarning(ind, true);
}), null); }), null);
@ -1162,7 +1162,7 @@ namespace DS4Windows
else if (lag[ind] && device.Latency < flashWhenLateAt) else if (lag[ind] && device.Latency < flashWhenLateAt)
{ {
lag[ind] = false; lag[ind] = false;
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) uiContext?.Post(new SendOrPostCallback(delegate (object state)
{ {
LagFlashWarning(ind, false); LagFlashWarning(ind, false);
}), null); }), null);
@ -1185,7 +1185,7 @@ namespace DS4Windows
if (device.firstReport && device.IsAlive()) if (device.firstReport && device.IsAlive())
{ {
device.firstReport = false; device.firstReport = false;
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) uiContext?.Post(new SendOrPostCallback(delegate (object state)
{ {
OnDeviceStatusChanged(this, ind); OnDeviceStatusChanged(this, ind);
}), null); }), null);
@ -1194,7 +1194,7 @@ namespace DS4Windows
{ {
byte tempBattery = currentBattery[ind] = cState.Battery; byte tempBattery = currentBattery[ind] = cState.Battery;
bool tempCharging = charging[ind] = device.isCharging(); bool tempCharging = charging[ind] = device.isCharging();
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) uiContext?.Post(new SendOrPostCallback(delegate (object state)
{ {
OnBatteryStatusChange(this, ind, tempBattery, tempCharging); OnBatteryStatusChange(this, ind, tempBattery, tempCharging);
}), null); }), null);

View File

@ -246,7 +246,7 @@ namespace DS4Windows
*/ */
//tabProfiles.Controls.Add(opt); //tabProfiles.Controls.Add(opt);
autoProfilesTimer.Elapsed += CheckAutoProfiles; //autoProfilesTimer.Elapsed += CheckAutoProfiles;
autoProfilesTimer.Interval = 1000; autoProfilesTimer.Interval = 1000;
autoProfilesTimer.AutoReset = false; autoProfilesTimer.AutoReset = false;
@ -268,11 +268,12 @@ namespace DS4Windows
Enable_Controls(3, false); Enable_Controls(3, false);
btnStartStop.Text = Properties.Resources.StartText; btnStartStop.Text = Properties.Resources.StartText;
hotkeysTimer.Elapsed += Hotkeys; //hotkeysTimer.Elapsed += Hotkeys;
hotkeysTimer.AutoReset = false; hotkeysTimer.AutoReset = false;
if (SwipeProfiles) if (SwipeProfiles)
{ {
hotkeysTimer.Start(); ChangeHotkeysStatus(true);
//hotkeysTimer.Start();
} }
startToolStripMenuItem.Text = btnStartStop.Text; startToolStripMenuItem.Text = btnStartStop.Text;
@ -434,6 +435,34 @@ namespace DS4Windows
lbLastMessage.ForeColor = SystemColors.GrayText; lbLastMessage.ForeColor = SystemColors.GrayText;
} }
private void ChangeAutoProfilesStatus(bool state)
{
if (state)
{
autoProfilesTimer.Elapsed += CheckAutoProfiles;
autoProfilesTimer.Start();
}
else
{
autoProfilesTimer.Stop();
autoProfilesTimer.Elapsed -= CheckAutoProfiles;
}
}
private void ChangeHotkeysStatus(bool state)
{
if (state)
{
hotkeysTimer.Elapsed += Hotkeys;
hotkeysTimer.Start();
}
else
{
hotkeysTimer.Stop();
hotkeysTimer.Elapsed -= Hotkeys;
}
}
private void blankControllerTab() private void blankControllerTab()
{ {
for (int Index = 0, PadsLen = Pads.Length; for (int Index = 0, PadsLen = Pads.Length;
@ -535,30 +564,33 @@ namespace DS4Windows
string slide = Program.rootHub.TouchpadSlide(i); string slide = Program.rootHub.TouchpadSlide(i);
if (slide == "left") if (slide == "left")
{ {
int ind = i;
this.BeginInvoke((System.Action)(() => this.BeginInvoke((System.Action)(() =>
{ {
if (cbs[i].SelectedIndex <= 0) if (cbs[ind].SelectedIndex <= 0)
cbs[i].SelectedIndex = cbs[i].Items.Count - 2; cbs[ind].SelectedIndex = cbs[ind].Items.Count - 2;
else else
cbs[i].SelectedIndex--; cbs[ind].SelectedIndex--;
})); }));
} }
else if (slide == "right") else if (slide == "right")
{ {
int ind = i;
this.BeginInvoke((System.Action)(() => this.BeginInvoke((System.Action)(() =>
{ {
if (cbs[i].SelectedIndex == cbs[i].Items.Count - 2) if (cbs[ind].SelectedIndex == cbs[ind].Items.Count - 2)
cbs[i].SelectedIndex = 0; cbs[ind].SelectedIndex = 0;
else else
cbs[i].SelectedIndex++; cbs[ind].SelectedIndex++;
})); }));
} }
if (slide.Contains("t")) if (slide.Contains("t"))
{ {
int ind = i;
this.BeginInvoke((System.Action)(() => this.BeginInvoke((System.Action)(() =>
{ {
ShowNotification(this, Properties.Resources.UsingProfile.Replace("*number*", (i + 1).ToString()).Replace("*Profile name*", cbs[i].Text)); ShowNotification(this, Properties.Resources.UsingProfile.Replace("*number*", (ind + 1).ToString()).Replace("*Profile name*", cbs[ind].Text));
})); }));
} }
} }
@ -599,8 +631,10 @@ namespace DS4Windows
turnOffTemp = true; turnOffTemp = true;
if (btnStartStop.Text == Properties.Resources.StopText) if (btnStartStop.Text == Properties.Resources.StopText)
{ {
autoProfilesTimer.Stop(); //autoProfilesTimer.Stop();
hotkeysTimer.Stop(); //hotkeysTimer.Stop();
ChangeAutoProfilesStatus(false);
ChangeHotkeysStatus(false);
this.Invoke((System.Action)(() => { this.Invoke((System.Action)(() => {
this.changingService = true; this.changingService = true;
@ -614,8 +648,10 @@ namespace DS4Windows
this.Invoke((System.Action)(() => this.Invoke((System.Action)(() =>
{ {
hotkeysTimer.Start(); //hotkeysTimer.Start();
autoProfilesTimer.Start(); ChangeHotkeysStatus(true);
ChangeAutoProfilesStatus(true);
//autoProfilesTimer.Start();
})); }));
} }
} }
@ -688,11 +724,13 @@ namespace DS4Windows
bool timerEnabled = autoProfilesTimer.Enabled; bool timerEnabled = autoProfilesTimer.Enabled;
if (pathCount > 0 && !timerEnabled) if (pathCount > 0 && !timerEnabled)
{ {
autoProfilesTimer.Start(); ChangeAutoProfilesStatus(true);
//autoProfilesTimer.Start();
} }
else if (pathCount == 0 && timerEnabled) else if (pathCount == 0 && timerEnabled)
{ {
autoProfilesTimer.Stop(); //autoProfilesTimer.Stop();
ChangeAutoProfilesStatus(false);
} }
} }
@ -939,12 +977,14 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
{ {
if (SwipeProfiles && !hotkeysTimer.Enabled) if (SwipeProfiles && !hotkeysTimer.Enabled)
{ {
hotkeysTimer.Start(); ChangeHotkeysStatus(true);
//hotkeysTimer.Start();
} }
if (programpaths.Count > 0 && !autoProfilesTimer.Enabled) if (programpaths.Count > 0 && !autoProfilesTimer.Enabled)
{ {
autoProfilesTimer.Start(); ChangeAutoProfilesStatus(true);
//autoProfilesTimer.Start();
} }
startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StopText; startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StopText;
@ -963,8 +1003,10 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
private void ServiceShutdownFinish() private void ServiceShutdownFinish()
{ {
hotkeysTimer.Stop(); ChangeAutoProfilesStatus(false);
autoProfilesTimer.Stop(); ChangeHotkeysStatus(false);
//hotkeysTimer.Stop();
//autoProfilesTimer.Stop();
startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StartText; startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StartText;
blankControllerTab(); blankControllerTab();
populateFullNotifyText(); populateFullNotifyText();
@ -1007,11 +1049,10 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
hotplugCounter++; hotplugCounter++;
} }
var uiContext = SynchronizationContext.Current;
if (!inHotPlug) if (!inHotPlug)
{ {
inHotPlug = true; inHotPlug = true;
TaskRunner.Run(() => { Thread.Sleep(1500); InnerHotplug2(uiContext); }); TaskRunner.Run(() => { Thread.Sleep(1500); InnerHotplug2(); });
} }
} }
} }
@ -1025,7 +1066,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
base.WndProc(ref m); base.WndProc(ref m);
} }
private void InnerHotplug2(SynchronizationContext uiContext) private void InnerHotplug2()
{ {
inHotPlug = true; inHotPlug = true;
@ -1037,7 +1078,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
while (loopHotplug == true) while (loopHotplug == true)
{ {
Program.rootHub.HotPlug(uiContext); Program.rootHub.HotPlug();
//TaskRunner.Run(() => { Program.rootHub.HotPlug(uiContext); }); //TaskRunner.Run(() => { Program.rootHub.HotPlug(uiContext); });
lock (hotplugCounterLock) lock (hotplugCounterLock)
{ {
@ -2152,11 +2193,13 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
bool timerEnabled = hotkeysTimer.Enabled; bool timerEnabled = hotkeysTimer.Enabled;
if (swipe && !timerEnabled) if (swipe && !timerEnabled)
{ {
hotkeysTimer.Start(); ChangeHotkeysStatus(true);
//hotkeysTimer.Start();
} }
else if (!swipe && timerEnabled) else if (!swipe && timerEnabled)
{ {
hotkeysTimer.Stop(); ChangeHotkeysStatus(false);
//hotkeysTimer.Stop();
} }
} }

View File

@ -392,16 +392,6 @@ namespace DS4Windows
return result; return result;
} }
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 Queue<Action> eventQueue = new Queue<Action>();
private object eventQueueLock = new object(); private object eventQueueLock = new object();
@ -446,7 +436,7 @@ namespace DS4Windows
warnInterval = WARN_INTERVAL_BT; warnInterval = WARN_INTERVAL_BT;
audio = new DS4Audio(); audio = new DS4Audio();
micAudio = new DS4Audio(DS4Library.CoreAudio.DataFlow.Capture); micAudio = new DS4Audio(DS4Library.CoreAudio.DataFlow.Capture);
synced = isValidSerial(); runCalib = synced = isValidSerial();
} }
} }
else else
@ -808,10 +798,7 @@ namespace DS4Windows
sendOutputReport(true, true); // Kick Windows into noticing the disconnection. sendOutputReport(true, true); // Kick Windows into noticing the disconnection.
StopOutputUpdate(); StopOutputUpdate();
isDisconnecting = true; isDisconnecting = true;
uiContext.Send(new SendOrPostCallback(delegate (object state4) Removal?.Invoke(this, EventArgs.Empty);
{
Removal?.Invoke(this, EventArgs.Empty);
}), null);
timeoutExecuted = true; timeoutExecuted = true;
return; return;
@ -838,10 +825,7 @@ namespace DS4Windows
StopOutputUpdate(); StopOutputUpdate();
isDisconnecting = true; isDisconnecting = true;
uiContext.Send(new SendOrPostCallback(delegate (object state4) Removal?.Invoke(this, EventArgs.Empty);
{
Removal?.Invoke(this, EventArgs.Empty);
}), null);
timeoutExecuted = true; timeoutExecuted = true;
return; return;
@ -1016,7 +1000,7 @@ namespace DS4Windows
bool controllerSynced = inputReport[31] == 0; bool controllerSynced = inputReport[31] == 0;
if (controllerSynced != synced) if (controllerSynced != synced)
{ {
synced = controllerSynced; runCalib = synced = controllerSynced;
SyncChange?.Invoke(this, EventArgs.Empty); SyncChange?.Invoke(this, EventArgs.Empty);
sendOutputReport(true, true); sendOutputReport(true, true);
} }
@ -1292,10 +1276,7 @@ namespace DS4Windows
if (callRemoval) if (callRemoval)
{ {
uiContext.Send(new SendOrPostCallback(delegate (object state) Removal?.Invoke(this, EventArgs.Empty);
{
Removal?.Invoke(this, EventArgs.Empty);
}), null);
//System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); }); //System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
} }
@ -1327,10 +1308,7 @@ namespace DS4Windows
{ {
isDisconnecting = true; isDisconnecting = true;
uiContext.Send(new SendOrPostCallback(delegate (object state4) Removal?.Invoke(this, EventArgs.Empty);
{
Removal?.Invoke(this, EventArgs.Empty);
}), null);
//System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); }); //System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
//Removal?.Invoke(this, EventArgs.Empty); //Removal?.Invoke(this, EventArgs.Empty);

View File

@ -33,7 +33,7 @@ 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.5.6")] [assembly: AssemblyVersion("1.5.7")]
[assembly: AssemblyFileVersion("1.5.6")] [assembly: AssemblyFileVersion("1.5.7")]
[assembly: NeutralResourcesLanguage("en")] [assembly: NeutralResourcesLanguage("en")]

View File

@ -13,7 +13,7 @@ website at [ds4windows.com](http://ds4windows.com).
- **[Main builds of DS4Windows](https://github.com/Ryochan7/DS4Windows/releases)** - **[Main builds of DS4Windows](https://github.com/Ryochan7/DS4Windows/releases)**
- Alternative builds: - Alternative builds:
- [UdpServer ViGEm build](http://ryochan7.xyz/ds4windows/test/DS4Windows_1.5.5_ViGEm_UdpServer_x64.zip) - [UdpServer ViGEm build](http://ryochan7.xyz/ds4windows/test/DS4Windows_1.5.6_ViGEm_UdpServer_x64.zip)
## Requirements ## Requirements

View File

@ -1,8 +1,9 @@
# TODO # TODO
* ~~Perform some final cleanup and release version 1.5~~ * ~~Perform some final cleanup and release version 1.5~~
* Attempt to remove reliance on the main thread when disconnecting a device. * ~~Attempt to remove reliance on the main thread when disconnecting a device.
Currently used to delay hotplug routine Currently used to delay hotplug routine~~
* Look into newer version of HidGuardian
* Look into distributing profile properties around various objects * Look into distributing profile properties around various objects
rather than using a lot of getters to obtain properties each poll. rather than using a lot of getters to obtain properties each poll.
It will complicate the architecture a little bit but hopefully It will complicate the architecture a little bit but hopefully