Fan curve auto apply

This commit is contained in:
seerge
2023-03-02 00:07:07 +01:00
parent f59070cb96
commit e68282050b
6 changed files with 133 additions and 73 deletions

View File

@@ -169,6 +169,11 @@ public class ASUSWmi
public void SetFanCurve(int device, byte[] curve) public void SetFanCurve(int device, byte[] curve)
{ {
if (curve.Length != 16) return;
if (curve.All(singleByte => singleByte == 0)) return;
Debug.WriteLine(BitConverter.ToString(curve));
if (device == 1) if (device == 1)
DeviceSet(DevsGPUFanCurve, curve); DeviceSet(DevsGPUFanCurve, curve);
else else

35
Fans.Designer.cs generated
View File

@@ -45,6 +45,7 @@
trackCPU = new TrackBar(); trackCPU = new TrackBar();
trackTotal = new TrackBar(); trackTotal = new TrackBar();
buttonApplyPower = new Button(); buttonApplyPower = new Button();
checkAuto = new CheckBox();
((System.ComponentModel.ISupportInitialize)chartCPU).BeginInit(); ((System.ComponentModel.ISupportInitialize)chartCPU).BeginInit();
((System.ComponentModel.ISupportInitialize)chartGPU).BeginInit(); ((System.ComponentModel.ISupportInitialize)chartGPU).BeginInit();
groupBox1.SuspendLayout(); groupBox1.SuspendLayout();
@@ -74,7 +75,7 @@
// //
// buttonReset // buttonReset
// //
buttonReset.Location = new Point(619, 1016); buttonReset.Location = new Point(362, 1016);
buttonReset.Name = "buttonReset"; buttonReset.Name = "buttonReset";
buttonReset.Size = new Size(254, 46); buttonReset.Size = new Size(254, 46);
buttonReset.TabIndex = 2; buttonReset.TabIndex = 2;
@@ -104,6 +105,7 @@
groupBox1.Controls.Add(trackTotal); groupBox1.Controls.Add(trackTotal);
groupBox1.Location = new Point(12, 12); groupBox1.Location = new Point(12, 12);
groupBox1.Name = "groupBox1"; groupBox1.Name = "groupBox1";
groupBox1.Padding = new Padding(5);
groupBox1.Size = new Size(330, 979); groupBox1.Size = new Size(330, 979);
groupBox1.TabIndex = 4; groupBox1.TabIndex = 4;
groupBox1.TabStop = false; groupBox1.TabStop = false;
@@ -113,7 +115,7 @@
// //
labelApplied.AutoSize = true; labelApplied.AutoSize = true;
labelApplied.ForeColor = Color.Tomato; labelApplied.ForeColor = Color.Tomato;
labelApplied.Location = new Point(12, 37); labelApplied.Location = new Point(14, 39);
labelApplied.Name = "labelApplied"; labelApplied.Name = "labelApplied";
labelApplied.Size = new Size(143, 32); labelApplied.Size = new Size(143, 32);
labelApplied.TabIndex = 13; labelApplied.TabIndex = 13;
@@ -121,11 +123,12 @@
// //
// pictureFine // pictureFine
// //
pictureFine.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
pictureFine.BackgroundImage = Properties.Resources.everything_is_fine_itsfine; pictureFine.BackgroundImage = Properties.Resources.everything_is_fine_itsfine;
pictureFine.BackgroundImageLayout = ImageLayout.Zoom; pictureFine.BackgroundImageLayout = ImageLayout.Zoom;
pictureFine.Location = new Point(12, 725); pictureFine.Location = new Point(9, 730);
pictureFine.Name = "pictureFine"; pictureFine.Name = "pictureFine";
pictureFine.Size = new Size(304, 240); pictureFine.Size = new Size(311, 240);
pictureFine.TabIndex = 12; pictureFine.TabIndex = 12;
pictureFine.TabStop = false; pictureFine.TabStop = false;
pictureFine.Visible = false; pictureFine.Visible = false;
@@ -133,7 +136,8 @@
// labelInfo // labelInfo
// //
labelInfo.AutoSize = true; labelInfo.AutoSize = true;
labelInfo.Location = new Point(22, 644); labelInfo.Dock = DockStyle.Bottom;
labelInfo.Location = new Point(5, 942);
labelInfo.Name = "labelInfo"; labelInfo.Name = "labelInfo";
labelInfo.Size = new Size(65, 32); labelInfo.Size = new Size(65, 32);
labelInfo.TabIndex = 11; labelInfo.TabIndex = 11;
@@ -143,7 +147,7 @@
// //
labelCPU.AutoSize = true; labelCPU.AutoSize = true;
labelCPU.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); labelCPU.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
labelCPU.Location = new Point(195, 123); labelCPU.Location = new Point(197, 125);
labelCPU.Name = "labelCPU"; labelCPU.Name = "labelCPU";
labelCPU.Size = new Size(61, 32); labelCPU.Size = new Size(61, 32);
labelCPU.TabIndex = 10; labelCPU.TabIndex = 10;
@@ -154,7 +158,7 @@
// //
labelTotal.AutoSize = true; labelTotal.AutoSize = true;
labelTotal.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); labelTotal.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
labelTotal.Location = new Point(37, 123); labelTotal.Location = new Point(39, 125);
labelTotal.Name = "labelTotal"; labelTotal.Name = "labelTotal";
labelTotal.Size = new Size(70, 32); labelTotal.Size = new Size(70, 32);
labelTotal.TabIndex = 9; labelTotal.TabIndex = 9;
@@ -164,7 +168,7 @@
// label2 // label2
// //
label2.AutoSize = true; label2.AutoSize = true;
label2.Location = new Point(198, 89); label2.Location = new Point(200, 91);
label2.Name = "label2"; label2.Name = "label2";
label2.Size = new Size(58, 32); label2.Size = new Size(58, 32);
label2.TabIndex = 8; label2.TabIndex = 8;
@@ -174,7 +178,7 @@
// label1 // label1
// //
label1.AutoSize = true; label1.AutoSize = true;
label1.Location = new Point(39, 89); label1.Location = new Point(41, 91);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(65, 32); label1.Size = new Size(65, 32);
label1.TabIndex = 7; label1.TabIndex = 7;
@@ -215,11 +219,22 @@
buttonApplyPower.Text = "Apply Power Limits"; buttonApplyPower.Text = "Apply Power Limits";
buttonApplyPower.UseVisualStyleBackColor = true; buttonApplyPower.UseVisualStyleBackColor = true;
// //
// checkAuto
//
checkAuto.AutoSize = true;
checkAuto.Location = new Point(708, 1022);
checkAuto.Name = "checkAuto";
checkAuto.Size = new Size(165, 36);
checkAuto.TabIndex = 12;
checkAuto.Text = "Auto Apply";
checkAuto.UseVisualStyleBackColor = true;
//
// Fans // Fans
// //
AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1154, 1089); ClientSize = new Size(1154, 1089);
Controls.Add(checkAuto);
Controls.Add(buttonApplyPower); Controls.Add(buttonApplyPower);
Controls.Add(groupBox1); Controls.Add(groupBox1);
Controls.Add(chartGPU); Controls.Add(chartGPU);
@@ -243,6 +258,7 @@
((System.ComponentModel.ISupportInitialize)trackCPU).EndInit(); ((System.ComponentModel.ISupportInitialize)trackCPU).EndInit();
((System.ComponentModel.ISupportInitialize)trackTotal).EndInit(); ((System.ComponentModel.ISupportInitialize)trackTotal).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
@@ -262,5 +278,6 @@
private Label labelInfo; private Label labelInfo;
private PictureBox pictureFine; private PictureBox pictureFine;
private Label labelApplied; private Label labelApplied;
private CheckBox checkAuto;
} }
} }

