Improved logging

This commit is contained in:
seerge
2023-03-30 21:10:35 +02:00
parent 7e0459bd44
commit d15c6cb073
5 changed files with 69 additions and 51 deletions

View File

@@ -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];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
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];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
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.All(singleByte => singleByte == 0)) return;
if (curve.Length != 16) return -1;
if (curve.All(singleByte => singleByte == 0)) return -1;
string name;
int result;
switch (device)
{
case 1:
DeviceSet(DevsGPUFanCurve, curve);
name = "GPU";
result = DeviceSet(DevsGPUFanCurve, curve, "FanGPU");
break;
case 2:
DeviceSet(DevsMidFanCurve, curve);
name = "Mid";
result = DeviceSet(DevsMidFanCurve, curve, "FanMid");
break;
default:
DeviceSet(DevsCPUFanCurve, curve);
name = "CPU";
result = DeviceSet(DevsCPUFanCurve, curve, "FanCPU");
break;
}
Logger.WriteLine("Fans" + name + " " + BitConverter.ToString(curve));
return result;
}
public byte[] GetFanCurve(int device, int mode = 0)
@@ -254,7 +261,7 @@ public class ASUSWmi
setting[4] = color.B;
setting[5] = (byte)speed;
DeviceSet(TUF_KB, setting);
DeviceSet(TUF_KB, setting, "TUF RGB");
//Debug.WriteLine(BitConverter.ToString(setting));
}
@@ -274,7 +281,7 @@ public class ASUSWmi
state = state | 0x01 << 8;
DeviceSet(TUF_KB_STATE, state);
DeviceSet(TUF_KB_STATE, state, "TUF_KB");
}
public void SubscribeToEvents(Action<object, EventArrivedEventArgs> EventHandler)

View File

@@ -334,7 +334,7 @@ namespace GHelper
}
void ApplyProfile(Series series, int device)
void SaveProfile(Series series, int device)
{
byte[] curve = new byte[16];
int i = 0;
@@ -346,17 +346,19 @@ namespace GHelper
}
Program.config.setFanConfig(device, curve);
Program.wmi.SetFanCurve(device, curve);
//Program.wmi.SetFanCurve(device, curve);
}
private void ButtonApply_Click(object? sender, EventArgs e)
{
ApplyProfile(seriesCPU, 0);
ApplyProfile(seriesGPU, 1);
SaveProfile(seriesCPU, 0);
SaveProfile(seriesGPU, 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)
@@ -373,7 +375,7 @@ namespace GHelper
Program.config.setConfigPerf("auto_apply", 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);
}

View File

@@ -16,7 +16,7 @@
<PlatformTarget>x64</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.43</AssemblyVersion>
<AssemblyVersion>0.44</AssemblyVersion>
</PropertyGroup>
<ItemGroup>

View File

@@ -632,6 +632,7 @@ public class NativeMethods
{
dm.dmDisplayFrequency = frequency;
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;
}

View File

@@ -716,19 +716,18 @@ namespace GHelper
if (frequency > 0)
{
NativeMethods.SetRefreshRate(frequency);
Logger.WriteLine("Screen " + frequency.ToString() + "Hz");
}
if (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)
{
Program.wmi.DeviceSet(ASUSWmi.ScreenMiniled, miniled);
Program.wmi.DeviceSet(ASUSWmi.ScreenMiniled, miniled, "Miniled");
Debug.WriteLine("Miniled " + miniled);
}
@@ -901,37 +900,45 @@ namespace GHelper
if (limit_cpu < ASUSWmi.MinCPU) return;
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)
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));
Program.wmi.SetFanCurve(1, Program.config.getFanConfig(1));
int cpuResult = Program.wmi.SetFanCurve(0, Program.config.getFanConfig(0));
int gpuResult = Program.wmi.SetFanCurve(1, Program.config.getFanConfig(1));
if (Program.config.getConfig("mid_fan") == 1)
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
{
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);
timer.Elapsed += delegate
@@ -943,12 +950,9 @@ namespace GHelper
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)
{
@@ -978,8 +982,7 @@ namespace GHelper
Program.config.setConfig("performance_" + (int)SystemInformation.PowerStatus.PowerLineStatus, PerformanceMode);
Program.config.setConfig("performance_mode", PerformanceMode);
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
Logger.WriteLine("PerfMode " + perfName + " " + PerformanceMode);
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode, "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);
@@ -1164,8 +1173,7 @@ namespace GHelper
foreach (var process in Process.GetProcessesByName(kill)) process.Kill();
}
Program.wmi.DeviceSet(ASUSWmi.GPUEco, eco);
Logger.WriteLine("Setting Eco mode: " + eco);
Program.wmi.DeviceSet(ASUSWmi.GPUEco, eco, "GPUEco");
Program.settingsForm.BeginInvoke(delegate
{
@@ -1199,7 +1207,7 @@ namespace GHelper
DialogResult dialogResult = MessageBox.Show("Switching off Ultimate Mode requires restart", "Reboot now?", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
Program.wmi.DeviceSet(ASUSWmi.GPUMux, 1);
Program.wmi.DeviceSet(ASUSWmi.GPUMux, 1, "GPUMux");
restart = true;
changed = true;
}
@@ -1209,7 +1217,7 @@ namespace GHelper
DialogResult dialogResult = MessageBox.Show("Ultimate Mode requires restart", "Reboot now?", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
Program.wmi.DeviceSet(ASUSWmi.GPUMux, 0);
Program.wmi.DeviceSet(ASUSWmi.GPUMux, 0, "GPUMux");
restart = true;
changed = true;
}
@@ -1325,7 +1333,7 @@ namespace GHelper
labelBatteryTitle.Text = "Battery Charge Limit: " + limit.ToString() + "%";
sliderBattery.Value = limit;
Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit);
Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit, "BatteryLimit");
Program.config.setConfig("charge_limit", limit);
}