mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Improved logging
This commit is contained in:
@@ -157,21 +157,31 @@ public class ASUSWmi
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] DeviceSet(uint DeviceID, int Status)
|
public int DeviceSet(uint DeviceID, int Status, string logName)
|
||||||
{
|
{
|
||||||
byte[] args = new byte[8];
|
byte[] args = new byte[8];
|
||||||
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
|
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
|
||||||
BitConverter.GetBytes((uint)Status).CopyTo(args, 4);
|
BitConverter.GetBytes((uint)Status).CopyTo(args, 4);
|
||||||
return CallMethod(DEVS, args);
|
|
||||||
|
byte[] status = CallMethod(DEVS, args);
|
||||||
|
int result = BitConverter.ToInt32(status, 0);
|
||||||
|
|
||||||
|
Logger.WriteLine(logName + " = " + Status + " : " + (result == 1 ? "OK" : result));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public byte[] DeviceSet(uint DeviceID, byte[] Params)
|
public int DeviceSet(uint DeviceID, byte[] Params, string logName)
|
||||||
{
|
{
|
||||||
byte[] args = new byte[4 + Params.Length];
|
byte[] args = new byte[4 + Params.Length];
|
||||||
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
|
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
|
||||||
Params.CopyTo(args, 4);
|
Params.CopyTo(args, 4);
|
||||||
return CallMethod(DEVS, args);
|
|
||||||
|
byte[] status = CallMethod(DEVS, args);
|
||||||
|
int result = BitConverter.ToInt32(status, 0);
|
||||||
|
|
||||||
|
Logger.WriteLine(logName + " = " + BitConverter.ToString(Params) + " : " + (result == 1 ? "OK" : result));
|
||||||
|
return BitConverter.ToInt32(status, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -192,31 +202,28 @@ public class ASUSWmi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void SetFanCurve(int device, byte[] curve)
|
public int SetFanCurve(int device, byte[] curve)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (curve.Length != 16) return;
|
if (curve.Length != 16) return -1;
|
||||||
if (curve.All(singleByte => singleByte == 0)) return;
|
if (curve.All(singleByte => singleByte == 0)) return -1;
|
||||||
|
|
||||||
string name;
|
int result;
|
||||||
|
|
||||||
switch (device)
|
switch (device)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
DeviceSet(DevsGPUFanCurve, curve);
|
result = DeviceSet(DevsGPUFanCurve, curve, "FanGPU");
|
||||||
name = "GPU";
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
DeviceSet(DevsMidFanCurve, curve);
|
result = DeviceSet(DevsMidFanCurve, curve, "FanMid");
|
||||||
name = "Mid";
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DeviceSet(DevsCPUFanCurve, curve);
|
result = DeviceSet(DevsCPUFanCurve, curve, "FanCPU");
|
||||||
name = "CPU";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.WriteLine("Fans" + name + " " + BitConverter.ToString(curve));
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] GetFanCurve(int device, int mode = 0)
|
public byte[] GetFanCurve(int device, int mode = 0)
|
||||||
@@ -254,7 +261,7 @@ public class ASUSWmi
|
|||||||
setting[4] = color.B;
|
setting[4] = color.B;
|
||||||
setting[5] = (byte)speed;
|
setting[5] = (byte)speed;
|
||||||
|
|
||||||
DeviceSet(TUF_KB, setting);
|
DeviceSet(TUF_KB, setting, "TUF RGB");
|
||||||
//Debug.WriteLine(BitConverter.ToString(setting));
|
//Debug.WriteLine(BitConverter.ToString(setting));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -274,7 +281,7 @@ public class ASUSWmi
|
|||||||
|
|
||||||
state = state | 0x01 << 8;
|
state = state | 0x01 << 8;
|
||||||
|
|
||||||
DeviceSet(TUF_KB_STATE, state);
|
DeviceSet(TUF_KB_STATE, state, "TUF_KB");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SubscribeToEvents(Action<object, EventArrivedEventArgs> EventHandler)
|
public void SubscribeToEvents(Action<object, EventArrivedEventArgs> EventHandler)
|
||||||
|
|||||||
14
app/Fans.cs
14
app/Fans.cs
@@ -334,7 +334,7 @@ namespace GHelper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyProfile(Series series, int device)
|
void SaveProfile(Series series, int device)
|
||||||
{
|
{
|
||||||
byte[] curve = new byte[16];
|
byte[] curve = new byte[16];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -346,17 +346,19 @@ namespace GHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
Program.config.setFanConfig(device, curve);
|
Program.config.setFanConfig(device, curve);
|
||||||
Program.wmi.SetFanCurve(device, curve);
|
//Program.wmi.SetFanCurve(device, curve);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ButtonApply_Click(object? sender, EventArgs e)
|
private void ButtonApply_Click(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ApplyProfile(seriesCPU, 0);
|
SaveProfile(seriesCPU, 0);
|
||||||
ApplyProfile(seriesGPU, 1);
|
SaveProfile(seriesGPU, 1);
|
||||||
if (Program.config.getConfig("mid_fan") == 1)
|
if (Program.config.getConfig("mid_fan") == 1)
|
||||||
ApplyProfile(seriesMid, 2);
|
SaveProfile(seriesMid, 2);
|
||||||
|
|
||||||
|
Program.settingsForm.AutoFans(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonReset_Click(object? sender, EventArgs e)
|
private void ButtonReset_Click(object? sender, EventArgs e)
|
||||||
@@ -373,7 +375,7 @@ namespace GHelper
|
|||||||
Program.config.setConfigPerf("auto_apply", 0);
|
Program.config.setConfigPerf("auto_apply", 0);
|
||||||
Program.config.setConfigPerf("auto_apply_power", 0);
|
Program.config.setConfigPerf("auto_apply_power", 0);
|
||||||
|
|
||||||
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, Program.config.getConfig("performance_mode"));
|
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, Program.config.getConfig("performance_mode"), "PerfMode");
|
||||||
|
|
||||||
ApplyLabel(false);
|
ApplyLabel(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
<AssemblyVersion>0.43</AssemblyVersion>
|
<AssemblyVersion>0.44</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -632,6 +632,7 @@ public class NativeMethods
|
|||||||
{
|
{
|
||||||
dm.dmDisplayFrequency = frequency;
|
dm.dmDisplayFrequency = frequency;
|
||||||
int iRet = NativeMethods.ChangeDisplaySettingsEx(laptopScreen, ref dm, IntPtr.Zero, DisplaySettingsFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);
|
int iRet = NativeMethods.ChangeDisplaySettingsEx(laptopScreen, ref dm, IntPtr.Zero, DisplaySettingsFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);
|
||||||
|
Logger.WriteLine("Screen = " + frequency.ToString() + "Hz : " + (iRet == 0 ? "OK" : iRet));
|
||||||
return iRet;
|
return iRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -716,19 +716,18 @@ namespace GHelper
|
|||||||
if (frequency > 0)
|
if (frequency > 0)
|
||||||
{
|
{
|
||||||
NativeMethods.SetRefreshRate(frequency);
|
NativeMethods.SetRefreshRate(frequency);
|
||||||
Logger.WriteLine("Screen " + frequency.ToString() + "Hz");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overdrive >= 0)
|
if (overdrive >= 0)
|
||||||
{
|
{
|
||||||
if (Program.config.getConfig("no_overdrive") == 1) overdrive = 0;
|
if (Program.config.getConfig("no_overdrive") == 1) overdrive = 0;
|
||||||
Program.wmi.DeviceSet(ASUSWmi.ScreenOverdrive, overdrive);
|
Program.wmi.DeviceSet(ASUSWmi.ScreenOverdrive, overdrive, "ScreenOverdrive");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (miniled >= 0)
|
if (miniled >= 0)
|
||||||
{
|
{
|
||||||
Program.wmi.DeviceSet(ASUSWmi.ScreenMiniled, miniled);
|
Program.wmi.DeviceSet(ASUSWmi.ScreenMiniled, miniled, "Miniled");
|
||||||
Debug.WriteLine("Miniled " + miniled);
|
Debug.WriteLine("Miniled " + miniled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -901,37 +900,45 @@ namespace GHelper
|
|||||||
if (limit_cpu < ASUSWmi.MinCPU) return;
|
if (limit_cpu < ASUSWmi.MinCPU) return;
|
||||||
|
|
||||||
if (Program.wmi.DeviceGet(ASUSWmi.PPT_TotalA0) >= 0)
|
if (Program.wmi.DeviceGet(ASUSWmi.PPT_TotalA0) >= 0)
|
||||||
Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA0, limit_total);
|
Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA0, limit_total, "PowerLimit A");
|
||||||
|
|
||||||
if (Program.wmi.DeviceGet(ASUSWmi.PPT_CPUB0) >= 0)
|
if (Program.wmi.DeviceGet(ASUSWmi.PPT_CPUB0) >= 0)
|
||||||
Program.wmi.DeviceSet(ASUSWmi.PPT_CPUB0, limit_cpu);
|
Program.wmi.DeviceSet(ASUSWmi.PPT_CPUB0, limit_cpu, "PowerLimit B");
|
||||||
|
|
||||||
|
|
||||||
Logger.WriteLine("PowerLimits " + limit_total.ToString() + ", " + limit_cpu.ToString());
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void AutoFansAndPower()
|
public void AutoFans(bool force = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Program.config.getConfigPerf("auto_apply") == 1)
|
if (force || Program.config.getConfigPerf("auto_apply") == 1)
|
||||||
{
|
{
|
||||||
Program.wmi.SetFanCurve(0, Program.config.getFanConfig(0));
|
int cpuResult = Program.wmi.SetFanCurve(0, Program.config.getFanConfig(0));
|
||||||
Program.wmi.SetFanCurve(1, Program.config.getFanConfig(1));
|
int gpuResult = Program.wmi.SetFanCurve(1, Program.config.getFanConfig(1));
|
||||||
|
|
||||||
if (Program.config.getConfig("mid_fan") == 1)
|
if (Program.config.getConfig("mid_fan") == 1)
|
||||||
Program.wmi.SetFanCurve(2, Program.config.getFanConfig(2));
|
Program.wmi.SetFanCurve(2, Program.config.getFanConfig(2));
|
||||||
|
|
||||||
labelPerf.Text = "Performance Mode+";
|
if (cpuResult != 1 || gpuResult != 1) // something went wrong, resetting to default profile
|
||||||
|
{
|
||||||
|
int mode = Program.config.getConfig("performance_mode");
|
||||||
|
Logger.WriteLine("Bios rejected fan curve, resetting mode to " + mode);
|
||||||
|
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, mode, "PerformanceMode");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
labelPerf.Text = "Performance Mode+";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
labelPerf.Text = "Performance Mode";
|
labelPerf.Text = "Performance Mode";
|
||||||
}
|
|
||||||
|
|
||||||
if (Program.config.getConfigPerf("auto_apply_power") == 1)
|
}
|
||||||
|
|
||||||
|
public void AutoPower(bool force = false)
|
||||||
|
{
|
||||||
|
if (force || Program.config.getConfigPerf("auto_apply_power") == 1)
|
||||||
{
|
{
|
||||||
var timer = new System.Timers.Timer(1000);
|
var timer = new System.Timers.Timer(1000);
|
||||||
timer.Elapsed += delegate
|
timer.Elapsed += delegate
|
||||||
@@ -943,12 +950,9 @@ namespace GHelper
|
|||||||
timer.Start();
|
timer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Program.config.getConfigPerf("auto_boost") != -1)
|
|
||||||
{
|
|
||||||
NativeMethods.SetCPUBoost(Program.config.getConfigPerf("auto_boost"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void SetPerformanceMode(int PerformanceMode = ASUSWmi.PerformanceBalanced, bool notify = false)
|
public void SetPerformanceMode(int PerformanceMode = ASUSWmi.PerformanceBalanced, bool notify = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -978,8 +982,7 @@ namespace GHelper
|
|||||||
Program.config.setConfig("performance_" + (int)SystemInformation.PowerStatus.PowerLineStatus, PerformanceMode);
|
Program.config.setConfig("performance_" + (int)SystemInformation.PowerStatus.PowerLineStatus, PerformanceMode);
|
||||||
Program.config.setConfig("performance_mode", PerformanceMode);
|
Program.config.setConfig("performance_mode", PerformanceMode);
|
||||||
|
|
||||||
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
|
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode, "PerformanceMode");
|
||||||
Logger.WriteLine("PerfMode " + perfName + " " + PerformanceMode);
|
|
||||||
|
|
||||||
if (notify && (oldMode != PerformanceMode))
|
if (notify && (oldMode != PerformanceMode))
|
||||||
{
|
{
|
||||||
@@ -993,7 +996,13 @@ namespace GHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoFansAndPower();
|
AutoFans();
|
||||||
|
AutoPower();
|
||||||
|
|
||||||
|
if (Program.config.getConfigPerf("auto_boost") != -1)
|
||||||
|
{
|
||||||
|
NativeMethods.SetCPUBoost(Program.config.getConfigPerf("auto_boost"));
|
||||||
|
}
|
||||||
|
|
||||||
NativeMethods.SetPowerScheme(PerformanceMode);
|
NativeMethods.SetPowerScheme(PerformanceMode);
|
||||||
|
|
||||||
@@ -1164,8 +1173,7 @@ namespace GHelper
|
|||||||
foreach (var process in Process.GetProcessesByName(kill)) process.Kill();
|
foreach (var process in Process.GetProcessesByName(kill)) process.Kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
Program.wmi.DeviceSet(ASUSWmi.GPUEco, eco);
|
Program.wmi.DeviceSet(ASUSWmi.GPUEco, eco, "GPUEco");
|
||||||
Logger.WriteLine("Setting Eco mode: " + eco);
|
|
||||||
|
|
||||||
Program.settingsForm.BeginInvoke(delegate
|
Program.settingsForm.BeginInvoke(delegate
|
||||||
{
|
{
|
||||||
@@ -1199,7 +1207,7 @@ namespace GHelper
|
|||||||
DialogResult dialogResult = MessageBox.Show("Switching off Ultimate Mode requires restart", "Reboot now?", MessageBoxButtons.YesNo);
|
DialogResult dialogResult = MessageBox.Show("Switching off Ultimate Mode requires restart", "Reboot now?", MessageBoxButtons.YesNo);
|
||||||
if (dialogResult == DialogResult.Yes)
|
if (dialogResult == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
Program.wmi.DeviceSet(ASUSWmi.GPUMux, 1);
|
Program.wmi.DeviceSet(ASUSWmi.GPUMux, 1, "GPUMux");
|
||||||
restart = true;
|
restart = true;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
@@ -1209,7 +1217,7 @@ namespace GHelper
|
|||||||
DialogResult dialogResult = MessageBox.Show("Ultimate Mode requires restart", "Reboot now?", MessageBoxButtons.YesNo);
|
DialogResult dialogResult = MessageBox.Show("Ultimate Mode requires restart", "Reboot now?", MessageBoxButtons.YesNo);
|
||||||
if (dialogResult == DialogResult.Yes)
|
if (dialogResult == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
Program.wmi.DeviceSet(ASUSWmi.GPUMux, 0);
|
Program.wmi.DeviceSet(ASUSWmi.GPUMux, 0, "GPUMux");
|
||||||
restart = true;
|
restart = true;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
@@ -1325,7 +1333,7 @@ namespace GHelper
|
|||||||
labelBatteryTitle.Text = "Battery Charge Limit: " + limit.ToString() + "%";
|
labelBatteryTitle.Text = "Battery Charge Limit: " + limit.ToString() + "%";
|
||||||
sliderBattery.Value = limit;
|
sliderBattery.Value = limit;
|
||||||
|
|
||||||
Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit);
|
Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit, "BatteryLimit");
|
||||||
Program.config.setConfig("charge_limit", limit);
|
Program.config.setConfig("charge_limit", limit);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user