mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-23 23:21:49 +01:00
Make lightbar pulse mode time dependent.
Duration might change later. Related to issue #18.
This commit is contained in:
parent
52e7c2309b
commit
133d092aab
@ -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 (fadedirection[deviceNum])
|
||||
fadetimer[deviceNum] += 1;
|
||||
if (!fadewatches[deviceNum].IsRunning)
|
||||
{
|
||||
bool temp = fadedirection[deviceNum];
|
||||
fadedirection[deviceNum] = !temp;
|
||||
fadewatches[deviceNum].Restart();
|
||||
ratio = temp ? 100.0 : 0.0;
|
||||
}
|
||||
else
|
||||
fadetimer[deviceNum] -= 1;
|
||||
{
|
||||
long elapsed = fadewatches[deviceNum].ElapsedMilliseconds;
|
||||
|
||||
color = getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]);
|
||||
if (fadedirection[deviceNum])
|
||||
{
|
||||
if (elapsed < PULSE_FLASH_DURATION)
|
||||
{
|
||||
ratio = 100.0 * (elapsed / (double)PULSE_FLASH_DURATION);
|
||||
}
|
||||
else
|
||||
{
|
||||
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), ratio);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user