Change lightbar pulse charging mode to be time dependent

This commit is contained in:
Travis Nickles 2017-04-22 18:01:31 -07:00
parent 064b478683
commit 8df30a5bbb
2 changed files with 49 additions and 14 deletions

View File

@ -232,20 +232,25 @@ namespace DS4Windows
{ {
DS4Device device = devices.ElementAt<DS4Device>(i); DS4Device device = devices.ElementAt<DS4Device>(i);
if (QuickCharge && device?.getConnectionType() == ConnectionType.BT && (bool)device?.isCharging()) if (device.isDisconnectingStatus())
continue;
if (QuickCharge && device?.getConnectionType() == ConnectionType.BT &&
(bool)device?.isCharging())
{ {
device.DisconnectBT(); device.DisconnectBT();
continue; continue;
} }
if (device.isDisconnectingStatus())
continue;
if (((Func<bool>)delegate if (((Func<bool>)delegate
{ {
for (Int32 Index = 0, arlength = DS4Controllers.Length; Index < arlength; Index++) for (Int32 Index = 0, arlength = DS4Controllers.Length; Index < arlength; Index++)
if (DS4Controllers[Index] != null && DS4Controllers[Index].getMacAddress() == device.getMacAddress()) {
if (DS4Controllers[Index] != null &&
DS4Controllers[Index].getMacAddress() == device.getMacAddress())
return true; return true;
}
return false; return false;
})()) })())
continue; continue;
@ -266,6 +271,7 @@ namespace DS4Windows
if (!DinputOnly[Index]) if (!DinputOnly[Index])
x360Bus.Plugin(Index); x360Bus.Plugin(Index);
TouchPadOn(Index, device); TouchPadOn(Index, device);
//string filename = Path.GetFileName(ProfilePath[Index]); //string filename = Path.GetFileName(ProfilePath[Index]);
if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml")) if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml"))
{ {

View File

@ -25,7 +25,6 @@ namespace DS4Windows
{ 252, 28 } // on 90% of the time at 90 { 252, 28 } // on 90% of the time at 90
}; };
static double[] counters = new double[4] { 0, 0, 0, 0 }; static double[] counters = new double[4] { 0, 0, 0, 0 };
public static double[] fadetimer = new double[4] { 0, 0, 0, 0 };
public static Stopwatch[] fadewatches = { new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch() }; public static Stopwatch[] fadewatches = { new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch() };
static bool[] fadedirection = new bool[4] { false, false, false, false }; static bool[] fadedirection = new bool[4] { false, false, false, false };
static DateTime[] oldnow = { DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow }; static DateTime[] oldnow = { DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow };
@ -33,6 +32,7 @@ namespace DS4Windows
public static DS4Color[] forcedColor = new DS4Color[4]; public static DS4Color[] forcedColor = new DS4Color[4];
public static byte[] forcedFlash = new byte[4]; public static byte[] forcedFlash = new byte[4];
internal const int PULSE_FLASH_DURATION = 2000; internal const int PULSE_FLASH_DURATION = 2000;
internal const int PULSE_CHARGING_DURATION = 4000;
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)
@ -173,17 +173,46 @@ namespace DS4Windows
{ {
case 1: case 1:
{ {
if (fadetimer[deviceNum] <= 0.0) double ratio = 0.0;
fadedirection[deviceNum] = true;
else if (fadetimer[deviceNum] >= 100.0) if (!fadewatches[deviceNum].IsRunning)
fadedirection[deviceNum] = false; {
bool temp = fadedirection[deviceNum];
fadedirection[deviceNum] = !temp;
fadewatches[deviceNum].Restart();
ratio = temp ? 100.0 : 0.0;
}
else
{
long elapsed = fadewatches[deviceNum].ElapsedMilliseconds;
if (fadedirection[deviceNum]) if (fadedirection[deviceNum])
fadetimer[deviceNum] += 0.1; {
if (elapsed < PULSE_CHARGING_DURATION)
{
ratio = 100.0 * (elapsed / (double)PULSE_CHARGING_DURATION);
}
else else
fadetimer[deviceNum] -= 0.1; {
ratio = 100.0;
fadewatches[deviceNum].Stop();
}
}
else
{
if (elapsed < PULSE_CHARGING_DURATION)
{
ratio = (0 - 100.0) * (elapsed / (double)PULSE_CHARGING_DURATION) + 100.0;
}
else
{
ratio = 0.0;
fadewatches[deviceNum].Stop();
}
}
}
color = getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]); color = getTransitionedColor(color, new DS4Color(0, 0, 0), ratio);
break; break;
} }
case 2: case 2: