Some changes made for lightbar modes

This commit is contained in:
Travis Nickles 2017-04-21 19:58:27 -07:00
parent 03029b32c0
commit 8c02cb7309
3 changed files with 93 additions and 44 deletions

View File

@ -29,7 +29,9 @@ namespace DS4Windows
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];
public static void updateLightBar(DS4Device device, int deviceNum, DS4State cState, DS4StateExposed eState, Mouse tp)
public static void updateLightBar(DS4Device device, int deviceNum, DS4State cState,
DS4StateExposed eState, Mouse tp)
{ {
/* /*
* TODO: Remove more property usage and use explicit getter methods instead. * TODO: Remove more property usage and use explicit getter methods instead.
@ -39,22 +41,23 @@ namespace DS4Windows
DS4Color color; DS4Color color;
if (!defualtLight && !forcelight[deviceNum]) if (!defualtLight && !forcelight[deviceNum])
{ {
if (UseCustomLed[deviceNum]) if (getUseCustomLed(deviceNum))
{ {
if (getLedAsBatteryIndicator(deviceNum)) if (getLedAsBatteryIndicator(deviceNum))
{ {
DS4Color fullColor = CustomColor[deviceNum]; DS4Color fullColor = getCustomColor(deviceNum);
DS4Color lowColor = LowColor[deviceNum]; DS4Color lowColor = getLowColor(deviceNum);
color = getTransitionedColor(lowColor, fullColor, device.Battery); color = getTransitionedColor(lowColor, fullColor, device.Battery);
} }
else else
color = CustomColor[deviceNum]; color = getCustomColor(deviceNum);
} }
else else
{ {
double rainbow = Rainbow[deviceNum]; double rainbow = getRainbow(deviceNum);
if (rainbow > 0) 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
{ {
@ -79,32 +82,31 @@ namespace DS4Windows
{ {
//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 = getMainColor(deviceNum);
DS4Color lowColor = LowColor[deviceNum]; DS4Color lowColor = getLowColor(deviceNum);
color = getTransitionedColor(lowColor, fullColor, (uint)device.getBattery()); color = getTransitionedColor(lowColor, fullColor, (uint)device.getBattery());
} }
} }
else else
{ {
color = MainColor[deviceNum]; color = getMainColor(deviceNum);
} }
} }
if (device.getBattery() <= getFlashAt(deviceNum) && !defualtLight && !device.isCharging()) if (device.getBattery() <= getFlashAt(deviceNum) && !defualtLight && !device.isCharging())
{ {
DS4Color flashColor = FlashColor[deviceNum]; DS4Color flashColor = getFlashColor(deviceNum);
if (!(flashColor.red == 0 && if (!(flashColor.red == 0 &&
flashColor.green == 0 && flashColor.green == 0 &&
flashColor.blue == 0)) flashColor.blue == 0))
color = flashColor; color = flashColor;
if (FlashType[deviceNum] == 1) if (getFlashType(deviceNum) == 1)
{ {
if (fadetimer[deviceNum] <= 0) if (fadetimer[deviceNum] <= 0.0)
fadedirection[deviceNum] = true; fadedirection[deviceNum] = true;
else if (fadetimer[deviceNum] >= 100) else if (fadetimer[deviceNum] >= 100.0)
fadedirection[deviceNum] = false; fadedirection[deviceNum] = false;
if (fadedirection[deviceNum]) if (fadedirection[deviceNum])
@ -117,8 +119,10 @@ namespace DS4Windows
} }
int idleDisconnectTimeout = getIdleDisconnectTimeout(deviceNum); int idleDisconnectTimeout = getIdleDisconnectTimeout(deviceNum);
if (idleDisconnectTimeout > 0 && getLedAsBatteryIndicator(deviceNum) && (!device.isCharging() || device.getBattery() >= 100)) if (idleDisconnectTimeout > 0 && getLedAsBatteryIndicator(deviceNum) &&
{//Fade lightbar by idle time (!device.isCharging() || device.getBattery() >= 100))
{
//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).TotalMilliseconds; double topratio = TimeSpan.FromSeconds(idleDisconnectTimeout).TotalMilliseconds;
@ -135,22 +139,22 @@ namespace DS4Windows
{ {
case 1: case 1:
{ {
if (fadetimer[deviceNum] <= 0) if (fadetimer[deviceNum] <= 0.0)
fadedirection[deviceNum] = true; fadedirection[deviceNum] = true;
else if (fadetimer[deviceNum] >= 105) else if (fadetimer[deviceNum] >= 100.0)
fadedirection[deviceNum] = false; fadedirection[deviceNum] = false;
if (fadedirection[deviceNum]) if (fadedirection[deviceNum])
fadetimer[deviceNum] += .1; fadetimer[deviceNum] += 0.1;
else else
fadetimer[deviceNum] -= .1; fadetimer[deviceNum] -= 0.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] += 0.167;
color = HuetoRGB((float)counters[deviceNum] % 360, 255); color = HuetoRGB((float)counters[deviceNum] % 360, 255);
break; break;
} }
@ -180,7 +184,8 @@ namespace DS4Windows
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)
{ //Thing I did for Distance {
//Thing I did for Distance
float rumble = device.getLeftHeavySlowRumble() / 2.55f; float rumble = device.getLeftHeavySlowRumble() / 2.55f;
byte max = Max(color.red, Max(color.green, color.blue)); byte max = Max(color.red, Max(color.green, color.blue));
if (device.getLeftHeavySlowRumble() > 100) if (device.getLeftHeavySlowRumble() > 100)

View File

@ -687,6 +687,7 @@ namespace DS4Windows
return dState; return dState;
} }
/* TODO: Possibly remove usage of this version of the method */
private static bool ShiftTrigger(int trigger, int device, DS4State cState, DS4StateExposed eState, Mouse tp) private static bool ShiftTrigger(int trigger, int device, DS4State cState, DS4StateExposed eState, Mouse tp)
{ {
bool result = false; bool result = false;
@ -2264,7 +2265,6 @@ namespace DS4Windows
if (Math.Abs(b1 - b2) > 10) if (Math.Abs(b1 - b2) > 10)
{ {
result = false; result = false;
} }
return result; return result;
@ -2397,6 +2397,7 @@ namespace DS4Windows
return result; return result;
} }
/* TODO: Possibly remove usage of this version of the method */
public static bool getBoolMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp) public static bool getBoolMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp)
{ {
bool result = false; bool result = false;
@ -2716,6 +2717,7 @@ namespace DS4Windows
return result; return result;
} }
/* TODO: Possibly remove usage of this version of the method */
public static bool getBoolActionMapping(int device, DS4Controls control, public static bool getBoolActionMapping(int device, DS4Controls control,
DS4State cState, DS4StateExposed eState, Mouse tp, bool analog=false) DS4State cState, DS4StateExposed eState, Mouse tp, bool analog=false)
{ {
@ -3086,6 +3088,7 @@ namespace DS4Windows
return result; return result;
} }
/* TODO: Possibly remove usage of this version of the method */
//Returns false for any bool, //Returns false for any bool,
//if control is one of the xy axis returns 127 //if control is one of the xy axis returns 127
//if its a trigger returns 0 //if its a trigger returns 0
@ -3153,7 +3156,8 @@ namespace DS4Windows
} }
} }
private static void resetToDefaultValue2(DS4Controls control, DS4State cState, DS4StateFieldMapping fieldMap) private static void resetToDefaultValue2(DS4Controls control, DS4State cState,
DS4StateFieldMapping fieldMap)
{ {
int controlNum = (int)control; int controlNum = (int)control;
DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum]; DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum];

