mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Adjusted PPTs for 2021 model, added windows PowerModes
This commit is contained in:
18
ASUSWmi.cs
18
ASUSWmi.cs
@@ -27,12 +27,16 @@ public class ASUSWmi
|
|||||||
public const uint DevsCPUFanCurve = 0x00110024;
|
public const uint DevsCPUFanCurve = 0x00110024;
|
||||||
public const uint DevsGPUFanCurve = 0x00110025;
|
public const uint DevsGPUFanCurve = 0x00110025;
|
||||||
|
|
||||||
public const int PPT_TotalA0 = 0x001200A0;
|
public const int PPT_TotalA0 = 0x001200A0; // Total PPT on 2022 and CPU PPT on 2021
|
||||||
public const int PPT_TotalA1 = 0x001200A1;
|
public const int PPT_EDCA1 = 0x001200A1; // CPU EDC
|
||||||
|
public const int PPT_TDCA2 = 0x001200A2; // CPU TDC
|
||||||
|
public const int PPT_APUA3 = 0x001200A3; // APU PPT ON 2021, doesn't work on 2022
|
||||||
|
|
||||||
public const int PPT_CPUB0 = 0x001200B0;
|
public const int PPT_CPUB0 = 0x001200B0; // CPU PPT on 2022
|
||||||
public const int PPT_CPUB1 = 0x001200B1;
|
public const int PPT_CPUB1 = 0x001200B1; // APU PPT on 2022
|
||||||
public const int PPT_CPUA2 = 0x001200A2;
|
|
||||||
|
public const int PPT_APUC1 = 0x001200C1;
|
||||||
|
public const int PPT_APUC2 = 0x001200C2;
|
||||||
|
|
||||||
public const int PerformanceBalanced = 0;
|
public const int PerformanceBalanced = 0;
|
||||||
public const int PerformanceTurbo = 1;
|
public const int PerformanceTurbo = 1;
|
||||||
@@ -44,11 +48,11 @@ public class ASUSWmi
|
|||||||
|
|
||||||
|
|
||||||
public const int MaxTotal = 150;
|
public const int MaxTotal = 150;
|
||||||
public const int MinTotal = 15;
|
public const int MinTotal = 5;
|
||||||
public const int DefaultTotal = 125;
|
public const int DefaultTotal = 125;
|
||||||
|
|
||||||
public const int MaxCPU = 90;
|
public const int MaxCPU = 90;
|
||||||
public const int MinCPU = 15;
|
public const int MinCPU = 5;
|
||||||
public const int DefaultCPU = 80;
|
public const int DefaultCPU = 80;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
Fans.cs
13
Fans.cs
@@ -168,8 +168,17 @@ namespace GHelper
|
|||||||
public void InitPower(bool changed = false)
|
public void InitPower(bool changed = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
panelPower.Visible = (Program.wmi.DeviceGet(ASUSWmi.PPT_TotalA0) >= 0);
|
bool cpuBmode = (Program.wmi.DeviceGet(ASUSWmi.PPT_CPUB0) >= 0); // 2022 model +
|
||||||
panelCPU.Visible = (Program.wmi.DeviceGet(ASUSWmi.PPT_CPUB0) >= 0);
|
bool cpuAmode = (Program.wmi.DeviceGet(ASUSWmi.PPT_TotalA0) >= 0); // 2021 model +
|
||||||
|
|
||||||
|
panelPower.Visible = cpuAmode;
|
||||||
|
panelCPU.Visible = cpuBmode;
|
||||||
|
|
||||||
|
// Yes, that's stupid, but Total slider on 2021 model actually adjusts CPU PPT
|
||||||
|
if (!cpuBmode)
|
||||||
|
{
|
||||||
|
label1.Text = "CPU SPPT";
|
||||||
|
}
|
||||||
|
|
||||||
int limit_total;
|
int limit_total;
|
||||||
int limit_cpu;
|
int limit_cpu;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
<AssemblyVersion>0.27</AssemblyVersion>
|
<AssemblyVersion>0.28</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -458,6 +458,15 @@ public class NativeMethods
|
|||||||
static readonly Guid GUID_CPU = new Guid("54533251-82be-4824-96c1-47b60b740d00");
|
static readonly Guid GUID_CPU = new Guid("54533251-82be-4824-96c1-47b60b740d00");
|
||||||
static readonly Guid GUID_BOOST = new Guid("be337238-0d82-4146-a960-4f3749d470c7");
|
static readonly Guid GUID_BOOST = new Guid("be337238-0d82-4146-a960-4f3749d470c7");
|
||||||
|
|
||||||
|
[DllImportAttribute("powrprof.dll", EntryPoint = "PowerGetActualOverlayScheme")]
|
||||||
|
public static extern uint PowerGetActualOverlayScheme(out Guid ActualOverlayGuid);
|
||||||
|
|
||||||
|
[DllImportAttribute("powrprof.dll", EntryPoint = "PowerGetEffectiveOverlayScheme")]
|
||||||
|
public static extern uint PowerGetEffectiveOverlayScheme(out Guid EffectiveOverlayGuid);
|
||||||
|
|
||||||
|
[DllImportAttribute("powrprof.dll", EntryPoint = "PowerSetActiveOverlayScheme")]
|
||||||
|
public static extern uint PowerSetActiveOverlayScheme(Guid OverlaySchemeGuid);
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||||
public struct DEVMODE
|
public struct DEVMODE
|
||||||
{
|
{
|
||||||
@@ -666,4 +675,20 @@ public class NativeMethods
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SetPowerScheme(int mode)
|
||||||
|
{
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case 0: // balanced
|
||||||
|
PowerSetActiveOverlayScheme(new Guid("00000000-0000-0000-0000-000000000000"));
|
||||||
|
break;
|
||||||
|
case 1: // turbo
|
||||||
|
PowerSetActiveOverlayScheme(new Guid("ded574b5-45a0-4f42-8737-46345c09c238"));
|
||||||
|
break;
|
||||||
|
case 2: //silent
|
||||||
|
PowerSetActiveOverlayScheme(new Guid("961cc777-2547-4f9d-8174-7d86181b8a7a"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
57
Program.cs
57
Program.cs
@@ -46,31 +46,6 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// Native methods for sleep detection
|
|
||||||
|
|
||||||
[DllImport("Powrprof.dll", SetLastError = true)]
|
|
||||||
static extern uint PowerRegisterSuspendResumeNotification(uint flags, ref DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS receipient, ref IntPtr registrationHandle);
|
|
||||||
|
|
||||||
|
|
||||||
private const int WM_POWERBROADCAST = 536; // (0x218)
|
|
||||||
private const int PBT_APMPOWERSTATUSCHANGE = 10; // (0xA) - Power status has changed.
|
|
||||||
private const int PBT_APMRESUMEAUTOMATIC = 18; // (0x12) - Operation is resuming automatically from a low-power state.This message is sent every time the system resumes.
|
|
||||||
private const int PBT_APMRESUMESUSPEND = 7; // (0x7) - Operation is resuming from a low-power state.This message is sent after PBT_APMRESUMEAUTOMATIC if the resume is triggered by user input, such as pressing a key.
|
|
||||||
private const int PBT_APMSUSPEND = 4; // (0x4) - System is suspending operation.
|
|
||||||
private const int PBT_POWERSETTINGCHANGE = 32787; // (0x8013) - A power setting change event has been received.
|
|
||||||
private const int DEVICE_NOTIFY_CALLBACK = 2;
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
struct DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS
|
|
||||||
{
|
|
||||||
public DeviceNotifyCallbackRoutine Callback;
|
|
||||||
public IntPtr Context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public delegate int DeviceNotifyCallbackRoutine(IntPtr context, int type, IntPtr setting);
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
public static NotifyIcon trayIcon = new NotifyIcon
|
public static NotifyIcon trayIcon = new NotifyIcon
|
||||||
{
|
{
|
||||||
Text = "G-Helper",
|
Text = "G-Helper",
|
||||||
@@ -128,20 +103,6 @@ namespace GHelper
|
|||||||
SetAutoModes();
|
SetAutoModes();
|
||||||
HardwareMonitor.RecreateGpuTemperatureProvider();
|
HardwareMonitor.RecreateGpuTemperatureProvider();
|
||||||
|
|
||||||
// Subscribing for native power change events
|
|
||||||
|
|
||||||
/*
|
|
||||||
IntPtr registrationHandle = new IntPtr();
|
|
||||||
DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS recipient = new DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS();
|
|
||||||
recipient.Callback = new DeviceNotifyCallbackRoutine(DeviceNotifyCallback);
|
|
||||||
recipient.Context = IntPtr.Zero;
|
|
||||||
|
|
||||||
IntPtr pRecipient = Marshal.AllocHGlobal(Marshal.SizeOf(recipient));
|
|
||||||
Marshal.StructureToPtr(recipient, pRecipient, false);
|
|
||||||
|
|
||||||
uint result = PowerRegisterSuspendResumeNotification(DEVICE_NOTIFY_CALLBACK, ref recipient, ref registrationHandle);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Subscribing for monitor power on events
|
// Subscribing for monitor power on events
|
||||||
var settingGuid = new NativeMethods.PowerSettingGuid();
|
var settingGuid = new NativeMethods.PowerSettingGuid();
|
||||||
unRegPowerNotify = NativeMethods.RegisterPowerSettingNotification(ds, settingGuid.ConsoleDisplayState, NativeMethods.DEVICE_NOTIFY_WINDOW_HANDLE);
|
unRegPowerNotify = NativeMethods.RegisterPowerSettingNotification(ds, settingGuid.ConsoleDisplayState, NativeMethods.DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||||
@@ -149,29 +110,11 @@ namespace GHelper
|
|||||||
// Subscribing for system power change events
|
// Subscribing for system power change events
|
||||||
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
|
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
|
||||||
|
|
||||||
|
|
||||||
CheckForUpdates();
|
CheckForUpdates();
|
||||||
Application.Run();
|
Application.Run();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int DeviceNotifyCallback(IntPtr context, int type, IntPtr setting)
|
|
||||||
{
|
|
||||||
Logger.WriteLine($"Power callback {type}");
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case PBT_APMRESUMEAUTOMATIC:
|
|
||||||
settingsForm.BeginInvoke(delegate
|
|
||||||
{
|
|
||||||
SetAutoModes();
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static async void CheckForUpdates()
|
static async void CheckForUpdates()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
15
Settings.cs
15
Settings.cs
@@ -741,9 +741,11 @@ namespace GHelper
|
|||||||
if (limit_cpu > ASUSWmi.MaxCPU) return;
|
if (limit_cpu > ASUSWmi.MaxCPU) return;
|
||||||
if (limit_cpu < ASUSWmi.MinCPU) return;
|
if (limit_cpu < ASUSWmi.MinCPU) return;
|
||||||
|
|
||||||
Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA0, limit_total);
|
if (Program.wmi.DeviceGet(ASUSWmi.PPT_TotalA0) >= 0)
|
||||||
Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA1, limit_total);
|
Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA0, limit_total);
|
||||||
Program.wmi.DeviceSet(ASUSWmi.PPT_CPUB0, limit_cpu);
|
|
||||||
|
if (Program.wmi.DeviceGet(ASUSWmi.PPT_CPUB0) >= 0)
|
||||||
|
Program.wmi.DeviceSet(ASUSWmi.PPT_CPUB0, limit_cpu);
|
||||||
|
|
||||||
Logger.WriteLine("PowerLimits " + limit_total.ToString() + ", " + limit_cpu.ToString());
|
Logger.WriteLine("PowerLimits " + limit_total.ToString() + ", " + limit_cpu.ToString());
|
||||||
|
|
||||||
@@ -819,6 +821,13 @@ namespace GHelper
|
|||||||
|
|
||||||
AutoFansAndPower();
|
AutoFansAndPower();
|
||||||
|
|
||||||
|
NativeMethods.SetPowerScheme(PerformanceMode);
|
||||||
|
|
||||||
|
if (NativeMethods.PowerGetEffectiveOverlayScheme(out Guid activeScheme) == 0)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Effective :" + activeScheme);
|
||||||
|
}
|
||||||
|
|
||||||
if (fans != null && fans.Text != "")
|
if (fans != null && fans.Text != "")
|
||||||
{
|
{
|
||||||
fans.InitFans();
|
fans.InitFans();
|
||||||
|
|||||||
Reference in New Issue
Block a user