Eco tweaks

This commit is contained in:
Serge
2023-05-11 10:52:40 +02:00
parent 22f136fe9e
commit 97c97e8e19
4 changed files with 23 additions and 20 deletions

1
app/Extra.Designer.cs generated
View File

@@ -234,6 +234,7 @@ namespace GHelper
// numericBacklightTime
//
numericBacklightTime.Location = new Point(477, 131);
numericBacklightTime.Maximum = new decimal(new int[] { 3600, 0, 0, 0 });
numericBacklightTime.Name = "numericBacklightTime";
numericBacklightTime.Size = new Size(240, 39);
numericBacklightTime.TabIndex = 47;

View File

@@ -90,10 +90,10 @@ public class NvidiaGpuControl : IGpuControl
}
public void RestartGPU()
public bool RestartGPU()
{
if (!IsValid) return;
if (!IsValid) return false;
try
{
@@ -104,10 +104,12 @@ public class NvidiaGpuControl : IGpuControl
Thread.Sleep(3000);
RunCMD("pnputil", $"/enable-device /deviceid \"{pnpDeviceId}\"");
Thread.Sleep(2000);
return true;
}
catch (Exception ex )
{
Logger.WriteLine(ex.ToString());
return false;
}
}

View File

@@ -81,9 +81,9 @@ public static class HardwareControl
cpuTemp = ct.NextValue() - 273;
}
}
catch
catch (Exception ex)
{
Debug.WriteLine("Failed reading CPU temp");
Debug.WriteLine("Failed reading CPU temp :" + ex.Message);
}
try
@@ -94,8 +94,7 @@ public static class HardwareControl
catch (Exception ex)
{
gpuTemp = -1;
Debug.WriteLine("Failed reading GPU temp");
Debug.WriteLine(ex.ToString());
Debug.WriteLine("Failed reading GPU temp :" + ex.Message);
}
if (gpuTemp is null || gpuTemp < 0)

View File

@@ -1453,19 +1453,20 @@ namespace GHelper
}
public void RestartGPU()
public bool RestartGPU()
{
if (HardwareControl.GpuControl is null) return;
if (!HardwareControl.GpuControl!.IsNvidia) return;
if (HardwareControl.GpuControl is null) return false;
if (!HardwareControl.GpuControl!.IsNvidia) return false;
DialogResult dialogResult = MessageBox.Show("Something is using dGPU. Restart it in a device manager and try to set Eco again?", Properties.Strings.EcoMode, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No) return;
DialogResult dialogResult = MessageBox.Show("Something is using dGPU and blocking Eco mode. Restart dGPU in a device manager and try to set Eco again?", Properties.Strings.EcoMode, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No) return false;
Program.RunAsAdmin();
Logger.WriteLine("Trying to restart GPU");
var nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
nvControl.RestartGPU();
return nvControl.RestartGPU();
}
public void SetGPUEco(int eco, bool hardWay = false)
@@ -1480,24 +1481,24 @@ namespace GHelper
Task.Run(async () =>
{
int status;
if (eco == 1)
{
string[] tokill = { "EADesktop", "RadeonSoftware" };
foreach (string kill in tokill)
foreach (var process in Process.GetProcessesByName(kill)) process.Kill();
}
}
int status = Program.wmi.SetGPUEco(eco);
status = Program.wmi.SetGPUEco(eco);
if (status == 0 && eco == 1 && hardWay)
{
RestartGPU();
Program.wmi.SetGPUEco(eco);
if (RestartGPU()) Program.wmi.SetGPUEco(1);
}
await Task.Delay(TimeSpan.FromSeconds(1));
await Task.Delay(TimeSpan.FromMilliseconds(500));
Program.settingsForm.BeginInvoke(delegate
{
InitGPUMode();
@@ -1506,7 +1507,7 @@ namespace GHelper
if (eco == 0)
{
await Task.Delay(TimeSpan.FromSeconds(1));
await Task.Delay(TimeSpan.FromMilliseconds(1000));
HardwareControl.RecreateGpuControl();
SetGPUClocks(false);
}