diff --git a/DS4Windows/DS4Control/DS4LightBar.cs b/DS4Windows/DS4Control/DS4LightBar.cs index 981837b..c43638f 100644 --- a/DS4Windows/DS4Control/DS4LightBar.cs +++ b/DS4Windows/DS4Control/DS4LightBar.cs @@ -31,6 +31,11 @@ namespace DS4Windows public static byte[] forcedFlash = new byte[4]; 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. + * Testing in proper optimized release builds shows that it is + * still necessary to reduce lag. + */ DS4Color color; if (!defualtLight && !forcelight[deviceNum]) { @@ -86,7 +91,7 @@ namespace DS4Windows } - if (device.Battery <= FlashAt[deviceNum] && !defualtLight && !device.Charging) + if (device.getBattery() <= FlashAt[deviceNum] && !defualtLight && !device.isCharging()) { if (!(FlashColor[deviceNum].red == 0 && FlashColor[deviceNum].green == 0 && @@ -106,7 +111,7 @@ namespace DS4Windows } } - if (IdleDisconnectTimeout[deviceNum] > 0 && LedAsBatteryIndicator[deviceNum] && (!device.Charging || device.Battery >= 100)) + if (IdleDisconnectTimeout[deviceNum] > 0 && LedAsBatteryIndicator[deviceNum] && (!device.isCharging() || device.getBattery() >= 100)) {//Fade lightbar by idle time TimeSpan timeratio = new TimeSpan(DateTime.UtcNow.Ticks - device.lastActive.Ticks); double botratio = timeratio.TotalMilliseconds; @@ -164,7 +169,7 @@ namespace DS4Windows if (device.LeftHeavySlowRumble > 100) color = getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), rumble); else - color = getTransitionedColor(color, getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), 39.6078f), device.LeftHeavySlowRumble); + color = getTransitionedColor(color, getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), 39.6078f), device.getLeftHeavySlowRumble()); } DS4HapticState haptics = new DS4HapticState { @@ -177,7 +182,7 @@ namespace DS4Windows haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)(25 - forcedFlash[deviceNum]); haptics.LightBarExplicitlyOff = true; } - else if (device.Battery <= FlashAt[deviceNum] && FlashType[deviceNum] == 0 && !defualtLight && !device.Charging) + else if (device.getBattery() <= getFlashAt(deviceNum) && getFlashType(deviceNum) == 0 && !defualtLight && !device.isCharging()) { int level = device.Battery / 10; //if (level >= 10) @@ -185,9 +190,9 @@ namespace DS4Windows haptics.LightBarFlashDurationOn = BatteryIndicatorDurations[level, 0]; haptics.LightBarFlashDurationOff = BatteryIndicatorDurations[level, 1]; } - else if (distanceprofile && device.LeftHeavySlowRumble > 155) //also part of Distance + else if (distanceprofile && device.getLeftHeavySlowRumble() > 155) //also part of Distance { - haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)((-device.LeftHeavySlowRumble + 265)); + haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)((-device.getLeftHeavySlowRumble() + 265)); haptics.LightBarExplicitlyOff = true; } else @@ -201,7 +206,9 @@ namespace DS4Windows { haptics.LightBarExplicitlyOff = true; } - if (device.LightBarOnDuration != haptics.LightBarFlashDurationOn && device.LightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0) + + byte tempLightBarOnDuration = device.getLightBarOnDuration(); + if (tempLightBarOnDuration != haptics.LightBarFlashDurationOn && tempLightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0) haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1; // Comment out code for now. This condition gets hit too often and bogs down the GUI diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 1b54c39..bf10b79 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -280,7 +280,17 @@ namespace DS4Windows public static int[] IdleDisconnectTimeout => m_Config.idleDisconnectTimeout; public static byte[] TouchSensitivity => m_Config.touchSensitivity; public static byte[] FlashType => m_Config.flashType; + public static byte getFlashType(int index) + { + return m_Config.flashType[index]; + } + public static int[] FlashAt => m_Config.flashAt; + public static int getFlashAt(int index) + { + return m_Config.flashAt[index]; + } + public static bool[] LedAsBatteryIndicator => m_Config.ledAsBattery; public static int[] ChargingType => m_Config.chargingType; public static bool[] DinputOnly => m_Config.dinputOnly; @@ -320,7 +330,7 @@ namespace DS4Windows public static bool[] MouseAccel => m_Config.mouseAccel; public static string[] LaunchProgram => m_Config.launchProgram; public static string[] ProfilePath => m_Config.profilePath; - public static bool[] DistanceProfiles => m_Config.distanceProfiles; + public static bool[] DistanceProfiles = m_Config.distanceProfiles; public static List[] ProfileActions => m_Config.profileActions; public static void UpdateDS4CSetting (int deviceNum, string buttonName, bool shift, object action, string exts, DS4KeyType kt, int trigger = 0) diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 21dc79e..7adbb30 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -156,7 +156,16 @@ namespace DS4Windows public int IdleTimeout { get; set; } // behavior only active when > 0 public int Battery => battery; + public int getBattery() + { + return battery; + } + public bool Charging => charging; + public bool isCharging() + { + return charging; + } public byte RightLightFastRumble { @@ -178,6 +187,11 @@ namespace DS4Windows } } + public byte getLeftHeavySlowRumble() + { + return leftHeavySlowRumble; + } + public DS4Color LightBarColor { get { return ligtBarColor; } @@ -201,6 +215,11 @@ namespace DS4Windows } } } + + public byte getLightBarOnDuration() + { + return ledFlashOn; + } public byte LightBarOffDuration { @@ -214,6 +233,11 @@ namespace DS4Windows } } + public byte getLightBarOffDuration() + { + return ledFlashOff; + } + public DS4Touchpad Touchpad { get { return touchpad; } } public DS4SixAxis SixAxis { get { return sixAxis; } }