From 0e728ccc64ef45985ab29f9c7e412a09ddb05b72 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Tue, 27 Jun 2023 16:10:00 +0200 Subject: [PATCH] Reset UV --- app/Fans.cs | 13 ++++--- app/Mode/ModeControl.cs | 85 +++++++++++++++++++++++++---------------- app/Program.cs | 2 +- 3 files changed, 61 insertions(+), 39 deletions(-) diff --git a/app/Fans.cs b/app/Fans.cs index 5b868f65..a5d35278 100644 --- a/app/Fans.cs +++ b/app/Fans.cs @@ -183,7 +183,7 @@ namespace GHelper private void CheckApplyUV_Click(object? sender, EventArgs e) { AppConfig.SetMode("auto_uv", checkApplyUV.Checked ? 1 : 0); - modeControl.AutoUV(); + modeControl.AutoRyzen(); } public void InitAll() @@ -246,7 +246,7 @@ namespace GHelper private void ButtonApplyAdvanced_Click(object? sender, EventArgs e) { - modeControl.SetUV(true); + modeControl.SetRyzen(true); checkApplyUV.Enabled = true; } @@ -831,10 +831,6 @@ namespace GHelper AppConfig.SetMode("auto_apply", 0); AppConfig.SetMode("auto_apply_power", 0); - Program.acpi.DeviceSet(AsusACPI.PerformanceMode, Modes.GetCurrentBase(), "Mode"); - - if (Program.acpi.IsXGConnected()) - AsusUSB.ResetXGM(); trackUV.Value = 0; trackUViGPU.Value = 0; @@ -843,6 +839,11 @@ namespace GHelper AdvancedScroll(); AppConfig.SetMode("cpu_temp", -1); + modeControl.ResetPerformanceMode(); + + if (Program.acpi.IsXGConnected()) AsusUSB.ResetXGM(); + + if (gpuVisible) { trackGPUCore.Value = 0; diff --git a/app/Mode/ModeControl.cs b/app/Mode/ModeControl.cs index 2f9be948..4a2c2b73 100644 --- a/app/Mode/ModeControl.cs +++ b/app/Mode/ModeControl.cs @@ -12,11 +12,14 @@ namespace GHelper.Mode private static bool customFans = false; private static int customPower = 0; + private int _cpuUV = 0; + private int _igpuUV = 0; + static System.Timers.Timer reapplyTimer = default!; public ModeControl() { - reapplyTimer = new System.Timers.Timer(5000); + reapplyTimer = new System.Timers.Timer(30 * 1000); reapplyTimer.Elapsed += ReapplyTimer_Elapsed; reapplyTimer.Enabled = false; } @@ -38,6 +41,13 @@ namespace GHelper.Mode SetPerformanceMode(Modes.GetCurrent()); } + + public void ResetPerformanceMode() + { + ResetRyzen(); + Program.acpi.DeviceSet(AsusACPI.PerformanceMode, Modes.GetCurrentBase(), "Mode"); + } + public void SetPerformanceMode(int mode = -1, bool notify = false) { @@ -193,7 +203,7 @@ namespace GHelper.Mode if (applyPower) SetPower(); SetGPUPower(); - AutoUV(); + AutoRyzen(); }; timer.Start(); } @@ -201,7 +211,7 @@ namespace GHelper.Mode { if (applyPower) SetPower(true); SetGPUPower(); - AutoUV(); + AutoRyzen(); } } @@ -319,13 +329,6 @@ namespace GHelper.Mode } - - public void AutoUV() - { - if (!AppConfig.IsMode("auto_uv")) return; - SetUV(); - } - public void SetCPUTemp(int? cpuTemp, bool log = true) { if (cpuTemp >= RyzenControl.MinTemp && cpuTemp <= RyzenControl.MaxTemp) @@ -338,43 +341,47 @@ namespace GHelper.Mode reapplyTimer.Enabled = AppConfig.IsMode("auto_uv"); - } else + } + else { reapplyTimer.Enabled = false; } } - public void SetUV(bool launchAsAdmin = false) + public void SetUV(int cpuUV) { + if (cpuUV >= RyzenControl.MinCPUUV && cpuUV <= RyzenControl.MaxCPUUV) + { + var uvResult = SendCommand.set_coall(cpuUV); + Logger.WriteLine($"UV: {cpuUV} {uvResult}"); + if (uvResult == Smu.Status.OK) _cpuUV = cpuUV; + } + } + public void SetUViGPU(int igpuUV) + { + if (igpuUV >= RyzenControl.MinIGPUUV && igpuUV <= RyzenControl.MaxIGPUUV) + { + var iGPUResult = SendCommand.set_cogfx(igpuUV); + Logger.WriteLine($"iGPU UV: {igpuUV} {iGPUResult}"); + if (iGPUResult == Smu.Status.OK) _igpuUV = igpuUV; + } + } + + + public void SetRyzen(bool launchAsAdmin = false) + { if (!ProcessHelper.IsUserAdministrator()) { if (launchAsAdmin) ProcessHelper.RunAsAdmin("uv"); return; } - if (!RyzenControl.IsAMD()) return; - - int cpuUV = AppConfig.GetMode("cpu_uv", 0); - int igpuUV = AppConfig.GetMode("igpu_uv", 0); - int cpuTemp = AppConfig.GetMode("cpu_temp"); - try { - if (cpuUV >= RyzenControl.MinCPUUV && cpuUV <= RyzenControl.MaxCPUUV) - { - var uvResult = SendCommand.set_coall(cpuUV); - Logger.WriteLine($"UV: {cpuUV} {uvResult}"); - } - - if (igpuUV >= RyzenControl.MinIGPUUV && igpuUV <= RyzenControl.MaxIGPUUV) - { - var iGPUResult = SendCommand.set_cogfx(igpuUV); - Logger.WriteLine($"iGPU UV: {igpuUV} {iGPUResult}"); - } - - SetCPUTemp(cpuTemp); - + SetUV(AppConfig.GetMode("cpu_uv", 0)); + SetUViGPU(AppConfig.GetMode("igpu_uv", 0)); + SetCPUTemp(AppConfig.GetMode("cpu_temp")); } catch (Exception ex) { @@ -382,5 +389,19 @@ namespace GHelper.Mode } } + public void ResetRyzen() + { + if (_cpuUV != 0) SetUV(0); + if (_igpuUV != 0) SetUViGPU(0); + } + + public void AutoRyzen() + { + if (!RyzenControl.IsAMD()) return; + + if (AppConfig.IsMode("auto_uv")) SetRyzen(); + else ResetRyzen(); + } + } } diff --git a/app/Program.cs b/app/Program.cs index 9ae4e554..165cfa8b 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -218,7 +218,7 @@ namespace GHelper case "uv": Startup.ReScheduleAdmin(); settingsForm.FansToggle(2); - modeControl.SetUV(); + modeControl.SetRyzen(); break; } }