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
// //
numericBacklightTime.Location = new Point(477, 131); numericBacklightTime.Location = new Point(477, 131);
numericBacklightTime.Maximum = new decimal(new int[] { 3600, 0, 0, 0 });
numericBacklightTime.Name = "numericBacklightTime"; numericBacklightTime.Name = "numericBacklightTime";
numericBacklightTime.Size = new Size(240, 39); numericBacklightTime.Size = new Size(240, 39);
numericBacklightTime.TabIndex = 47; 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 try
{ {
@@ -104,10 +104,12 @@ public class NvidiaGpuControl : IGpuControl
Thread.Sleep(3000); Thread.Sleep(3000);
RunCMD("pnputil", $"/enable-device /deviceid \"{pnpDeviceId}\""); RunCMD("pnputil", $"/enable-device /deviceid \"{pnpDeviceId}\"");
Thread.Sleep(2000); Thread.Sleep(2000);
return true;
} }
catch (Exception ex ) catch (Exception ex )
{ {
Logger.WriteLine(ex.ToString()); Logger.WriteLine(ex.ToString());
return false;
} }
} }

View File

@@ -81,9 +81,9 @@ public static class HardwareControl
cpuTemp = ct.NextValue() - 273; cpuTemp = ct.NextValue() - 273;
} }
} }
catch catch (Exception ex)
{ {
Debug.WriteLine("Failed reading CPU temp"); Debug.WriteLine("Failed reading CPU temp :" + ex.Message);
} }
try try
@@ -94,8 +94,7 @@ public static class HardwareControl
catch (Exception ex) catch (Exception ex)
{ {
gpuTemp = -1; gpuTemp = -1;
Debug.WriteLine("Failed reading GPU temp"); Debug.WriteLine("Failed reading GPU temp :" + ex.Message);
Debug.WriteLine(ex.ToString());
} }
if (gpuTemp is null || gpuTemp < 0) 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 is null) return false;
if (!HardwareControl.GpuControl!.IsNvidia) return; 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); 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; if (dialogResult == DialogResult.No) return false;
Program.RunAsAdmin(); Program.RunAsAdmin();
Logger.WriteLine("Trying to restart GPU"); Logger.WriteLine("Trying to restart GPU");
var nvControl = (NvidiaGpuControl)HardwareControl.GpuControl; var nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
nvControl.RestartGPU(); return nvControl.RestartGPU();
} }
public void SetGPUEco(int eco, bool hardWay = false) public void SetGPUEco(int eco, bool hardWay = false)
@@ -1480,24 +1481,24 @@ namespace GHelper
Task.Run(async () => Task.Run(async () =>
{ {
int status;
if (eco == 1) if (eco == 1)
{ {
string[] tokill = { "EADesktop", "RadeonSoftware" }; string[] tokill = { "EADesktop", "RadeonSoftware" };
foreach (string kill in tokill) foreach (string kill in tokill)
foreach (var process in Process.GetProcessesByName(kill)) process.Kill(); 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) if (status == 0 && eco == 1 && hardWay)
{ {
RestartGPU(); if (RestartGPU()) Program.wmi.SetGPUEco(1);
Program.wmi.SetGPUEco(eco);
} }
await Task.Delay(TimeSpan.FromMilliseconds(500));
await Task.Delay(TimeSpan.FromSeconds(1));
Program.settingsForm.BeginInvoke(delegate Program.settingsForm.BeginInvoke(delegate
{ {
InitGPUMode(); InitGPUMode();
@@ -1506,7 +1507,7 @@ namespace GHelper
if (eco == 0) if (eco == 0)
{ {
await Task.Delay(TimeSpan.FromSeconds(1)); await Task.Delay(TimeSpan.FromMilliseconds(1000));
HardwareControl.RecreateGpuControl(); HardwareControl.RecreateGpuControl();
SetGPUClocks(false); SetGPUClocks(false);
} }