From 1a12162ba177f2afacdbc90193d364d4084e83d5 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Tue, 27 Jun 2023 13:42:06 +0200 Subject: [PATCH] Re-apply temp-limit --- app/Display/ScreenControl.cs | 5 ++-- app/Extra.cs | 1 - app/Fans.cs | 9 ++++---- app/Gpu/GPUModeControl.cs | 4 +--- app/Input/InputDispatcher.cs | 2 +- app/Mode/ModeControl.cs | 45 +++++++++++++++++++++++++++++------- app/Program.cs | 7 +++--- app/Ryzen/SendCommand.cs | 22 ++++++++---------- app/Settings.cs | 11 ++++----- 9 files changed, 64 insertions(+), 42 deletions(-) diff --git a/app/Display/ScreenControl.cs b/app/Display/ScreenControl.cs index f54dc8c5..18fe8d8f 100644 --- a/app/Display/ScreenControl.cs +++ b/app/Display/ScreenControl.cs @@ -4,7 +4,6 @@ namespace GHelper.Display { public class ScreenControl { - static SettingsForm settings = Program.settingsForm; public void AutoScreen(bool force = false) { if (force || AppConfig.Is("screen_auto")) @@ -82,9 +81,9 @@ namespace GHelper.Display AppConfig.Set("frequency", frequency); AppConfig.Set("overdrive", overdrive); - settings.Invoke(delegate + Program.settingsForm.Invoke(delegate { - settings.VisualiseScreen( + Program.settingsForm.VisualiseScreen( screenEnabled: screenEnabled, screenAuto: screenAuto, frequency: frequency, diff --git a/app/Extra.cs b/app/Extra.cs index 3271acaf..463c151a 100644 --- a/app/Extra.cs +++ b/app/Extra.cs @@ -12,7 +12,6 @@ namespace GHelper ScreenControl screenControl = new ScreenControl(); - Dictionary customActions = new Dictionary { {"","--------------" }, diff --git a/app/Fans.cs b/app/Fans.cs index a0d91d2d..5b868f65 100644 --- a/app/Fans.cs +++ b/app/Fans.cs @@ -11,7 +11,7 @@ namespace GHelper { int curIndex = -1; - DataPoint curPoint = null; + DataPoint? curPoint = null; Series seriesCPU; Series seriesGPU; @@ -25,7 +25,7 @@ namespace GHelper const int fansMax = 100; NvidiaGpuControl? nvControl = null; - ModeControl modeControl = new ModeControl(); + ModeControl modeControl = Program.modeControl; public Fans() { @@ -183,6 +183,7 @@ namespace GHelper private void CheckApplyUV_Click(object? sender, EventArgs e) { AppConfig.SetMode("auto_uv", checkApplyUV.Checked ? 1 : 0); + modeControl.AutoUV(); } public void InitAll() @@ -974,8 +975,8 @@ namespace GHelper { // Get the neighboring DataPoints of the hit point - DataPoint upperPoint = null; - DataPoint lowerPoint = null; + DataPoint? upperPoint = null; + DataPoint? lowerPoint = null; if (index > 0) { diff --git a/app/Gpu/GPUModeControl.cs b/app/Gpu/GPUModeControl.cs index 550c47b6..59ce9a7d 100644 --- a/app/Gpu/GPUModeControl.cs +++ b/app/Gpu/GPUModeControl.cs @@ -1,7 +1,6 @@ using GHelper.Display; using GHelper.Gpu.NVidia; using GHelper.Helpers; -using GHelper.Mode; using System.Diagnostics; namespace GHelper.Gpu @@ -9,7 +8,6 @@ namespace GHelper.Gpu public class GPUModeControl { static SettingsForm settings = Program.settingsForm; - ModeControl modeControl = new ModeControl(); ScreenControl screenControl = new ScreenControl(); public void InitGPUMode() @@ -153,7 +151,7 @@ namespace GHelper.Gpu { await Task.Delay(TimeSpan.FromMilliseconds(3000)); HardwareControl.RecreateGpuControl(); - modeControl.SetGPUClocks(false); + Program.modeControl.SetGPUClocks(false); } }); diff --git a/app/Input/InputDispatcher.cs b/app/Input/InputDispatcher.cs index c6d1ffc9..39e12797 100644 --- a/app/Input/InputDispatcher.cs +++ b/app/Input/InputDispatcher.cs @@ -17,7 +17,7 @@ namespace GHelper.Input public static Keys keyProfile = Keys.F5; public static Keys keyApp = Keys.F12; - static ModeControl modeControl = new ModeControl(); + static ModeControl modeControl = Program.modeControl; static ScreenControl screenControl = new ScreenControl(); KeyboardListener listener; diff --git a/app/Mode/ModeControl.cs b/app/Mode/ModeControl.cs index 99ba61a0..2f9be948 100644 --- a/app/Mode/ModeControl.cs +++ b/app/Mode/ModeControl.cs @@ -12,6 +12,20 @@ namespace GHelper.Mode private static bool customFans = false; private static int customPower = 0; + static System.Timers.Timer reapplyTimer = default!; + + public ModeControl() + { + reapplyTimer = new System.Timers.Timer(5000); + reapplyTimer.Elapsed += ReapplyTimer_Elapsed; + reapplyTimer.Enabled = false; + } + + private void ReapplyTimer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e) + { + SetCPUTemp(AppConfig.GetMode("cpu_temp"), false); + } + public void AutoPerformance(bool powerChanged = false) { var Plugged = SystemInformation.PowerStatus.PowerLineStatus; @@ -141,7 +155,6 @@ namespace GHelper.Mode AppConfig.Is("manual_mode") || AppConfig.ContainsModel("GU603") || AppConfig.ContainsModel("GU604") || - AppConfig.ContainsModel("FX517") || AppConfig.ContainsModel("G733"); } @@ -313,6 +326,24 @@ namespace GHelper.Mode SetUV(); } + public void SetCPUTemp(int? cpuTemp, bool log = true) + { + if (cpuTemp >= RyzenControl.MinTemp && cpuTemp <= RyzenControl.MaxTemp) + { + var resultCPU = SendCommand.set_tctl_temp((uint)cpuTemp); + if (log) Logger.WriteLine($"CPU Temp: {cpuTemp} {resultCPU}"); + + var restultAPU = SendCommand.set_apu_skin_temp_limit((uint)cpuTemp); + if (log) Logger.WriteLine($"APU Temp: {cpuTemp} {restultAPU}"); + + reapplyTimer.Enabled = AppConfig.IsMode("auto_uv"); + + } else + { + reapplyTimer.Enabled = false; + } + } + public void SetUV(bool launchAsAdmin = false) { @@ -332,19 +363,17 @@ namespace GHelper.Mode { if (cpuUV >= RyzenControl.MinCPUUV && cpuUV <= RyzenControl.MaxCPUUV) { - SendCommand.set_coall(cpuUV); + var uvResult = SendCommand.set_coall(cpuUV); + Logger.WriteLine($"UV: {cpuUV} {uvResult}"); } if (igpuUV >= RyzenControl.MinIGPUUV && igpuUV <= RyzenControl.MaxIGPUUV) { - SendCommand.set_cogfx(igpuUV); + var iGPUResult = SendCommand.set_cogfx(igpuUV); + Logger.WriteLine($"iGPU UV: {igpuUV} {iGPUResult}"); } - if (cpuTemp >= RyzenControl.MinTemp && cpuTemp <= RyzenControl.MaxTemp) - { - SendCommand.set_tctl_temp((uint)cpuTemp); - SendCommand.set_apu_skin_temp_limit((uint)cpuTemp); - } + SetCPUTemp(cpuTemp); } catch (Exception ex) diff --git a/app/Program.cs b/app/Program.cs index 13e53f8b..9ae4e554 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -22,12 +22,13 @@ namespace GHelper Visible = true }; - public static AsusACPI? acpi; + public static AsusACPI acpi; public static SettingsForm settingsForm = new SettingsForm(); + public static ModeControl modeControl = new ModeControl(); - public static GPUModeControl gpuControl = new GPUModeControl(); - public static ScreenControl screenControl = new ScreenControl(); + static GPUModeControl gpuControl = new GPUModeControl(); + static ScreenControl screenControl = new ScreenControl(); public static ToastForm toast = new ToastForm(); diff --git a/app/Ryzen/SendCommand.cs b/app/Ryzen/SendCommand.cs index 271bcd97..f59a28e4 100644 --- a/app/Ryzen/SendCommand.cs +++ b/app/Ryzen/SendCommand.cs @@ -189,7 +189,7 @@ namespace Ryzen } //TCTL Temp Limit - public static void set_tctl_temp(uint value) + public static Smu.Status? set_tctl_temp(uint value) { RyzenAccess.Initialize(); uint[] Args = new uint[6]; @@ -227,9 +227,8 @@ namespace Ryzen break; } - Logger.WriteLine($"CPU Temp: {value} {result}"); - RyzenAccess.Deinitialize(); + return result; } //cHTC Temp Limit @@ -261,7 +260,7 @@ namespace Ryzen } //Skin Temp limit - public static void set_apu_skin_temp_limit(uint value) + public static Smu.Status? set_apu_skin_temp_limit(uint value) { RyzenAccess.Initialize(); uint[] Args = new uint[6]; @@ -285,9 +284,9 @@ namespace Ryzen break; } - Logger.WriteLine($"APU Temp: {value} {result}"); - RyzenAccess.Deinitialize(); + + return result; } //VRM Current @@ -908,7 +907,7 @@ namespace Ryzen } //Set All Core Curve Optimiser - public static void set_coall(int value) + public static Smu.Status? set_coall(int value) { uint uvalue = Convert.ToUInt32(0x100000 - (uint)(-1 * value)); @@ -944,9 +943,9 @@ namespace Ryzen break; } - Logger.WriteLine($"UV: {value} {result}"); - RyzenAccess.Deinitialize(); + return result; + } //Set Per Core Curve Optimiser @@ -982,7 +981,7 @@ namespace Ryzen } //Set iGPU Curve Optimiser - public static void set_cogfx(int value) + public static Smu.Status? set_cogfx(int value) { uint uvalue = Convert.ToUInt32(0x100000 - (uint)(-1 * value)); @@ -1010,9 +1009,8 @@ namespace Ryzen break; } - Logger.WriteLine($"iGPU UV: {value} {result}"); - RyzenAccess.Deinitialize(); + return result; } //Disable OC diff --git a/app/Settings.cs b/app/Settings.cs index accc7fa5..e29c7219 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -20,7 +20,6 @@ namespace GHelper ContextMenuStrip contextMenuStrip = new CustomContextMenu(); ToolStripMenuItem menuSilent, menuBalanced, menuTurbo, menuEco, menuStandard, menuUltimate, menuOptimized; - ModeControl modeControl = new ModeControl(); GPUModeControl gpuControl = new GPUModeControl(); ScreenControl screenControl = new ScreenControl(); @@ -39,7 +38,7 @@ namespace GHelper public SettingsForm() { - + InitializeComponent(); InitTheme(true); @@ -183,10 +182,8 @@ namespace GHelper SetContextMenu(); - } - private void SettingsForm_VisibleChanged(object? sender, EventArgs e) { aTimer.Enabled = this.Visible; @@ -1125,17 +1122,17 @@ namespace GHelper private void ButtonSilent_Click(object? sender, EventArgs e) { - modeControl.SetPerformanceMode(AsusACPI.PerformanceSilent); + Program.modeControl.SetPerformanceMode(AsusACPI.PerformanceSilent); } private void ButtonBalanced_Click(object? sender, EventArgs e) { - modeControl.SetPerformanceMode(AsusACPI.PerformanceBalanced); + Program.modeControl.SetPerformanceMode(AsusACPI.PerformanceBalanced); } private void ButtonTurbo_Click(object? sender, EventArgs e) { - modeControl.SetPerformanceMode(AsusACPI.PerformanceTurbo); + Program.modeControl.SetPerformanceMode(AsusACPI.PerformanceTurbo); }