View File

@ -295,6 +295,10 @@ namespace DS4Windows
public static int[] ButtonMouseSensitivity => m_Config.buttonMouseSensitivity; public static int[] ButtonMouseSensitivity => m_Config.buttonMouseSensitivity;
public static byte[] RumbleBoost => m_Config.rumble; public static byte[] RumbleBoost => m_Config.rumble;
public static double[] Rainbow => m_Config.rainbow; public static double[] Rainbow => m_Config.rainbow;
public static double getRainbow(int index)
{
return m_Config.rainbow[index];
}
public static bool[] FlushHIDQueue => m_Config.flushHIDQueue; public static bool[] FlushHIDQueue => m_Config.flushHIDQueue;
public static bool getFlushHIDQueue(int index) public static bool getFlushHIDQueue(int index)
{ {
@ -352,12 +356,32 @@ namespace DS4Windows
public static int[] GyroSensitivity => m_Config.gyroSensitivity; public static int[] GyroSensitivity => m_Config.gyroSensitivity;
public static int[] GyroInvert => m_Config.gyroInvert; public static int[] GyroInvert => m_Config.gyroInvert;
public static DS4Color[] MainColor => m_Config.m_Leds; public static DS4Color[] MainColor => m_Config.m_Leds;
public static DS4Color getMainColor(int index)
{
return m_Config.m_Leds[index];
}
public static DS4Color[] LowColor => m_Config.m_LowLeds; public static DS4Color[] LowColor => m_Config.m_LowLeds;
public static DS4Color getLowColor(int 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[] CustomColor => m_Config.m_CustomLeds; public static DS4Color[] CustomColor => m_Config.m_CustomLeds;
public static DS4Color getCustomColor(int index)
{
return m_Config.m_CustomLeds[index];
}
public static bool[] UseCustomLed => m_Config.useCustomLeds; public static bool[] UseCustomLed => m_Config.useCustomLeds;
public static bool getUseCustomLed(int index)
{
return m_Config.useCustomLeds[index];
}
public static DS4Color[] FlashColor => m_Config.m_FlashLeds; public static DS4Color[] FlashColor => m_Config.m_FlashLeds;
public static DS4Color getFlashColor(int index)
{
return m_Config.m_FlashLeds[index];
}
public static byte[] TapSensitivity => m_Config.tapSensitivity; public static byte[] TapSensitivity => m_Config.tapSensitivity;
public static bool[] DoubleTap => m_Config.doubleTap; public static bool[] DoubleTap => m_Config.doubleTap;
public static int[] ScrollSensitivity => m_Config.scrollSensitivity; public static int[] ScrollSensitivity => m_Config.scrollSensitivity;
@ -656,15 +680,17 @@ namespace DS4Windows
private static byte applyRatio(byte b1, byte b2, double r) private static byte applyRatio(byte b1, byte b2, double r)
{ {
if (r > 100) if (r > 100.0)
r = 100; r = 100.0;
else if (r < 0) else if (r < 0.0)
r = 0; r = 0.0;
r /= 100f;
return (byte)Math.Round((b1 * (1 - r) + b2 *r),0); r /= 100.0;
return (byte)Math.Round((b1 * (1 - r) + b2 * r), 0);
} }
public static DS4Color getTransitionedColor(DS4Color c1, DS4Color c2, double ratio) public static DS4Color getTransitionedColor(DS4Color c1, DS4Color c2, double ratio)
{//; {
//Color cs = Color.FromArgb(c1.red, c1.green, c1.blue); //Color cs = Color.FromArgb(c1.red, c1.green, c1.blue);
c1.red = applyRatio(c1.red, c2.red, ratio); c1.red = applyRatio(c1.red, c2.red, ratio);
c1.green = applyRatio(c1.green, c2.green, ratio); c1.green = applyRatio(c1.green, c2.green, ratio);
@ -689,6 +715,7 @@ namespace DS4Windows
csR = HuetoRGB(hue2,sat2,bri2 - br*ratio); csR = HuetoRGB(hue2,sat2,bri2 - br*ratio);
else else
csR = HuetoRGB(hue2 - hr * ratio, sat2 - sr * ratio, bri2 - br * ratio); csR = HuetoRGB(hue2 - hr * ratio, sat2 - sr * ratio, bri2 - br * ratio);
return csR; return csR;
} }
@ -699,28 +726,41 @@ namespace DS4Windows
float m = bri - C / 2; float m = bri - C / 2;
float R, G, B; float R, G, B;
if (0 <= hue && hue < 60) if (0 <= hue && hue < 60)
{ R = C; G = X; B = 0;} {
R = C; G = X; B = 0;
}
else if (60 <= hue && hue < 120) else if (60 <= hue && hue < 120)
{R = X; G = C; B = 0; } {
R = X; G = C; B = 0;
}
else if (120 <= hue && hue < 180) else if (120 <= hue && hue < 180)
{ R = 0; G = C; B = X; } {
R = 0; G = C; B = X;
}
else if (180 <= hue && hue < 240) else if (180 <= hue && hue < 240)
{ R = 0; G = X; B = C; } {
R = 0; G = X; B = C;
}
else if (240 <= hue && hue < 300) else if (240 <= hue && hue < 300)
{ R = X; G = 0; B = C; } {
R = X; G = 0; B = C;
}
else if (300 <= hue && hue < 360) else if (300 <= hue && hue < 360)
{ R = C; G = 0; B = X; } {
R = C; G = 0; B = X;
}
else else
{ R = 255; G = 0; B = 0; } {
R = 255; G = 0; B = 0;
}
R += m; G += m; B += m; R += m; G += m; B += m;
R *= 255; G *= 255; B *= 255; R *= 255.0f; G *= 255.0f; B *= 255.0f;
return Color.FromArgb((int)R, (int)G, (int)B); return Color.FromArgb((int)R, (int)G, (int)B);
} }
} }
public class BackingStore public class BackingStore
{ {
//public String m_Profile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + "\\Profiles.xml"; //public String m_Profile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + "\\Profiles.xml";