diff --git a/AsusFanControlGUI/App.config b/AsusFanControlGUI/App.config index f538c99..d5531ab 100644 --- a/AsusFanControlGUI/App.config +++ b/AsusFanControlGUI/App.config @@ -34,6 +34,12 @@ False + + 1 + + + 2000 + diff --git a/AsusFanControlGUI/Form1.Designer.cs b/AsusFanControlGUI/Form1.Designer.cs index 11b6fbf..a6c8f26 100644 --- a/AsusFanControlGUI/Form1.Designer.cs +++ b/AsusFanControlGUI/Form1.Designer.cs @@ -45,6 +45,10 @@ this.toolStripMenuItemForbidUnsafeSettings = new System.Windows.Forms.ToolStripMenuItem(); this.allowFanCurveSettingViaTextToolStripMenuItem = 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.label5 = new System.Windows.Forms.Label(); this.pictureBoxFanCurve = new System.Windows.Forms.PictureBox(); @@ -70,10 +74,7 @@ this.label3 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label10 = new System.Windows.Forms.Label(); - 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.label11 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.trackBarFanSpeed)).BeginInit(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxFanCurve)).BeginInit(); @@ -100,18 +101,17 @@ // label1 // 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.Name = "label1"; this.label1.Size = new System.Drawing.Size(88, 16); this.label1.TabIndex = 1; this.label1.Text = "Current value:"; - this.label1.Click += new System.EventHandler(this.label1_Click); // // labelValue // 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.Name = "labelValue"; this.labelValue.Size = new System.Drawing.Size(11, 16); @@ -121,7 +121,7 @@ // label2 // 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.Name = "label2"; this.label2.Size = new System.Drawing.Size(85, 16); @@ -130,7 +130,7 @@ // // 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.Name = "button1"; this.button1.Size = new System.Drawing.Size(29, 28); @@ -142,7 +142,7 @@ // labelRPM // 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.Name = "labelRPM"; this.labelRPM.Size = new System.Drawing.Size(11, 16); @@ -152,7 +152,7 @@ // labelCPUTemp // 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.Name = "labelCPUTemp"; this.labelCPUTemp.Size = new System.Drawing.Size(11, 16); @@ -161,7 +161,7 @@ // // 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.Name = "button2"; this.button2.Size = new System.Drawing.Size(29, 28); @@ -173,7 +173,7 @@ // label4 // 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.Name = "label4"; this.label4.Size = new System.Drawing.Size(116, 16); @@ -185,8 +185,8 @@ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem1, - this.toolStripMenuItemCheckForUpdates, - this.optionsToolStripMenuItem}); + this.optionsToolStripMenuItem, + this.toolStripMenuItemCheckForUpdates}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(595, 28); @@ -201,7 +201,7 @@ this.allowFanCurveSettingViaTextToolStripMenuItem, this.resetToDefaultsToolStripMenuItem}); 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"; // // toolStripMenuItemTurnOffControlOnExit @@ -235,10 +235,43 @@ this.resetToDefaultsToolStripMenuItem.Text = "Reset to defaults"; 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 // 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.Click += new System.EventHandler(this.toolStripMenuItemCheckForUpdates_Click); // @@ -391,6 +424,7 @@ 0, 0, 0}); + this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); // // groupBox2 // @@ -400,7 +434,7 @@ this.groupBox2.Controls.Add(this.label7); this.groupBox2.Controls.Add(this.numericUpDown1); 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.Size = new System.Drawing.Size(214, 87); this.groupBox2.TabIndex = 19; @@ -447,10 +481,11 @@ this.numericUpDown2.Size = new System.Drawing.Size(68, 22); this.numericUpDown2.TabIndex = 22; this.numericUpDown2.Value = new decimal(new int[] { - 3000, + 2000, 0, 0, 0}); + this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged); // // label7 // @@ -463,7 +498,7 @@ // // 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.Size = new System.Drawing.Size(574, 16); this.label3.TabIndex = 20; @@ -484,49 +519,25 @@ // label10 // 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.Size = new System.Drawing.Size(574, 2); this.label10.TabIndex = 24; // - // optionsToolStripMenuItem + // label11 // - this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.startupSettingsToolStripMenuItem}); - this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; - this.optionsToolStripMenuItem.Size = new System.Drawing.Size(75, 26); - 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(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); + this.label11.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.label11.Location = new System.Drawing.Point(15, 542); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(574, 2); + this.label11.TabIndex = 25; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 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.button4); this.Controls.Add(this.button3); @@ -549,6 +560,7 @@ this.Margin = new System.Windows.Forms.Padding(4); this.Name = "Form1"; this.Text = "AsusFanControlEnhanced"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Shown += new System.EventHandler(this.Form1_Shown); this.Resize += new System.EventHandler(this.Form1_Resize); ((System.ComponentModel.ISupportInitialize)(this.trackBarFanSpeed)).EndInit(); @@ -613,6 +625,7 @@ private System.Windows.Forms.ToolStripMenuItem startupSettingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem startMinimisedToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem startWithWindowsToolStripMenuItem; + private System.Windows.Forms.Label label11; } } diff --git a/AsusFanControlGUI/Form1.cs b/AsusFanControlGUI/Form1.cs index a4fa2ff..75f4641 100644 --- a/AsusFanControlGUI/Form1.cs +++ b/AsusFanControlGUI/Form1.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; +using System.Drawing.Drawing2D; using System.Linq; using System.Reflection; using System.Security.AccessControl; @@ -13,7 +14,9 @@ using System.Windows.Forms; using AsusFanControl; using AsusFanControlGUI.Properties; using Microsoft.Win32; +using static System.Security.Cryptography.ECCurve; using static System.Windows.Forms.VisualStyles.VisualStyleElement; +using static AsusFanControlGUI.Form1; namespace AsusFanControlGUI { @@ -21,7 +24,7 @@ namespace AsusFanControlGUI { private readonly Random rnd = new Random(); readonly AsusControl asusControl = new AsusControl(); - int fanSpeed = 0; + int currentFanSpeed = 0; public Form1() { @@ -47,6 +50,8 @@ namespace AsusFanControlGUI fanControl.Checked = Properties.Settings.Default.fanControlState == "Manual"; fanCurve.Checked = Properties.Settings.Default.fanControlState == "Curve"; allowFanCurveSettingViaTextToolStripMenuItem.Checked = Properties.Settings.Default.allowFanCurveSettingViaText; + numericUpDown1.Value = Properties.Settings.Default.hysteresis; + numericUpDown2.Value = Properties.Settings.Default.updateSpeed; // Manually trigger events radioButton1_CheckedChanged(radioButton1, EventArgs.Empty); fanCurve_CheckedChanged(fanCurve, EventArgs.Empty); @@ -81,7 +86,7 @@ namespace AsusFanControlGUI return; } - Console.WriteLine($"Refreshing {rnd.Next(100)}"); + //Console.WriteLine($"Refreshing {rnd.Next(100)}"); // Update fan speeds and CPU temperature. // Run both tasks concurrently Task fanSpeedsTask = Task.Run(() => string.Join(" ", asusControl.GetFanSpeeds())); @@ -117,8 +122,8 @@ namespace AsusFanControlGUI private void OnProcessExit(object sender, EventArgs e) { - if (Properties.Settings.Default.turnOffControlOnExit) - setFanSpeed(0, null); + // if (Properties.Settings.Default.turnOffControlOnExit) + // asusControl.SetFanSpeeds(0); } 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) { @@ -158,35 +163,36 @@ namespace AsusFanControlGUI trackBarFanSpeed.Enabled = true; trackBarSetFanSpeed(); + await Task.Delay(2000); + fanControl_CheckedChanged(sender, e); } else { - trackBarFanSpeed.Enabled=false; + trackBarFanSpeed.Enabled = false; } } - bool turnedoff = false; - private async void setFanSpeed(int value, bool? isTurnedOn) + bool firstRun = true; + private async void setFanSpeed(int value, bool? xyz) { - if (fanSpeed == value) + if (currentFanSpeed == value) return; - if (turnedoff && value == 0) - return; - - fanSpeed = value; await Task.Run(() => asusControl.SetFanSpeeds(value)); + currentFanSpeed = value; if (value == 0) - { labelValue.Text = "turned off"; - turnedoff = true; - } else + labelValue.Text = value.ToString() + "% (PWM Fan)"; + + if (firstRun) { - labelValue.Text = value.ToString() + "%"; - turnedoff = false; + await Task.Delay(1000); + currentFanSpeed = 999999; + setFanSpeed(value, null); + firstRun = false; } } @@ -205,6 +211,8 @@ namespace AsusFanControlGUI Decimal trackBarFanSpeedValue = trackBarFanSpeed.Value; 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); } @@ -225,8 +233,8 @@ namespace AsusFanControlGUI private async void button2_Click(object sender, EventArgs e) { - ulong fanSpeed = await Task.Run(() => asusControl.Thermal_Read_Cpu_Temperature()); - labelCPUTemp.Text = $"{fanSpeed}"; + ulong currentTemp = await Task.Run(() => asusControl.Thermal_Read_Cpu_Temperature()); + labelCPUTemp.Text = $"{currentTemp}"; } // My Code: @@ -250,8 +258,11 @@ namespace AsusFanControlGUI const int tempMin = 20; const int tempMax = 100; const int tempInterval = 10; + private void pictureBoxFanCurve_Paint(object sender, PaintEventArgs e) { + + // Get the graphics object to draw on the picture box Graphics g = e.Graphics; @@ -268,6 +279,9 @@ namespace AsusFanControlGUI int x = 40 + (temp - 20) * graphWidth / 80; 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); + + // Draw vertical gridlines + g.DrawLine(Pens.LightGray, x, 40, x, pictureBoxFanCurve.Height - 40); } // Draw the X-axis label (Temperature) @@ -282,6 +296,9 @@ namespace AsusFanControlGUI int y = pictureBoxFanCurve.Height - 40 - speed * graphHeight / 100; g.DrawLine(Pens.Black, 35, y, 45, y); 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) @@ -304,6 +321,7 @@ namespace AsusFanControlGUI .ToArray(); using Pen thickPen = new Pen(Color.Black, 3f); + thickPen.LineJoin = LineJoin.Round; g.DrawLines(thickPen, graphPoints); } } @@ -457,6 +475,43 @@ namespace AsusFanControlGUI 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 lowerPoint = fanCurvePoints.OrderByDescending(p => p.Value.X).FirstOrDefault(p => (ulong)p.Value.X <= currentTemp); + KeyValuePair 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() { if (!fanCurve.Checked) @@ -464,56 +519,31 @@ namespace AsusFanControlGUI label3.Text = $""; return; } - Console.WriteLine("Fan Curve, " + (int)numericUpDown2.Value); + //Console.WriteLine("Fan Curve, " + (int)numericUpDown2.Value); // Read 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 - KeyValuePair lowerPoint = fanCurvePoints.OrderByDescending(p => p.Value.X).FirstOrDefault(p => (ulong)p.Value.X <= currentTemp); - KeyValuePair upperPoint = fanCurvePoints.OrderBy(p => p.Value.X).FirstOrDefault(p => (ulong)p.Value.X >= currentTemp); - - // 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) + // Apply hysteresis to prevent rapid fan speed changes + int hysteresis = (int)numericUpDown1.Value; // Adjust the hysteresis value as needed + if ((int)currentTemp > lastTemperature + hysteresis || (int)currentTemp < lastTemperature - hysteresis || fanSpeed < 10) { - // Temperature is outside the range, yield control to the system. - label3.Text = "Control yeilded to system when outside range."; - Console.WriteLine("Temperature is outside the range, yield control to the system."); - 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 + // Update the fan speed + fanSpeed = Math.Max(0, Math.Min(100, fanSpeed)); + setFanSpeed((int)fanSpeed, 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}"); - lastFanSpeed = lowerPoint.Value.Y; - } - 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) + Console.WriteLine($"Set fan speed to {(int)fanSpeed}% {rnd.Next(1000)}, last fan speed = {lastTemperature}"); + if (fanSpeed != 0) { - // Update the fan speed - 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; - + label3.Text = $"Set fan speed to {(int)fanSpeed}%, current temp: {currentTemp}°C";// (Stamp: {rnd.Next(1000)})"; } + lastTemperature = (int)currentTemp; + + } - }; await Task.Delay((int)numericUpDown2.Value); runFanCurve(); @@ -521,7 +551,7 @@ namespace AsusFanControlGUI } // 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(); } - private void label1_Click(object sender, EventArgs e) - { - - } - private void resetToDefaultsToolStripMenuItem_Click(object sender, EventArgs e) { 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()}"; } } diff --git a/AsusFanControlGUI/Properties/Settings.Designer.cs b/AsusFanControlGUI/Properties/Settings.Designer.cs index 64e7833..f3308f4 100644 --- a/AsusFanControlGUI/Properties/Settings.Designer.cs +++ b/AsusFanControlGUI/Properties/Settings.Designer.cs @@ -118,5 +118,29 @@ namespace AsusFanControlGUI.Properties { 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; + } + } } } diff --git a/AsusFanControlGUI/Properties/Settings.settings b/AsusFanControlGUI/Properties/Settings.settings index 0cb2862..be921f4 100644 --- a/AsusFanControlGUI/Properties/Settings.settings +++ b/AsusFanControlGUI/Properties/Settings.settings @@ -26,5 +26,11 @@ False + + 1 + + + 2000 + \ No newline at end of file