Skip to content

Commit

Permalink
Revert "Add an option to use seperated TDP when device power on Batte…
Browse files Browse the repository at this point in the history
…ry Mode (#833)"

This reverts commit a95132c.
  • Loading branch information
Valkirie committed Nov 22, 2023
1 parent a95132c commit 4d269a0
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 252 deletions.
21 changes: 2 additions & 19 deletions HandheldCompanion/Managers/PerformanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
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;
Expand Down Expand Up @@ -102,9 +99,6 @@ 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;

Expand All @@ -121,11 +115,6 @@ 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)
Expand All @@ -151,24 +140,18 @@ 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(TDPOverrideValues);
RequestTDP(profile.TDPOverrideValues);
StartTDPWatchdog();
AutoTDPMax = SettingsManager.GetInt("ConfigurableTDPOverrideUp");
}
else
{
// Both manual TDP and AutoTDP are on,
// use manual slider as the max limit for AutoTDP
AutoTDPMax = TDPOverrideValues[0];
AutoTDPMax = profile.TDPOverrideValues[0];
StopTDPWatchdog(true);
}
}
Expand Down
2 changes: 0 additions & 2 deletions HandheldCompanion/Misc/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ 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; }
Expand Down
18 changes: 0 additions & 18 deletions HandheldCompanion/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions HandheldCompanion/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2357,10 +2357,4 @@ with motion input enabled, use selected button(s) to disable motion.</value>
<data name="LayoutPage_SetAsDefault" xml:space="preserve">
<value>Make this the default layout</value>
</data>
<data name="ProfilesPage_TDPOnBattery" xml:space="preserve">
<value>TDP settings On Battery</value>
</data>
<data name="ProfilesPage_TDPOnBatteryDesc" xml:space="preserve">
<value>Using seperated TDP settings when On Battery</value>
</data>
</root>
61 changes: 0 additions & 61 deletions HandheldCompanion/Views/Pages/ProfilesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -657,68 +657,7 @@
</DockPanel>
</StackPanel>
</Grid>
<!-- TDP On Battery limit -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*" MinWidth="200" />
<ColumnDefinition MinWidth="200" />
</Grid.ColumnDefinitions>

<StackPanel Orientation="Vertical">
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Text="{x:Static resx:Resources.ProfilesPage_TDPOnBattery}" />
<TextBlock
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Static resx:Resources.ProfilesPage_TDPOnBatteryDesc}"
TextWrapping="Wrap" />
</StackPanel>

<ui:ToggleSwitch
Name="TDPOnBatteryToggle"
IsEnabled="{Binding ElementName=TDPToggle, Path=IsOn}"
Grid.Column="1"
HorizontalAlignment="Right"
Style="{DynamicResource InvertedToggleSwitchStyle}"
Toggled="TDPOnBatteryToggle_Toggled" />
</Grid>
<!-- Content -->
<Grid IsEnabled="{Binding ElementName=TDPToggle, Path=IsOn}">

<StackPanel>
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{x:Static resx:Resources.ProfilesPage_PowerLimitTarget}" />

<DockPanel ScrollViewer.PanningMode="HorizontalOnly">
<TextBlock
Width="35"
VerticalAlignment="Center"
Text="{Binding Value, StringFormat=N0, ElementName=TDPOnBatterySlider, Mode=OneWay}"
TextAlignment="Center" />
<TextBlock
Width="30"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{x:Static resx:Resources.QuickPerformancePage_TDPUnitWatt}" />
<Slider IsEnabled="{Binding ElementName=TDPOnBatteryToggle, Path=IsOn}"
x:Name="TDPOnBatterySlider"
Margin="6,0,0,0"
VerticalAlignment="Center"
AutoToolTipPrecision="0"
IsMoveToPointEnabled="True"
IsSnapToTickEnabled="True"
LargeChange="5"
Maximum="30"
Minimum="5"
SmallChange="1"
Style="{DynamicResource SliderStyle1}"
TickFrequency="1"
TickPlacement="BottomRight"
ValueChanged="TDPOnBatterySlider_ValueChanged" />
</DockPanel>
</StackPanel>
</Grid>
<!-- Separator -->
<Separator
Margin="-46,0,-16,0"
Expand Down
41 changes: 0 additions & 41 deletions HandheldCompanion/Views/Pages/ProfilesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public void SettingsManager_SettingValueChanged(string name, object value)
using (new ScopedLock(updateLock))
{
TDPSlider.Minimum = (double)value;
TDPOnBatterySlider.Minimum = (double)value;
}
}
break;
Expand All @@ -139,7 +138,6 @@ public void SettingsManager_SettingValueChanged(string name, object value)
using (new ScopedLock(updateLock))
{
TDPSlider.Maximum = (double)value;
TDPOnBatterySlider.Maximum = (double)value;
}
}
break;
Expand Down Expand Up @@ -403,17 +401,6 @@ private void DrawProfile()
TDPSlider.Minimum = SettingsManager.GetInt("ConfigurableTDPOverrideDown");
TDPSlider.Maximum = SettingsManager.GetInt("ConfigurableTDPOverrideUp");

