From 12d1fe92312a8c1147b27e03fcee5025603bf1a5 Mon Sep 17 00:00:00 2001 From: jays2kings Date: Fri, 23 May 2014 19:44:30 -0400 Subject: [PATCH] Fix connecting issue, small ui/gui improvements, like the start with windows doesn't hide when small, there's a tooltip on the rainbow icon, and the lightbar shows the default light blue when stopping/closing ds4windows. The lightbar also doesn't go weird when charging and idle timeout is on. --- DS4Control/Control.cs | 34 +++++++++++++++++- DS4Control/DS4LightBar.cs | 2 +- DS4Tool/Hotkeys.cs | 4 ++- DS4Tool/Options.cs | 3 +- DS4Tool/Properties/Resources.resx | 8 ----- DS4Tool/Properties/Resources1.Designer.cs | 18 ---------- DS4Tool/ScpForm.Designer.cs | 21 ++--------- DS4Tool/ScpForm.cs | 44 +++++++++++++---------- 8 files changed, 67 insertions(+), 67 deletions(-) diff --git a/DS4Control/Control.cs b/DS4Control/Control.cs index e96c464..94fcbb6 100644 --- a/DS4Control/Control.cs +++ b/DS4Control/Control.cs @@ -205,13 +205,45 @@ namespace DS4Control Global.ControllerStatusChanged(this); } + public static void TimeoutConnection(DS4Device d) + { + try + { + System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); + sw.Start(); + while (!d.IsAlive()) + { + if (sw.ElapsedMilliseconds < 1000) + System.Threading.Thread.SpinWait(500); + //If weve been waiting less than 1 second let the thread keep its processing chunk + else + System.Threading.Thread.Sleep(500); + //If weve been waiting more than 1 second give up some resources + + if (sw.ElapsedMilliseconds > 5000) throw new TimeoutException(); //Weve waited long enough + } + sw.Reset(); + } + catch (TimeoutException e) + { + d.DisconnectBT(); + } + } + public string getDS4ControllerInfo(int index) { if (DS4Controllers[index] != null) { DS4Device d = DS4Controllers[index]; if (!d.IsAlive()) - return "Connecting..."; // awaiting the first battery charge indication + //return "Connecting..."; // awaiting the first battery charge indication + { + var TimeoutThread = new System.Threading.Thread(() => TimeoutConnection(d)); + TimeoutThread.IsBackground = true; + TimeoutThread.Name = "TimeoutFor" + d.MacAddress.ToString(); + TimeoutThread.Start(); + return "Connecting..."; + } String battery; if (d.Charging) { diff --git a/DS4Control/DS4LightBar.cs b/DS4Control/DS4LightBar.cs index 8a8cf82..408a743 100644 --- a/DS4Control/DS4LightBar.cs +++ b/DS4Control/DS4LightBar.cs @@ -72,7 +72,7 @@ namespace DS4Control color = Global.loadColor(deviceNum); } - if (Global.getIdleDisconnectTimeout(deviceNum) > 0) + if (Global.getIdleDisconnectTimeout(deviceNum) > 0 && !device.Charging) {//Fade lightbar by idle time TimeSpan timeratio = new TimeSpan(DateTime.UtcNow.Ticks - device.lastActive.Ticks); double botratio = timeratio.TotalMilliseconds; diff --git a/DS4Tool/Hotkeys.cs b/DS4Tool/Hotkeys.cs index beec1ba..ad84dd3 100644 --- a/DS4Tool/Hotkeys.cs +++ b/DS4Tool/Hotkeys.cs @@ -54,7 +54,9 @@ namespace ScpServer private void linkUninstall_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { - System.Diagnostics.Process.Start(Global.appdatapath + "\\Virtual Bus Driver\\ScpDriver.exe"); + if (System.IO.File.Exists(Global.appdatapath + "\\Virtual Bus Driver\\ScpDriver.exe")) + try { System.Diagnostics.Process.Start(Global.appdatapath + "\\Virtual Bus Driver\\ScpDriver.exe"); } + catch { System.Diagnostics.Process.Start(Global.appdatapath + "\\Virtual Bus Driver"); } } } } diff --git a/DS4Tool/Options.cs b/DS4Tool/Options.cs index d135163..0296164 100644 --- a/DS4Tool/Options.cs +++ b/DS4Tool/Options.cs @@ -119,7 +119,8 @@ namespace ScpServer tp.SetToolTip(cBDoubleTap, "Tap and hold to drag, slight delay with one tap"); tp.SetToolTip(btnLightbar, "Click to change color"); tp.SetToolTip(lBControlTip, "You can also use your controller to change controls"); - tp.SetToolTip(touchpadJitterCompensation, "Use Sixaxis to help calulate touchpad movement"); + tp.SetToolTip(touchpadJitterCompensation, "Use Sixaxis to help calulate touchpad movement"); + tp.SetToolTip(pBRainbow, "Always on Rainbow Mode"); advColorDialog.OnUpdateColor += advColorDialog_OnUpdateColor; btnLeftStick.Enter += btnSticks_Enter; btnRightStick.Enter += btnSticks_Enter; diff --git a/DS4Tool/Properties/Resources.resx b/DS4Tool/Properties/Resources.resx index ffca937..a26ee81 100644 --- a/DS4Tool/Properties/Resources.resx +++ b/DS4Tool/Properties/Resources.resx @@ -121,14 +121,6 @@ ..\Resources\DS4.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - Start - To be localized. - - - Stop - To be localized. - ..\Resources\360 fades.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/DS4Tool/Properties/Resources1.Designer.cs b/DS4Tool/Properties/Resources1.Designer.cs index a6eb09f..5c7cf75 100644 --- a/DS4Tool/Properties/Resources1.Designer.cs +++ b/DS4Tool/Properties/Resources1.Designer.cs @@ -160,15 +160,6 @@ namespace ScpServer.Properties { } } - /// - /// Looks up a localized string similar to Start. - /// - public static string Start { - get { - return ResourceManager.GetString("Start", resourceCulture); - } - } - /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -179,15 +170,6 @@ namespace ScpServer.Properties { } } - /// - /// Looks up a localized string similar to Stop. - /// - public static string Stop { - get { - return ResourceManager.GetString("Stop", resourceCulture); - } - } - /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/DS4Tool/ScpForm.Designer.cs b/DS4Tool/ScpForm.Designer.cs index aa3c047..3991b16 100644 --- a/DS4Tool/ScpForm.Designer.cs +++ b/DS4Tool/ScpForm.Designer.cs @@ -39,7 +39,6 @@ this.llbHelp = new System.Windows.Forms.LinkLabel(); this.btnStartStop = new System.Windows.Forms.Button(); this.btnClear = new System.Windows.Forms.Button(); - this.btnStop = new System.Windows.Forms.Button(); this.lnkControllers = new System.Windows.Forms.LinkLabel(); this.hideDS4CheckBox = new System.Windows.Forms.CheckBox(); this.startMinimizedCheckBox = new System.Windows.Forms.CheckBox(); @@ -125,7 +124,6 @@ this.pnlButton.Controls.Add(this.llbHelp); this.pnlButton.Controls.Add(this.btnStartStop); this.pnlButton.Controls.Add(this.btnClear); - this.pnlButton.Controls.Add(this.btnStop); this.pnlButton.Controls.Add(this.lnkControllers); this.pnlButton.Dock = System.Windows.Forms.DockStyle.Bottom; this.pnlButton.Location = new System.Drawing.Point(0, 477); @@ -177,19 +175,6 @@ this.btnClear.UseVisualStyleBackColor = true; this.btnClear.Click += new System.EventHandler(this.btnClear_Click); // - // btnStop - // - this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnStop.Enabled = false; - this.btnStop.Location = new System.Drawing.Point(710, 6); - this.btnStop.Name = "btnStop"; - this.btnStop.Size = new System.Drawing.Size(75, 23); - this.btnStop.TabIndex = 2; - this.btnStop.Text = "Stop"; - this.btnStop.UseVisualStyleBackColor = true; - this.btnStop.Visible = false; - this.btnStop.Click += new System.EventHandler(this.btnStop_Click); - // // lnkControllers // this.lnkControllers.AutoSize = true; @@ -517,11 +502,10 @@ // this.lbLastMessage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.lbLastMessage.ForeColor = System.Drawing.SystemColors.GrayText; - this.lbLastMessage.Location = new System.Drawing.Point(12, 106); + this.lbLastMessage.Location = new System.Drawing.Point(12, 110); this.lbLastMessage.Name = "lbLastMessage"; - this.lbLastMessage.Size = new System.Drawing.Size(551, 20); + this.lbLastMessage.Size = new System.Drawing.Size(434, 17); this.lbLastMessage.TabIndex = 41; - this.lbLastMessage.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; this.lbLastMessage.Visible = false; // // notifyIcon1 @@ -642,7 +626,6 @@ private System.Windows.Forms.ColumnHeader chData; private System.Windows.Forms.Timer tmrUpdate; private System.Windows.Forms.Panel pnlButton; - private System.Windows.Forms.Button btnStop; private System.Windows.Forms.Button btnStartStop; private System.Windows.Forms.Panel pnlDebug; private System.Windows.Forms.Button btnClear; diff --git a/DS4Tool/ScpForm.cs b/DS4Tool/ScpForm.cs index 22a21f7..407c69b 100644 --- a/DS4Tool/ScpForm.cs +++ b/DS4Tool/ScpForm.cs @@ -14,7 +14,7 @@ namespace ScpServer { private DS4Control.Control rootHub; delegate void LogDebugDelegate(DateTime Time, String Data); - double version = 7.412; + double version = 7.42; protected Label[] Pads; protected ComboBox[] cbs; @@ -260,11 +260,7 @@ namespace ScpServer else lbLastMessage.Visible = true; if (protexts != null) for (int i = 0; i < 4; i++) - if (this.Width > 665) - protexts[i].Visible = true; - else - protexts[i].Visible = false; - StartWindowsCheckBox.Visible = (this.Width > 665); + protexts[i].Visible = (this.Width > 665); } protected void btnStartStop_Click(object sender, EventArgs e) @@ -273,21 +269,27 @@ namespace ScpServer } protected void btnStartStop_Clicked() { - if (btnStartStop.Text == Properties.Resources.Start - && rootHub.Start()) - btnStartStop.Text = Properties.Resources.Stop; - else if (btnStartStop.Text == Properties.Resources.Stop - && rootHub.Stop()) - btnStartStop.Text = Properties.Resources.Start; - } - protected void btnStop_Click(object sender, EventArgs e) - { - if (rootHub.Stop()) + if (btnStartStop.Text == "Start") { - btnStartStop.Enabled = true; - btnStop.Enabled = false; + for (int i = 0; i < 4; i++) + Global.LoadProfile(i); + rootHub.Start(); + btnStartStop.Text = "Stop"; + } + + else if (btnStartStop.Text == "Stop") + { + for (int i = 0; i < 4; i++) + { + Global.setRainbow(i, 0); + Global.setLedAsBatteryIndicator(i, false); + Global.saveColor(i, 128, 255, 255); + } + rootHub.Stop(); + btnStartStop.Text = "Start"; } } + protected void btnClear_Click(object sender, EventArgs e) { lvDebug.Items.Clear(); @@ -571,6 +573,12 @@ namespace ScpServer Global.setFormWidth(this.Width); Global.setFormHeight(this.Height); Global.Save(); + for (int i = 0; i < 4; i++) + { + Global.setRainbow(i, 0); + Global.setLedAsBatteryIndicator(i, false); + Global.saveColor(i, 128, 255, 255); + } rootHub.Stop(); }