Files
AsusFanControlEnhanced/AsusFanControlGUI/Form1.cs
2024-03-07 23:42:43 +01:00

112 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AsusFanControl;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace AsusFanControlGUI
{
public partial class Form1 : Form
{
AsusControl asusControl = new AsusControl();
int fanSpeed = 0;
public Form1()
{
InitializeComponent();
AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);
toolStripMenuItemTurnOffControlOnExit.Checked = Properties.Settings.Default.turnOffControlOnExit;
toolStripMenuItemForbidUnsafeSettings.Checked = Properties.Settings.Default.forbidUnsafeSettings;
trackBarFanSpeed.Value = Properties.Settings.Default.fanSpeed;
}
private void OnProcessExit(object sender, EventArgs e)
{
if (Properties.Settings.Default.turnOffControlOnExit)
asusControl.SetFanSpeeds(0);
}
private void toolStripMenuItemTurnOffControlOnExit_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.turnOffControlOnExit = toolStripMenuItemTurnOffControlOnExit.Checked;
Properties.Settings.Default.Save();
}
private void toolStripMenuItemForbidUnsafeSettings_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.forbidUnsafeSettings = toolStripMenuItemForbidUnsafeSettings.Checked;
Properties.Settings.Default.Save();
}
private void toolStripMenuItemCheckForUpdates_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/Karmel0x/AsusFanControl/releases");
}
private void setFanSpeed()
{
var value = trackBarFanSpeed.Value;
Properties.Settings.Default.fanSpeed = value;
Properties.Settings.Default.Save();
if (!checkBoxTurnOn.Checked)
value = 0;
if (value == 0)
labelValue.Text = "turned off";
else
labelValue.Text = value.ToString();
if (fanSpeed == value)
return;
fanSpeed = value;
asusControl.SetFanSpeeds(value);
}
private void checkBoxTurnOn_CheckedChanged(object sender, EventArgs e)
{
setFanSpeed();
}
private void trackBarFanSpeed_MouseCaptureChanged(object sender, EventArgs e)
{
if (Properties.Settings.Default.forbidUnsafeSettings)
{
if (trackBarFanSpeed.Value < 40)
trackBarFanSpeed.Value = 40;
else if (trackBarFanSpeed.Value > 99)
trackBarFanSpeed.Value = 99;
}
setFanSpeed();
}
private void trackBarFanSpeed_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode != Keys.Left && e.KeyCode != Keys.Right)
return;
trackBarFanSpeed_MouseCaptureChanged(sender, e);
}
private void button1_Click(object sender, EventArgs e)
{
labelRPM.Text = string.Join(" ", asusControl.GetFanSpeeds());
}
private void button2_Click(object sender, EventArgs e)
{
labelCPUTemp.Text = $"{asusControl.Thermal_Read_Cpu_Temperature()}";
}
}
}