From 36f01ac30c6da6ba23771da5d45c82ac52fd286c Mon Sep 17 00:00:00 2001 From: jays2kings Date: Thu, 22 May 2014 15:13:38 -0400 Subject: [PATCH] When using Idle timeout, The lightbar now will fade as the controller sits idle. Added a decimal place to idle timeout so you can use half/etc. minutes now. Proper Display of percentages of dead-zones when reentering options --- DS4Control/DS4LightBar.cs | 15 ++++++++++++--- DS4Library/DS4Device.cs | 2 +- DS4Tool/Options.Designer.cs | 1 + DS4Tool/Options.cs | 20 ++++++++++---------- DS4Tool/ScpForm.cs | 4 ++-- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/DS4Control/DS4LightBar.cs b/DS4Control/DS4LightBar.cs index 78b2b53..8cb5181 100644 --- a/DS4Control/DS4LightBar.cs +++ b/DS4Control/DS4LightBar.cs @@ -25,19 +25,20 @@ namespace DS4Control static DateTime oldnow = DateTime.Now; public static void updateLightBar(DS4Device device, int deviceNum) { - DS4Color color; + DS4Color color; if (Global.getRainbow(deviceNum) > 0) {// Display rainbow DateTime now = DateTime.Now; if (now >= oldnow + TimeSpan.FromMilliseconds(10)) //update by the millisecond that way it's a smooth transtion { oldnow = now; - counters[deviceNum] += 1.5*3 / Global.getRainbow(deviceNum); + counters[deviceNum] += 1.5 * 3 / Global.getRainbow(deviceNum); } if (Global.getLedAsBatteryIndicator(deviceNum) && (device.Charging == false || device.Battery >= 100))// when charged, don't show the charging animation color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(2.55 * device.Battery)); else color = HuetoRGB((float)counters[deviceNum] % 360, 255); + } else if (Global.getLedAsBatteryIndicator(deviceNum)) { @@ -62,7 +63,7 @@ namespace DS4Control } else // Display rainbow when charging. { - counters[deviceNum]+= .167; + counters[deviceNum] += .167; color = HuetoRGB((float)counters[deviceNum] % 360, 255); } } @@ -71,6 +72,14 @@ namespace DS4Control color = Global.loadColor(deviceNum); } + if (Global.getIdleDisconnectTimeout(deviceNum) > 0) + {//Fade lightbar by idle time + TimeSpan timeratio = new TimeSpan(DateTime.Now.Ticks - device.lastActive.Ticks) + new TimeSpan(4, 0, 0); //The nows are off by 4 hours, not sure why... + double botratio = timeratio.TotalMilliseconds; + double topratio = TimeSpan.FromSeconds(Global.getIdleDisconnectTimeout(deviceNum)).TotalMilliseconds; + double ratio = ((botratio / topratio) * 100); + color = Global.getTransitionedColor(color, new DS4Color { red = 0, green = 0, blue = 0 }, (uint)ratio); + } DS4HapticState haptics = new DS4HapticState { LightBarColor = color diff --git a/DS4Library/DS4Device.cs b/DS4Library/DS4Device.cs index bd5c297..8cf07ec 100644 --- a/DS4Library/DS4Device.cs +++ b/DS4Library/DS4Device.cs @@ -67,7 +67,7 @@ namespace DS4Library private byte ledFlashOn, ledFlashOff; private Thread ds4Input, ds4Output; private int battery; - private DateTime lastActive = DateTime.UtcNow; + public DateTime lastActive = DateTime.UtcNow; private bool charging; public event EventHandler Report = null; public event EventHandler Removal = null; diff --git a/DS4Tool/Options.Designer.cs b/DS4Tool/Options.Designer.cs index cc9809a..d3984e6 100644 --- a/DS4Tool/Options.Designer.cs +++ b/DS4Tool/Options.Designer.cs @@ -1272,6 +1272,7 @@ // // idleDisconnectTimeout // + this.idleDisconnectTimeout.DecimalPlaces = 1; this.idleDisconnectTimeout.Location = new System.Drawing.Point(114, 247); this.idleDisconnectTimeout.Maximum = new decimal(new int[] { 60, diff --git a/DS4Tool/Options.cs b/DS4Tool/Options.cs index 67d0191..d135163 100644 --- a/DS4Tool/Options.cs +++ b/DS4Tool/Options.cs @@ -55,7 +55,7 @@ namespace ScpServer touchpadJitterCompensation.Checked = Global.getTouchpadJitterCompensation(device); cBlowerRCOn.Checked = Global.getLowerRCOn(device); flushHIDQueue.Checked = Global.getFlushHIDQueue(device); - idleDisconnectTimeout.Value = (int)(Global.getIdleDisconnectTimeout(device)/60); + idleDisconnectTimeout.Value = Math.Round((decimal)(Global.getIdleDisconnectTimeout(device) / 60d), 1); tBMouseSens.Value = Global.getButtonMouseSensitivity(device); lBMouseSens.Text = tBMouseSens.Value.ToString(); // Force update of color choosers @@ -79,8 +79,8 @@ namespace ScpServer pBRainbow.Image = colored; ToggleRainbow(true); } - numUDLS.Value = (decimal)Global.getLSDeadzone(device) / 127; - numUDRS.Value = (decimal)Global.getRSDeadzone(device) / 127; + numUDLS.Value = Math.Round((decimal)(Global.getLSDeadzone(device) / 127d ), 3); + numUDRS.Value = Math.Round((decimal)(Global.getRSDeadzone(device) / 127d ), 3); } else Set(); @@ -216,8 +216,8 @@ namespace ScpServer { Global.saveColor(device, (byte)redBar.Value, (byte)greenBar.Value, (byte)blueBar.Value); Global.saveLowColor(device, (byte)lowRedBar.Value, (byte)lowGreenBar.Value, (byte)lowBlueBar.Value); - Global.setLeftTriggerMiddle(device, (byte)(numUDL2.Value * 255)); - Global.setRightTriggerMiddle(device, (byte)(numUDR2.Value * 255)); + Global.setLeftTriggerMiddle(device, (byte)Math.Round((numUDL2.Value * 255), 0)); + Global.setRightTriggerMiddle(device, (byte)Math.Round((numUDR2.Value * 255), 0)); Global.saveRumbleBoost(device, (byte)rumbleBoostBar.Value); Global.setFlashWhenLowBattery(device, flashLed.Checked); Global.setTouchSensitivity(device, (byte)numUDTouch.Value); @@ -227,11 +227,11 @@ namespace ScpServer Global.setDoubleTap(device, cBDoubleTap.Checked); Global.setButtonMouseSensitivity(device, tBMouseSens.Value); Global.setTapSensitivity(device, (byte)numUDTap.Value); - Global.setIdleDisconnectTimeout(device, (int)(idleDisconnectTimeout.Value * 60)); + Global.setIdleDisconnectTimeout(device, (int)(idleDisconnectTimeout.Value * 60)); Global.setButtonMouseSensitivity(device, tBMouseSens.Value); Global.setRainbow(device, (int)numUDRainbow.Value); - Global.setRSDeadzone(device, (byte)(numUDRS.Value * 127)); - Global.setLSDeadzone(device, (byte)(numUDLS.Value * 127)); + Global.setRSDeadzone(device, (byte)Math.Round((numUDRS.Value * 127), 0)); + Global.setLSDeadzone(device, (byte)Math.Round((numUDLS.Value * 127), 0)); if (numUDRainbow.Value == 0) pBRainbow.Image = greyscale; else pBRainbow.Image = colored; } @@ -810,12 +810,12 @@ namespace ScpServer private void numUDRS_ValueChanged(object sender, EventArgs e) { - Global.setRSDeadzone(device, (byte)(numUDRS.Value * 127)); + Global.setRSDeadzone(device, (byte)Math.Round((numUDRS.Value * 127),0)); } private void numUDLS_ValueChanged(object sender, EventArgs e) { - Global.setLSDeadzone(device, (byte)(numUDLS.Value * 127)); + Global.setLSDeadzone(device, (byte)Math.Round((numUDLS.Value * 127),0)); } } diff --git a/DS4Tool/ScpForm.cs b/DS4Tool/ScpForm.cs index 5317166..23e2049 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.31; + double version = 7.4; protected Label[] Pads; protected ComboBox[] cbs; @@ -408,7 +408,7 @@ namespace ScpServer string filename = cbs[tdevice].Items[cbs[tdevice].SelectedIndex].ToString(); if (MessageBox.Show("\"" + filename + "\" cannot be restored.", "Delete Profile?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { - System.IO.File.Delete(Global.appdatapath + filename + ".xml"); + System.IO.File.Delete(Global.appdatapath + "\\Profiles\\" +filename + ".xml"); Global.setAProfile(tdevice, null); RefreshProfiles(); }