diff --git a/HandheldCompanion/Managers/PerformanceManager.cs b/HandheldCompanion/Managers/PerformanceManager.cs
index 1c2608213..f5480eb99 100644
--- a/HandheldCompanion/Managers/PerformanceManager.cs
+++ b/HandheldCompanion/Managers/PerformanceManager.cs
@@ -2,12 +2,15 @@
using HandheldCompanion.Processors;
using HandheldCompanion.Utils;
using HandheldCompanion.Views;
+using HandheldCompanion.Views.Pages;
+using Microsoft.Win32;
using RTSSSharedMemoryNET;
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Timers;
+using System.Windows.Forms;
using Timer = System.Timers.Timer;
namespace HandheldCompanion.Managers;
@@ -99,6 +102,9 @@ public PerformanceManager()
autoWatchdog = new Timer { Interval = INTERVAL_AUTO, AutoReset = true, Enabled = false };
autoWatchdog.Elapsed += AutoTDPWatchdog_Elapsed;
+ // Monitor Power Status
+ SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
+
ProfileManager.Applied += ProfileManager_Applied;
ProfileManager.Discarded += ProfileManager_Discarded;
@@ -115,6 +121,11 @@ public PerformanceManager()
MaxDegreeOfParallelism = Convert.ToInt32(Environment.ProcessorCount / 2);
}
+ private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
+ {
+ ProfilesPage.RequestUpdate();
+ }
+
private void SettingsManagerOnSettingValueChanged(string name, object value)
{
switch (name)
@@ -140,10 +151,16 @@ private void ProfileManager_Applied(Profile profile, ProfileUpdateSource source)
// apply profile defined TDP
if (profile.TDPOverrideEnabled && profile.TDPOverrideValues is not null)
{
+ double[] TDPOverrideValues;
+ // Check if using TDP on Battery & is not Plugged in
+ bool PluggedInStatus = SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online;
+ if (profile.TDPOnBatteryEnabled && profile.TDPOnBatteryValues is not null && !PluggedInStatus) TDPOverrideValues = profile.TDPOnBatteryValues;
+ else TDPOverrideValues = profile.TDPOverrideValues;
+
if (!profile.AutoTDPEnabled)
{
// Manual TDP is set, use it and set max limit
- RequestTDP(profile.TDPOverrideValues);
+ RequestTDP(TDPOverrideValues);
StartTDPWatchdog();
AutoTDPMax = SettingsManager.GetInt("ConfigurableTDPOverrideUp");
}
@@ -151,7 +168,7 @@ private void ProfileManager_Applied(Profile profile, ProfileUpdateSource source)
{
// Both manual TDP and AutoTDP are on,
// use manual slider as the max limit for AutoTDP
- AutoTDPMax = profile.TDPOverrideValues[0];
+ AutoTDPMax = TDPOverrideValues[0];
StopTDPWatchdog(true);
}
}
diff --git a/HandheldCompanion/Misc/Profile.cs b/HandheldCompanion/Misc/Profile.cs
index 9fcd34dad..fa37addc6 100644
--- a/HandheldCompanion/Misc/Profile.cs
+++ b/HandheldCompanion/Misc/Profile.cs
@@ -123,6 +123,8 @@ public Profile(string path) : this()
// power
public bool TDPOverrideEnabled { get; set; }
public double[] TDPOverrideValues { get; set; }
+ public bool TDPOnBatteryEnabled { get; set; }
+ public double[] TDPOnBatteryValues { get; set; }
public bool GPUOverrideEnabled { get; set; }
public double GPUOverrideValue { get; set; }
diff --git a/HandheldCompanion/Properties/Resources.Designer.cs b/HandheldCompanion/Properties/Resources.Designer.cs
index 9bcd89f4c..baaf7f709 100644
--- a/HandheldCompanion/Properties/Resources.Designer.cs
+++ b/HandheldCompanion/Properties/Resources.Designer.cs
@@ -4986,6 +4986,24 @@ public static string ProfilesPage_SustainedPowerDesc {
}
}
+ ///
+ /// Looks up a localized string similar to TDP settings On Battery.
+ ///
+ public static string ProfilesPage_TDPOnBattery {
+ get {
+ return ResourceManager.GetString("ProfilesPage_TDPOnBattery", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Using seperated TDP settings when On Battery.
+ ///
+ public static string ProfilesPage_TDPOnBatteryDesc {
+ get {
+ return ResourceManager.GetString("ProfilesPage_TDPOnBatteryDesc", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Thermal Power (TDP) limit.
///
diff --git a/HandheldCompanion/Properties/Resources.resx b/HandheldCompanion/Properties/Resources.resx
index 647981f7e..f87ba6584 100644
--- a/HandheldCompanion/Properties/Resources.resx
+++ b/HandheldCompanion/Properties/Resources.resx
@@ -2357,4 +2357,10 @@ with motion input enabled, use selected button(s) to disable motion.
Make this the default layout
+
+ TDP settings On Battery
+
+
+ Using seperated TDP settings when On Battery
+
\ No newline at end of file
diff --git a/HandheldCompanion/Views/Pages/ProfilesPage.xaml b/HandheldCompanion/Views/Pages/ProfilesPage.xaml
index f3b3e67f6..5d356660f 100644
--- a/HandheldCompanion/Views/Pages/ProfilesPage.xaml
+++ b/HandheldCompanion/Views/Pages/ProfilesPage.xaml
@@ -657,7 +657,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
e)
+ {
+ if (!TDPOnBatterySlider.IsInitialized)
+ return;
+
+ // wait until lock is released
+ if (updateLock)
+ return;
+
+ selectedProfile.TDPOnBatteryValues = new double[3]
+ {
+ (int)TDPOnBatterySlider.Value,
+ (int)TDPOnBatterySlider.Value,
+ (int)TDPOnBatterySlider.Value
+ };
+ RequestUpdate();
+ }
+
private void FramerateToggle_Toggled(object sender, RoutedEventArgs e)
{
// UI thread (async)
diff --git a/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml b/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml
index a412bb363..946d768bd 100644
--- a/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml
+++ b/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml
@@ -231,9 +231,68 @@
TickPlacement="BottomRight"
ValueChanged="TDPSlider_ValueChanged" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
diff --git a/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs b/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs
index cb02f5b9d..7a1410c17 100644
--- a/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs
+++ b/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs
@@ -11,6 +11,8 @@
using System.Timers;
using System.Windows;
using System.Windows.Controls;
+using Microsoft.Win32;
+
using Page = System.Windows.Controls.Page;
namespace HandheldCompanion.Views.QuickPages;
@@ -260,6 +262,7 @@ public void SubmitProfile(ProfileUpdateSource source = ProfileUpdateSource.Quick
private void HotkeysManager_CommandExecuted(string listener)
{
// UI thread (async)
+ bool PluggedInStatus = System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus == System.Windows.Forms.PowerLineStatus.Online;
Application.Current.Dispatcher.BeginInvoke(() =>
{
switch (listener)
@@ -268,16 +271,16 @@ private void HotkeysManager_CommandExecuted(string listener)
{
if (currentProfile is null || !currentProfile.TDPOverrideEnabled)
return;
-
- TDPSlider.Value++;
+ if(!PluggedInStatus && currentProfile.TDPOnBatteryEnabled) TDPOnBatterySlider.Value++;
+ else TDPSlider.Value++;
}
break;
case "decreaseTDP":
{
if (currentProfile is null || !currentProfile.TDPOverrideEnabled)
return;
-
- TDPSlider.Value--;
+ if (!PluggedInStatus && currentProfile.TDPOnBatteryEnabled) TDPOnBatterySlider.Value--;
+ else TDPSlider.Value--;
}
break;
}
@@ -296,6 +299,7 @@ public void SettingsManager_SettingValueChanged(string name, object value)
using (new ScopedLock(updateLock))
{
TDPSlider.Minimum = (double)value;
+ TDPOnBatterySlider.Minimum = (double)value;
}
}
break;
@@ -304,6 +308,7 @@ public void SettingsManager_SettingValueChanged(string name, object value)
using (new ScopedLock(updateLock))
{
TDPSlider.Maximum = (double)value;
+ TDPOnBatterySlider.Maximum = (double)value;
}
}
break;
@@ -386,6 +391,13 @@ private void ProfileApplied(Profile profile, ProfileUpdateSource source)
: MainWindow.CurrentDevice.nTDP;
TDPSlider.Value = TDP[(int)PowerType.Slow];
+ // TDP On Battery
+ TDPOnBatteryToggle.IsOn = currentProfile.TDPOnBatteryEnabled;
+ var TDPOnBattery = currentProfile.TDPOnBatteryValues is not null
+ ? currentProfile.TDPOnBatteryValues
+ : MainWindow.CurrentDevice.nTDP;
+ TDPOnBatterySlider.Value = TDPOnBattery[(int)PowerType.Slow];
+
// GPU
GPUToggle.IsOn = currentProfile.GPUOverrideEnabled;
GPUSlider.Value = currentProfile.GPUOverrideValue != 0 ? currentProfile.GPUOverrideValue : 255 * 50;
@@ -487,6 +499,7 @@ private void CreateProfile()
currentProfile.Layout = (ProfileManager.GetProfileWithDefaultLayout()?.Layout ?? LayoutTemplate.DefaultLayout.Layout).Clone() as Layout;
currentProfile.LayoutTitle = LayoutTemplate.DesktopLayout.Name;
currentProfile.TDPOverrideValues = MainWindow.CurrentDevice.nTDP;
+ currentProfile.TDPOnBatteryValues = MainWindow.CurrentDevice.nTDP;
// if an update is pending, execute it and stop timer
if (UpdateTimer.Enabled)
@@ -588,6 +601,34 @@ private void TDPSlider_ValueChanged(object sender, RoutedPropertyChangedEventArg
};
RequestUpdate();
}
+ private void TDPOnBatteryToggle_Toggled(object sender, RoutedEventArgs e)
+ {
+ if (currentProfile is null)
+ return;
+
+ if (updateLock)
+ return;
+
+ currentProfile.TDPOnBatteryEnabled = TDPOnBatteryToggle.IsOn;
+ RequestUpdate();
+ }
+
+ private void TDPOnBatterySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (currentProfile is null)
+ return;
+
+ if (updateLock)
+ return;
+
+ currentProfile.TDPOnBatteryValues = new double[3]
+ {
+ (int)TDPOnBatterySlider.Value,
+ (int)TDPOnBatterySlider.Value,
+ (int)TDPOnBatterySlider.Value
+ };
+ RequestUpdate();
+ }
private void AutoTDPToggle_Toggled(object sender, RoutedEventArgs e)
{