Make sure lightbar rainbow mode works properly with multiple devices

This commit is contained in:
Travis Nickles 2017-04-22 03:31:53 -07:00
parent 133d092aab
commit 3c7aa0d477
2 changed files with 14 additions and 9 deletions

View File

@ -28,7 +28,7 @@ namespace DS4Windows
public static double[] fadetimer = 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; static DateTime[] oldnow = { DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow };
public static bool[] forcelight = new bool[4] { false, false, false, false }; public static bool[] forcelight = new bool[4] { false, false, false, false };
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];
@ -63,14 +63,15 @@ namespace DS4Windows
{ {
// Display rainbow // Display rainbow
DateTime now = DateTime.UtcNow; DateTime now = DateTime.UtcNow;
if (now >= oldnow + TimeSpan.FromMilliseconds(10)) //update by the millisecond that way it's a smooth transtion if (now >= oldnow[deviceNum] + TimeSpan.FromMilliseconds(10)) //update by the millisecond that way it's a smooth transtion
{ {
oldnow = now; oldnow[deviceNum] = now;
if (device.isCharging()) if (device.isCharging())
counters[deviceNum] -= 1.5 * 3 / rainbow; counters[deviceNum] -= 1.5 * 3 / rainbow;
else else
counters[deviceNum] += 1.5 * 3 / rainbow; counters[deviceNum] += 1.5 * 3 / rainbow;
} }
if (counters[deviceNum] < 0) if (counters[deviceNum] < 0)
counters[deviceNum] = 180000; counters[deviceNum] = 180000;
else if (counters[deviceNum] > 180000) else if (counters[deviceNum] > 180000)
@ -159,11 +160,11 @@ namespace DS4Windows
TimeSpan timeratio = new TimeSpan(DateTime.UtcNow.Ticks - device.lastActive.Ticks); TimeSpan timeratio = new TimeSpan(DateTime.UtcNow.Ticks - device.lastActive.Ticks);
double botratio = timeratio.TotalMilliseconds; double botratio = timeratio.TotalMilliseconds;
double topratio = TimeSpan.FromSeconds(idleDisconnectTimeout).TotalMilliseconds; double topratio = TimeSpan.FromSeconds(idleDisconnectTimeout).TotalMilliseconds;
double ratio = ((botratio / topratio) * 100); double ratio = 100.0 * (botratio / topratio);
if (ratio >= 50 && ratio <= 100) 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) else if (ratio >= 100.0)
color = getTransitionedColor(color, new DS4Color(0, 0, 0), 100); color = getTransitionedColor(color, new DS4Color(0, 0, 0), 100.0);
} }
if (device.isCharging() && device.getBattery() < 100) if (device.isCharging() && device.getBattery() < 100)
@ -193,7 +194,7 @@ namespace DS4Windows
} }
case 3: case 3:
{ {
color = ChargingColor[deviceNum]; color = getChargingColor(deviceNum);
break; break;
} }
default: break; default: break;

View File

@ -366,6 +366,10 @@ namespace DS4Windows
return m_Config.m_LowLeds[index]; return m_Config.m_LowLeds[index];
} }
public static DS4Color[] ChargingColor => m_Config.m_ChargingLeds; public static DS4Color[] ChargingColor => m_Config.m_ChargingLeds;
public static DS4Color getChargingColor(int index)
{
return m_Config.m_ChargingLeds[index];
}
public static DS4Color[] CustomColor => m_Config.m_CustomLeds; public static DS4Color[] CustomColor => m_Config.m_CustomLeds;
public static DS4Color getCustomColor(int index) public static DS4Color getCustomColor(int index)
{ {