Trim more property usage

This commit is contained in:
Travis Nickles 2017-04-15 23:22:04 -07:00
parent 5aff8d95f0
commit 92b4e2da24
3 changed files with 75 additions and 31 deletions

View File

@ -41,11 +41,10 @@ namespace DS4Windows
{ {
if (UseCustomLed[deviceNum]) if (UseCustomLed[deviceNum])
{ {
if (LedAsBatteryIndicator[deviceNum]) if (getLedAsBatteryIndicator(deviceNum))
{ {
DS4Color fullColor = CustomColor[deviceNum]; DS4Color fullColor = CustomColor[deviceNum];
DS4Color lowColor = LowColor[deviceNum]; DS4Color lowColor = LowColor[deviceNum];
color = getTransitionedColor(lowColor, fullColor, device.Battery); color = getTransitionedColor(lowColor, fullColor, device.Battery);
} }
else else
@ -53,35 +52,37 @@ namespace DS4Windows
} }
else else
{ {
if (Rainbow[deviceNum] > 0) double rainbow = Rainbow[deviceNum];
if (rainbow > 0)
{// 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 + TimeSpan.FromMilliseconds(10)) //update by the millisecond that way it's a smooth transtion
{ {
oldnow = now; oldnow = now;
if (device.Charging) if (device.isCharging())
counters[deviceNum] -= 1.5 * 3 / Rainbow[deviceNum]; counters[deviceNum] -= 1.5 * 3 / rainbow;
else else
counters[deviceNum] += 1.5 * 3 / Rainbow[deviceNum]; counters[deviceNum] += 1.5 * 3 / rainbow;
} }
if (counters[deviceNum] < 0) if (counters[deviceNum] < 0)
counters[deviceNum] = 180000; counters[deviceNum] = 180000;
if (counters[deviceNum] > 180000) else if (counters[deviceNum] > 180000)
counters[deviceNum] = 0; counters[deviceNum] = 0;
if (LedAsBatteryIndicator[deviceNum])
color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(2.55 * device.Battery)); if (getLedAsBatteryIndicator(deviceNum))
color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(2.55 * device.getBattery()));
else else
color = HuetoRGB((float)counters[deviceNum] % 360, 255); color = HuetoRGB((float)counters[deviceNum] % 360, 255);
} }
else if (LedAsBatteryIndicator[deviceNum]) else if (getLedAsBatteryIndicator(deviceNum))
{ {
//if (device.Charging == false || device.Battery >= 100) // when charged, don't show the charging animation //if (device.Charging == false || device.Battery >= 100) // when charged, don't show the charging animation
{ {
DS4Color fullColor = MainColor[deviceNum]; DS4Color fullColor = MainColor[deviceNum];
DS4Color lowColor = LowColor[deviceNum]; DS4Color lowColor = LowColor[deviceNum];
color = getTransitionedColor(lowColor, fullColor, (uint)device.Battery); color = getTransitionedColor(lowColor, fullColor, (uint)device.getBattery());
} }
} }
else else
@ -91,60 +92,75 @@ namespace DS4Windows
} }
if (device.getBattery() <= FlashAt[deviceNum] && !defualtLight && !device.isCharging()) if (device.getBattery() <= getFlashAt(deviceNum) && !defualtLight && !device.isCharging())
{ {
if (!(FlashColor[deviceNum].red == 0 && DS4Color flashColor = FlashColor[deviceNum];
FlashColor[deviceNum].green == 0 && if (!(flashColor.red == 0 &&
FlashColor[deviceNum].blue == 0)) flashColor.green == 0 &&
color = FlashColor[deviceNum]; flashColor.blue == 0))
color = flashColor;
if (FlashType[deviceNum] == 1) if (FlashType[deviceNum] == 1)
{ {
if (fadetimer[deviceNum] <= 0) if (fadetimer[deviceNum] <= 0)
fadedirection[deviceNum] = true; fadedirection[deviceNum] = true;
else if (fadetimer[deviceNum] >= 100) else if (fadetimer[deviceNum] >= 100)
fadedirection[deviceNum] = false; fadedirection[deviceNum] = false;
if (fadedirection[deviceNum]) if (fadedirection[deviceNum])
fadetimer[deviceNum] += 1; fadetimer[deviceNum] += 1;
else else
fadetimer[deviceNum] -= 1; fadetimer[deviceNum] -= 1;
color = getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]); color = getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]);
} }
} }
if (IdleDisconnectTimeout[deviceNum] > 0 && LedAsBatteryIndicator[deviceNum] && (!device.isCharging() || device.getBattery() >= 100)) int idleDisconnectTimeout = getIdleDisconnectTimeout(deviceNum);
if (idleDisconnectTimeout > 0 && getLedAsBatteryIndicator(deviceNum) && (!device.isCharging() || device.getBattery() >= 100))
{//Fade lightbar by idle time {//Fade lightbar by idle time
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[deviceNum]).TotalMilliseconds; double topratio = TimeSpan.FromSeconds(idleDisconnectTimeout).TotalMilliseconds;
double ratio = ((botratio / topratio) * 100); double ratio = ((botratio / topratio) * 100);
if (ratio >= 50 && ratio <= 100) if (ratio >= 50 && ratio <= 100)
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)
color = getTransitionedColor(color, new DS4Color(0, 0, 0), 100); color = getTransitionedColor(color, new DS4Color(0, 0, 0), 100);
} }
if (device.Charging && device.Battery < 100)
switch (ChargingType[deviceNum]) if (device.isCharging() && device.getBattery() < 100)
{
switch (getChargingType(deviceNum))
{ {
case 1: case 1:
{
if (fadetimer[deviceNum] <= 0) if (fadetimer[deviceNum] <= 0)
fadedirection[deviceNum] = true; fadedirection[deviceNum] = true;
else if (fadetimer[deviceNum] >= 105) else if (fadetimer[deviceNum] >= 105)
fadedirection[deviceNum] = false; fadedirection[deviceNum] = false;
if (fadedirection[deviceNum]) if (fadedirection[deviceNum])
fadetimer[deviceNum] += .1; fadetimer[deviceNum] += .1;
else else
fadetimer[deviceNum] -= .1; fadetimer[deviceNum] -= .1;
color = getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]); color = getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]);
break; break;
}
case 2: case 2:
{
counters[deviceNum] += .167; counters[deviceNum] += .167;
color = HuetoRGB((float)counters[deviceNum] % 360, 255); color = HuetoRGB((float)counters[deviceNum] % 360, 255);
break; break;
}
case 3: case 3:
{
color = ChargingColor[deviceNum]; color = ChargingColor[deviceNum];
break; break;
default: }
break; default: break;
}
} }
} }
else if (forcelight[deviceNum]) else if (forcelight[deviceNum])
@ -155,11 +171,12 @@ namespace DS4Windows
color = new DS4Color(0, 0, 0); color = new DS4Color(0, 0, 0);
else else
{ {
if (device.ConnectionType == ConnectionType.BT) if (device.getConnectionType() == ConnectionType.BT)
color = new DS4Color(32, 64, 64); color = new DS4Color(32, 64, 64);
else else
color = new DS4Color(0, 0, 0); color = new DS4Color(0, 0, 0);
} }
bool distanceprofile = DistanceProfiles[deviceNum] || tempprofileDistance[deviceNum]; bool distanceprofile = DistanceProfiles[deviceNum] || tempprofileDistance[deviceNum];
//distanceprofile = (ProfilePath[deviceNum].ToLower().Contains("distance") || tempprofilename[deviceNum].ToLower().Contains("distance")); //distanceprofile = (ProfilePath[deviceNum].ToLower().Contains("distance") || tempprofilename[deviceNum].ToLower().Contains("distance"));
if (distanceprofile && !defualtLight) if (distanceprofile && !defualtLight)
@ -171,10 +188,12 @@ namespace DS4Windows
else else
color = getTransitionedColor(color, getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), 39.6078f), device.getLeftHeavySlowRumble()); color = getTransitionedColor(color, getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), 39.6078f), device.getLeftHeavySlowRumble());
} }
DS4HapticState haptics = new DS4HapticState DS4HapticState haptics = new DS4HapticState
{ {
LightBarColor = color LightBarColor = color
}; };
if (haptics.IsLightBarSet()) if (haptics.IsLightBarSet())
{ {
if (forcelight[deviceNum] && forcedFlash[deviceNum] > 0) if (forcelight[deviceNum] && forcedFlash[deviceNum] > 0)

View File

@ -325,7 +325,15 @@ namespace DS4Windows
} }
public static bool[] LedAsBatteryIndicator => m_Config.ledAsBattery; public static bool[] LedAsBatteryIndicator => m_Config.ledAsBattery;
public static bool getLedAsBatteryIndicator(int index)
{
return m_Config.ledAsBattery[index];
}
public static int[] ChargingType => m_Config.chargingType; public static int[] ChargingType => m_Config.chargingType;
public static int getChargingType(int index)
{
return m_Config.chargingType[index];
}
public static bool[] DinputOnly => m_Config.dinputOnly; public static bool[] DinputOnly => m_Config.dinputOnly;
public static bool[] StartTouchpadOff => m_Config.startTouchpadOff; public static bool[] StartTouchpadOff => m_Config.startTouchpadOff;
public static bool[] UseTPforControls => m_Config.useTPforControls; public static bool[] UseTPforControls => m_Config.useTPforControls;

