From dd4d85f254c27a2c4fdf75230f0ff19d6e31eaaf Mon Sep 17 00:00:00 2001 From: seerge Date: Mon, 13 Mar 2023 23:28:57 +0100 Subject: [PATCH] Turbo boost dropdown --- Fans.Designer.cs | 41 ++++++++++++++++++++++++++--------------- Fans.cs | 18 +++++++----------- HardwareMonitor.cs | 14 +++++++++++--- NativeMethods.cs | 3 ++- 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Fans.Designer.cs b/Fans.Designer.cs index ce8773e1..cdf6b2bc 100644 --- a/Fans.Designer.cs +++ b/Fans.Designer.cs @@ -31,11 +31,12 @@ System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); panelFans = new Panel(); + labelBoost = new Label(); + comboBoost = new ComboBox(); picturePerf = new PictureBox(); tableFanCharts = new TableLayoutPanel(); chartGPU = new System.Windows.Forms.DataVisualization.Charting.Chart(); chartCPU = new System.Windows.Forms.DataVisualization.Charting.Chart(); - checkBoost = new CheckBox(); labelFans = new Label(); checkAuto = new CheckBox(); buttonReset = new Button(); @@ -72,9 +73,10 @@ // // panelFans // + panelFans.Controls.Add(labelBoost); + panelFans.Controls.Add(comboBoost); panelFans.Controls.Add(picturePerf); panelFans.Controls.Add(tableFanCharts); - panelFans.Controls.Add(checkBoost); panelFans.Controls.Add(labelFans); panelFans.Controls.Add(checkAuto); panelFans.Controls.Add(buttonReset); @@ -87,6 +89,26 @@ panelFans.Size = new Size(824, 1159); panelFans.TabIndex = 12; // + // labelBoost + // + labelBoost.AutoSize = true; + labelBoost.Location = new Point(396, 18); + labelBoost.Name = "labelBoost"; + labelBoost.Size = new Size(125, 32); + labelBoost.TabIndex = 39; + labelBoost.Text = "CPU Boost"; + // + // comboBoost + // + comboBoost.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoost.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoost.FormattingEnabled = true; + comboBoost.Items.AddRange(new object[] { "Disabled", "Enabled", "Aggressive", "Efficient Enabled", "Efficient Aggressive" }); + comboBoost.Location = new Point(526, 15); + comboBoost.Name = "comboBoost"; + comboBoost.Size = new Size(266, 40); + comboBoost.TabIndex = 38; + // // picturePerf // picturePerf.BackgroundImage = Properties.Resources.icons8_fan_head_96; @@ -141,18 +163,6 @@ chartCPU.TabIndex = 14; chartCPU.Text = "chartCPU"; // - // checkBoost - // - checkBoost.AutoSize = true; - checkBoost.ForeColor = SystemColors.ControlText; - checkBoost.Location = new Point(475, 18); - checkBoost.Margin = new Padding(4, 2, 4, 2); - checkBoost.Name = "checkBoost"; - checkBoost.Size = new Size(320, 36); - checkBoost.TabIndex = 35; - checkBoost.Text = "CPU Turbo Boost enabled"; - checkBoost.UseVisualStyleBackColor = true; - // // labelFans // labelFans.AutoSize = true; @@ -453,9 +463,10 @@ private TableLayoutPanel tableFanCharts; private System.Windows.Forms.DataVisualization.Charting.Chart chartGPU; private System.Windows.Forms.DataVisualization.Charting.Chart chartCPU; - private CheckBox checkBoost; private Label labelFans; private PictureBox picturePerf; private PictureBox pictureBox1; + private ComboBox comboBoost; + private Label labelBoost; } } \ No newline at end of file diff --git a/Fans.cs b/Fans.cs index 3812f33a..cbb6af4b 100644 --- a/Fans.cs +++ b/Fans.cs @@ -115,7 +115,7 @@ namespace GHelper InitPower(); InitBoost(); - checkBoost.Click += CheckBoost_Click; + comboBoost.SelectedIndexChanged += ComboBoost_Changed; Shown += Fans_Shown; @@ -125,19 +125,15 @@ namespace GHelper public void InitBoost() { int boost = NativeMethods.GetCPUBoost(); - checkBoost.Checked = (boost > 0); + if (boost >= 0) + comboBoost.SelectedIndex = boost; } - private void CheckBoost_Click(object? sender, EventArgs e) + private void ComboBoost_Changed(object? sender, EventArgs e) { - if (sender is null) - return; - - CheckBox chk = (CheckBox)sender; - if (chk.Checked) - NativeMethods.SetCPUBoost(2); - else - NativeMethods.SetCPUBoost(0); + if (sender is null) return; + ComboBox cmb = (ComboBox)sender; + NativeMethods.SetCPUBoost(cmb.SelectedIndex); } private void CheckApplyPower_Click(object? sender, EventArgs e) diff --git a/HardwareMonitor.cs b/HardwareMonitor.cs index c5a6b118..e6c4f9f0 100644 --- a/HardwareMonitor.cs +++ b/HardwareMonitor.cs @@ -19,7 +19,14 @@ public class HardwareMonitor var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true); cpuTemp = ct.NextValue() - 273; ct.Dispose(); + } + catch + { + Logger.WriteLine("Failed reading CPU temp"); + } + try + { var cb = new PerformanceCounter("Power Meter", "Power", "Power Meter (0)", true); batteryDischarge = cb.NextValue() / 1000; cb.Dispose(); @@ -27,15 +34,16 @@ public class HardwareMonitor } catch { - //Logger.WriteLine("Failed reading sensors"); + Logger.WriteLine("Failed reading Battery discharge"); } try { gpuTemp = GpuTemperatureProvider?.GetCurrentTemperature(); - } catch + } catch (Exception ex) { - //Logger.WriteLine("Failed reading GPU temps"); + Logger.WriteLine("Failed reading GPU temp"); + Logger.WriteLine(ex.ToString()); } } diff --git a/NativeMethods.cs b/NativeMethods.cs index 8553f3d8..c63ef9da 100644 --- a/NativeMethods.cs +++ b/NativeMethods.cs @@ -654,6 +654,7 @@ public class NativeMethods PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid); + /* var hrDC = PowerWriteDCValueIndex( IntPtr.Zero, activeSchemeGuid, @@ -662,7 +663,7 @@ public class NativeMethods boost); PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid); - + */ } }