Major bugfixes.

Can now begin at system startup.
This commit is contained in:
Darren Ohonba - Evans
2024-05-24 00:07:59 +01:00
parent cccb93f739
commit b27d2d13ee
5 changed files with 216 additions and 120 deletions

View File

@@ -34,6 +34,12 @@
<setting name="startMinimised" serializeAs="String"> <setting name="startMinimised" serializeAs="String">
<value>False</value> <value>False</value>
</setting> </setting>
<setting name="hysteresis" serializeAs="String">
<value>1</value>
</setting>
<setting name="updateSpeed" serializeAs="String">
<value>2000</value>
</setting>
</AsusFanControlGUI.Properties.Settings> </AsusFanControlGUI.Properties.Settings>
</userSettings> </userSettings>
</configuration> </configuration>

View File

@@ -45,6 +45,10 @@
this.toolStripMenuItemForbidUnsafeSettings = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemForbidUnsafeSettings = new System.Windows.Forms.ToolStripMenuItem();
this.allowFanCurveSettingViaTextToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.allowFanCurveSettingViaTextToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.resetToDefaultsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.resetToDefaultsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.startupSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.startMinimisedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.startWithWindowsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemCheckForUpdates = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemCheckForUpdates = new System.Windows.Forms.ToolStripMenuItem();
this.label5 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label();
this.pictureBoxFanCurve = new System.Windows.Forms.PictureBox(); this.pictureBoxFanCurve = new System.Windows.Forms.PictureBox();
@@ -70,10 +74,7 @@
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox1 = new System.Windows.Forms.TextBox();
this.label10 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label();
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.label11 = new System.Windows.Forms.Label();
this.startupSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.startMinimisedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.startWithWindowsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.trackBarFanSpeed)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBarFanSpeed)).BeginInit();
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxFanCurve)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxFanCurve)).BeginInit();
@@ -100,18 +101,17 @@
// label1 // label1
// //
this.label1.AutoSize = true; this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 534); this.label1.Location = new System.Drawing.Point(13, 566);
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(88, 16); this.label1.Size = new System.Drawing.Size(88, 16);
this.label1.TabIndex = 1; this.label1.TabIndex = 1;
this.label1.Text = "Current value:"; this.label1.Text = "Current value:";
this.label1.Click += new System.EventHandler(this.label1_Click);
// //
// labelValue // labelValue
// //
this.labelValue.AutoSize = true; this.labelValue.AutoSize = true;
this.labelValue.Location = new System.Drawing.Point(118, 534); this.labelValue.Location = new System.Drawing.Point(118, 566);
this.labelValue.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.labelValue.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labelValue.Name = "labelValue"; this.labelValue.Name = "labelValue";
this.labelValue.Size = new System.Drawing.Size(11, 16); this.labelValue.Size = new System.Drawing.Size(11, 16);
@@ -121,7 +121,7 @@
// label2 // label2
// //
this.label2.AutoSize = true; this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(50, 566); this.label2.Location = new System.Drawing.Point(50, 598);
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Name = "label2"; this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(85, 16); this.label2.Size = new System.Drawing.Size(85, 16);
@@ -130,7 +130,7 @@
// //
// button1 // button1
// //
this.button1.Location = new System.Drawing.Point(13, 560); this.button1.Location = new System.Drawing.Point(13, 592);
this.button1.Margin = new System.Windows.Forms.Padding(4); this.button1.Margin = new System.Windows.Forms.Padding(4);
this.button1.Name = "button1"; this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(29, 28); this.button1.Size = new System.Drawing.Size(29, 28);
@@ -142,7 +142,7 @@
// labelRPM // labelRPM
// //
this.labelRPM.AutoSize = true; this.labelRPM.AutoSize = true;
this.labelRPM.Location = new System.Drawing.Point(153, 566); this.labelRPM.Location = new System.Drawing.Point(153, 598);
this.labelRPM.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.labelRPM.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labelRPM.Name = "labelRPM"; this.labelRPM.Name = "labelRPM";
this.labelRPM.Size = new System.Drawing.Size(11, 16); this.labelRPM.Size = new System.Drawing.Size(11, 16);
@@ -152,7 +152,7 @@
// labelCPUTemp // labelCPUTemp
// //
this.labelCPUTemp.AutoSize = true; this.labelCPUTemp.AutoSize = true;
this.labelCPUTemp.Location = new System.Drawing.Point(185, 602); this.labelCPUTemp.Location = new System.Drawing.Point(185, 634);
this.labelCPUTemp.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.labelCPUTemp.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labelCPUTemp.Name = "labelCPUTemp"; this.labelCPUTemp.Name = "labelCPUTemp";
this.labelCPUTemp.Size = new System.Drawing.Size(11, 16); this.labelCPUTemp.Size = new System.Drawing.Size(11, 16);
@@ -161,7 +161,7 @@
// //
// button2 // button2
// //
this.button2.Location = new System.Drawing.Point(13, 596); this.button2.Location = new System.Drawing.Point(13, 628);
this.button2.Margin = new System.Windows.Forms.Padding(4); this.button2.Margin = new System.Windows.Forms.Padding(4);
this.button2.Name = "button2"; this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(29, 28); this.button2.Size = new System.Drawing.Size(29, 28);
@@ -173,7 +173,7 @@
// label4 // label4
// //
this.label4.AutoSize = true; this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(50, 602); this.label4.Location = new System.Drawing.Point(50, 634);
this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label4.Name = "label4"; this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(116, 16); this.label4.Size = new System.Drawing.Size(116, 16);
@@ -185,8 +185,8 @@
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItem1, this.toolStripMenuItem1,
this.toolStripMenuItemCheckForUpdates, this.optionsToolStripMenuItem,
this.optionsToolStripMenuItem}); this.toolStripMenuItemCheckForUpdates});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(595, 28); this.menuStrip1.Size = new System.Drawing.Size(595, 28);
@@ -201,7 +201,7 @@
this.allowFanCurveSettingViaTextToolStripMenuItem, this.allowFanCurveSettingViaTextToolStripMenuItem,
this.resetToDefaultsToolStripMenuItem}); this.resetToDefaultsToolStripMenuItem});
this.toolStripMenuItem1.Name = "toolStripMenuItem1"; this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(89, 26); this.toolStripMenuItem1.Size = new System.Drawing.Size(89, 24);
this.toolStripMenuItem1.Text = "Advanced"; this.toolStripMenuItem1.Text = "Advanced";
// //
// toolStripMenuItemTurnOffControlOnExit // toolStripMenuItemTurnOffControlOnExit
@@ -235,10 +235,43 @@
this.resetToDefaultsToolStripMenuItem.Text = "Reset to defaults"; this.resetToDefaultsToolStripMenuItem.Text = "Reset to defaults";
this.resetToDefaultsToolStripMenuItem.Click += new System.EventHandler(this.resetToDefaultsToolStripMenuItem_Click); this.resetToDefaultsToolStripMenuItem.Click += new System.EventHandler(this.resetToDefaultsToolStripMenuItem_Click);
// //
// optionsToolStripMenuItem
//
this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.startupSettingsToolStripMenuItem});
this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(75, 24);
this.optionsToolStripMenuItem.Text = "Options";
//
// startupSettingsToolStripMenuItem
//
this.startupSettingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.startMinimisedToolStripMenuItem,
this.startWithWindowsToolStripMenuItem});
this.startupSettingsToolStripMenuItem.Name = "startupSettingsToolStripMenuItem";
this.startupSettingsToolStripMenuItem.Size = new System.Drawing.Size(197, 26);
this.startupSettingsToolStripMenuItem.Text = "Startup Settings";
//
// startMinimisedToolStripMenuItem
//
this.startMinimisedToolStripMenuItem.CheckOnClick = true;
this.startMinimisedToolStripMenuItem.Name = "startMinimisedToolStripMenuItem";
this.startMinimisedToolStripMenuItem.Size = new System.Drawing.Size(220, 26);
this.startMinimisedToolStripMenuItem.Text = "Start Minimised";
this.startMinimisedToolStripMenuItem.Click += new System.EventHandler(this.startMinimisedToolStripMenuItem_Click);
//
// startWithWindowsToolStripMenuItem
//
this.startWithWindowsToolStripMenuItem.CheckOnClick = true;
this.startWithWindowsToolStripMenuItem.Name = "startWithWindowsToolStripMenuItem";
this.startWithWindowsToolStripMenuItem.Size = new System.Drawing.Size(220, 26);
this.startWithWindowsToolStripMenuItem.Text = "Start with Windows";
this.startWithWindowsToolStripMenuItem.Click += new System.EventHandler(this.startWithWindowsToolStripMenuItem1_Click_1);
//
// toolStripMenuItemCheckForUpdates // toolStripMenuItemCheckForUpdates
// //
this.toolStripMenuItemCheckForUpdates.Name = "toolStripMenuItemCheckForUpdates"; this.toolStripMenuItemCheckForUpdates.Name = "toolStripMenuItemCheckForUpdates";
this.toolStripMenuItemCheckForUpdates.Size = new System.Drawing.Size(142, 26); this.toolStripMenuItemCheckForUpdates.Size = new System.Drawing.Size(142, 24);
this.toolStripMenuItemCheckForUpdates.Text = "Check for updates"; this.toolStripMenuItemCheckForUpdates.Text = "Check for updates";
this.toolStripMenuItemCheckForUpdates.Click += new System.EventHandler(this.toolStripMenuItemCheckForUpdates_Click); this.toolStripMenuItemCheckForUpdates.Click += new System.EventHandler(this.toolStripMenuItemCheckForUpdates_Click);
// //
@@ -391,6 +424,7 @@
0, 0,
0, 0,
0}); 0});
this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
// //
// groupBox2 // groupBox2
// //
@@ -400,7 +434,7 @@
this.groupBox2.Controls.Add(this.label7); this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.numericUpDown1); this.groupBox2.Controls.Add(this.numericUpDown1);
this.groupBox2.Controls.Add(this.label6); this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Location = new System.Drawing.Point(364, 537); this.groupBox2.Location = new System.Drawing.Point(364, 569);
this.groupBox2.Name = "groupBox2"; this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(214, 87); this.groupBox2.Size = new System.Drawing.Size(214, 87);
this.groupBox2.TabIndex = 19; this.groupBox2.TabIndex = 19;
@@ -447,10 +481,11 @@
this.numericUpDown2.Size = new System.Drawing.Size(68, 22); this.numericUpDown2.Size = new System.Drawing.Size(68, 22);
this.numericUpDown2.TabIndex = 22; this.numericUpDown2.TabIndex = 22;
this.numericUpDown2.Value = new decimal(new int[] { this.numericUpDown2.Value = new decimal(new int[] {
3000, 2000,
0, 0,
0, 0,
0}); 0});
this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
// //
// label7 // label7
// //
@@ -463,7 +498,7 @@
// //
// label3 // label3
// //
this.label3.Location = new System.Drawing.Point(12, 656); this.label3.Location = new System.Drawing.Point(12, 688);
this.label3.Name = "label3"; this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(574, 16); this.label3.Size = new System.Drawing.Size(574, 16);
this.label3.TabIndex = 20; this.label3.TabIndex = 20;
@@ -484,49 +519,25 @@
// label10 // label10
// //
this.label10.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.label10.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label10.Location = new System.Drawing.Point(12, 645); this.label10.Location = new System.Drawing.Point(12, 677);
this.label10.Name = "label10"; this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(574, 2); this.label10.Size = new System.Drawing.Size(574, 2);
this.label10.TabIndex = 24; this.label10.TabIndex = 24;
// //
// optionsToolStripMenuItem // label11
// //
this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.label11.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.startupSettingsToolStripMenuItem}); this.label11.Location = new System.Drawing.Point(15, 542);
this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; this.label11.Name = "label11";
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(75, 26); this.label11.Size = new System.Drawing.Size(574, 2);
this.optionsToolStripMenuItem.Text = "Options"; this.label11.TabIndex = 25;
//
// startupSettingsToolStripMenuItem
//
this.startupSettingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.startMinimisedToolStripMenuItem,
this.startWithWindowsToolStripMenuItem});
this.startupSettingsToolStripMenuItem.Name = "startupSettingsToolStripMenuItem";
this.startupSettingsToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.startupSettingsToolStripMenuItem.Text = "Startup Settings";
//
// startMinimisedToolStripMenuItem
//
this.startMinimisedToolStripMenuItem.CheckOnClick = true;
this.startMinimisedToolStripMenuItem.Name = "startMinimisedToolStripMenuItem";
this.startMinimisedToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.startMinimisedToolStripMenuItem.Text = "Start Minimised";
this.startMinimisedToolStripMenuItem.Click += new System.EventHandler(this.startMinimisedToolStripMenuItem_Click);
//
// startWithWindowsToolStripMenuItem
//
this.startWithWindowsToolStripMenuItem.CheckOnClick = true;
this.startWithWindowsToolStripMenuItem.Name = "startWithWindowsToolStripMenuItem";
this.startWithWindowsToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.startWithWindowsToolStripMenuItem.Text = "Start with Windows";
this.startWithWindowsToolStripMenuItem.Click += new System.EventHandler(this.startWithWindowsToolStripMenuItem1_Click_1);
// //
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(595, 685); this.ClientSize = new System.Drawing.Size(595, 716);
this.Controls.Add(this.label11);
this.Controls.Add(this.label10); this.Controls.Add(this.label10);
this.Controls.Add(this.button4); this.Controls.Add(this.button4);
this.Controls.Add(this.button3); this.Controls.Add(this.button3);
@@ -549,6 +560,7 @@
this.Margin = new System.Windows.Forms.Padding(4); this.Margin = new System.Windows.Forms.Padding(4);
this.Name = "Form1"; this.Name = "Form1";
this.Text = "AsusFanControlEnhanced"; this.Text = "AsusFanControlEnhanced";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
this.Shown += new System.EventHandler(this.Form1_Shown); this.Shown += new System.EventHandler(this.Form1_Shown);
this.Resize += new System.EventHandler(this.Form1_Resize); this.Resize += new System.EventHandler(this.Form1_Resize);
((System.ComponentModel.ISupportInitialize)(this.trackBarFanSpeed)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBarFanSpeed)).EndInit();
@@ -613,6 +625,7 @@
private System.Windows.Forms.ToolStripMenuItem startupSettingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem startupSettingsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem startMinimisedToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem startMinimisedToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem startWithWindowsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem startWithWindowsToolStripMenuItem;
private System.Windows.Forms.Label label11;
} }
} }

