This commit is contained in:
Serge
2023-06-27 16:10:00 +02:00
parent 1a12162ba1
commit 0e728ccc64
3 changed files with 61 additions and 39 deletions

View File

@@ -183,7 +183,7 @@ namespace GHelper
private void CheckApplyUV_Click(object? sender, EventArgs e) private void CheckApplyUV_Click(object? sender, EventArgs e)
{ {
AppConfig.SetMode("auto_uv", checkApplyUV.Checked ? 1 : 0); AppConfig.SetMode("auto_uv", checkApplyUV.Checked ? 1 : 0);
modeControl.AutoUV(); modeControl.AutoRyzen();
} }
public void InitAll() public void InitAll()
@@ -246,7 +246,7 @@ namespace GHelper
private void ButtonApplyAdvanced_Click(object? sender, EventArgs e) private void ButtonApplyAdvanced_Click(object? sender, EventArgs e)
{ {
modeControl.SetUV(true); modeControl.SetRyzen(true);
checkApplyUV.Enabled = true; checkApplyUV.Enabled = true;
} }
@@ -831,10 +831,6 @@ namespace GHelper
AppConfig.SetMode("auto_apply", 0); AppConfig.SetMode("auto_apply", 0);
AppConfig.SetMode("auto_apply_power", 0); AppConfig.SetMode("auto_apply_power", 0);
Program.acpi.DeviceSet(AsusACPI.PerformanceMode, Modes.GetCurrentBase(), "Mode");
if (Program.acpi.IsXGConnected())
AsusUSB.ResetXGM();
trackUV.Value = 0; trackUV.Value = 0;
trackUViGPU.Value = 0; trackUViGPU.Value = 0;
@@ -843,6 +839,11 @@ namespace GHelper
AdvancedScroll(); AdvancedScroll();
AppConfig.SetMode("cpu_temp", -1); AppConfig.SetMode("cpu_temp", -1);
modeControl.ResetPerformanceMode();
if (Program.acpi.IsXGConnected()) AsusUSB.ResetXGM();
if (gpuVisible) if (gpuVisible)
{ {
trackGPUCore.Value = 0; trackGPUCore.Value = 0;

View File

@@ -12,11 +12,14 @@ namespace GHelper.Mode
private static bool customFans = false; private static bool customFans = false;
private static int customPower = 0; private static int customPower = 0;
private int _cpuUV = 0;
private int _igpuUV = 0;
static System.Timers.Timer reapplyTimer = default!; static System.Timers.Timer reapplyTimer = default!;
public ModeControl() public ModeControl()
{ {
reapplyTimer = new System.Timers.Timer(5000); reapplyTimer = new System.Timers.Timer(30 * 1000);
reapplyTimer.Elapsed += ReapplyTimer_Elapsed; reapplyTimer.Elapsed += ReapplyTimer_Elapsed;
reapplyTimer.Enabled = false; reapplyTimer.Enabled = false;
} }
@@ -38,6 +41,13 @@ namespace GHelper.Mode
SetPerformanceMode(Modes.GetCurrent()); SetPerformanceMode(Modes.GetCurrent());
} }
public void ResetPerformanceMode()
{
ResetRyzen();
Program.acpi.DeviceSet(AsusACPI.PerformanceMode, Modes.GetCurrentBase(), "Mode");
}
public void SetPerformanceMode(int mode = -1, bool notify = false) public void SetPerformanceMode(int mode = -1, bool notify = false)
{ {
@@ -193,7 +203,7 @@ namespace GHelper.Mode
if (applyPower) SetPower(); if (applyPower) SetPower();
SetGPUPower(); SetGPUPower();
AutoUV(); AutoRyzen();
}; };
timer.Start(); timer.Start();
} }
@@ -201,7 +211,7 @@ namespace GHelper.Mode
{ {
if (applyPower) SetPower(true); if (applyPower) SetPower(true);
SetGPUPower(); 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) public void SetCPUTemp(int? cpuTemp, bool log = true)
{ {
if (cpuTemp >= RyzenControl.MinTemp && cpuTemp <= RyzenControl.MaxTemp) if (cpuTemp >= RyzenControl.MinTemp && cpuTemp <= RyzenControl.MaxTemp)
@@ -338,43 +341,47 @@ namespace GHelper.Mode
reapplyTimer.Enabled = AppConfig.IsMode("auto_uv"); reapplyTimer.Enabled = AppConfig.IsMode("auto_uv");
} else }
else
{ {
reapplyTimer.Enabled = false; 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 (!ProcessHelper.IsUserAdministrator())
{ {
if (launchAsAdmin) ProcessHelper.RunAsAdmin("uv"); if (launchAsAdmin) ProcessHelper.RunAsAdmin("uv");
return; 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 try
{ {
if (cpuUV >= RyzenControl.MinCPUUV && cpuUV <= RyzenControl.MaxCPUUV) SetUV(AppConfig.GetMode("cpu_uv", 0));
{ SetUViGPU(AppConfig.GetMode("igpu_uv", 0));
var uvResult = SendCommand.set_coall(cpuUV); SetCPUTemp(AppConfig.GetMode("cpu_temp"));
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);
} }
catch (Exception ex) 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();
}
} }
} }

View File

@@ -218,7 +218,7 @@ namespace GHelper
case "uv": case "uv":
Startup.ReScheduleAdmin(); Startup.ReScheduleAdmin();
settingsForm.FansToggle(2); settingsForm.FansToggle(2);
modeControl.SetUV(); modeControl.SetRyzen();
break; break;
} }
} }