// Sustained TDP On Battery settings (slow, stapm, long)
TDPOnBatteryToggle.IsOn = selectedProfile.TDPOnBatteryEnabled;
var TDPOnBattery = selectedProfile.TDPOnBatteryValues is not null
? selectedProfile.TDPOnBatteryValues
: MainWindow.CurrentDevice.nTDP;
TDPOnBatterySlider.Value = TDPOnBattery[(int)PowerType.Slow];

// define slider(s) min and max values based on device specifications
TDPOnBatterySlider.Minimum = SettingsManager.GetInt("ConfigurableTDPOverrideDown");
TDPOnBatterySlider.Maximum = SettingsManager.GetInt("ConfigurableTDPOverrideUp");

// Automatic TDP
AutoTDPToggle.IsOn = selectedProfile.AutoTDPEnabled;
AutoTDPSlider.Value = (int)selectedProfile.AutoTDPRequestedFPS;
Expand Down Expand Up @@ -585,34 +572,6 @@ private void TDPSlider_ValueChanged(object sender, RoutedPropertyChangedEventArg
RequestUpdate();
}

private void TDPOnBatteryToggle_Toggled(object sender, RoutedEventArgs e)
{
// wait until lock is released
if (updateLock)
return;

selectedProfile.TDPOnBatteryEnabled = TDPOnBatteryToggle.IsOn;
RequestUpdate();
}

private void TDPOnBatterySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> 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)
Expand Down
61 changes: 1 addition & 60 deletions HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,68 +231,9 @@
TickPlacement="BottomRight"
ValueChanged="TDPSlider_ValueChanged" />
</DockPanel>

<!-- TDP On Battery Limit -->
<Grid Margin="0,8,0,0" d:Visibility="Visible" Visibility="{Binding ElementName=TDPToggle, Path=IsOn, Converter={StaticResource BooleanToVisibilityConverter}}">
<DockPanel>
<ui:FontIcon
Height="40"
HorizontalAlignment="Center"
FontFamily="{DynamicResource SymbolThemeFontFamily}"
Glyph="&#xEBA9;" />

<ui:SimpleStackPanel Margin="12,0,0,0" VerticalAlignment="Center">
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Text="{x:Static resx:Resources.ProfilesPage_TDPOnBattery}" />
<TextBlock
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Static resx:Resources.ProfilesPage_TDPOnBatteryDesc}"
TextWrapping="Wrap" />
</ui:SimpleStackPanel>
</DockPanel>

<ui:ToggleSwitch
Name="TDPOnBatteryToggle"
Grid.Column="1"
HorizontalAlignment="Right"
Style="{DynamicResource InvertedToggleSwitchStyle}"
Toggled="TDPOnBatteryToggle_Toggled"/>
</Grid>

<StackPanel d:Visibility="Visible" Visibility="{Binding ElementName=TDPOnBatteryToggle, Path=IsOn, Converter={StaticResource BooleanToVisibilityConverter}}">
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{x:Static resx:Resources.QuickProfilesPage_PowerLimitTarget}" />
<DockPanel Margin="8,0,0,0" ScrollViewer.PanningMode="HorizontalOnly">
<TextBlock
Width="35"
VerticalAlignment="Center"
Text="{Binding Value, StringFormat=N0, ElementName=TDPOnBatterySlider, Mode=OneWay}"
TextAlignment="Center" />
<TextBlock
Width="30"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{x:Static resx:Resources.QuickPerformancePage_TDPUnitWatt}" />
<Slider
x:Name="TDPOnBatterySlider"
Margin="8,0,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
AutoToolTipPrecision="0"
IsMoveToPointEnabled="True"
IsSnapToTickEnabled="True"
LargeChange="5"
SmallChange="1"
Style="{DynamicResource SliderStyle1}"
TickFrequency="1"
TickPlacement="BottomRight"
ValueChanged="TDPOnBatterySlider_ValueChanged" />
</DockPanel>
</StackPanel>
</StackPanel>
</ui:SimpleStackPanel>

<Separator Background="{DynamicResource ExpanderHeaderBackground}" />

<!-- Auto TDP -->
Expand Down
Loading

0 comments on commit 4d269a0

Please sign in to comment.