Bugfixes
This commit is contained in:
@@ -1,34 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
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;
|
||||
using LibreHardwareMonitor.Hardware;
|
||||
using System.Management;
|
||||
using System;
|
||||
using AsusFanControl.Domain.services;
|
||||
|
||||
namespace AsusFanControlGUI
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
// Dependency injection
|
||||
private readonly FanCurve _fanCurve;
|
||||
|
||||
private readonly Random rnd = new Random();
|
||||
readonly AsusControl asusControl = new AsusControl();
|
||||
int currentFanSpeed = 0;
|
||||
int currentFanRPM = 0;
|
||||
ulong currentTemp = 0;
|
||||
|
||||
public Form1()
|
||||
int temperatureLowerBound = 20;
|
||||
int temperatureUpperBound = 105;
|
||||
|
||||
int fanSpeedLowerBound = 1;
|
||||
int fanSpeedUpperBound = 100;
|
||||
|
||||
public Form1(
|
||||
FanCurve fanCurve
|
||||
)
|
||||
{
|
||||
_fanCurve = fanCurve;
|
||||
|
||||
InitializeComponent();
|
||||
AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);
|
||||
|
||||
@@ -42,94 +51,142 @@ namespace AsusFanControlGUI
|
||||
{
|
||||
if (IsHandleCreated)
|
||||
{
|
||||
startErrorHandler();
|
||||
|
||||
toolStripMenuItemTurnOffControlOnExit.Checked = Properties.Settings.Default.turnOffControlOnExit;
|
||||
// Load settings from the settings file
|
||||
//toolStripMenuItemTurnOffControlOnExit.Checked = Properties.Settings.Default.turnOffControlOnExit;
|
||||
toolStripMenuItemForbidUnsafeSettings.Checked = Properties.Settings.Default.forbidUnsafeSettings;
|
||||
startMinimisedToolStripMenuItem.Checked = Properties.Settings.Default.startMinimised;
|
||||
startWithWindowsToolStripMenuItem.Checked = Properties.Settings.Default.startWithWindows;
|
||||
//startWithWindowsToolStripMenuItem.Checked = Properties.Settings.Default.startWithWindows;
|
||||
checkIfAppIsInStartup();
|
||||
trackBarFanSpeed.Value = Properties.Settings.Default.fanSpeed;
|
||||
radioButton1.Checked = Properties.Settings.Default.fanControlState == "Off";
|
||||
fanControl.Checked = Properties.Settings.Default.fanControlState == "Manual";
|
||||
fanCurve.Checked = Properties.Settings.Default.fanControlState == "Curve";
|
||||
fanControlRadioButton.Checked = Properties.Settings.Default.fanControlState == "Manual";
|
||||
fanCurveRadioButton.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);
|
||||
fanControl_CheckedChanged(fanControl, EventArgs.Empty);
|
||||
fanCurve_CheckedChanged(fanCurveRadioButton, EventArgs.Empty);
|
||||
fanControl_CheckedChanged(fanControlRadioButton, EventArgs.Empty);
|
||||
allowFanCurveSettingViaTextToolStripMenuItem_Click(allowFanCurveSettingViaTextToolStripMenuItem, EventArgs.Empty);
|
||||
|
||||
Properties.Settings.Default.PropertyChanged += (sender, e) =>
|
||||
{
|
||||
if (e.PropertyName == "FanCurvePoints")
|
||||
{
|
||||
textBox1.Text = Properties.Settings.Default.FanCurvePoints;
|
||||
CurvePointsTextbox.Text = Properties.Settings.Default.FanCurvePoints;
|
||||
}
|
||||
};
|
||||
SetFanCurvePoints(null);
|
||||
//SetFanCurvePoints("20,1;60,1;61,20;70,20;71,30;80,55");
|
||||
Timer_Tick();
|
||||
SetFanCurvePoints(Properties.Settings.Default.FanCurvePoints);
|
||||
AutoRefreshStats();
|
||||
startErrorHandler(temperatureLowerBound, temperatureUpperBound);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Restart the init function after a short delay
|
||||
await System.Threading.Tasks.Task.Delay(20);
|
||||
await Task.Delay(20);
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
private async void startErrorHandler()
|
||||
public void checkForNewVersion()
|
||||
{
|
||||
int minTemp = 1;
|
||||
int maxTemp = 200;
|
||||
Console.WriteLine("Running");
|
||||
if ((fanCurve.Checked || fanControl.Checked) && (currentTemp < (ulong)minTemp || currentTemp > (ulong)maxTemp))
|
||||
// Check for new version
|
||||
// If new version is available, show a notification
|
||||
// If the user clicks on the notification, open the download page in the default web browser
|
||||
// https://github.com/Darren80/AsusFanControlEnhanced/releases
|
||||
}
|
||||
|
||||
private async void startErrorHandler(int minTemp, int maxTemp, bool debug = false)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// Give it a second chance
|
||||
await Task.Delay(1000);
|
||||
ulong temp = await Task.Run(() => asusControl.Thermal_Read_Cpu_Temperature());
|
||||
if (temp >= (ulong)minTemp && temp < (ulong)maxTemp)
|
||||
// Wait for X seconds
|
||||
await Task.Delay(3000);
|
||||
|
||||
// Check if the CPU temperature is outside of the good range
|
||||
// Out of bounds values
|
||||
|
||||
Console.WriteLine($"Current temp: {currentTemp}");
|
||||
if ((currentTemp < (ulong)minTemp || currentTemp > (ulong)maxTemp) || debug)
|
||||
{
|
||||
return;
|
||||
Console.WriteLine("Error!");
|
||||
|
||||
Properties.Settings.Default.wasError = true;
|
||||
string errorMsg = $"CPU temprature is outside of good range at {currentTemp}°C. \n" +
|
||||
$"Maybe try restarting the application? Options -> Restart application";
|
||||
Properties.Settings.Default.errorMsg = errorMsg;
|
||||
Properties.Settings.Default.Save();
|
||||
|
||||
Console.WriteLine(errorMsg);
|
||||
InvisibleLabel.Text = errorMsg;
|
||||
InvisibleLabel.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
InvisibleLabel.Text = "";
|
||||
InvisibleLabel.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task updateFanRPMLabel()
|
||||
{
|
||||
var speeds = await Task.Run(() => asusControl.GetFanSpeeds());
|
||||
Console.WriteLine($"Fan speeds: {string.Join(" ", speeds)}");
|
||||
labelRPM.Text = string.Join(" ", speeds);
|
||||
}
|
||||
|
||||
public async Task updateCPUTempLabel()
|
||||
{
|
||||
var temp = await Task.Run(() => asusControl.Thermal_Read_Cpu_Temperature());
|
||||
Console.WriteLine($"CPU temp: {temp}");
|
||||
currentTemp = temp;
|
||||
labelCPUTemp.Text = $"{temp}";
|
||||
}
|
||||
|
||||
private async void AutoRefreshStats()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (WindowState == FormWindowState.Minimized)
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
Properties.Settings.Default.wasError = true;
|
||||
Properties.Settings.Default.errorMsg = $"CPU temprature were outside of good range at {currentTemp}°C, either something has not loaded properly or CPU sensors are faulty.";
|
||||
Properties.Settings.Default.Save();
|
||||
Console.WriteLine("Restarting");
|
||||
Application.Restart();
|
||||
Environment.Exit(0);
|
||||
Console.WriteLine($"Refreshing stats");
|
||||
|
||||
// Update fan speeds and CPU temperature.
|
||||
// Run both tasks concurrently
|
||||
// Wait for both tasks to complete
|
||||
await Task.WhenAll(updateFanRPMLabel(), updateCPUTempLabel());
|
||||
}
|
||||
}
|
||||
|
||||
private async void Timer_Tick()
|
||||
private void checkIfAppIsInStartup()
|
||||
{
|
||||
if (WindowState == FormWindowState.Minimized)
|
||||
string appName = Assembly.GetExecutingAssembly().GetName().Name;
|
||||
|
||||
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
|
||||
startWithWindowsToolStripMenuItem.Checked = registryKey.GetValue(appName) != null;
|
||||
|
||||
// If app name is in startup, but app path does not match the current app path, update the startup entry
|
||||
if (startWithWindowsToolStripMenuItem.Checked)
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
Timer_Tick();
|
||||
return;
|
||||
string appPath = Assembly.GetExecutingAssembly().Location;
|
||||
string registryValue = registryKey.GetValue(appName).ToString();
|
||||
if (registryValue != appPath)
|
||||
{
|
||||
Console.WriteLine("Updating startup entry");
|
||||
registryKey.SetValue(appName, appPath);
|
||||
}
|
||||
}
|
||||
|
||||
//Console.WriteLine($"Refreshing {rnd.Next(100)}");
|
||||
// Update fan speeds and CPU temperature.
|
||||
// Run both tasks concurrently
|
||||
Task<string> fanSpeedsTask = Task.Run(() => string.Join(" ", asusControl.GetFanSpeeds()));
|
||||
Task<string> cpuTempTask = Task.Run(() => $"{asusControl.Thermal_Read_Cpu_Temperature()}");
|
||||
|
||||
// Wait for both tasks to complete
|
||||
await Task.WhenAll(fanSpeedsTask, cpuTempTask);
|
||||
|
||||
// Get the results from the completed tasks
|
||||
labelRPM.Text = fanSpeedsTask.Result;
|
||||
labelCPUTemp.Text = cpuTempTask.Result;
|
||||
currentTemp = (ulong)Decimal.Parse(cpuTempTask.Result);
|
||||
startErrorHandler();
|
||||
|
||||
await Task.Delay(250);
|
||||
Timer_Tick();
|
||||
}
|
||||
|
||||
private void AddToStartup()
|
||||
@@ -157,8 +214,8 @@ namespace AsusFanControlGUI
|
||||
|
||||
private void toolStripMenuItemTurnOffControlOnExit_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Properties.Settings.Default.turnOffControlOnExit = toolStripMenuItemTurnOffControlOnExit.Checked;
|
||||
Properties.Settings.Default.Save();
|
||||
//Properties.Settings.Default.turnOffControlOnExit = toolStripMenuItemTurnOffControlOnExit.Checked;
|
||||
//Properties.Settings.Default.Save();
|
||||
}
|
||||
|
||||
private void toolStripMenuItemForbidUnsafeSettings_CheckedChanged(object sender, EventArgs e)
|
||||
@@ -172,6 +229,19 @@ namespace AsusFanControlGUI
|
||||
System.Diagnostics.Process.Start("https://github.com/Darren80/AsusFanControlEnhanced/releases");
|
||||
}
|
||||
|
||||
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Get version number
|
||||
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
MessageBox.Show($"AsusFanControlEnhanced\n\nVersion: {version}\n\nAuthor: Darren80\n\nhttps://github.com/Darren80/AsusFanControlEnhanced", "About AsusFanControlEnhanced");
|
||||
}
|
||||
|
||||
private void setNotifyIconText(string text)
|
||||
{
|
||||
Console.WriteLine($"Setting notify icon text to: {text}");
|
||||
notifyIcon1.Text = text;
|
||||
}
|
||||
|
||||
private void radioButton1_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (radioButton1.Checked)
|
||||
@@ -179,14 +249,14 @@ namespace AsusFanControlGUI
|
||||
Properties.Settings.Default.fanControlState = "Off";
|
||||
Properties.Settings.Default.Save();
|
||||
|
||||
notifyIcon1.Text = $"AsusFanControlEnhanced - Off";
|
||||
setNotifyIconText("AsusFanControlEnhanced - Off");
|
||||
setFanSpeed(0, null);
|
||||
}
|
||||
}
|
||||
|
||||
private async void fanControl_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (fanControl.Checked)
|
||||
if (fanControlRadioButton.Checked)
|
||||
{
|
||||
Properties.Settings.Default.fanControlState = "Manual";
|
||||
Properties.Settings.Default.Save();
|
||||
@@ -206,11 +276,11 @@ namespace AsusFanControlGUI
|
||||
bool firstRun = true;
|
||||
private async void setFanSpeed(int value, bool? xyz)
|
||||
{
|
||||
if (currentFanSpeed == value)
|
||||
if (currentFanRPM == value)
|
||||
return;
|
||||
|
||||
await Task.Run(() => asusControl.SetFanSpeeds(value));
|
||||
currentFanSpeed = value;
|
||||
currentFanRPM = value;
|
||||
|
||||
if (value == 0)
|
||||
labelValue.Text = "turned off";
|
||||
@@ -220,7 +290,7 @@ namespace AsusFanControlGUI
|
||||
if (firstRun)
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
currentFanSpeed = 999999;
|
||||
currentFanRPM = 999999;
|
||||
setFanSpeed(value, null);
|
||||
firstRun = false;
|
||||
}
|
||||
@@ -243,11 +313,11 @@ namespace AsusFanControlGUI
|
||||
label5.Text = trackBarFanSpeedValue.ToString() + "% Fan";
|
||||
Console.WriteLine($"Setting speed to: {(int)trackBarFanSpeedValue}");
|
||||
label3.Text = $"Setting speed to: {(int)trackBarFanSpeedValue}%";// (Stamp: {rnd.Next(1000)})";
|
||||
notifyIcon1.Text = $"AsusFanControlEnhanced - Fan Speed: {(int)trackBarFanSpeedValue}%";
|
||||
setNotifyIconText($"Fan RPM: {(int)trackBarFanSpeedValue}% - Temp: {currentTemp}°C");
|
||||
if ((int)trackBarFanSpeedValue == 0)
|
||||
notifyIcon1.Text = $"AsusFanControlEnhanced - Off";
|
||||
setNotifyIconText("AsusFanControlEnhanced - Off");
|
||||
|
||||
setFanSpeed((int)trackBarFanSpeedValue, fanControl.Checked);
|
||||
setFanSpeed((int)trackBarFanSpeedValue, fanControlRadioButton.Checked);
|
||||
}
|
||||
|
||||
private void trackBarFanSpeed_KeyUp(object sender, KeyEventArgs e)
|
||||
@@ -269,12 +339,9 @@ namespace AsusFanControlGUI
|
||||
ulong temp = await Task.Run(() => asusControl.Thermal_Read_Cpu_Temperature());
|
||||
currentTemp = temp;
|
||||
labelCPUTemp.Text = $"{temp}";
|
||||
startErrorHandler();
|
||||
startErrorHandler(temperatureLowerBound, temperatureUpperBound);
|
||||
}
|
||||
|
||||
// My Code:
|
||||
private Point maxPoint;
|
||||
private Point minPoint;
|
||||
private Dictionary<int, Point> fanCurvePoints = new Dictionary<int, Point>()
|
||||
{
|
||||
{ 1, new Point(20, 1) },
|
||||
@@ -284,15 +351,6 @@ namespace AsusFanControlGUI
|
||||
{ 8, new Point(71, 30) },
|
||||
{ 9, new Point(80, 55) },
|
||||
};
|
||||
private Timer fanCurveTimer; // Declare the timer as a class-level variable
|
||||
|
||||
// Set up the graph dimensions
|
||||
const int padding = 40;
|
||||
|
||||
// Draw the temperature axis and labels
|
||||
const int tempMin = 20;
|
||||
const int tempMax = 100;
|
||||
const int tempInterval = 10;
|
||||
|
||||
private void pictureBoxFanCurve_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
@@ -364,8 +422,29 @@ namespace AsusFanControlGUI
|
||||
private void pictureBoxFanCurve_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
|
||||
(int temperature, int fanSpeed) = mousePosition(e.Location);
|
||||
(int temperature, int fanSpeed) = convertMousePositionToTemperatureAndFanSpeed(e.Location);
|
||||
|
||||
if (temperature < temperatureLowerBound || temperature > temperatureUpperBound)
|
||||
{
|
||||
temperature = Math.Max(temperatureLowerBound, Math.Min(temperature, temperatureUpperBound));
|
||||
}
|
||||
if (fanSpeed < fanSpeedLowerBound || fanSpeed > fanSpeedUpperBound)
|
||||
{
|
||||
fanSpeed = Math.Max(fanSpeedLowerBound, Math.Min(fanSpeed, fanSpeedUpperBound));
|
||||
}
|
||||
|
||||
// If a point already exists at the same temperature, update its fan speed
|
||||
foreach (KeyValuePair<int, Point> point in fanCurvePoints)
|
||||
{
|
||||
if (point.Value.X == temperature)
|
||||
{
|
||||
fanCurvePoints[point.Key] = new Point(temperature, fanSpeed);
|
||||
pictureBoxFanCurve.Invalidate(); // Redraw the graph
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the maximum number of points has been reached
|
||||
if (fanCurvePoints.Count >= 20)
|
||||
{
|
||||
MessageBox.Show("Maximum number of points reached.");
|
||||
@@ -387,7 +466,7 @@ namespace AsusFanControlGUI
|
||||
|
||||
private int selectedPointId = 0;
|
||||
|
||||
private (int temperature, int fanSpeed) mousePosition(Point e)
|
||||
private (int temperature, int fanSpeed) convertMousePositionToTemperatureAndFanSpeed(Point e)
|
||||
{
|
||||
// Set up the graph dimensions
|
||||
int padding = 40;
|
||||
@@ -409,7 +488,7 @@ namespace AsusFanControlGUI
|
||||
private KeyValuePair<int, Point> nearestPointToMouse(MouseEventArgs e, int maxDistance)
|
||||
{
|
||||
|
||||
(int temperature, int fanSpeed) = mousePosition(e.Location);
|
||||
(int temperature, int fanSpeed) = convertMousePositionToTemperatureAndFanSpeed(e.Location);
|
||||
|
||||
|
||||
var nearestPoints = fanCurvePoints
|
||||
@@ -466,7 +545,7 @@ namespace AsusFanControlGUI
|
||||
if (selectedPointId != 0)
|
||||
{
|
||||
// Get mouse location on grid
|
||||
(int temperature, int fanSpeed) = mousePosition(e.Location);
|
||||
(int temperature, int fanSpeed) = convertMousePositionToTemperatureAndFanSpeed(e.Location);
|
||||
|
||||
if (temperature < minimumTemperature || temperature > maximumTemperature)
|
||||
{
|
||||
@@ -492,7 +571,7 @@ namespace AsusFanControlGUI
|
||||
{
|
||||
selectedPointId = 0;
|
||||
toolTip1.SetToolTip(pictureBoxFanCurve, "Fan Curve Graph");
|
||||
SaveFanCurvePoints();
|
||||
SaveFanCurvePoints(fanCurvePoints);
|
||||
runFanCurve(true, true);
|
||||
|
||||
// fanCurvePoints.ToList().ForEach(point => Console.Write($"ID: {point.Key}, X: {point.Value.X}, Y: {point.Value.Y}"));
|
||||
@@ -510,7 +589,7 @@ namespace AsusFanControlGUI
|
||||
{
|
||||
Properties.Settings.Default.fanControlState = "Curve";
|
||||
Properties.Settings.Default.Save();
|
||||
Console.WriteLine(fanCurve.Checked);
|
||||
Console.WriteLine(fanCurveRadioButton.Checked);
|
||||
runFanCurve();
|
||||
}
|
||||
|
||||
@@ -541,7 +620,7 @@ namespace AsusFanControlGUI
|
||||
// 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.");
|
||||
notifyIcon1.Text = $"AsusFanControlEnhanced - Off";
|
||||
setNotifyIconText("AsusFanControlEnhanced - Off");
|
||||
return 0;
|
||||
}else
|
||||
{
|
||||
@@ -554,24 +633,19 @@ namespace AsusFanControlGUI
|
||||
|
||||
private async void runFanCurve(bool bypassHysteresisCheck=false, bool runOnce=false)
|
||||
{
|
||||
if (!fanCurve.Checked)
|
||||
if (!fanCurveRadioButton.Checked)
|
||||
{
|
||||
label3.Text = $"";
|
||||
return;
|
||||
}
|
||||
//Console.WriteLine("Fan Curve, " + (int)numericUpDown2.Value);
|
||||
|
||||
// Read the current temperature
|
||||
ulong temp = await Task.Run(() => asusControl.Thermal_Read_Cpu_Temperature()); // Implement the ReadTemperature method to get the current temperature
|
||||
currentTemp = temp;
|
||||
startErrorHandler();
|
||||
//Console.WriteLine("Temp, " + currentTemp);
|
||||
|
||||
double fanSpeed = CalculateFanSpeed(temp);
|
||||
double fanSpeed = CalculateFanSpeed(currentTemp);
|
||||
|
||||
// Apply hysteresis to prevent rapid fan speed changes
|
||||
int hysteresis = (int)numericUpDown1.Value; // Adjust the hysteresis value as needed
|
||||
if ((int)temp > lastTemperature + hysteresis || (int)temp < lastTemperature - hysteresis || fanSpeed < 10 || bypassHysteresisCheck)
|
||||
if ((int)currentTemp > lastTemperature + hysteresis || (int)currentTemp < lastTemperature - hysteresis || fanSpeed < 10 || bypassHysteresisCheck)
|
||||
{
|
||||
// Update the fan speed
|
||||
fanSpeed = Math.Max(0, Math.Min(100, fanSpeed));
|
||||
@@ -580,10 +654,10 @@ namespace AsusFanControlGUI
|
||||
Console.WriteLine($"Set fan speed to {(int)fanSpeed}% {rnd.Next(1000)}, last fan speed = {lastTemperature}");
|
||||
if (fanSpeed != 0)
|
||||
{
|
||||
label3.Text = $"Set fan speed to {(int)fanSpeed}%, current temp: {temp}°C";// (Stamp: {rnd.Next(1000)})";
|
||||
notifyIcon1.Text = $"AsusFanControlEnhanced - Current Temp: {(int)temp}°C - Fan Speed: {(int)fanSpeed}%";
|
||||
label3.Text = $"Set fan speed to {(int)fanSpeed}%, current temp: {currentTemp}°C";// (Stamp: {rnd.Next(1000)})";
|
||||
setNotifyIconText($"Fan RPM: {(int)fanSpeed}% - Temp: {currentTemp}°C");
|
||||
}
|
||||
lastTemperature = (int)temp;
|
||||
lastTemperature = (int)currentTemp;
|
||||
|
||||
}
|
||||
|
||||
@@ -597,8 +671,6 @@ namespace AsusFanControlGUI
|
||||
// Keep track of the last fan speed to apply hysteresis
|
||||
private int lastTemperature = 0;
|
||||
|
||||
|
||||
|
||||
private void Form1_Resize(object sender, EventArgs e)
|
||||
{
|
||||
if (WindowState == FormWindowState.Minimized)
|
||||
@@ -637,9 +709,13 @@ namespace AsusFanControlGUI
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveFanCurvePoints()
|
||||
private void SaveFanCurvePoints(Dictionary<int, Point> _fanCurvePoints)
|
||||
{
|
||||
string fanCurvePointsString = string.Join("-", fanCurvePoints.OrderBy(x => x.Value.X).Select(x => $"{x.Value.X},{x.Value.Y}"));
|
||||
// Save to state
|
||||
fanCurvePoints = _fanCurvePoints;
|
||||
|
||||
// Convert the fan curve points to a string
|
||||
string fanCurvePointsString = string.Join("-", _fanCurvePoints.OrderBy(x => x.Value.X).Select(x => $"{x.Value.X},{x.Value.Y}"));
|
||||
|
||||
Properties.Settings.Default.FanCurvePoints = fanCurvePointsString;
|
||||
Properties.Settings.Default.Save();
|
||||
@@ -647,56 +723,52 @@ namespace AsusFanControlGUI
|
||||
Console.WriteLine(fanCurvePointsString);
|
||||
}
|
||||
|
||||
private void SetFanCurvePoints(String? fanCurveString)
|
||||
private void SetFanCurvePoints(String fanCurvePointsString)
|
||||
{
|
||||
int count = 1;
|
||||
string fanCurvePointsString = fanCurveString ?? Properties.Settings.Default.FanCurvePoints;
|
||||
Console.WriteLine(fanCurvePointsString);
|
||||
|
||||
if (string.IsNullOrEmpty(fanCurvePointsString))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Parse the string
|
||||
Dictionary<int, Point> fanCurvePointsDictionaryFromString;
|
||||
try
|
||||
{
|
||||
|
||||
fanCurvePoints = fanCurvePointsString.Split('-')
|
||||
.Select(x =>
|
||||
{
|
||||
string[] parts = x.Split(',');
|
||||
return new KeyValuePair<int, Point>(count++, new Point(int.Parse(parts[0]), int.Parse(parts[1])));
|
||||
})
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
|
||||
//Save
|
||||
textBox1.Text = fanCurvePointsString;
|
||||
SaveFanCurvePoints();
|
||||
fanCurvePointsDictionaryFromString = _fanCurve.convertStringToPointsDictionary(
|
||||
fanCurvePointsString, temperatureLowerBound, temperatureUpperBound, fanSpeedLowerBound, fanSpeedUpperBound
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Show the error message and stack trace in a MessageBox
|
||||
//MessageBox.Show($"An error occurred: {ex.Message}\n\nStack Trace:\n{ex.StackTrace}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
throw;
|
||||
}
|
||||
|
||||
//Save
|
||||
// CurvePointsTextbox.Text = fanCurvePointsString;
|
||||
SaveFanCurvePoints(fanCurvePointsDictionaryFromString);
|
||||
|
||||
pictureBoxFanCurve.Invalidate();
|
||||
}
|
||||
|
||||
private void button4_Click(object sender, EventArgs e)
|
||||
{
|
||||
textBox1.Text = Properties.Settings.Default.FanCurvePoints;
|
||||
SetFanCurvePoints(null);
|
||||
try
|
||||
{
|
||||
SetFanCurvePoints(Properties.Settings.Default.DefaultFanCurvePoints);
|
||||
CurvePointsTextbox.Text = Properties.Settings.Default.DefaultFanCurvePoints;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void button3_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
SetFanCurvePoints(textBox1.Text);
|
||||
SetFanCurvePoints(CurvePointsTextbox.Text);
|
||||
MessageBox.Show("Save successful.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("An error occurred: " + ex.Message);
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -714,12 +786,12 @@ namespace AsusFanControlGUI
|
||||
|
||||
try
|
||||
{
|
||||
SetFanCurvePoints(textBox1.Text);
|
||||
SetFanCurvePoints(CurvePointsTextbox.Text);
|
||||
MessageBox.Show("Save successful.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("An error occurred: " + ex.Message);
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -729,19 +801,19 @@ namespace AsusFanControlGUI
|
||||
{
|
||||
Properties.Settings.Default.allowFanCurveSettingViaText = true;
|
||||
Properties.Settings.Default.Save();
|
||||
button3.Enabled = true; textBox1.ReadOnly = false; button4.Enabled = true;
|
||||
button3.Enabled = true; CurvePointsTextbox.ReadOnly = false; //ResetCurvePoints.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Properties.Settings.Default.allowFanCurveSettingViaText = false;
|
||||
Properties.Settings.Default.Save();
|
||||
button3.Enabled = false; textBox1.ReadOnly = true; button4.Enabled = false;
|
||||
button3.Enabled = false; CurvePointsTextbox.ReadOnly = true; //ResetCurvePoints.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void textBox1_MouseHover(object sender, EventArgs e)
|
||||
{
|
||||
toolTip1.Show(textBox1.Text, textBox1);
|
||||
toolTip1.Show(CurvePointsTextbox.Text, CurvePointsTextbox);
|
||||
}
|
||||
|
||||
private void startWithWindowsToolStripMenuItem1_Click_1(object sender, EventArgs e)
|
||||
@@ -750,6 +822,7 @@ namespace AsusFanControlGUI
|
||||
{
|
||||
Properties.Settings.Default.startWithWindows = true;
|
||||
Properties.Settings.Default.Save();
|
||||
RemoveFromStartup();
|
||||
AddToStartup();
|
||||
}
|
||||
else
|
||||
@@ -791,7 +864,7 @@ namespace AsusFanControlGUI
|
||||
Console.WriteLine($"asdad: {Properties.Settings.Default.wasError}");
|
||||
if (Properties.Settings.Default.wasError == true)
|
||||
{
|
||||
MessageBox.Show($"An error caused the application to restart:\n\nError: {Properties.Settings.Default.errorMsg}");
|
||||
//MessageBox.Show($"An error caused the application to restart:\n\nError: {Properties.Settings.Default.errorMsg}");
|
||||
Properties.Settings.Default.wasError = false;
|
||||
Properties.Settings.Default.errorMsg = "";
|
||||
Properties.Settings.Default.Save();
|
||||
@@ -805,8 +878,7 @@ namespace AsusFanControlGUI
|
||||
|
||||
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (Properties.Settings.Default.turnOffControlOnExit)
|
||||
asusControl.SetFanSpeeds(0);
|
||||
asusControl.SetFanSpeeds(0);
|
||||
}
|
||||
|
||||
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
|
||||
@@ -853,6 +925,58 @@ namespace AsusFanControlGUI
|
||||
}
|
||||
}
|
||||
|
||||
public static double GetCpuTemperature()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Create a ManagementObjectSearcher to query WMI
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature");
|
||||
|
||||
// Iterate through the results
|
||||
foreach (ManagementObject obj in searcher.Get())
|
||||
{
|
||||
// The temperature is given in tenths of Kelvin. Convert to Celsius.
|
||||
double temperature = Convert.ToDouble(obj["CurrentTemperature"].ToString());
|
||||
temperature = (temperature / 10.0) - 273.15;
|
||||
|
||||
return temperature;
|
||||
}
|
||||
}
|
||||
catch (ManagementException e)
|
||||
{
|
||||
Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("An unexpected error occurred: " + e.Message);
|
||||
}
|
||||
|
||||
// Return 0 if no temperature data is found or an error occurs
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void InvisibleLabel_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void contextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void toolStripMenuItemTurnOffControlOnExit_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//notifyIcon1.BalloonTipText = string.Join(" ", asusControl.GetFanSpeeds()) + $" Temp: {asusControl.Thermal_Read_Cpu_Temperature()}"; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user