From ac19a822f7a2f8caf4a5389ff0a0e2f2069f9e6f Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Tue, 9 May 2023 16:13:35 +0200 Subject: [PATCH] GPU eco check --- app/ASUSWmi.cs | 17 ++++++++++++++++- app/Settings.cs | 19 ++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/ASUSWmi.cs b/app/ASUSWmi.cs index 255c1b9a..b1a9bc61 100644 --- a/app/ASUSWmi.cs +++ b/app/ASUSWmi.cs @@ -1,4 +1,5 @@ -using System.Management; +using GHelper; +using System.Management; using System.Runtime.InteropServices; public class ASUSWmi @@ -218,6 +219,20 @@ public class ASUSWmi return CallMethod(DSTS, args); } + public int SetGPUEco(int eco) + { + int ecoFlag = DeviceGet(GPUEco); + if (ecoFlag < 0) return -1; + + if (ecoFlag == 1 && eco == 0) + return DeviceSet(GPUEco, eco, "GPUEco"); + + if (ecoFlag == 0 && eco == 1) + return DeviceSet(GPUEco, eco, "GPUEco"); + + return -1; + } + public int SetFanCurve(int device, byte[] curve) { diff --git a/app/Settings.cs b/app/Settings.cs index dff3e027..101793c8 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -1313,7 +1313,7 @@ namespace GHelper if (eco == 1) if ((GpuAuto && IsPlugged()) || (ForceGPU && GpuMode == ASUSWmi.GPUModeStandard)) { - SetEcoGPU(0); + SetGPUEco(0); return true; } if (eco == 0) @@ -1326,7 +1326,7 @@ namespace GHelper if (dialogResult == DialogResult.No) return false; } - SetEcoGPU(1); + SetGPUEco(1); return true; } } @@ -1337,15 +1337,16 @@ namespace GHelper public bool ReEnableGPU() { - if (Screen.AllScreens.Length <= 1) return false; + if (Program.config.getConfig("gpu_reenable") != 1) return false; + if (Screen.AllScreens.Length <= 1) return false; Logger.WriteLine("Re-enabling gpu for 503 model"); Thread.Sleep(1000); - SetEcoGPU(1); + SetGPUEco(1); Thread.Sleep(1000); - SetEcoGPU(0); + SetGPUEco(0); return true; } @@ -1414,7 +1415,7 @@ namespace GHelper } - public void SetEcoGPU(int eco) + public void SetGPUEco(int eco) { ButtonEnabled(buttonOptimized, false); @@ -1435,7 +1436,7 @@ namespace GHelper foreach (var process in Process.GetProcessesByName(kill)) process.Kill(); } - Program.wmi.DeviceSet(ASUSWmi.GPUEco, eco, "GPUEco"); + Program.wmi.SetGPUEco(eco); if (eco == 0) HardwareControl.RecreateGpuControlWithDelay(); @@ -1491,13 +1492,13 @@ namespace GHelper else if (GPUMode == ASUSWmi.GPUModeEco) { VisualiseGPUMode(GPUMode); - SetEcoGPU(1); + SetGPUEco(1); changed = true; } else if (GPUMode == ASUSWmi.GPUModeStandard) { VisualiseGPUMode(GPUMode); - SetEcoGPU(0); + SetGPUEco(0); changed = true; }