checkbox, cpu temp, command line change

This commit is contained in:
Karmel0x
2023-11-07 21:33:02 +01:00
parent 584bcadd2a
commit bd0162e5f4
10 changed files with 250 additions and 69 deletions

View File

@@ -26,10 +26,10 @@ namespace AsusFanControl
AsusWinIO64.HealthyTable_SetFanTestMode((char)(value > 0 ? 0x01 : 0x00));
}
public void SetFanSpeed(int percent)
public void SetFanSpeed(int percent, byte fanIndex = 0)
{
var value = (byte)(percent / 100.0f * 255);
SetFanSpeed(value);
SetFanSpeed(value, fanIndex);
}
public void SetFansSpeed(byte value)
@@ -67,5 +67,15 @@ namespace AsusFanControl
return fanSpeeds;
}
public int HealthyTable_FanCounts()
{
return AsusWinIO64.HealthyTable_FanCounts();
}
public ulong Thermal_Read_Cpu_Temperature()
{
return AsusWinIO64.Thermal_Read_Cpu_Temperature();
}
}
}

View File

@@ -18,5 +18,7 @@ namespace AsusSystemAnalysis
public static extern void HealthyTable_SetFanTestMode(char mode);
[DllImport("AsusWinIO64.dll")]
public static extern void HealthyTable_SetFanPwmDuty(short duty);
[DllImport("AsusWinIO64.dll")]
public static extern ulong Thermal_Read_Cpu_Temperature();
}
}

View File

@@ -13,31 +13,77 @@ namespace AsusFanControl
{
if (args.Length < 1)
{
Console.WriteLine("Usage: AsusFanControl <fanSpeedPercent>");
return 1;
}
bool tryParse = int.TryParse(args[0], out int num);
if (!tryParse)
{
Console.WriteLine("Please enter a numeric value for fan speed.");
return 1;
}
if ((num != 0 && num < 40) || num > 99)
{
Console.WriteLine("Please enter a value for fan speed between 40 and 99 or 0 for turning off test mode.");
Console.WriteLine("If you want to skip these limits you need to change it in source code.");
Console.WriteLine("Usage: AsusFanControl <args>");
Console.WriteLine("\t--get-fan-speeds");
Console.WriteLine("\t--set-fan-speeds=0-100 (percent value, 0 for turning off test mode)");
Console.WriteLine("\t--get-fan-count");
Console.WriteLine("\t--get-fan-speed=fanId (comma separated)");
Console.WriteLine("\t--set-fan-speed=fanId:0-100 (comma separated, percent value, 0 for turning off test mode)");
Console.WriteLine("\t--get-cpu-temp");
return 1;
}
var asusControl = new AsusControl();
foreach (var arg in args)
{
if (arg.StartsWith("--get-fan-speeds"))
{
var fanSpeeds = asusControl.GetFanSpeeds();
Console.WriteLine($"Current fan speeds: {string.Join(" ", fanSpeeds)}");
Console.WriteLine($"Current fan speeds: {string.Join(" ", fanSpeeds)} RPM");
}
asusControl.SetFansSpeed(num);
if (arg.StartsWith("--set-fan-speeds"))
{
var newSpeedStr = arg.Split('=')[1];
var newSpeed = int.Parse(newSpeedStr);
asusControl.SetFansSpeed(newSpeed);
if(newSpeed == 0)
Console.WriteLine("Test mode turned off");
else
Console.WriteLine($"New fan speeds: {newSpeed}%");
}
if (arg.StartsWith("--get-fan-speed="))
{
var fanIds = arg.Split('=')[1].Split(',');
foreach (var fanIdStr in fanIds)
{
var fanId = int.Parse(fanIdStr);
var fanSpeed = asusControl.GetFanSpeed((byte)fanId);
Console.WriteLine($"Current fan speed for fan {fanId}: {fanSpeed} RPM");
}
}
if (arg.StartsWith("--get-fan-count"))
{
var fanCount = asusControl.HealthyTable_FanCounts();
Console.WriteLine($"Fan count: {fanCount}");
}
if (arg.StartsWith("--set-fan-speed="))
{
var fanSettings = arg.Split('=')[1].Split(',');
foreach (var fanSetting in fanSettings)
{
var fanId = int.Parse(fanSetting.Split(':')[0]);
var fanSpeed = int.Parse(fanSetting.Split(':')[1]);
asusControl.SetFanSpeed(fanSpeed, (byte)fanId);
if (fanSpeed == 0)
Console.WriteLine($"Test mode turned off for fan {fanId}");
else
Console.WriteLine($"New fan speed for fan {fanId}: {fanSpeed}%");
}
}
if (arg.StartsWith("--get-cpu-temp"))
{
var cpuTemp = asusControl.Thermal_Read_Cpu_Temperature();
Console.WriteLine($"Current CPU temp: {cpuTemp}");
}
}
return 0;
}

View File

