diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs index 13b09785..4f192368 100644 --- a/app/AsusACPI.cs +++ b/app/AsusACPI.cs @@ -1,4 +1,5 @@ -using System.Management; +using GHelper; +using System.Management; using System.Runtime.InteropServices; public enum AsusFan @@ -346,6 +347,32 @@ public class AsusACPI return -1; } + public int GetFan(AsusFan device) + { + int fan = -1; + + switch (device) + { + case AsusFan.GPU: + fan = Program.acpi.DeviceGet(GPU_Fan); + break; + case AsusFan.Mid: + fan = Program.acpi.DeviceGet(Mid_Fan); + break; + default: + fan = Program.acpi.DeviceGet(CPU_Fan); + break; + } + + if (fan < 0) + { + fan += 65536; + if (fan <= 0 || fan > 100) fan = -1; + } + + return fan; + } + public int SetFanRange(AsusFan device, byte[] curve) { byte min = (byte)(curve[8] * 255 / 100); @@ -379,7 +406,7 @@ public class AsusACPI // it seems to be a bug, when some old model's bios can go nuts if fan is set to 100% - for (int i = 8; i < curve.Length; i++) curve[i] = (byte)(Math.Max((byte)0, Math.Min((byte)99, curve[i])) * fanScale / 100); + for (int i = 8; i < curve.Length; i++) curve[i] = (byte)(Math.Max((byte)0, Math.Min((byte)100, curve[i])) * fanScale / 100); switch (device) { diff --git a/app/Fans.Designer.cs b/app/Fans.Designer.cs index eebf25c8..6c2cd780 100644 --- a/app/Fans.Designer.cs +++ b/app/Fans.Designer.cs @@ -31,14 +31,14 @@ namespace GHelper /// private void InitializeComponent() { - ChartArea chartArea9 = new ChartArea(); - Title title9 = new Title(); - ChartArea chartArea10 = new ChartArea(); - Title title10 = new Title(); - ChartArea chartArea11 = new ChartArea(); - Title title11 = new Title(); - ChartArea chartArea12 = new ChartArea(); - Title title12 = new Title(); + ChartArea chartArea1 = new ChartArea(); + Title title1 = new Title(); + ChartArea chartArea2 = new ChartArea(); + Title title2 = new Title(); + ChartArea chartArea3 = new ChartArea(); + Title title3 = new Title(); + ChartArea chartArea4 = new ChartArea(); + Title title4 = new Title(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Fans)); panelFans = new Panel(); labelTip = new Label(); @@ -55,6 +55,7 @@ namespace GHelper picturePerf = new PictureBox(); labelFans = new Label(); panelApplyFans = new Panel(); + buttonCalibrate = new RButton(); labelFansResult = new Label(); checkApplyFans = new RCheckBox(); buttonReset = new RButton(); @@ -128,6 +129,10 @@ namespace GHelper labelGPUCore = new Label(); trackGPUCore = new TrackBar(); labelGPUCoreTitle = new Label(); + panelGPUClockLimit = new Panel(); + labelGPUClockLimit = new Label(); + trackGPUClockLimit = new TrackBar(); + labelGPUClockLimitTitle = new Label(); panelTitleGPU = new Panel(); pictureGPU = new PictureBox(); labelGPU = new Label(); @@ -136,10 +141,6 @@ namespace GHelper buttonAdvanced = new RButton(); buttonGPU = new RButton(); buttonCPU = new RButton(); - panelGPUClockLimit = new Panel(); - labelGPUClockLimit = new Label(); - trackGPUClockLimit = new TrackBar(); - labelGPUClockLimitTitle = new Label(); panelFans.SuspendLayout(); tableFanCharts.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)chartGPU).BeginInit(); @@ -188,12 +189,12 @@ namespace GHelper ((System.ComponentModel.ISupportInitialize)trackGPUMemory).BeginInit(); panelGPUCore.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)trackGPUCore).BeginInit(); + panelGPUClockLimit.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)trackGPUClockLimit).BeginInit(); panelTitleGPU.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureGPU).BeginInit(); panelNav.SuspendLayout(); tableNav.SuspendLayout(); - panelGPUClockLimit.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)trackGPUClockLimit).BeginInit(); SuspendLayout(); // // panelFans @@ -239,7 +240,7 @@ namespace GHelper tableFanCharts.Location = new Point(0, 66); tableFanCharts.Margin = new Padding(4); tableFanCharts.Name = "tableFanCharts"; - tableFanCharts.Padding = new Padding(10, 0, 10, 10); + tableFanCharts.Padding = new Padding(10, 0, 10, 5); tableFanCharts.RowCount = 2; tableFanCharts.RowStyles.Add(new RowStyle(SizeType.Percent, 25F)); tableFanCharts.RowStyles.Add(new RowStyle(SizeType.Percent, 25F)); @@ -250,60 +251,60 @@ namespace GHelper // // chartGPU // - chartArea9.Name = "ChartArea1"; - chartGPU.ChartAreas.Add(chartArea9); + chartArea1.Name = "ChartArea1"; + chartGPU.ChartAreas.Add(chartArea1); chartGPU.Dock = DockStyle.Fill; - chartGPU.Location = new Point(12, 491); + chartGPU.Location = new Point(12, 493); chartGPU.Margin = new Padding(2, 10, 2, 10); chartGPU.Name = "chartGPU"; - chartGPU.Size = new Size(782, 461); + chartGPU.Size = new Size(782, 463); chartGPU.TabIndex = 17; chartGPU.Text = "chartGPU"; - title9.Name = "Title1"; - chartGPU.Titles.Add(title9); + title1.Name = "Title1"; + chartGPU.Titles.Add(title1); // // chartCPU // - chartArea10.Name = "ChartArea1"; - chartCPU.ChartAreas.Add(chartArea10); + chartArea2.Name = "ChartArea1"; + chartCPU.ChartAreas.Add(chartArea2); chartCPU.Dock = DockStyle.Fill; chartCPU.Location = new Point(12, 10); chartCPU.Margin = new Padding(2, 10, 2, 10); chartCPU.Name = "chartCPU"; - chartCPU.Size = new Size(782, 461); + chartCPU.Size = new Size(782, 463); chartCPU.TabIndex = 14; chartCPU.Text = "chartCPU"; - title10.Name = "Title1"; - chartCPU.Titles.Add(title10); + title2.Name = "Title1"; + chartCPU.Titles.Add(title2); // // chartXGM // - chartArea11.Name = "ChartAreaXGM"; - chartXGM.ChartAreas.Add(chartArea11); + chartArea3.Name = "ChartAreaXGM"; + chartXGM.ChartAreas.Add(chartArea3); chartXGM.Dock = DockStyle.Fill; - chartXGM.Location = new Point(12, 1453); + chartXGM.Location = new Point(12, 1459); chartXGM.Margin = new Padding(2, 10, 2, 10); chartXGM.Name = "chartXGM"; - chartXGM.Size = new Size(782, 464); + chartXGM.Size = new Size(782, 463); chartXGM.TabIndex = 14; chartXGM.Text = "chartXGM"; - title11.Name = "Title4"; - chartXGM.Titles.Add(title11); + title3.Name = "Title4"; + chartXGM.Titles.Add(title3); chartXGM.Visible = false; // // chartMid // - chartArea12.Name = "ChartArea3"; - chartMid.ChartAreas.Add(chartArea12); + chartArea4.Name = "ChartArea3"; + chartMid.ChartAreas.Add(chartArea4); chartMid.Dock = DockStyle.Fill; - chartMid.Location = new Point(12, 972); + chartMid.Location = new Point(12, 976); chartMid.Margin = new Padding(2, 10, 2, 10); chartMid.Name = "chartMid"; - chartMid.Size = new Size(782, 461); + chartMid.Size = new Size(782, 463); chartMid.TabIndex = 14; chartMid.Text = "chartMid"; - title12.Name = "Title3"; - chartMid.Titles.Add(title12); + title4.Name = "Title3"; + chartMid.Titles.Add(title4); chartMid.Visible = false; // // panelTitleFans @@ -410,6 +411,7 @@ namespace GHelper // // panelApplyFans // + panelApplyFans.Controls.Add(buttonCalibrate); panelApplyFans.Controls.Add(labelFansResult); panelApplyFans.Controls.Add(checkApplyFans); panelApplyFans.Controls.Add(buttonReset); @@ -420,16 +422,32 @@ namespace GHelper panelApplyFans.Size = new Size(806, 116); panelApplyFans.TabIndex = 43; // + // buttonCalibrate + // + buttonCalibrate.Activated = false; + buttonCalibrate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCalibrate.BackColor = SystemColors.ControlLight; + buttonCalibrate.BorderColor = Color.Transparent; + buttonCalibrate.BorderRadius = 2; + buttonCalibrate.FlatStyle = FlatStyle.Flat; + buttonCalibrate.Location = new Point(239, 42); + buttonCalibrate.Margin = new Padding(4, 2, 4, 2); + buttonCalibrate.Name = "buttonCalibrate"; + buttonCalibrate.Secondary = true; + buttonCalibrate.Size = new Size(135, 50); + buttonCalibrate.TabIndex = 43; + buttonCalibrate.Text = "Calibrate"; + buttonCalibrate.UseVisualStyleBackColor = false; + // // labelFansResult // - labelFansResult.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + labelFansResult.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; labelFansResult.ForeColor = Color.Red; - labelFansResult.Location = new Point(24, 4); + labelFansResult.Location = new Point(18, 6); labelFansResult.Margin = new Padding(4, 0, 4, 0); labelFansResult.Name = "labelFansResult"; - labelFansResult.Size = new Size(762, 32); + labelFansResult.Size = new Size(771, 32); labelFansResult.TabIndex = 42; - labelFansResult.TextAlign = ContentAlignment.TopRight; labelFansResult.Visible = false; // // checkApplyFans @@ -458,7 +476,7 @@ namespace GHelper buttonReset.Margin = new Padding(4, 2, 4, 2); buttonReset.Name = "buttonReset"; buttonReset.Secondary = true; - buttonReset.Size = new Size(274, 50); + buttonReset.Size = new Size(216, 50); buttonReset.TabIndex = 18; buttonReset.Text = Properties.Strings.FactoryDefaults; buttonReset.UseVisualStyleBackColor = false; @@ -1337,6 +1355,56 @@ namespace GHelper labelGPUCoreTitle.TabIndex = 17; labelGPUCoreTitle.Text = "Core Clock Offset"; // + // panelGPUClockLimit + // + panelGPUClockLimit.AutoSize = true; + panelGPUClockLimit.AutoSizeMode = AutoSizeMode.GrowAndShrink; + panelGPUClockLimit.Controls.Add(labelGPUClockLimit); + panelGPUClockLimit.Controls.Add(trackGPUClockLimit); + panelGPUClockLimit.Controls.Add(labelGPUClockLimitTitle); + panelGPUClockLimit.Dock = DockStyle.Top; + panelGPUClockLimit.Location = new Point(0, 60); + panelGPUClockLimit.Margin = new Padding(4); + panelGPUClockLimit.MaximumSize = new Size(0, 124); + panelGPUClockLimit.Name = "panelGPUClockLimit"; + panelGPUClockLimit.Size = new Size(520, 124); + panelGPUClockLimit.TabIndex = 48; + // + // labelGPUClockLimit + // + labelGPUClockLimit.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + labelGPUClockLimit.Location = new Point(326, 16); + labelGPUClockLimit.Margin = new Padding(4, 0, 4, 0); + labelGPUClockLimit.Name = "labelGPUClockLimit"; + labelGPUClockLimit.Size = new Size(176, 32); + labelGPUClockLimit.TabIndex = 29; + labelGPUClockLimit.Text = "1500 MHz"; + labelGPUClockLimit.TextAlign = ContentAlignment.TopRight; + // + // trackGPUClockLimit + // + trackGPUClockLimit.LargeChange = 100; + trackGPUClockLimit.Location = new Point(6, 48); + trackGPUClockLimit.Margin = new Padding(4, 2, 4, 2); + trackGPUClockLimit.Maximum = 3000; + trackGPUClockLimit.Name = "trackGPUClockLimit"; + trackGPUClockLimit.RightToLeft = RightToLeft.No; + trackGPUClockLimit.Size = new Size(496, 90); + trackGPUClockLimit.SmallChange = 10; + trackGPUClockLimit.TabIndex = 18; + trackGPUClockLimit.TickFrequency = 50; + trackGPUClockLimit.TickStyle = TickStyle.TopLeft; + // + // labelGPUClockLimitTitle + // + labelGPUClockLimitTitle.AutoSize = true; + labelGPUClockLimitTitle.Location = new Point(10, 16); + labelGPUClockLimitTitle.Margin = new Padding(4, 0, 4, 0); + labelGPUClockLimitTitle.Name = "labelGPUClockLimitTitle"; + labelGPUClockLimitTitle.Size = new Size(188, 32); + labelGPUClockLimitTitle.TabIndex = 17; + labelGPUClockLimitTitle.Text = "Core Clock Limit"; + // // panelTitleGPU // panelTitleGPU.AutoSize = true; @@ -1459,56 +1527,6 @@ namespace GHelper buttonCPU.TextImageRelation = TextImageRelation.ImageBeforeText; buttonCPU.UseVisualStyleBackColor = false; // - // panelGPUClockLimit - // - panelGPUClockLimit.AutoSize = true; - panelGPUClockLimit.AutoSizeMode = AutoSizeMode.GrowAndShrink; - panelGPUClockLimit.Controls.Add(labelGPUClockLimit); - panelGPUClockLimit.Controls.Add(trackGPUClockLimit); - panelGPUClockLimit.Controls.Add(labelGPUClockLimitTitle); - panelGPUClockLimit.Dock = DockStyle.Top; - panelGPUClockLimit.Location = new Point(0, 60); - panelGPUClockLimit.Margin = new Padding(4); - panelGPUClockLimit.MaximumSize = new Size(0, 124); - panelGPUClockLimit.Name = "panelGPUClockLimit"; - panelGPUClockLimit.Size = new Size(520, 124); - panelGPUClockLimit.TabIndex = 48; - // - // labelGPUClockLimit - // - labelGPUClockLimit.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - labelGPUClockLimit.Location = new Point(326, 16); - labelGPUClockLimit.Margin = new Padding(4, 0, 4, 0); - labelGPUClockLimit.Name = "labelGPUClockLimit"; - labelGPUClockLimit.Size = new Size(176, 32); - labelGPUClockLimit.TabIndex = 29; - labelGPUClockLimit.Text = "1500 MHz"; - labelGPUClockLimit.TextAlign = ContentAlignment.TopRight; - // - // trackGPUClockLimit - // - trackGPUClockLimit.LargeChange = 100; - trackGPUClockLimit.Location = new Point(6, 48); - trackGPUClockLimit.Margin = new Padding(4, 2, 4, 2); - trackGPUClockLimit.Maximum = 3000; - trackGPUClockLimit.Name = "trackGPUClockLimit"; - trackGPUClockLimit.RightToLeft = RightToLeft.No; - trackGPUClockLimit.Size = new Size(496, 90); - trackGPUClockLimit.SmallChange = 10; - trackGPUClockLimit.TabIndex = 18; - trackGPUClockLimit.TickFrequency = 50; - trackGPUClockLimit.TickStyle = TickStyle.TopLeft; - // - // labelGPUClockLimitTitle - // - labelGPUClockLimitTitle.AutoSize = true; - labelGPUClockLimitTitle.Location = new Point(10, 16); - labelGPUClockLimitTitle.Margin = new Padding(4, 0, 4, 0); - labelGPUClockLimitTitle.Name = "labelGPUClockLimitTitle"; - labelGPUClockLimitTitle.Size = new Size(188, 32); - labelGPUClockLimitTitle.TabIndex = 17; - labelGPUClockLimitTitle.Text = "Core Clock Limit"; - // // Fans // AutoScaleDimensions = new SizeF(192F, 192F); @@ -1597,14 +1615,14 @@ namespace GHelper panelGPUCore.ResumeLayout(false); panelGPUCore.PerformLayout(); ((System.ComponentModel.ISupportInitialize)trackGPUCore).EndInit(); + panelGPUClockLimit.ResumeLayout(false); + panelGPUClockLimit.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)trackGPUClockLimit).EndInit(); panelTitleGPU.ResumeLayout(false); panelTitleGPU.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureGPU).EndInit(); panelNav.ResumeLayout(false); tableNav.ResumeLayout(false); - panelGPUClockLimit.ResumeLayout(false); - panelGPUClockLimit.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)trackGPUClockLimit).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -1711,5 +1729,6 @@ namespace GHelper private Label labelGPUClockLimit; private TrackBar trackGPUClockLimit; private Label labelGPUClockLimitTitle; + private RButton buttonCalibrate; } } \ No newline at end of file diff --git a/app/Fans.cs b/app/Fans.cs index 71a3f9c3..9ebbc0cd 100644 --- a/app/Fans.cs +++ b/app/Fans.cs @@ -18,8 +18,6 @@ namespace GHelper Series seriesMid; Series seriesXGM; - static int MinRPM, MaxRPM; - static bool gpuVisible = true; static bool fanRpm = true; @@ -28,6 +26,8 @@ namespace GHelper NvidiaGpuControl? nvControl = null; ModeControl modeControl = Program.modeControl; + public static System.Timers.Timer timer = default!; + public Fans() { @@ -59,8 +59,6 @@ namespace GHelper InitTheme(true); - MinRPM = 18; - MaxRPM = HardwareControl.fanMax; labelTip.Visible = false; labelTip.BackColor = Color.Transparent; @@ -200,13 +198,139 @@ namespace GHelper checkApplyUV.Click += CheckApplyUV_Click; + timer = new System.Timers.Timer(1000); + timer.Elapsed += Timer_Elapsed; + buttonCalibrate.Click += ButtonCalibrate_Click; + ToggleNavigation(0); FormClosed += Fans_FormClosed; } - + const int FAN_COUNT = 3; + static int[] fanMin, fanMax; + static int sameCount = 0; + static int calibrationStep = 0; + + private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e) + { + int fan; + bool same = true; + + for (int i = 0; i < FAN_COUNT; i++) + { + fan = Program.acpi.GetFan((AsusFan)i); + + if (calibrationStep == 1) + { + if (fan < fanMin[i]) + { + fanMin[i] = fan; + same = false; + } + + } + + if (calibrationStep == 2) + { + if (fan > fanMax[i]) + { + fanMax[i] = fan; + same = false; + } + } + } + + if (same) sameCount++; + else sameCount = 0; + + if (calibrationStep == 1) + { + LabelFansResult("Measuring Min Speed - CPU: " + fanMin[(int)AsusFan.CPU]*100 + ", GPU: " + fanMin[(int)AsusFan.GPU] * 100 + " (" + sameCount + "s)"); + } + + if (calibrationStep == 2) + { + LabelFansResult("Measuring Max Speed - CPU: " + fanMax[(int)AsusFan.CPU] * 100 + ", GPU: " + fanMax[(int)AsusFan.GPU] * 100 + " (" + sameCount + "s)"); + } + + + if (sameCount >= 15) + { + + for (int i = 0; i < FAN_COUNT; i++) + { + if (fanMin[i] > 0 && fanMin[i] < 30) AppConfig.Set("fan_min_" + i, fanMin[i]); + if (fanMax[i] > 30 && fanMax[i] < 80) AppConfig.Set("fan_max_" + i, fanMax[i]); + } + + sameCount = 0; + CalibrateNext(); + } + + } + + private void CalibrateNext() + { + calibrationStep++; + + if (calibrationStep == 1) + { + for (int i = 0; i < FAN_COUNT; i++) + Program.acpi.SetFanCurve((AsusFan)i, new byte[] { 20, 30, 40, 50, 60, 70, 80, 90, 1, 1, 1, 1, 1, 1, 1, 1 }); + return; + } + + if (calibrationStep == 2) + { + for (int i = 0; i < FAN_COUNT; i++) + Program.acpi.SetFanCurve((AsusFan)i, new byte[] { 20, 30, 40, 50, 60, 70, 80, 90, 100, 100, 100, 100, 100, 100, 100, 100 }); + return; + } + + timer.Enabled = false; + modeControl.SetPerformanceMode(); + + string label = "Measured - CPU: " + AppConfig.Get("fan_min_" + (int)AsusFan.CPU) * 100 + ".." + AppConfig.Get("fan_max_" + (int)AsusFan.CPU) * 100; + + if (AppConfig.Get("fan_max_" + (int)AsusFan.GPU) > 0) + label = label + ", GPU: " + AppConfig.Get("fan_min_" + (int)AsusFan.GPU) * 100 + ".." + AppConfig.Get("fan_max_" + (int)AsusFan.GPU) * 100; + + if (AppConfig.Get("fan_max_" + (int)AsusFan.Mid) > 0) + label = label + ", Mid: " + AppConfig.Get("fan_min_" + (int)AsusFan.Mid) * 100 + ".." + AppConfig.Get("fan_max_" + (int)AsusFan.Mid) * 100; + + LabelFansResult(label); + + Invoke(delegate + { + buttonCalibrate.Enabled = true; + SetAxis(chartCPU, AsusFan.CPU); + SetAxis(chartGPU, AsusFan.GPU); + if (chartMid.Visible) SetAxis(chartMid, AsusFan.Mid); + + }); + + } + + private void ButtonCalibrate_Click(object? sender, EventArgs e) + { + fanMin = new int[] { 100, 100, 100 }; + fanMax = new int[] { 0, 0, 0 }; + + calibrationStep = 0; + buttonCalibrate.Enabled = false; + timer.Enabled = true; + + for (int i = 0; i < FAN_COUNT; i++) + { + AppConfig.Remove("fan_min_" + i); + AppConfig.Remove("fan_max_" + i); + } + + CalibrateNext(); + } + private void ChartCPU_MouseClick(object? sender, MouseEventArgs e) { if (sender is null) return; @@ -571,15 +695,17 @@ namespace GHelper VisualiseGPUSettings(); } - static string ChartPercToRPM(int percentage, AsusFan device, string unit = "") + static string ChartYLabel(int percentage, AsusFan device, string unit = "") { if (percentage == 0) return "OFF"; - int Max = MaxRPM; + int Min = AppConfig.Get("fan_min_" + (int)device, HardwareControl.DEFAULT_FAN_MIN); + int Max = AppConfig.Get("fan_max_" + (int)device, HardwareControl.DEFAULT_FAN_MAX); + if (device == AsusFan.XGM) Max = 72; if (fanRpm) - return (200 * Math.Round((float)(MinRPM * 100 + (Max - MinRPM) * percentage) / 200)).ToString() + unit; + return (200 * Math.Round((float)(Min * 100 + (Max - Min) * percentage) / 200)).ToString() + unit; else return percentage + "%"; } @@ -591,7 +717,7 @@ namespace GHelper for (int i = 0; i <= fansMax - 10; i += 10) { - chart.ChartAreas[0].AxisY.CustomLabels.Add(i - 2, i + 2, ChartPercToRPM(i, device)); + chart.ChartAreas[0].AxisY.CustomLabels.Add(i - 2, i + 2, ChartYLabel(i, device)); } chart.ChartAreas[0].AxisY.CustomLabels.Add(fansMax - 2, fansMax + 2, Properties.Strings.RPM); @@ -724,8 +850,11 @@ namespace GHelper public void LabelFansResult(string text) { - labelFansResult.Text = text; - labelFansResult.Visible = (text.Length > 0); + Invoke(delegate + { + labelFansResult.Text = text; + labelFansResult.Visible = (text.Length > 0); + }); } private void Fans_FormClosing(object? sender, FormClosingEventArgs e) @@ -994,7 +1123,6 @@ namespace GHelper { curPoint = null; curIndex = -1; - labelTip.Visible = false; SaveProfile(seriesCPU, AsusFan.CPU); @@ -1017,7 +1145,9 @@ namespace GHelper private void ChartCPU_MouseLeave(object? sender, EventArgs e) { - Chart_Save(); + curPoint = null; + curIndex = -1; + labelTip.Visible = false; } private void ChartCPU_MouseMove(object? sender, MouseEventArgs e, AsusFan device) @@ -1081,7 +1211,7 @@ namespace GHelper tip = true; } - labelTip.Text = Math.Round(curPoint.XValue) + "C, " + ChartPercToRPM((int)curPoint.YValues[0], device, " " + Properties.Strings.RPM); + labelTip.Text = Math.Round(curPoint.XValue) + "C, " + ChartYLabel((int)curPoint.YValues[0], device, " " + Properties.Strings.RPM); labelTip.Top = e.Y + ((Control)sender).Top; labelTip.Left = e.X - 50; diff --git a/app/Gpu/GPUModeControl.cs b/app/Gpu/GPUModeControl.cs index 1816e0f4..7eea41bc 100644 --- a/app/Gpu/GPUModeControl.cs +++ b/app/Gpu/GPUModeControl.cs @@ -44,9 +44,7 @@ namespace GHelper.Gpu // GPU mode not supported if (eco < 0 && mux < 0) { - if (gpuExists is null) - gpuExists = HardwareControl.FormatFan(Program.acpi.DeviceGet(AsusACPI.GPU_Fan)) is not null; - + if (gpuExists is null) gpuExists = Program.acpi.GetFan(AsusFan.GPU) >= 0; settings.HideGPUModes((bool)gpuExists); } } diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs index a6720d6c..31081b7f 100644 --- a/app/HardwareControl.cs +++ b/app/HardwareControl.cs @@ -10,8 +10,10 @@ using System.Management; public static class HardwareControl { - const int DEFAULT_FAN_MAX = 58; - const int INADEQUATE_MAX = 80; + public const int DEFAULT_FAN_MIN = 18; + public const int DEFAULT_FAN_MAX = 58; + + const int INADEQUATE_MAX = 72; public static IGpuControl? GpuControl; @@ -35,20 +37,17 @@ public static class HardwareControl static long lastUpdate; - static int _fanMax = DEFAULT_FAN_MAX; + static int[] _fanMax = new int[3] { DEFAULT_FAN_MAX, DEFAULT_FAN_MAX, DEFAULT_FAN_MAX }; static bool _fanRpm = false; - public static int fanMax + public static int GetFanMax(AsusFan device) { - get - { - return _fanMax; - } - set - { - AppConfig.Set("fan_max", value); - _fanMax = value; - } + return _fanMax[(int)device]; + } + + public static void SetFanMax(AsusFan device, int value) + { + AppConfig.Set("fan_max_" + (int)device, value); } public static bool fanRpm @@ -66,32 +65,32 @@ public static class HardwareControl static HardwareControl() { - _fanMax = AppConfig.Get("fan_max"); - if (_fanMax > INADEQUATE_MAX) _fanMax = -1; // skipping inadvequate settings + for (int i = 0; i < 3; i++) + { + _fanMax[i] = AppConfig.Get("fan_max_" + i); + + if (_fanMax[i] > INADEQUATE_MAX) _fanMax[i] = -1; // skipping inadvequate settings + + if (_fanMax[i] < 0 && AppConfig.ContainsModel("401")) _fanMax[i] = 72; + if (_fanMax[i] < 0 && AppConfig.ContainsModel("503")) _fanMax[i] = 68; + if (_fanMax[i] < 0) _fanMax[i] = DEFAULT_FAN_MAX; + } - if (_fanMax < 0 && AppConfig.ContainsModel("401")) _fanMax = 72; - if (_fanMax < 0 && AppConfig.ContainsModel("503")) _fanMax = 68; - if (_fanMax < 0) _fanMax = DEFAULT_FAN_MAX; _fanRpm = AppConfig.IsNotFalse("fan_rpm"); } - public static string FormatFan(int fan) + public static string FormatFan(AsusFan device, int value) { - // fix for old models - if (fan < 0) - { - fan += 65536; - if (fan <= 0 || fan > 100) return null; //nothing reasonable - } + if (value < 0) return null; - if (fan > fanMax && fan <= INADEQUATE_MAX) fanMax = fan; + if (value > GetFanMax(device) && value <= INADEQUATE_MAX) SetFanMax(device, value); if (fanRpm) - return GHelper.Properties.Strings.FanSpeed + ": " + (fan * 100).ToString() + "RPM"; + return GHelper.Properties.Strings.FanSpeed + ": " + (value * 100).ToString() + "RPM"; else - return GHelper.Properties.Strings.FanSpeed + ": " + Math.Min(Math.Round((float)fan / fanMax * 100), 100).ToString() + "%"; // relatively to 6000 rpm + return GHelper.Properties.Strings.FanSpeed + ": " + Math.Min(Math.Round((float)value / GetFanMax(device) * 100), 100).ToString() + "%"; // relatively to 6000 rpm } private static int GetGpuUse() @@ -246,9 +245,9 @@ public static class HardwareControl gpuTemp = -1; gpuUse = -1; - cpuFan = FormatFan(Program.acpi.DeviceGet(AsusACPI.CPU_Fan)); - gpuFan = FormatFan(Program.acpi.DeviceGet(AsusACPI.GPU_Fan)); - midFan = FormatFan(Program.acpi.DeviceGet(AsusACPI.Mid_Fan)); + cpuFan = FormatFan(AsusFan.CPU, Program.acpi.GetFan(AsusFan.CPU)); + gpuFan = FormatFan(AsusFan.GPU, Program.acpi.GetFan(AsusFan.GPU)); + midFan = FormatFan(AsusFan.Mid, Program.acpi.GetFan(AsusFan.Mid)); cpuTemp = GetCPUTemp();