Make lightbar pulse mode time dependent.

Duration might change later. Related to issue #18.
This commit is contained in:
Travis Nickles 2017-04-22 03:09:11 -07:00
parent 52e7c2309b
commit 133d092aab

View File

@ -5,6 +5,8 @@ using System.Text;
using System.Drawing;
using static System.Math;
using static DS4Windows.Global;
using System.Diagnostics;
namespace DS4Windows
{
public class DS4LightBar
@ -24,11 +26,13 @@ namespace DS4Windows
};
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() };
static bool[] fadedirection = new bool[4] { false, false, false, false };
static DateTime oldnow = DateTime.UtcNow;
public static bool[] forcelight = new bool[4] { false, false, false, false };
public static DS4Color[] forcedColor = new DS4Color[4];
public static byte[] forcedFlash = new byte[4];
internal const int PULSE_FLASH_DURATION = 2000;
public static void updateLightBar(DS4Device device, int deviceNum, DS4State cState,
DS4StateExposed eState, Mouse tp)
@ -104,17 +108,46 @@ namespace DS4Windows
if (getFlashType(deviceNum) == 1)
{
if (fadetimer[deviceNum] <= 0.0)
fadedirection[deviceNum] = true;
else if (fadetimer[deviceNum] >= 100.0)
fadedirection[deviceNum] = false;
double ratio = 0.0;
if (!fadewatches[deviceNum].IsRunning)
{
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])
fadetimer[deviceNum] += 1;
{
if (elapsed < PULSE_FLASH_DURATION)
{
ratio = 100.0 * (elapsed / (double)PULSE_FLASH_DURATION);
}
else
fadetimer[deviceNum] -= 1;
{
ratio = 100.0;
fadewatches[deviceNum].Stop();
}
}
else
{
if (elapsed < PULSE_FLASH_DURATION)
{
ratio = (0 - 100.0) * (elapsed / (double)PULSE_FLASH_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);
}
}