@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="AsusFanControlGUI.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<userSettings>
<AsusFanControlGUI.Properties.Settings>
<setting name="fanSpeed" serializeAs="String">
<value>90</value>
</setting>
</AsusFanControlGUI.Properties.Settings>
</userSettings>
</configuration>

View File

@@ -29,29 +29,34 @@
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.trackBar1 = new System.Windows.Forms.TrackBar();
this.trackBarFanSpeed = new System.Windows.Forms.TrackBar();
this.label1 = new System.Windows.Forms.Label();
this.labelValue = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.labelRPM = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
this.checkBoxTurnOn = new System.Windows.Forms.CheckBox();
this.labelCPUTemp = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.trackBarFanSpeed)).BeginInit();
this.SuspendLayout();
//
// trackBar1
// trackBarFanSpeed
//
this.trackBar1.Location = new System.Drawing.Point(12, 12);
this.trackBar1.Maximum = 100;
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(300, 45);
this.trackBar1.TabIndex = 0;
this.trackBar1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.trackBar1_KeyUp);
this.trackBar1.MouseCaptureChanged += new System.EventHandler(this.trackBar1_MouseCaptureChanged);
this.trackBarFanSpeed.Location = new System.Drawing.Point(12, 35);
this.trackBarFanSpeed.Maximum = 100;
this.trackBarFanSpeed.Name = "trackBarFanSpeed";
this.trackBarFanSpeed.Size = new System.Drawing.Size(300, 45);
this.trackBarFanSpeed.TabIndex = 0;
this.trackBarFanSpeed.Value = 100;
this.trackBarFanSpeed.KeyUp += new System.Windows.Forms.KeyEventHandler(this.trackBar1_KeyUp);
this.trackBarFanSpeed.MouseCaptureChanged += new System.EventHandler(this.trackBar1_MouseCaptureChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 60);
this.label1.Location = new System.Drawing.Point(12, 83);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(73, 13);
this.label1.TabIndex = 1;
@@ -60,7 +65,7 @@
// labelValue
//
this.labelValue.AutoSize = true;
this.labelValue.Location = new System.Drawing.Point(91, 60);
this.labelValue.Location = new System.Drawing.Point(91, 83);
this.labelValue.Name = "labelValue";
this.labelValue.Size = new System.Drawing.Size(10, 13);
this.labelValue.TabIndex = 2;
@@ -69,7 +74,7 @@
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(40, 81);
this.label2.Location = new System.Drawing.Point(40, 112);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(71, 13);
this.label2.TabIndex = 3;
@@ -77,7 +82,7 @@
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 76);
this.button1.Location = new System.Drawing.Point(12, 107);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(22, 23);
this.button1.TabIndex = 4;
@@ -88,27 +93,70 @@
// labelRPM
//
this.labelRPM.AutoSize = true;
this.labelRPM.Location = new System.Drawing.Point(117, 81);
this.labelRPM.Location = new System.Drawing.Point(117, 112);
this.labelRPM.Name = "labelRPM";
this.labelRPM.Size = new System.Drawing.Size(10, 13);
this.labelRPM.TabIndex = 5;
this.labelRPM.Text = "-";
//
// checkBoxTurnOn
//
this.checkBoxTurnOn.AutoSize = true;
this.checkBoxTurnOn.Location = new System.Drawing.Point(12, 12);
this.checkBoxTurnOn.Name = "checkBoxTurnOn";
this.checkBoxTurnOn.Size = new System.Drawing.Size(63, 17);
this.checkBoxTurnOn.TabIndex = 6;
this.checkBoxTurnOn.Text = "Turn on";
this.checkBoxTurnOn.UseVisualStyleBackColor = true;
this.checkBoxTurnOn.CheckedChanged += new System.EventHandler(this.checkBoxTurnOn_CheckedChanged);
//
// labelCPUTemp
//
this.labelCPUTemp.AutoSize = true;
this.labelCPUTemp.Location = new System.Drawing.Point(141, 141);
this.labelCPUTemp.Name = "labelCPUTemp";
this.labelCPUTemp.Size = new System.Drawing.Size(10, 13);
this.labelCPUTemp.TabIndex = 9;
this.labelCPUTemp.Text = "-";
//
// button2
//
this.button2.Location = new System.Drawing.Point(12, 136);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(22, 23);
this.button2.TabIndex = 8;
this.button2.Text = "↻";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(40, 141);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(95, 13);
this.label4.TabIndex = 7;
this.label4.Text = "Current CPU temp:";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(324, 111);
this.ClientSize = new System.Drawing.Size(324, 174);
this.Controls.Add(this.labelCPUTemp);
this.Controls.Add(this.button2);
this.Controls.Add(this.label4);
this.Controls.Add(this.checkBoxTurnOn);
this.Controls.Add(this.labelRPM);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.labelValue);
this.Controls.Add(this.label1);
this.Controls.Add(this.trackBar1);
this.Controls.Add(this.trackBarFanSpeed);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "Asus Fan Control";
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.trackBarFanSpeed)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -116,12 +164,16 @@
#endregion
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.TrackBar trackBarFanSpeed;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label labelValue;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label labelRPM;
private System.Windows.Forms.CheckBox checkBoxTurnOn;
private System.Windows.Forms.Label labelCPUTemp;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label4;
}
}

