mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Added possible fix for bios unsetting ppts after wake up
This commit is contained in:
@@ -310,6 +310,7 @@ namespace Tools
|
|||||||
public class NativeMethods
|
public class NativeMethods
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public const int KEYEVENTF_EXTENDEDKEY = 1;
|
public const int KEYEVENTF_EXTENDEDKEY = 1;
|
||||||
public const int KEYEVENTF_KEYUP = 2;
|
public const int KEYEVENTF_KEYUP = 2;
|
||||||
|
|
||||||
|
|||||||
59
Program.cs
59
Program.cs
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
public class HardwareMonitor
|
public class HardwareMonitor
|
||||||
{
|
{
|
||||||
@@ -36,6 +37,32 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// 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",
|
||||||
@@ -84,6 +111,16 @@ namespace GHelper
|
|||||||
|
|
||||||
SetAutoModes();
|
SetAutoModes();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
|
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
|
||||||
|
|
||||||
IntPtr ds = settingsForm.Handle;
|
IntPtr ds = settingsForm.Handle;
|
||||||
@@ -92,6 +129,28 @@ namespace GHelper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static int DeviceNotifyCallback(IntPtr context, int type, IntPtr setting)
|
||||||
|
{
|
||||||
|
//Debug.WriteLine($"Power callback type: {type}");
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case PBT_APMRESUMEAUTOMATIC:
|
||||||
|
settingsForm.BeginInvoke(delegate
|
||||||
|
{
|
||||||
|
// Setting "other" mode to prevent bios bugging with PPTs after wake up from sleep
|
||||||
|
int PerformanceMode = (config.getConfig("performance_mode") + 1) % 3;
|
||||||
|
wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
|
||||||
|
SetAutoModes();
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private static void SetAutoModes()
|
private static void SetAutoModes()
|
||||||
{
|
{
|
||||||
PowerLineStatus isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
|
PowerLineStatus isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
|
||||||
|
|||||||
29
Settings.cs
29
Settings.cs
@@ -702,6 +702,22 @@ namespace GHelper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void AutoFansAndPower()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (Program.config.getConfigPerf("auto_apply") == 1)
|
||||||
|
{
|
||||||
|
Program.wmi.SetFanCurve(0, Program.config.getFanConfig(0));
|
||||||
|
Program.wmi.SetFanCurve(1, Program.config.getFanConfig(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Program.config.getConfigPerf("auto_apply_power") == 1)
|
||||||
|
{
|
||||||
|
SetPower();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SetPerformanceMode(int PerformanceMode = ASUSWmi.PerformanceBalanced, bool notify = false)
|
public void SetPerformanceMode(int PerformanceMode = ASUSWmi.PerformanceBalanced, bool notify = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -732,16 +748,7 @@ namespace GHelper
|
|||||||
|
|
||||||
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
|
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
|
||||||
|
|
||||||
if (Program.config.getConfigPerf("auto_apply") == 1)
|
AutoFansAndPower();
|
||||||
{
|
|
||||||
Program.wmi.SetFanCurve(0, Program.config.getFanConfig(0));
|
|
||||||
Program.wmi.SetFanCurve(1, Program.config.getFanConfig(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Program.config.getConfigPerf("auto_apply_power") == 1)
|
|
||||||
{
|
|
||||||
SetPower();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fans != null && fans.Text != "")
|
if (fans != null && fans.Text != "")
|
||||||
{
|
{
|
||||||
@@ -749,6 +756,8 @@ namespace GHelper
|
|||||||
fans.InitPower();
|
fans.InitPower();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Debug.WriteLine("Perf:" + PerformanceMode);
|
||||||
|
|
||||||
if (notify && (oldMode != PerformanceMode))
|
if (notify && (oldMode != PerformanceMode))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user