79
Fans.cs
View File

@@ -93,6 +93,8 @@ namespace GHelper
buttonApplyPower.Click += ButtonApplyPower_Click; buttonApplyPower.Click += ButtonApplyPower_Click;
checkAuto.Click += CheckAuto_Click;
labelInfo.MaximumSize = new Size(300, 0); labelInfo.MaximumSize = new Size(300, 0);
labelInfo.Text = "Power Limits (PPT) is experimental feature.\n\nValues will be applied only after you click 'Apply' and reset after performance mode change.\n\nUse carefully and on your own risk!"; labelInfo.Text = "Power Limits (PPT) is experimental feature.\n\nValues will be applied only after you click 'Apply' and reset after performance mode change.\n\nUse carefully and on your own risk!";
@@ -103,6 +105,16 @@ namespace GHelper
} }
private void CheckAuto_Click(object? sender, EventArgs e)
{
if (sender is null)
return;
CheckBox chk = (CheckBox)sender;
Program.config.setConfig("auto_apply_" + Program.config.getConfig("performance_mode"), chk.Checked ? 1 : 0);
}
private void Fans_FormClosing(object? sender, FormClosingEventArgs e) private void Fans_FormClosing(object? sender, FormClosingEventArgs e)
{ {
if (e.CloseReason == CloseReason.UserClosing) if (e.CloseReason == CloseReason.UserClosing)
@@ -193,28 +205,12 @@ namespace GHelper
LoadProfile(seriesCPU, 0); LoadProfile(seriesCPU, 0);
LoadProfile(seriesGPU, 1); LoadProfile(seriesGPU, 1);
int auto_apply = Program.config.getConfig("auto_apply_" + Program.config.getConfig("performance_mode"));
checkAuto.Checked = (auto_apply == 1);
} }
byte[] StringToBytes(string str)
{
String[] arr = str.Split('-');
byte[] array = new byte[arr.Length];
for (int i = 0; i < arr.Length; i++) array[i] = Convert.ToByte(arr[i], 16);
return array;
}
string GetFanName(int device)
{
int mode = Program.config.getConfig("performance_mode");
string name;
if (device == 1)
name = "gpu";
else
name = "cpu";
return "fan_profile_" + name + "_" + mode;
}
void LoadProfile(Series series, int device, int def = 0) void LoadProfile(Series series, int device, int def = 0)
{ {
@@ -226,42 +222,13 @@ namespace GHelper
series.Points.Clear(); series.Points.Clear();
int mode = Program.config.getConfig("performance_mode"); int mode = Program.config.getConfig("performance_mode");
string curveString = Program.config.getConfigString(GetFanName(device)); byte[] curve = Program.config.getFanConfig(device);
byte[] curve = { };
if (curveString is not null)
curve = StringToBytes(curveString);
if (def == 1 || curve.Length != 16) if (def == 1 || curve.Length != 16)
curve = Program.wmi.GetFanCurve(device, mode); curve = Program.wmi.GetFanCurve(device, mode);
if (curve.All(singleByte => singleByte == 0)) if (curve.All(singleByte => singleByte == 0))
{ Program.config.getDefaultCurve(device);
switch (mode)
{
case 1:
if (device == 1)
curve = StringToBytes("14-3F-44-48-4C-50-54-62-16-1F-26-2D-39-47-55-5F");
else
curve = StringToBytes("14-3F-44-48-4C-50-54-62-11-1A-22-29-34-43-51-5A");
break;
case 2:
if (device == 1)
curve = StringToBytes("3C-41-42-46-47-4B-4C-62-08-11-11-1D-1D-26-26-2D");
else
curve = StringToBytes("3C-41-42-46-47-4B-4C-62-03-0C-0C-16-16-22-22-29");
break;
default:
if (device == 1)
curve = StringToBytes("3A-3D-40-44-48-4D-51-62-0C-16-1D-1F-26-2D-34-4A");
else
curve = StringToBytes("3A-3D-40-44-48-4D-51-62-08-11-16-1A-22-29-30-45");
break;
}
}
//Debug.WriteLine(BitConverter.ToString(curve)); //Debug.WriteLine(BitConverter.ToString(curve));
@@ -286,10 +253,7 @@ namespace GHelper
i++; i++;
} }
string bitCurve = BitConverter.ToString(curve); Program.config.setFanConfig(device, curve);
Debug.WriteLine(bitCurve);
Program.config.setConfig(GetFanName(device), bitCurve);
Program.wmi.SetFanCurve(device, curve); Program.wmi.SetFanCurve(device, curve);
} }
@@ -305,7 +269,12 @@ namespace GHelper
{ {
LoadProfile(seriesCPU, 0, 1); LoadProfile(seriesCPU, 0, 1);
LoadProfile(seriesGPU, 1, 1); LoadProfile(seriesGPU, 1, 1);
checkAuto.Checked = false;
Program.config.setConfig("auto_apply_" + Program.config.getConfig("performance_mode"), 0);
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, Program.config.getConfig("performance_mode")); Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, Program.config.getConfig("performance_mode"));
ResetApplyLabel(); ResetApplyLabel();
} }