View File

@ -192,6 +192,10 @@ namespace DS4Windows
public string MacAddress => Mac; public string MacAddress => Mac;
public ConnectionType ConnectionType => conType; public ConnectionType ConnectionType => conType;
public ConnectionType getConnectionType()
{
return this.conType;
}
// behavior only active when > 0 // behavior only active when > 0
private int idleTimeout = 0; private int idleTimeout = 0;
@ -215,6 +219,12 @@ namespace DS4Windows
return charging; return charging;
} }
private long lastTimeElapsed = 0;
public long getLastTimeElapsed()
{
return lastTimeElapsed;
}
public byte RightLightFastRumble public byte RightLightFastRumble
{ {
get { return rightLightFastRumble; } get { return rightLightFastRumble; }
@ -490,8 +500,10 @@ namespace DS4Windows
while (true) while (true)
{ {
string currerror = string.Empty; string currerror = string.Empty;
Latency.Add(sw.ElapsedMilliseconds - oldtime); long curtime = sw.ElapsedMilliseconds;
oldtime = sw.ElapsedMilliseconds; this.lastTimeElapsed = curtime - oldtime;
Latency.Add(this.lastTimeElapsed);
oldtime = curtime;
if (Latency.Count > 100) if (Latency.Count > 100)
Latency.RemoveAt(0); Latency.RemoveAt(0);
@ -683,16 +695,20 @@ namespace DS4Windows
// XXX fix initialization ordering so the null checks all go away // XXX fix initialization ordering so the null checks all go away
if (Report != null) if (Report != null)
Report(this, EventArgs.Empty); Report(this, EventArgs.Empty);
bool syncWriteReport = true; bool syncWriteReport = true;
if (conType == ConnectionType.BT) if (conType == ConnectionType.BT)
{ {
syncWriteReport = false; syncWriteReport = false;
} }
sendOutputReport(syncWriteReport); sendOutputReport(syncWriteReport);
if (!string.IsNullOrEmpty(error)) if (!string.IsNullOrEmpty(error))
error = string.Empty; error = string.Empty;
if (!string.IsNullOrEmpty(currerror)) if (!string.IsNullOrEmpty(currerror))
error = currerror; error = currerror;
cState.CopyTo(pState); cState.CopyTo(pState);
} }
} }
@ -950,10 +966,11 @@ namespace DS4Windows
public void pushHapticState(DS4HapticState hs) public void pushHapticState(DS4HapticState hs)
{ {
if (hapticStackIndex == hapticState.Length) int hapsLen = hapticState.Length;
if (hapticStackIndex == hapsLen)
{ {
DS4HapticState[] newHaptics = new DS4HapticState[hapticState.Length + 1]; DS4HapticState[] newHaptics = new DS4HapticState[hapsLen + 1];
Array.Copy(hapticState, newHaptics, hapticState.Length); Array.Copy(hapticState, newHaptics, hapsLen);
hapticState = newHaptics; hapticState = newHaptics;
} }
hapticState[hapticStackIndex++] = hs; hapticState[hapticStackIndex++] = hs;