View File

@@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Data; using System.Data;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Security.AccessControl; using System.Security.AccessControl;
@@ -13,7 +14,9 @@ using System.Windows.Forms;
using AsusFanControl; using AsusFanControl;
using AsusFanControlGUI.Properties; using AsusFanControlGUI.Properties;
using Microsoft.Win32; using Microsoft.Win32;
using static System.Security.Cryptography.ECCurve;
using static System.Windows.Forms.VisualStyles.VisualStyleElement; using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static AsusFanControlGUI.Form1;
namespace AsusFanControlGUI namespace AsusFanControlGUI
{ {
@@ -21,7 +24,7 @@ namespace AsusFanControlGUI
{ {
private readonly Random rnd = new Random(); private readonly Random rnd = new Random();
readonly AsusControl asusControl = new AsusControl(); readonly AsusControl asusControl = new AsusControl();
int fanSpeed = 0; int currentFanSpeed = 0;
public Form1() public Form1()
{ {
@@ -47,6 +50,8 @@ namespace AsusFanControlGUI
fanControl.Checked = Properties.Settings.Default.fanControlState == "Manual"; fanControl.Checked = Properties.Settings.Default.fanControlState == "Manual";
fanCurve.Checked = Properties.Settings.Default.fanControlState == "Curve"; fanCurve.Checked = Properties.Settings.Default.fanControlState == "Curve";
allowFanCurveSettingViaTextToolStripMenuItem.Checked = Properties.Settings.Default.allowFanCurveSettingViaText; allowFanCurveSettingViaTextToolStripMenuItem.Checked = Properties.Settings.Default.allowFanCurveSettingViaText;
numericUpDown1.Value = Properties.Settings.Default.hysteresis;
numericUpDown2.Value = Properties.Settings.Default.updateSpeed;
// Manually trigger events // Manually trigger events
radioButton1_CheckedChanged(radioButton1, EventArgs.Empty); radioButton1_CheckedChanged(radioButton1, EventArgs.Empty);
fanCurve_CheckedChanged(fanCurve, EventArgs.Empty); fanCurve_CheckedChanged(fanCurve, EventArgs.Empty);
@@ -81,7 +86,7 @@ namespace AsusFanControlGUI
return; return;
} }
Console.WriteLine($"Refreshing {rnd.Next(100)}"); //Console.WriteLine($"Refreshing {rnd.Next(100)}");
// Update fan speeds and CPU temperature. // Update fan speeds and CPU temperature.
// Run both tasks concurrently // Run both tasks concurrently
Task<string> fanSpeedsTask = Task.Run(() => string.Join(" ", asusControl.GetFanSpeeds())); Task<string> fanSpeedsTask = Task.Run(() => string.Join(" ", asusControl.GetFanSpeeds()));
@@ -117,8 +122,8 @@ namespace AsusFanControlGUI
private void OnProcessExit(object sender, EventArgs e) private void OnProcessExit(object sender, EventArgs e)
{ {
if (Properties.Settings.Default.turnOffControlOnExit) // if (Properties.Settings.Default.turnOffControlOnExit)
setFanSpeed(0, null); // asusControl.SetFanSpeeds(0);
} }
private void toolStripMenuItemTurnOffControlOnExit_CheckedChanged(object sender, EventArgs e) private void toolStripMenuItemTurnOffControlOnExit_CheckedChanged(object sender, EventArgs e)
@@ -149,7 +154,7 @@ namespace AsusFanControlGUI
} }
} }
private void fanControl_CheckedChanged(object sender, EventArgs e) private async void fanControl_CheckedChanged(object sender, EventArgs e)
{ {
if (fanControl.Checked) if (fanControl.Checked)
{ {
@@ -158,35 +163,36 @@ namespace AsusFanControlGUI
trackBarFanSpeed.Enabled = true; trackBarFanSpeed.Enabled = true;
trackBarSetFanSpeed(); trackBarSetFanSpeed();
await Task.Delay(2000);
fanControl_CheckedChanged(sender, e);
} }
else else
{ {
trackBarFanSpeed.Enabled=false; trackBarFanSpeed.Enabled = false;
} }
} }
bool turnedoff = false; bool firstRun = true;
private async void setFanSpeed(int value, bool? isTurnedOn) private async void setFanSpeed(int value, bool? xyz)
{ {
if (fanSpeed == value) if (currentFanSpeed == value)
return; return;
if (turnedoff && value == 0)
return;
fanSpeed = value;
await Task.Run(() => asusControl.SetFanSpeeds(value)); await Task.Run(() => asusControl.SetFanSpeeds(value));
currentFanSpeed = value;
if (value == 0) if (value == 0)
{
labelValue.Text = "turned off"; labelValue.Text = "turned off";
turnedoff = true;
}
else else
labelValue.Text = value.ToString() + "% (PWM Fan)";
if (firstRun)
{ {
labelValue.Text = value.ToString() + "%"; await Task.Delay(1000);
turnedoff = false; currentFanSpeed = 999999;
setFanSpeed(value, null);
firstRun = false;
} }
} }
@@ -205,6 +211,8 @@ namespace AsusFanControlGUI
Decimal trackBarFanSpeedValue = trackBarFanSpeed.Value; Decimal trackBarFanSpeedValue = trackBarFanSpeed.Value;
label5.Text = trackBarFanSpeedValue.ToString() + "% Fan"; label5.Text = trackBarFanSpeedValue.ToString() + "% Fan";
Console.WriteLine($"Setting speed to: {(int)trackBarFanSpeedValue}");
label3.Text = $"Setting speed to: {(int)trackBarFanSpeedValue}%";// (Stamp: {rnd.Next(1000)})";
setFanSpeed((int)trackBarFanSpeedValue, fanControl.Checked); setFanSpeed((int)trackBarFanSpeedValue, fanControl.Checked);
} }
@@ -225,8 +233,8 @@ namespace AsusFanControlGUI
private async void button2_Click(object sender, EventArgs e) private async void button2_Click(object sender, EventArgs e)
{ {
ulong fanSpeed = await Task.Run(() => asusControl.Thermal_Read_Cpu_Temperature()); ulong currentTemp = await Task.Run(() => asusControl.Thermal_Read_Cpu_Temperature());
labelCPUTemp.Text = $"{fanSpeed}"; labelCPUTemp.Text = $"{currentTemp}";
} }
// My Code: // My Code:
@@ -250,8 +258,11 @@ namespace AsusFanControlGUI
const int tempMin = 20; const int tempMin = 20;
const int tempMax = 100; const int tempMax = 100;
const int tempInterval = 10; const int tempInterval = 10;
private void pictureBoxFanCurve_Paint(object sender, PaintEventArgs e) private void pictureBoxFanCurve_Paint(object sender, PaintEventArgs e)
{ {
// Get the graphics object to draw on the picture box // Get the graphics object to draw on the picture box
Graphics g = e.Graphics; Graphics g = e.Graphics;
@@ -268,6 +279,9 @@ namespace AsusFanControlGUI
int x = 40 + (temp - 20) * graphWidth / 80; int x = 40 + (temp - 20) * graphWidth / 80;
g.DrawLine(Pens.Black, x, pictureBoxFanCurve.Height - 40 - 5, x, pictureBoxFanCurve.Height - 40 + 5); g.DrawLine(Pens.Black, x, pictureBoxFanCurve.Height - 40 - 5, x, pictureBoxFanCurve.Height - 40 + 5);
g.DrawString(temp.ToString(), Control.DefaultFont, Brushes.Black, x - 10, pictureBoxFanCurve.Height - 40 + 10); g.DrawString(temp.ToString(), Control.DefaultFont, Brushes.Black, x - 10, pictureBoxFanCurve.Height - 40 + 10);
// Draw vertical gridlines
g.DrawLine(Pens.LightGray, x, 40, x, pictureBoxFanCurve.Height - 40);
} }
// Draw the X-axis label (Temperature) // Draw the X-axis label (Temperature)
@@ -282,6 +296,9 @@ namespace AsusFanControlGUI
int y = pictureBoxFanCurve.Height - 40 - speed * graphHeight / 100; int y = pictureBoxFanCurve.Height - 40 - speed * graphHeight / 100;
g.DrawLine(Pens.Black, 35, y, 45, y); g.DrawLine(Pens.Black, 35, y, 45, y);
g.DrawString(speed.ToString(), Control.DefaultFont, Brushes.Black, 5f, y - 10); g.DrawString(speed.ToString(), Control.DefaultFont, Brushes.Black, 5f, y - 10);
// Draw horizontal gridlines
g.DrawLine(Pens.LightGray, 40, y, pictureBoxFanCurve.Width - 40, y);
} }
// Draw the Y-axis label (Fan Speed) // Draw the Y-axis label (Fan Speed)
@@ -304,6 +321,7 @@ namespace AsusFanControlGUI
.ToArray(); .ToArray();
using Pen thickPen = new Pen(Color.Black, 3f); using Pen thickPen = new Pen(Color.Black, 3f);
thickPen.LineJoin = LineJoin.Round;
g.DrawLines(thickPen, graphPoints); g.DrawLines(thickPen, graphPoints);
} }
} }
@@ -457,6 +475,43 @@ namespace AsusFanControlGUI
runFanCurve(); runFanCurve();
} }
public enum CurveType
{
Linear,
Quadratic,
Cubic
}
double curvatureFactor = 0.5;
// Fan speed calculation
double CalculateFanSpeed(double currentTemp)
{
// Find the fan curve points that bracket the current temperature
KeyValuePair<int, Point> lowerPoint = fanCurvePoints.OrderByDescending(p => p.Value.X).FirstOrDefault(p => (ulong)p.Value.X <= currentTemp);
KeyValuePair<int, Point> upperPoint = fanCurvePoints.OrderBy(p => p.Value.X).FirstOrDefault(p => (ulong)p.Value.X >= currentTemp);
if (lowerPoint.Key == upperPoint.Key)
{
return lowerPoint.Value.Y;
}
// Check if the current temperature is within the range of the fan curve points
if (lowerPoint.Key == 0 || upperPoint.Key == 0)
{
// Temperature is outside the range, yield control to the system.
label3.Text = "Control yeilded to system when temprature is outside range.";
Console.WriteLine("Temperature is outside the range, yield control to the system.");
return 0;
}else
{
}
double ratio = (currentTemp - lowerPoint.Value.X) / (upperPoint.Value.X - lowerPoint.Value.X);
return lowerPoint.Value.Y + (upperPoint.Value.Y - lowerPoint.Value.Y) * ratio;
}
private async void runFanCurve() private async void runFanCurve()
{ {
if (!fanCurve.Checked) if (!fanCurve.Checked)
@@ -464,56 +519,31 @@ namespace AsusFanControlGUI
label3.Text = $""; label3.Text = $"";
return; return;
} }
Console.WriteLine("Fan Curve, " + (int)numericUpDown2.Value); //Console.WriteLine("Fan Curve, " + (int)numericUpDown2.Value);
// Read the current temperature // Read the current temperature
ulong currentTemp = await Task.Run(() => asusControl.Thermal_Read_Cpu_Temperature()); // Implement the ReadTemperature method to get the current temperature ulong currentTemp = await Task.Run(() => asusControl.Thermal_Read_Cpu_Temperature()); // Implement the ReadTemperature method to get the current temperature
Console.WriteLine("Temp, " + currentTemp); //Console.WriteLine("Temp, " + currentTemp);
double fanSpeed = CalculateFanSpeed(currentTemp);
// Find the fan curve points that bracket the current temperature // Apply hysteresis to prevent rapid fan speed changes
KeyValuePair<int, Point> lowerPoint = fanCurvePoints.OrderByDescending(p => p.Value.X).FirstOrDefault(p => (ulong)p.Value.X <= currentTemp); int hysteresis = (int)numericUpDown1.Value; // Adjust the hysteresis value as needed
KeyValuePair<int, Point> upperPoint = fanCurvePoints.OrderBy(p => p.Value.X).FirstOrDefault(p => (ulong)p.Value.X >= currentTemp); if ((int)currentTemp > lastTemperature + hysteresis || (int)currentTemp < lastTemperature - hysteresis || fanSpeed < 10)
// Update UI on the main thread
label3.Text = $"Low: {lowerPoint.Value.X} High: {upperPoint.Value.X}";
// Check if the current temperature is within the range of the fan curve points
if (lowerPoint.Key == 0 || upperPoint.Key == 0)
{ {
// Temperature is outside the range, yield control to the system. // Update the fan speed
label3.Text = "Control yeilded to system when outside range."; fanSpeed = Math.Max(0, Math.Min(100, fanSpeed));
Console.WriteLine("Temperature is outside the range, yield control to the system."); setFanSpeed((int)fanSpeed, true); // Implement the SetFanSpeed method to control the fan speed
setFanSpeed(0, null);
}
else if (lowerPoint.Value.X == upperPoint.Value.X)
{
setFanSpeed(lowerPoint.Value.Y, true); // Implement the SetFanSpeed method to control the fan speed
Console.WriteLine($"Set fan speed to {lowerPoint.Value.Y}% {rnd.Next(1000)}, last fan speed = {lastFanSpeed}"); Console.WriteLine($"Set fan speed to {(int)fanSpeed}% {rnd.Next(1000)}, last fan speed = {lastTemperature}");
lastFanSpeed = lowerPoint.Value.Y; if (fanSpeed != 0)
}
else
{
// Calculate the fan speed based on linear interpolation between the bracket points
int fanSpeed;
double ratio = (currentTemp - (ulong)lowerPoint.Value.X) / (double)(upperPoint.Value.X - lowerPoint.Value.X);
fanSpeed = (int)(lowerPoint.Value.Y + (upperPoint.Value.Y - lowerPoint.Value.Y) * ratio);
// Apply hysteresis to prevent rapid fan speed changes
int hysteresis = (int)numericUpDown1.Value; // Adjust the hysteresis value as needed
if (fanSpeed > lastFanSpeed + hysteresis || fanSpeed < lastFanSpeed - hysteresis || fanSpeed < 10)
{ {
// Update the fan speed label3.Text = $"Set fan speed to {(int)fanSpeed}%, current temp: {currentTemp}°C";// (Stamp: {rnd.Next(1000)})";
fanSpeed = Math.Max(1, Math.Min(100, fanSpeed));
setFanSpeed(fanSpeed, true); // Implement the SetFanSpeed method to control the fan speed
Console.WriteLine($"Set fan speed to {fanSpeed}% {rnd.Next(1000)}, last fan speed = {lastFanSpeed}");
lastFanSpeed = fanSpeed;
} }
lastTemperature = (int)currentTemp;
}
};
await Task.Delay((int)numericUpDown2.Value); await Task.Delay((int)numericUpDown2.Value);
runFanCurve(); runFanCurve();
@@ -521,7 +551,7 @@ namespace AsusFanControlGUI
} }
// Keep track of the last fan speed to apply hysteresis // Keep track of the last fan speed to apply hysteresis
private int lastFanSpeed = 0; private int lastTemperature = 0;
@@ -629,11 +659,6 @@ namespace AsusFanControlGUI
trackBarSetFanSpeed(); trackBarSetFanSpeed();
} }
private void label1_Click(object sender, EventArgs e)
{
}
private void resetToDefaultsToolStripMenuItem_Click(object sender, EventArgs e) private void resetToDefaultsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
Properties.Settings.Default.Reset(); Properties.Settings.Default.Reset();
@@ -719,6 +744,28 @@ namespace AsusFanControlGUI
} }
} }
private void toolStripComboBox1_TextChanged(object sender, EventArgs e)
{
pictureBoxFanCurve.Invalidate();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (Properties.Settings.Default.turnOffControlOnExit)
asusControl.SetFanSpeeds(0);
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
Properties.Settings.Default.hysteresis = (int)numericUpDown1.Value;
Properties.Settings.Default.Save();
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
Properties.Settings.Default.updateSpeed = (int)numericUpDown2.Value;
Properties.Settings.Default.Save();
}
//notifyIcon1.BalloonTipText = string.Join(" ", asusControl.GetFanSpeeds()) + $" Temp: {asusControl.Thermal_Read_Cpu_Temperature()}"; } //notifyIcon1.BalloonTipText = string.Join(" ", asusControl.GetFanSpeeds()) + $" Temp: {asusControl.Thermal_Read_Cpu_Temperature()}"; }
} }

View File

@@ -118,5 +118,29 @@ namespace AsusFanControlGUI.Properties {
this["startMinimised"] = value; this["startMinimised"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("1")]
public int hysteresis {
get {
return ((int)(this["hysteresis"]));
}
set {
this["hysteresis"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("2000")]
public int updateSpeed {
get {
return ((int)(this["updateSpeed"]));
}
set {
this["updateSpeed"] = value;
}
}
} }
} }

View File

@@ -26,5 +26,11 @@
<Setting Name="startMinimised" Type="System.Boolean" Scope="User"> <Setting Name="startMinimised" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value> <Value Profile="(Default)">False</Value>
</Setting> </Setting>
<Setting Name="hysteresis" Type="System.Int32" Scope="User">
<Value Profile="(Default)">1</Value>
</Setting>
<Setting Name="updateSpeed" Type="System.Int32" Scope="User">
<Value Profile="(Default)">2000</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>