View File

@@ -15,7 +15,7 @@
<AssemblyName>GHelper</AssemblyName> <AssemblyName>GHelper</AssemblyName>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly> <ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AssemblyVersion>0.10.0</AssemblyVersion> <AssemblyVersion>0.11.0</AssemblyVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -75,6 +75,74 @@ public class AppConfig
File.WriteAllText(configFile, jsonString); File.WriteAllText(configFile, jsonString);
} }
public string getFanName(int device)
{
int mode = getConfig("performance_mode");
string name;
if (device == 1)
name = "gpu";
else
name = "cpu";
return "fan_profile_" + name + "_" + mode;
}
public byte[] getFanConfig(int device)
{
string curveString = getConfigString(getFanName(device));
byte[] curve = { };
if (curveString is not null)
curve = StringToBytes(curveString);
return curve;
}
public void setFanConfig(int device, byte[] curve)
{
string bitCurve = BitConverter.ToString(curve);
setConfig(getFanName(device), bitCurve);
}
public static byte[] StringToBytes(string str)
{
String[] arr = str.Split('-');
byte[] array = new byte[arr.Length];
for (int i = 0; i < arr.Length; i++) array[i] = Convert.ToByte(arr[i], 16);
return array;
}
public byte[] getDefaultCurve(int device)
{
int mode = getConfig("performance_mode");
byte[] curve;
switch (mode)
{
case 1:
if (device == 1)
curve = StringToBytes("14-3F-44-48-4C-50-54-62-16-1F-26-2D-39-47-55-5F");
else
curve = StringToBytes("14-3F-44-48-4C-50-54-62-11-1A-22-29-34-43-51-5A");
break;
case 2:
if (device == 1)
curve = StringToBytes("3C-41-42-46-47-4B-4C-62-08-11-11-1D-1D-26-26-2D");
else
curve = StringToBytes("3C-41-42-46-47-4B-4C-62-03-0C-0C-16-16-22-22-29");
break;
default:
if (device == 1)
curve = StringToBytes("3A-3D-40-44-48-4D-51-62-0C-16-1D-1F-26-2D-34-4A");
else
curve = StringToBytes("3A-3D-40-44-48-4D-51-62-08-11-16-1A-22-29-30-45");
break;
}
return curve;
}
} }
@@ -176,7 +244,8 @@ namespace GHelper
try try
{ {
Process proc = Process.Start(start); Process proc = Process.Start(start);
} catch }
catch
{ {
Debug.WriteLine("Failed to run " + fileName); Debug.WriteLine("Failed to run " + fileName);
} }

View File

@@ -1,5 +1,6 @@
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
using System.Security.Cryptography;
using System.Timers; using System.Timers;
namespace GHelper namespace GHelper
@@ -429,7 +430,7 @@ namespace GHelper
private static void OnTimedEvent(Object? source, ElapsedEventArgs? e) private static void OnTimedEvent(Object? source, ElapsedEventArgs? e)
{ {
RefreshSensors(); RefreshSensors();
aTimer.Interval = 2000; aTimer.Interval = 1000;
} }
private void SettingsForm_VisibleChanged(object? sender, EventArgs e) private void SettingsForm_VisibleChanged(object? sender, EventArgs e)
@@ -478,13 +479,12 @@ namespace GHelper
Program.config.setConfig("performance_mode", PerformanceMode); Program.config.setConfig("performance_mode", PerformanceMode);
try Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
if (Program.config.getConfig("auto_apply_" + PerformanceMode) == 1)
{ {
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode); Program.wmi.SetFanCurve(0, Program.config.getFanConfig(0));
} Program.wmi.SetFanCurve(1, Program.config.getFanConfig(1));
catch
{
labelPerf.Text = "Performance Mode: not supported";
} }
if (fans != null && fans.Text != "") if (fans != null && fans.Text != "")