View File

@@ -14,31 +14,54 @@ namespace AsusFanControlGUI
public partial class Form1 : Form
{
AsusControl asusControl = new AsusControl();
int fanSpeed = 0;
public Form1()
{
InitializeComponent();
trackBarFanSpeed.Value = Properties.Settings.Default.fanSpeed;
}
private void setFanSpeed(int value)
private void setFanSpeed()
{
if (value < 40)
var value = trackBarFanSpeed.Value;
Properties.Settings.Default.fanSpeed = value;
Properties.Settings.Default.Save();
if (!checkBoxTurnOn.Checked)
value = 0;
if (value > 99)
else if(value < 40)
value = 0;
else if (value > 99)
value = 99;
labelValue.Text = value == 0 ? "turned off (set value between 40 and 100)" : value.ToString();
if (!checkBoxTurnOn.Checked)
labelValue.Text = "turned off";
else if (value == 0)
labelValue.Text = "turned off (set value between 40 and 100)";
else
labelValue.Text = value.ToString();
if (fanSpeed == value)
return;
fanSpeed = value;
asusControl.SetFansSpeed(value);
}
private void trackBar1_MouseCaptureChanged(object sender, EventArgs e)
{
setFanSpeed(trackBar1.Value);
setFanSpeed();
}
private void trackBar1_KeyUp(object sender, KeyEventArgs e)
{
setFanSpeed(trackBar1.Value);
if (e.KeyCode != Keys.Left && e.KeyCode != Keys.Right)
return;
setFanSpeed();
}
private void button1_Click(object sender, EventArgs e)
@@ -46,5 +69,14 @@ namespace AsusFanControlGUI
labelRPM.Text = string.Join(" ", asusControl.GetFanSpeeds());
}
private void checkBoxTurnOn_CheckedChanged(object sender, EventArgs e)
{
setFanSpeed();
}
private void button2_Click(object sender, EventArgs e)
{
labelCPUTemp.Text = $"{asusControl.Thermal_Read_Cpu_Temperature()}";
}
}
}

View File

@@ -14,9 +14,15 @@ namespace AsusFanControlGUI
[STAThread]
static void Main()
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static void OnProcessExit(object sender, EventArgs e)
{
AsusSystemAnalysis.AsusWinIO64.HealthyTable_SetFanTestMode((char)(0x00));
}
}
}

View File

@@ -8,23 +8,31 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace AsusFanControlGUI.Properties
{
namespace AsusFanControlGUI.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.6.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("90")]
public int fanSpeed {
get {
return ((int)(this["fanSpeed"]));
}
set {
this["fanSpeed"] = value;
}
}
}
}

View File

@@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="AsusFanControlGUI.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="fanSpeed" Type="System.Int32" Scope="User">
<Value Profile="(Default)">90</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@@ -4,14 +4,25 @@
Go to [releases](../../releases)
### Run
Command line turn on: `AsusFanControl.exe <fan speed percent>`
Command line turn off: `AsusFanControl.exe 0`
<details>
<summary>Command line: `AsusFanControl.exe`</summary>
AsusFanControl.exe <args>
--get-fan-speeds
--set-fan-speeds=0-100 (percent value, 0 for turning off test mode)
--get-fan-count
--get-fan-speed=fanId (comma separated)
--set-fan-speed=fanId:0-100 (comma separated, percent value, 0 for turning off test mode)
--get-cpu-temp
</details>
GUI: `AsusFanControlGUI.exe`
![AsusFanControlGUI](https://github.com/Karmel0x/AsusFanControl/assets/25367564/cccd136c-f1cb-4218-b150-d874d0d5e5af)
![AsusFanControlGUI](https://github.com/Karmel0x/AsusFanControl/assets/25367564/fe197ad0-7079-4d51-ae78-177cb6369e96)
### Why need it?
My laptop does not support the [Fan Profile](https://github.com/Karmel0x/AsusFanControl/assets/25367564/924d990a-bf20-4b8d-bf9d-56c460174d99) option, but it often overheats. Looked for apps to control the fans, but none is working.
My laptop does not support the [Fan Profile](https://github.com/Karmel0x/AsusFanControl/assets/25367564/924d990a-bf20-4b8d-bf9d-56c460174d99) option, but it often overheats. Looked for apps to control fans, but none is working.
### Compatibility
This program should work on any laptop with x64 windows where [Fan Diagnosis](https://github.com/Karmel0x/AsusFanControl/assets/25367564/7129833b-97af-4da8-9148-b71e49552ea4) in [MyASUS](https://apps.microsoft.com/store/detail/myasus/9N7R5S6B0ZZH) application is working as it is using same library.