2014-03-28 02:50:40 +01:00
|
|
|
|
using System;
|
2014-09-02 01:23:02 +02:00
|
|
|
|
using System.Drawing;
|
Version 1.4.266
Flash Lightbar when at high latency now has the option to choose what
you decide is high latency
Show Notifications now has the option to only show warnings, such as
when a controller cannot be grabbed exclusively
Speaking of bad news for Windows 10 users: Hide DS4 has now been
disabled, until i can figure out why this is, it will be disabled, this
means some games that rely on this may not work properly or at all,
sorry about that
As for good news for Windows 10, did you know you can press Windows + G
to open a game bar which can record games. For Windows 10 users, there's
a new special action: Xbox Game DVR. Pick a trigger (only one button)
and tapping/holding/or double tapping does various things, such as
start/stop recording, save an ongoing recording, take a screenshot (via
the xbox app's option or your own hotkey ie form steam), or just open
the gamebar
Much of the code has been updated with c# 6.0
Added manifest so DS4Windows can notice Windows 10 and high DPIs, also
reorganized files
2015-07-31 05:34:22 +02:00
|
|
|
|
using static System.Math;
|
|
|
|
|
using static DS4Windows.Global;
|
2017-04-22 12:09:11 +02:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
2015-02-08 22:51:52 +01:00
|
|
|
|
namespace DS4Windows
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{
|
2014-06-02 05:19:04 +02:00
|
|
|
|
public class DS4LightBar
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly static byte[/* Light On duration */, /* Light Off duration */] BatteryIndicatorDurations =
|
|
|
|
|
{
|
2019-03-08 21:29:58 +01:00
|
|
|
|
{ 28, 252 }, // on 10% of the time at 0
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{ 28, 252 },
|
|
|
|
|
{ 56, 224 },
|
|
|
|
|
{ 84, 196 },
|
|
|
|
|
{ 112, 168 },
|
|
|
|
|
{ 140, 140 },
|
|
|
|
|
{ 168, 112 },
|
|
|
|
|
{ 196, 84 },
|
2017-07-18 22:37:01 +02:00
|
|
|
|
{ 224, 56 }, // on 80% of the time at 80, etc.
|
2019-03-08 21:29:58 +01:00
|
|
|
|
{ 252, 28 }, // on 90% of the time at 90
|
|
|
|
|
{ 0, 0 } // use on 100%. 0 is for "charging" OR anything sufficiently-"charged"
|
2014-03-28 02:50:40 +01:00
|
|
|
|
};
|
2017-07-18 22:37:01 +02:00
|
|
|
|
|
2014-06-02 19:29:38 +02:00
|
|
|
|
static double[] counters = new double[4] { 0, 0, 0, 0 };
|
2017-07-18 22:37:01 +02:00
|
|
|
|
public static Stopwatch[] fadewatches = new Stopwatch[4]
|
|
|
|
|
{ new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch() };
|
|
|
|
|
|
2014-06-02 19:29:38 +02:00
|
|
|
|
static bool[] fadedirection = new bool[4] { false, false, false, false };
|
2017-07-18 22:37:01 +02:00
|
|
|
|
static DateTime[] oldnow = new DateTime[4]
|
|
|
|
|
{ DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow };
|
|
|
|
|
|
2014-12-02 01:07:29 +01:00
|
|
|
|
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];
|
2017-04-22 12:09:11 +02:00
|
|
|
|
internal const int PULSE_FLASH_DURATION = 2000;
|
2017-09-20 05:08:03 +02:00
|
|
|
|
internal const double PULSE_FLASH_SEGMENTS = PULSE_FLASH_DURATION / 40;
|
2017-04-23 03:01:31 +02:00
|
|
|
|
internal const int PULSE_CHARGING_DURATION = 4000;
|
2018-04-03 06:40:49 +02:00
|
|
|
|
internal const double PULSE_CHARGING_SEGMENTS = (PULSE_CHARGING_DURATION / 40) - 2;
|
2017-04-22 04:58:27 +02:00
|
|
|
|
|
2017-09-20 07:52:33 +02:00
|
|
|
|
public static void updateLightBar(DS4Device device, int deviceNum)
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{
|
2014-06-02 05:19:04 +02:00
|
|
|
|
DS4Color color;
|
2020-02-22 19:32:19 +01:00
|
|
|
|
bool useForceLight = forcelight[deviceNum];
|
|
|
|
|
LightbarSettingInfo lightbarSettingInfo = getLightbarSettingsInfo(deviceNum);
|
|
|
|
|
LightbarDS4WinInfo lightModeInfo = lightbarSettingInfo.ds4winSettings;
|
|
|
|
|
if (!defaultLight && !useForceLight)
|
2014-06-02 05:19:04 +02:00
|
|
|
|
{
|
2020-02-22 19:32:19 +01:00
|
|
|
|
if (lightModeInfo.useCustomLed)
|
2015-11-28 06:47:26 +01:00
|
|
|
|
{
|
2020-02-22 19:32:19 +01:00
|
|
|
|
if (lightModeInfo.ledAsBattery)
|
2015-12-05 09:55:11 +01:00
|
|
|
|
{
|
2020-02-22 19:32:19 +01:00
|
|
|
|
ref DS4Color fullColor = ref lightModeInfo.m_CustomLed; // ref getCustomColor(deviceNum);
|
|
|
|
|
ref DS4Color lowColor = ref lightModeInfo.m_LowLed; //ref getLowColor(deviceNum);
|
2019-02-12 06:51:26 +01:00
|
|
|
|
color = getTransitionedColor(ref lowColor, ref fullColor, device.getBattery());
|
2015-12-05 09:55:11 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
2020-02-22 19:32:19 +01:00
|
|
|
|
color = lightModeInfo.m_CustomLed; //getCustomColor(deviceNum);
|
2015-11-28 06:47:26 +01:00
|
|
|
|
}
|
2014-07-26 01:17:45 +02:00
|
|
|
|
else
|
2014-03-29 06:29:08 +01:00
|
|
|
|
{
|
2020-02-22 19:32:19 +01:00
|
|
|
|
double rainbow = lightModeInfo.rainbow;// getRainbow(deviceNum);
|
2017-04-16 08:22:04 +02:00
|
|
|
|
if (rainbow > 0)
|
2017-04-22 04:58:27 +02:00
|
|
|
|
{
|
|
|
|
|
// Display rainbow
|
2014-07-26 01:17:45 +02:00
|
|
|
|
DateTime now = DateTime.UtcNow;
|
2017-04-22 12:31:53 +02:00
|
|
|
|
if (now >= oldnow[deviceNum] + TimeSpan.FromMilliseconds(10)) //update by the millisecond that way it's a smooth transtion
|
2014-06-02 05:19:04 +02:00
|
|
|
|
{
|
2017-04-22 12:31:53 +02:00
|
|
|
|
oldnow[deviceNum] = now;
|
2017-04-16 08:22:04 +02:00
|
|
|
|
if (device.isCharging())
|
|
|
|
|
counters[deviceNum] -= 1.5 * 3 / rainbow;
|
2014-07-26 01:17:45 +02:00
|
|
|
|
else
|
2017-04-16 08:22:04 +02:00
|
|
|
|
counters[deviceNum] += 1.5 * 3 / rainbow;
|
2014-07-26 01:17:45 +02:00
|
|
|
|
}
|
2017-04-22 12:31:53 +02:00
|
|
|
|
|
2014-07-26 01:17:45 +02:00
|
|
|
|
if (counters[deviceNum] < 0)
|
|
|
|
|
counters[deviceNum] = 180000;
|
2017-04-16 08:22:04 +02:00
|
|
|
|
else if (counters[deviceNum] > 180000)
|
2015-02-08 22:51:52 +01:00
|
|
|
|
counters[deviceNum] = 0;
|
2017-04-16 08:22:04 +02:00
|
|
|
|
|
2020-02-22 19:32:19 +01:00
|
|
|
|
double maxSat = lightModeInfo.maxRainbowSat; // GetMaxSatRainbow(deviceNum);
|
|
|
|
|
if (lightModeInfo.ledAsBattery)
|
2019-09-06 17:50:20 +02:00
|
|
|
|
{
|
|
|
|
|
byte useSat = (byte)(maxSat == 1.0 ?
|
|
|
|
|
device.getBattery() * 2.55 :
|
|
|
|
|
device.getBattery() * 2.55 * maxSat);
|
|
|
|
|
color = HuetoRGB((float)counters[deviceNum] % 360, useSat);
|
|
|
|
|
}
|
2014-07-26 01:17:45 +02:00
|
|
|
|
else
|
2019-09-06 17:50:20 +02:00
|
|
|
|
color = HuetoRGB((float)counters[deviceNum] % 360,
|
|
|
|
|
(byte)(maxSat == 1.0 ? 255 : 255 * maxSat));
|
2014-03-28 02:50:40 +01:00
|
|
|
|
|
2014-07-26 01:17:45 +02:00
|
|
|
|
}
|
2020-02-22 19:32:19 +01:00
|
|
|
|
else if (lightModeInfo.ledAsBattery)
|
2014-07-26 01:17:45 +02:00
|
|
|
|
{
|
2020-02-22 19:32:19 +01:00
|
|
|
|
ref DS4Color fullColor = ref lightModeInfo.m_Led; //ref getMainColor(deviceNum);
|
|
|
|
|
ref DS4Color lowColor = ref lightModeInfo.m_LowLed; //ref getLowColor(deviceNum);
|
2019-02-12 06:51:26 +01:00
|
|
|
|
color = getTransitionedColor(ref lowColor, ref fullColor, device.getBattery());
|
2014-07-26 01:17:45 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2014-06-02 19:29:38 +02:00
|
|
|
|
{
|
2017-04-22 04:58:27 +02:00
|
|
|
|
color = getMainColor(deviceNum);
|
2014-06-02 19:29:38 +02:00
|
|
|
|
}
|
2015-12-05 09:55:11 +01:00
|
|
|
|
}
|
2014-08-23 22:52:20 +02:00
|
|
|
|
|
2020-02-22 19:32:19 +01:00
|
|
|
|
if (device.getBattery() <= lightModeInfo.flashAt && !defaultLight && !device.isCharging())
|
2015-12-05 09:55:11 +01:00
|
|
|
|
{
|
2020-02-22 19:32:19 +01:00
|
|
|
|
ref DS4Color flashColor = ref lightModeInfo.m_FlashLed; //ref getFlashColor(deviceNum);
|
2017-04-16 08:22:04 +02:00
|
|
|
|
if (!(flashColor.red == 0 &&
|
|
|
|
|
flashColor.green == 0 &&
|
|
|
|
|
flashColor.blue == 0))
|
|
|
|
|
color = flashColor;
|
|
|
|
|
|
2020-02-22 19:32:19 +01:00
|
|
|
|
if (lightModeInfo.flashType == 1)
|
2014-08-23 22:52:20 +02:00
|
|
|
|
{
|
2017-04-22 12:09:11 +02:00
|
|
|
|
double ratio = 0.0;
|
2017-04-16 08:22:04 +02:00
|
|
|
|
|
2017-04-22 12:09:11 +02:00
|
|
|
|
if (!fadewatches[deviceNum].IsRunning)
|
|
|
|
|
{
|
|
|
|
|
bool temp = fadedirection[deviceNum];
|
|
|
|
|
fadedirection[deviceNum] = !temp;
|
|
|
|
|
fadewatches[deviceNum].Restart();
|
|
|
|
|
ratio = temp ? 100.0 : 0.0;
|
|
|
|
|
}
|
2015-12-05 09:55:11 +01:00
|
|
|
|
else
|
2017-04-22 12:09:11 +02:00
|
|
|
|
{
|
|
|
|
|
long elapsed = fadewatches[deviceNum].ElapsedMilliseconds;
|
|
|
|
|
|
|
|
|
|
if (fadedirection[deviceNum])
|
|
|
|
|
{
|
|
|
|
|
if (elapsed < PULSE_FLASH_DURATION)
|
|
|
|
|
{
|
2017-09-20 04:13:46 +02:00
|
|
|
|
elapsed = elapsed / 40;
|
2017-09-20 04:36:33 +02:00
|
|
|
|
ratio = 100.0 * (elapsed / PULSE_FLASH_SEGMENTS);
|
2017-04-22 12:09:11 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ratio = 100.0;
|
|
|
|
|
fadewatches[deviceNum].Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (elapsed < PULSE_FLASH_DURATION)
|
|
|
|
|
{
|
2017-09-20 04:13:46 +02:00
|
|
|
|
elapsed = elapsed / 40;
|
2017-09-20 04:36:33 +02:00
|
|
|
|
ratio = (0 - 100.0) * (elapsed / PULSE_FLASH_SEGMENTS) + 100.0;
|
2017-04-22 12:09:11 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ratio = 0.0;
|
|
|
|
|
fadewatches[deviceNum].Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-16 08:22:04 +02:00
|
|
|
|
|
2019-02-12 06:51:26 +01:00
|
|
|
|
DS4Color tempCol = new DS4Color(0, 0, 0);
|
|
|
|
|
color = getTransitionedColor(ref color, ref tempCol, ratio);
|
2015-12-05 09:55:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 08:22:04 +02:00
|
|
|
|
int idleDisconnectTimeout = getIdleDisconnectTimeout(deviceNum);
|
2020-02-22 19:32:19 +01:00
|
|
|
|
if (idleDisconnectTimeout > 0 && lightModeInfo.ledAsBattery &&
|
2017-04-22 04:58:27 +02:00
|
|
|
|
(!device.isCharging() || device.getBattery() >= 100))
|
|
|
|
|
{
|
2020-02-22 19:32:19 +01:00
|
|
|
|
// Fade lightbar by idle time
|
2015-12-05 09:55:11 +01:00
|
|
|
|
TimeSpan timeratio = new TimeSpan(DateTime.UtcNow.Ticks - device.lastActive.Ticks);
|
|
|
|
|
double botratio = timeratio.TotalMilliseconds;
|
2017-04-16 08:22:04 +02:00
|
|
|
|
double topratio = TimeSpan.FromSeconds(idleDisconnectTimeout).TotalMilliseconds;
|
2017-08-19 06:33:37 +02:00
|
|
|
|
double ratio = 100.0 * (botratio / topratio), elapsed = ratio;
|
2017-05-27 16:05:46 +02:00
|
|
|
|
if (ratio >= 50.0 && ratio < 100.0)
|
2017-08-19 06:33:37 +02:00
|
|
|
|
{
|
2019-02-12 06:51:26 +01:00
|
|
|
|
DS4Color emptyCol = new DS4Color(0, 0, 0);
|
|
|
|
|
color = getTransitionedColor(ref color, ref emptyCol,
|
2017-08-19 06:33:37 +02:00
|
|
|
|
(uint)(-100.0 * (elapsed = 0.02 * (ratio - 50.0)) * (elapsed - 2.0)));
|
|
|
|
|
}
|
2017-04-22 12:31:53 +02:00
|
|
|
|
else if (ratio >= 100.0)
|
2019-02-12 06:51:26 +01:00
|
|
|
|
{
|
|
|
|
|
DS4Color emptyCol = new DS4Color(0, 0, 0);
|
|
|
|
|
color = getTransitionedColor(ref color, ref emptyCol, 100.0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-05 09:55:11 +01:00
|
|
|
|
}
|
2017-04-16 08:22:04 +02:00
|
|
|
|
|
|
|
|
|
if (device.isCharging() && device.getBattery() < 100)
|
|
|
|
|
{
|
2020-02-22 19:32:19 +01:00
|
|
|
|
switch (lightModeInfo.chargingType)
|
2015-12-05 09:55:11 +01:00
|
|
|
|
{
|
|
|
|
|
case 1:
|
2017-04-16 08:22:04 +02:00
|
|
|
|
{
|
2017-04-23 03:01:31 +02:00
|
|
|
|
double ratio = 0.0;
|
2017-04-16 08:22:04 +02:00
|
|
|
|
|
2017-04-23 03:01:31 +02:00
|
|
|
|
if (!fadewatches[deviceNum].IsRunning)
|
|
|
|
|
{
|
|
|
|
|
bool temp = fadedirection[deviceNum];
|
|
|
|
|
fadedirection[deviceNum] = !temp;
|
|
|
|
|
fadewatches[deviceNum].Restart();
|
|
|
|
|
ratio = temp ? 100.0 : 0.0;
|
|
|
|
|
}
|
2015-02-08 22:51:52 +01:00
|
|
|
|
else
|
2017-04-23 03:01:31 +02:00
|
|
|
|
{
|
|
|
|
|
long elapsed = fadewatches[deviceNum].ElapsedMilliseconds;
|
|
|
|
|
|
|
|
|
|
if (fadedirection[deviceNum])
|
|
|
|
|
{
|
|
|
|
|
if (elapsed < PULSE_CHARGING_DURATION)
|
|
|
|
|
{
|
2017-09-20 05:08:03 +02:00
|
|
|
|
elapsed = elapsed / 40;
|
2018-04-03 06:40:49 +02:00
|
|
|
|
if (elapsed > PULSE_CHARGING_SEGMENTS)
|
|
|
|
|
elapsed = (long)PULSE_CHARGING_SEGMENTS;
|
2017-09-20 05:08:03 +02:00
|
|
|
|
ratio = 100.0 * (elapsed / PULSE_CHARGING_SEGMENTS);
|
2017-04-23 03:01:31 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ratio = 100.0;
|
|
|
|
|
fadewatches[deviceNum].Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (elapsed < PULSE_CHARGING_DURATION)
|
|
|
|
|
{
|
2017-09-20 05:08:03 +02:00
|
|
|
|
elapsed = elapsed / 40;
|
2018-04-03 06:40:49 +02:00
|
|
|
|
if (elapsed > PULSE_CHARGING_SEGMENTS)
|
|
|
|
|
elapsed = (long)PULSE_CHARGING_SEGMENTS;
|
2017-09-20 05:08:03 +02:00
|
|
|
|
ratio = (0 - 100.0) * (elapsed / PULSE_CHARGING_SEGMENTS) + 100.0;
|
2017-04-23 03:01:31 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ratio = 0.0;
|
|
|
|
|
fadewatches[deviceNum].Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-16 08:22:04 +02:00
|
|
|
|
|
2019-02-12 06:51:26 +01:00
|
|
|
|
DS4Color emptyCol = new DS4Color(0, 0, 0);
|
|
|
|
|
color = getTransitionedColor(ref color, ref emptyCol, ratio);
|
2015-12-05 09:55:11 +01:00
|
|
|
|
break;
|
2017-04-16 08:22:04 +02:00
|
|
|
|
}
|
2015-12-05 09:55:11 +01:00
|
|
|
|
case 2:
|
2017-04-16 08:22:04 +02:00
|
|
|
|
{
|
2017-04-22 04:58:27 +02:00
|
|
|
|
counters[deviceNum] += 0.167;
|
2015-12-05 09:55:11 +01:00
|
|
|
|
color = HuetoRGB((float)counters[deviceNum] % 360, 255);
|
|
|
|
|
break;
|
2017-04-16 08:22:04 +02:00
|
|
|
|
}
|
2015-12-05 09:55:11 +01:00
|
|
|
|
case 3:
|
2017-04-16 08:22:04 +02:00
|
|
|
|
{
|
2020-02-22 19:32:19 +01:00
|
|
|
|
color = lightModeInfo.m_ChargingLed; //getChargingColor(deviceNum);
|
2015-12-05 09:55:11 +01:00
|
|
|
|
break;
|
2017-04-16 08:22:04 +02:00
|
|
|
|
}
|
|
|
|
|
default: break;
|
2015-12-05 09:55:11 +01:00
|
|
|
|
}
|
2017-04-16 08:22:04 +02:00
|
|
|
|
}
|
2014-05-22 21:13:38 +02:00
|
|
|
|
}
|
2020-02-22 19:32:19 +01:00
|
|
|
|
else if (useForceLight)
|
2014-12-02 01:07:29 +01:00
|
|
|
|
{
|
|
|
|
|
color = forcedColor[deviceNum];
|
|
|
|
|
}
|
2014-06-02 19:29:38 +02:00
|
|
|
|
else if (shuttingdown)
|
2015-02-08 22:51:52 +01:00
|
|
|
|
color = new DS4Color(0, 0, 0);
|
2014-06-02 05:19:04 +02:00
|
|
|
|
else
|
2014-09-02 20:41:32 +02:00
|
|
|
|
{
|
2017-04-16 08:22:04 +02:00
|
|
|
|
if (device.getConnectionType() == ConnectionType.BT)
|
2015-02-12 20:36:40 +01:00
|
|
|
|
color = new DS4Color(32, 64, 64);
|
2014-09-02 20:41:32 +02:00
|
|
|
|
else
|
2015-02-08 22:51:52 +01:00
|
|
|
|
color = new DS4Color(0, 0, 0);
|
2014-09-02 20:41:32 +02:00
|
|
|
|
}
|
2017-04-16 08:22:04 +02:00
|
|
|
|
|
2017-03-23 05:45:20 +01:00
|
|
|
|
bool distanceprofile = DistanceProfiles[deviceNum] || tempprofileDistance[deviceNum];
|
|
|
|
|
//distanceprofile = (ProfilePath[deviceNum].ToLower().Contains("distance") || tempprofilename[deviceNum].ToLower().Contains("distance"));
|
2017-04-22 05:01:20 +02:00
|
|
|
|
if (distanceprofile && !defaultLight)
|
2017-04-22 04:58:27 +02:00
|
|
|
|
{
|
2017-04-22 12:31:53 +02:00
|
|
|
|
// Thing I did for Distance
|
2017-04-08 02:13:19 +02:00
|
|
|
|
float rumble = device.getLeftHeavySlowRumble() / 2.55f;
|
Version 1.4.266
Flash Lightbar when at high latency now has the option to choose what
you decide is high latency
Show Notifications now has the option to only show warnings, such as
when a controller cannot be grabbed exclusively
Speaking of bad news for Windows 10 users: Hide DS4 has now been
disabled, until i can figure out why this is, it will be disabled, this
means some games that rely on this may not work properly or at all,
sorry about that
As for good news for Windows 10, did you know you can press Windows + G
to open a game bar which can record games. For Windows 10 users, there's
a new special action: Xbox Game DVR. Pick a trigger (only one button)
and tapping/holding/or double tapping does various things, such as
start/stop recording, save an ongoing recording, take a screenshot (via
the xbox app's option or your own hotkey ie form steam), or just open
the gamebar
Much of the code has been updated with c# 6.0
Added manifest so DS4Windows can notice Windows 10 and high DPIs, also
reorganized files
2015-07-31 05:34:22 +02:00
|
|
|
|
byte max = Max(color.red, Max(color.green, color.blue));
|
2017-04-08 02:13:19 +02:00
|
|
|
|
if (device.getLeftHeavySlowRumble() > 100)
|
2019-02-12 06:51:26 +01:00
|
|
|
|
{
|
|
|
|
|
DS4Color maxCol = new DS4Color(max, max, 0);
|
|
|
|
|
DS4Color redCol = new DS4Color(255, 0, 0);
|
|
|
|
|
color = getTransitionedColor(ref maxCol, ref redCol, rumble);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-15 04:37:14 +02:00
|
|
|
|
else
|
2019-02-12 06:51:26 +01:00
|
|
|
|
{
|
|
|
|
|
DS4Color maxCol = new DS4Color(max, max, 0);
|
|
|
|
|
DS4Color redCol = new DS4Color(255, 0, 0);
|
|
|
|
|
DS4Color tempCol = getTransitionedColor(ref maxCol,
|
|
|
|
|
ref redCol, 39.6078f);
|
|
|
|
|
color = getTransitionedColor(ref color, ref tempCol,
|
|
|
|
|
device.getLeftHeavySlowRumble());
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-02 01:23:02 +02:00
|
|
|
|
}
|
2017-04-16 08:22:04 +02:00
|
|
|
|
|
2014-03-29 06:29:08 +01:00
|
|
|
|
DS4HapticState haptics = new DS4HapticState
|
|
|
|
|
{
|
|
|
|
|
LightBarColor = color
|
|
|
|
|
};
|
2017-04-16 08:22:04 +02:00
|
|
|
|
|
2014-03-29 06:29:08 +01:00
|
|
|
|
if (haptics.IsLightBarSet())
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{
|
2020-02-22 19:32:19 +01:00
|
|
|
|
if (useForceLight && forcedFlash[deviceNum] > 0)
|
2014-12-02 01:07:29 +01:00
|
|
|
|
{
|
|
|
|
|
haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)(25 - forcedFlash[deviceNum]);
|
|
|
|
|
haptics.LightBarExplicitlyOff = true;
|
|
|
|
|
}
|
2020-02-22 19:32:19 +01:00
|
|
|
|
else if (device.getBattery() <= lightModeInfo.flashAt && lightModeInfo.flashType == 0 && !defaultLight && !device.isCharging())
|
2014-03-29 06:29:08 +01:00
|
|
|
|
{
|
2017-04-01 07:42:10 +02:00
|
|
|
|
int level = device.getBattery() / 10;
|
2017-04-22 17:03:24 +02:00
|
|
|
|
if (level >= 10)
|
2019-03-08 21:29:58 +01:00
|
|
|
|
level = 10; // all values of >~100% are rendered the same
|
2017-04-22 17:03:24 +02:00
|
|
|
|
|
2014-03-29 06:29:08 +01:00
|
|
|
|
haptics.LightBarFlashDurationOn = BatteryIndicatorDurations[level, 0];
|
|
|
|
|
haptics.LightBarFlashDurationOff = BatteryIndicatorDurations[level, 1];
|
|
|
|
|
}
|
2017-03-24 03:32:33 +01:00
|
|
|
|
else if (distanceprofile && device.getLeftHeavySlowRumble() > 155) //also part of Distance
|
2014-09-02 01:23:02 +02:00
|
|
|
|
{
|
2017-03-24 03:32:33 +01:00
|
|
|
|
haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)((-device.getLeftHeavySlowRumble() + 265));
|
2014-09-02 01:23:02 +02:00
|
|
|
|
haptics.LightBarExplicitlyOff = true;
|
|
|
|
|
}
|
2014-03-29 06:29:08 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
2014-08-23 22:52:20 +02:00
|
|
|
|
//haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 0;
|
2014-06-02 05:19:04 +02:00
|
|
|
|
haptics.LightBarExplicitlyOff = true;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
}
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-03-29 06:29:08 +01:00
|
|
|
|
haptics.LightBarExplicitlyOff = true;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
2017-03-24 03:32:33 +01:00
|
|
|
|
|
|
|
|
|
byte tempLightBarOnDuration = device.getLightBarOnDuration();
|
|
|
|
|
if (tempLightBarOnDuration != haptics.LightBarFlashDurationOn && tempLightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0)
|
2014-09-02 01:23:02 +02:00
|
|
|
|
haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
|
2017-03-23 05:45:20 +01:00
|
|
|
|
|
2019-01-11 01:15:14 +01:00
|
|
|
|
device.SetHapticState(ref haptics);
|
|
|
|
|
//device.pushHapticState(ref haptics);
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
2014-12-02 01:07:29 +01:00
|
|
|
|
|
2017-04-22 05:01:20 +02:00
|
|
|
|
public static bool defaultLight = false, shuttingdown = false;
|
2015-12-18 07:25:51 +01:00
|
|
|
|
|
2014-04-30 21:32:44 +02:00
|
|
|
|
public static DS4Color HuetoRGB(float hue, byte sat)
|
|
|
|
|
{
|
|
|
|
|
byte C = sat;
|
|
|
|
|
int X = (int)((C * (float)(1 - Math.Abs((hue / 60) % 2 - 1))));
|
|
|
|
|
if (0 <= hue && hue < 60)
|
2015-02-08 22:51:52 +01:00
|
|
|
|
return new DS4Color(C, (byte)X, 0);
|
2014-04-30 21:32:44 +02:00
|
|
|
|
else if (60 <= hue && hue < 120)
|
2015-02-08 22:51:52 +01:00
|
|
|
|
return new DS4Color((byte)X, C, 0);
|
2014-04-30 21:32:44 +02:00
|
|
|
|
else if (120 <= hue && hue < 180)
|
2015-02-08 22:51:52 +01:00
|
|
|
|
return new DS4Color(0, C, (byte)X);
|
2014-04-30 21:32:44 +02:00
|
|
|
|
else if (180 <= hue && hue < 240)
|
2015-02-08 22:51:52 +01:00
|
|
|
|
return new DS4Color(0, (byte)X, C);
|
2014-04-30 21:32:44 +02:00
|
|
|
|
else if (240 <= hue && hue < 300)
|
2015-02-08 22:51:52 +01:00
|
|
|
|
return new DS4Color((byte)X, 0, C);
|
2014-04-30 21:32:44 +02:00
|
|
|
|
else if (300 <= hue && hue < 360)
|
2015-02-08 22:51:52 +01:00
|
|
|
|
return new DS4Color(C, 0, (byte)X);
|
2014-04-30 21:32:44 +02:00
|
|
|
|
else
|
2015-02-08 22:51:52 +01:00
|
|
|
|
return new DS4Color(Color.Red);
|
2014-09-02 01:23:02 +02:00
|
|
|
|
}
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|