From 4e6fa6d9b0fa0553f8480c1da29e94315c84b3f2 Mon Sep 17 00:00:00 2001 From: seerge Date: Wed, 8 Mar 2023 17:25:11 +0100 Subject: [PATCH] Auto Apply power limits --- ASUSWmi.cs | 1 - AppConfig.cs | 16 ++- Fans.Designer.cs | 280 +++++++++++++++++++++++++++-------------------- Fans.cs | 95 +++++++++------- GHelper.csproj | 2 +- Program.cs | 6 +- Settings.cs | 49 ++++++--- 7 files changed, 272 insertions(+), 177 deletions(-) diff --git a/ASUSWmi.cs b/ASUSWmi.cs index f81fc4b6..d13e7efb 100644 --- a/ASUSWmi.cs +++ b/ASUSWmi.cs @@ -200,7 +200,6 @@ public class ASUSWmi } - public void SubscribeToEvents(Action EventHandler) { ManagementEventWatcher watcher = new ManagementEventWatcher(); diff --git a/AppConfig.cs b/AppConfig.cs index 0b545b57..b629dec9 100644 --- a/AppConfig.cs +++ b/AppConfig.cs @@ -44,8 +44,9 @@ public class AppConfig File.WriteAllText(configFile, jsonString); } - public int getConfig(string name) + public int getConfig(string name, bool performance = false) { + if (config.ContainsKey(name)) return int.Parse(config[name].ToString()); else return -1; @@ -141,4 +142,17 @@ public class AppConfig return curve; } + public int getConfigPerf(string name) + { + int mode = getConfig("performance_mode"); + return getConfig(name + "_" + mode); + } + + public void setConfigPerf(string name, int value) + { + int mode = getConfig("performance_mode"); + setConfig(name + "_" + mode, value); + } + + } diff --git a/Fans.Designer.cs b/Fans.Designer.cs index 514304bc..2793a5a2 100644 --- a/Fans.Designer.cs +++ b/Fans.Designer.cs @@ -28,13 +28,18 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea4 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - chartCPU = new System.Windows.Forms.DataVisualization.Charting.Chart(); - buttonApply = new Button(); - buttonReset = new Button(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea5 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea6 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + panelFans = new Panel(); + checkAuto = new CheckBox(); chartGPU = new System.Windows.Forms.DataVisualization.Charting.Chart(); - groupBox1 = new GroupBox(); + buttonReset = new Button(); + buttonApply = new Button(); + chartCPU = new System.Windows.Forms.DataVisualization.Charting.Chart(); + panelPower = new Panel(); + labelPowerLimits = new Label(); + checkApplyPower = new CheckBox(); + buttonApplyPower = new Button(); panelCPU = new Panel(); labelCPU = new Label(); label2 = new Label(); @@ -46,11 +51,10 @@ labelApplied = new Label(); pictureFine = new PictureBox(); labelInfo = new Label(); - buttonApplyPower = new Button(); - checkAuto = new CheckBox(); - ((System.ComponentModel.ISupportInitialize)chartCPU).BeginInit(); + panelFans.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)chartGPU).BeginInit(); - groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)chartCPU).BeginInit(); + panelPower.SuspendLayout(); panelCPU.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)trackCPU).BeginInit(); panelTotal.SuspendLayout(); @@ -58,73 +62,138 @@ ((System.ComponentModel.ISupportInitialize)pictureFine).BeginInit(); SuspendLayout(); // - // chartCPU + // panelFans // - chartArea3.Name = "ChartArea1"; - chartCPU.ChartAreas.Add(chartArea3); - chartCPU.Location = new Point(390, 28); - chartCPU.Margin = new Padding(4, 2, 4, 2); - chartCPU.Name = "chartCPU"; - chartCPU.Size = new Size(832, 436); - chartCPU.TabIndex = 0; - chartCPU.Text = "chartCPU"; + panelFans.Controls.Add(checkAuto); + panelFans.Controls.Add(chartGPU); + panelFans.Controls.Add(buttonReset); + panelFans.Controls.Add(buttonApply); + panelFans.Controls.Add(chartCPU); + panelFans.Dock = DockStyle.Left; + panelFans.Location = new Point(363, 0); + panelFans.Margin = new Padding(10); + panelFans.MinimumSize = new Size(868, 1089); + panelFans.Name = "panelFans"; + panelFans.Padding = new Padding(10); + panelFans.Size = new Size(872, 1089); + panelFans.TabIndex = 12; // - // buttonApply + // checkAuto // - buttonApply.Location = new Point(946, 952); - buttonApply.Margin = new Padding(4, 2, 4, 2); - buttonApply.Name = "buttonApply"; - buttonApply.Size = new Size(274, 44); - buttonApply.TabIndex = 1; - buttonApply.Text = "Apply Fan Curve"; - buttonApply.UseVisualStyleBackColor = true; - // - // buttonReset - // - buttonReset.Location = new Point(390, 952); - buttonReset.Margin = new Padding(4, 2, 4, 2); - buttonReset.Name = "buttonReset"; - buttonReset.Size = new Size(274, 44); - buttonReset.TabIndex = 2; - buttonReset.Text = "Factory Defaults"; - buttonReset.UseVisualStyleBackColor = true; + checkAuto.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + checkAuto.AutoSize = true; + checkAuto.Location = new Point(584, 981); + checkAuto.Margin = new Padding(4, 2, 4, 2); + checkAuto.Name = "checkAuto"; + checkAuto.Size = new Size(165, 36); + checkAuto.TabIndex = 17; + checkAuto.Text = "Auto Apply"; + checkAuto.UseVisualStyleBackColor = true; // // chartGPU // - chartArea4.Name = "ChartArea1"; - chartGPU.ChartAreas.Add(chartArea4); - chartGPU.Location = new Point(390, 480); + chartGPU.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + chartArea5.Name = "ChartArea1"; + chartGPU.ChartAreas.Add(chartArea5); + chartGPU.Location = new Point(22, 502); chartGPU.Margin = new Padding(4, 2, 4, 2); chartGPU.Name = "chartGPU"; - chartGPU.Size = new Size(832, 450); - chartGPU.TabIndex = 3; + chartGPU.Size = new Size(810, 460); + chartGPU.TabIndex = 16; chartGPU.Text = "chart1"; // - // groupBox1 + // buttonReset // - groupBox1.Controls.Add(panelCPU); - groupBox1.Controls.Add(panelTotal); - groupBox1.Controls.Add(labelApplied); - groupBox1.Controls.Add(pictureFine); - groupBox1.Controls.Add(labelInfo); - groupBox1.Location = new Point(12, 12); - groupBox1.Margin = new Padding(4, 2, 4, 2); - groupBox1.Name = "groupBox1"; - groupBox1.Padding = new Padding(6, 4, 6, 4); - groupBox1.Size = new Size(356, 918); - groupBox1.TabIndex = 4; - groupBox1.TabStop = false; - groupBox1.Text = "Power Limits (PPT)"; + buttonReset.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonReset.Location = new Point(22, 1025); + buttonReset.Margin = new Padding(4, 2, 4, 2); + buttonReset.Name = "buttonReset"; + buttonReset.Size = new Size(231, 44); + buttonReset.TabIndex = 15; + buttonReset.Text = "Factory Defaults"; + buttonReset.UseVisualStyleBackColor = true; + // + // buttonApply + // + buttonApply.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonApply.Location = new Point(584, 1025); + buttonApply.Margin = new Padding(4, 2, 4, 2); + buttonApply.Name = "buttonApply"; + buttonApply.Size = new Size(248, 44); + buttonApply.TabIndex = 14; + buttonApply.Text = "Apply Fan Curve"; + buttonApply.UseVisualStyleBackColor = true; + // + // chartCPU + // + chartCPU.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + chartArea6.Name = "ChartArea1"; + chartCPU.ChartAreas.Add(chartArea6); + chartCPU.Location = new Point(22, 21); + chartCPU.Margin = new Padding(10); + chartCPU.Name = "chartCPU"; + chartCPU.Size = new Size(810, 460); + chartCPU.TabIndex = 13; + chartCPU.Text = "chartCPU"; + // + // panelPower + // + panelPower.Controls.Add(labelPowerLimits); + panelPower.Controls.Add(checkApplyPower); + panelPower.Controls.Add(buttonApplyPower); + panelPower.Controls.Add(panelCPU); + panelPower.Controls.Add(panelTotal); + panelPower.Controls.Add(labelApplied); + panelPower.Controls.Add(pictureFine); + panelPower.Controls.Add(labelInfo); + panelPower.Dock = DockStyle.Left; + panelPower.Location = new Point(0, 0); + panelPower.Name = "panelPower"; + panelPower.Size = new Size(363, 1089); + panelPower.TabIndex = 13; + // + // labelPowerLimits + // + labelPowerLimits.AutoSize = true; + labelPowerLimits.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + labelPowerLimits.Location = new Point(23, 15); + labelPowerLimits.Name = "labelPowerLimits"; + labelPowerLimits.Size = new Size(229, 32); + labelPowerLimits.TabIndex = 26; + labelPowerLimits.Text = "Power Limits (PPT)"; + // + // checkApplyPower + // + checkApplyPower.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + checkApplyPower.AutoSize = true; + checkApplyPower.Location = new Point(17, 981); + checkApplyPower.Margin = new Padding(4, 2, 4, 2); + checkApplyPower.Name = "checkApplyPower"; + checkApplyPower.Size = new Size(165, 36); + checkApplyPower.TabIndex = 25; + checkApplyPower.Text = "Auto Apply"; + checkApplyPower.UseVisualStyleBackColor = true; + // + // buttonApplyPower + // + buttonApplyPower.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonApplyPower.Location = new Point(17, 1025); + buttonApplyPower.Margin = new Padding(4, 2, 4, 2); + buttonApplyPower.Name = "buttonApplyPower"; + buttonApplyPower.Size = new Size(321, 44); + buttonApplyPower.TabIndex = 24; + buttonApplyPower.Text = "Apply Power Limits"; + buttonApplyPower.UseVisualStyleBackColor = true; // // panelCPU // panelCPU.Controls.Add(labelCPU); panelCPU.Controls.Add(label2); panelCPU.Controls.Add(trackCPU); - panelCPU.Location = new Point(186, 72); + panelCPU.Location = new Point(184, 89); panelCPU.Name = "panelCPU"; panelCPU.Size = new Size(160, 510); - panelCPU.TabIndex = 15; + panelCPU.TabIndex = 23; // // labelCPU // @@ -167,10 +236,10 @@ panelTotal.Controls.Add(labelTotal); panelTotal.Controls.Add(label1); panelTotal.Controls.Add(trackTotal); - panelTotal.Location = new Point(8, 72); + panelTotal.Location = new Point(17, 89); panelTotal.Name = "panelTotal"; panelTotal.Size = new Size(160, 511); - panelTotal.TabIndex = 14; + panelTotal.TabIndex = 22; // // labelTotal // @@ -213,11 +282,11 @@ // labelApplied.AutoSize = true; labelApplied.ForeColor = Color.Tomato; - labelApplied.Location = new Point(13, 36); + labelApplied.Location = new Point(23, 51); labelApplied.Margin = new Padding(4, 0, 4, 0); labelApplied.Name = "labelApplied"; labelApplied.Size = new Size(143, 32); - labelApplied.TabIndex = 13; + labelApplied.TabIndex = 21; labelApplied.Text = "Not Applied"; // // pictureFine @@ -225,73 +294,49 @@ pictureFine.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; pictureFine.BackgroundImageLayout = ImageLayout.Zoom; pictureFine.Image = Properties.Resources.everything_is_fine_itsfine; - pictureFine.Location = new Point(10, 682); + pictureFine.Location = new Point(17, 694); pictureFine.Margin = new Padding(4, 2, 4, 2); pictureFine.Name = "pictureFine"; - pictureFine.Size = new Size(336, 226); + pictureFine.Size = new Size(327, 254); pictureFine.SizeMode = PictureBoxSizeMode.Zoom; - pictureFine.TabIndex = 12; + pictureFine.TabIndex = 20; pictureFine.TabStop = false; pictureFine.Visible = false; // // labelInfo // - labelInfo.AutoSize = true; - labelInfo.Dock = DockStyle.Bottom; - labelInfo.Location = new Point(6, 882); + labelInfo.Location = new Point(17, 603); labelInfo.Margin = new Padding(4, 0, 4, 0); labelInfo.Name = "labelInfo"; - labelInfo.Size = new Size(65, 32); - labelInfo.TabIndex = 11; + labelInfo.Size = new Size(327, 371); + labelInfo.TabIndex = 19; labelInfo.Text = "label"; // - // buttonApplyPower - // - buttonApplyPower.Location = new Point(16, 952); - buttonApplyPower.Margin = new Padding(4, 2, 4, 2); - buttonApplyPower.Name = "buttonApplyPower"; - buttonApplyPower.Size = new Size(352, 44); - buttonApplyPower.TabIndex = 11; - buttonApplyPower.Text = "Apply Power Limits"; - buttonApplyPower.UseVisualStyleBackColor = true; - // - // checkAuto - // - checkAuto.AutoSize = true; - checkAuto.Location = new Point(772, 958); - checkAuto.Margin = new Padding(4, 2, 4, 2); - checkAuto.Name = "checkAuto"; - checkAuto.Size = new Size(165, 36); - checkAuto.TabIndex = 12; - checkAuto.Text = "Auto Apply"; - checkAuto.UseVisualStyleBackColor = true; - // // Fans // AutoScaleDimensions = new SizeF(192F, 192F); AutoScaleMode = AutoScaleMode.Dpi; AutoSize = true; - ClientSize = new Size(1242, 1020); - Controls.Add(checkAuto); - Controls.Add(buttonApplyPower); - Controls.Add(groupBox1); - Controls.Add(chartGPU); - Controls.Add(buttonReset); - Controls.Add(buttonApply); - Controls.Add(chartCPU); + AutoSizeMode = AutoSizeMode.GrowAndShrink; + ClientSize = new Size(1220, 1089); + Controls.Add(panelFans); + Controls.Add(panelPower); Margin = new Padding(4, 2, 4, 2); MaximizeBox = false; MdiChildrenMinimizedAnchorBottom = false; MinimizeBox = false; + MinimumSize = new Size(0, 1160); Name = "Fans"; ShowIcon = false; ShowInTaskbar = false; StartPosition = FormStartPosition.CenterScreen; Text = "Fans and Power"; - ((System.ComponentModel.ISupportInitialize)chartCPU).EndInit(); + panelFans.ResumeLayout(false); + panelFans.PerformLayout(); ((System.ComponentModel.ISupportInitialize)chartGPU).EndInit(); - groupBox1.ResumeLayout(false); - groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)chartCPU).EndInit(); + panelPower.ResumeLayout(false); + panelPower.PerformLayout(); panelCPU.ResumeLayout(false); panelCPU.PerformLayout(); ((System.ComponentModel.ISupportInitialize)trackCPU).EndInit(); @@ -300,28 +345,29 @@ ((System.ComponentModel.ISupportInitialize)trackTotal).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureFine).EndInit(); ResumeLayout(false); - PerformLayout(); } #endregion - - private System.Windows.Forms.DataVisualization.Charting.Chart chartCPU; - private Button buttonApply; - private Button buttonReset; - private System.Windows.Forms.DataVisualization.Charting.Chart chartGPU; - private GroupBox groupBox1; - private Button buttonApplyPower; - private Label labelInfo; - private PictureBox pictureFine; - private Label labelApplied; + private Panel panelFans; private CheckBox checkAuto; - private Panel panelTotal; - private Label labelTotal; - private Label label1; - private TrackBar trackTotal; + private System.Windows.Forms.DataVisualization.Charting.Chart chartGPU; + private Button buttonReset; + private Button buttonApply; + private System.Windows.Forms.DataVisualization.Charting.Chart chartCPU; + private Panel panelPower; + private CheckBox checkApplyPower; + private Button buttonApplyPower; private Panel panelCPU; private Label labelCPU; private Label label2; private TrackBar trackCPU; + private Panel panelTotal; + private Label labelTotal; + private Label label1; + private TrackBar trackTotal; + private Label labelApplied; + private PictureBox pictureFine; + private Label labelInfo; + private Label labelPowerLimits; } } \ No newline at end of file diff --git a/Fans.cs b/Fans.cs index f26f251d..715262a8 100644 --- a/Fans.cs +++ b/Fans.cs @@ -103,25 +103,30 @@ namespace GHelper buttonApplyPower.Click += ButtonApplyPower_Click; checkAuto.Click += CheckAuto_Click; + checkApplyPower.Click += CheckApplyPower_Click; //labelInfo.MaximumSize = new Size(280, 0); - labelInfo.Text = "Power Limits (PPT) is\nexperimental feature.\n\nValues will be applied\nonly after you click 'Apply'\nand reset after performance\nmode changes.\n\nUse carefully and\non your own risk!"; + labelInfo.Text = "Power Limits (PPT) is\nexperimental feature.\n\nUse carefully and\non your own risk!"; - LoadFans(); - VisualisePower(true); + InitFans(); + InitPower(); Shown += Fans_Shown; } + private void CheckApplyPower_Click(object? sender, EventArgs e) + { + if (sender is null) return; + CheckBox chk = (CheckBox)sender; + Program.config.setConfigPerf("auto_apply_power", chk.Checked ? 1 : 0); + } + private void CheckAuto_Click(object? sender, EventArgs e) { - if (sender is null) - return; - + if (sender is null) return; CheckBox chk = (CheckBox)sender; - - Program.config.setConfig("auto_apply_" + Program.config.getConfig("performance_mode"), chk.Checked ? 1 : 0); + Program.config.setConfigPerf("auto_apply", chk.Checked ? 1 : 0); } private void Fans_FormClosing(object? sender, FormClosingEventArgs e) @@ -135,40 +140,31 @@ namespace GHelper private void ButtonApplyPower_Click(object? sender, EventArgs e) { - int limit_total = trackTotal.Value; - int limit_cpu = trackCPU.Value; - - Program.config.setConfig("limit_total", limit_total); - Program.config.setConfig("limit_cpu", limit_cpu); - - Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA0, limit_total); - Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA1, limit_total); - - Program.wmi.DeviceSet(ASUSWmi.PPT_CPUB0, limit_cpu); - - labelApplied.ForeColor = Color.Blue; - labelApplied.Text = "Applied"; - + Program.settingsForm.SetPower(); + ApplyLabel(true); } - public void VisualisePower(bool init = false) + public void InitPower(bool changed = false) { - panelTotal.Visible = (Program.wmi.DeviceGet(ASUSWmi.PPT_TotalA0) >= 0); + panelPower.Visible = (Program.wmi.DeviceGet(ASUSWmi.PPT_TotalA0) >= 0); panelCPU.Visible = (Program.wmi.DeviceGet(ASUSWmi.PPT_CPUB0) >= 0); int limit_total; int limit_cpu; + bool apply = Program.config.getConfigPerf("auto_apply_power") == 1; - if (init) - { - limit_total = Program.config.getConfig("limit_total"); - limit_cpu = Program.config.getConfig("limit_cpu"); - } - else + if (changed) { limit_total = trackTotal.Value; limit_cpu = trackCPU.Value; + ApplyLabel(false); + } + else + { + limit_total = Program.config.getConfigPerf("limit_total"); + limit_cpu = Program.config.getConfigPerf("limit_cpu"); + ApplyLabel(apply); } if (limit_total < 0) limit_total = DefaultTotal; @@ -178,35 +174,48 @@ namespace GHelper if (limit_cpu < 0) limit_cpu = DefaultCPU; if (limit_cpu > MaxCPU) limit_cpu = MaxCPU; if (limit_cpu < MinCPU) limit_cpu = MinCPU; - if (limit_cpu > limit_total) limit_cpu = limit_total; trackTotal.Value = limit_total; trackCPU.Value = limit_cpu; + checkApplyPower.Checked = apply; labelTotal.Text = trackTotal.Value.ToString() + "W"; labelCPU.Text = trackCPU.Value.ToString() + "W"; - pictureFine.Visible = (limit_cpu > 85 || limit_total > 145); + + Program.config.setConfigPerf("limit_total", limit_total); + Program.config.setConfigPerf("limit_cpu", limit_cpu); } + private void TrackTotal_Scroll(object? sender, EventArgs e) { - VisualisePower(); + InitPower(true); } private void TrackCPU_Scroll(object? sender, EventArgs e) { - VisualisePower(); + InitPower(true); } - public void ResetApplyLabel() + + public void ApplyLabel(bool applied = false) { - labelApplied.ForeColor = Color.Red; - labelApplied.Text = "Not Applied"; + if (applied) + { + labelApplied.ForeColor = Color.Blue; + labelApplied.Text = "Applied"; + } + else + { + labelApplied.ForeColor = Color.Red; + labelApplied.Text = "Not Applied"; + + } } - public void LoadFans() + public void InitFans() { SetChart(chartCPU, 0); @@ -215,7 +224,7 @@ namespace GHelper LoadProfile(seriesCPU, 0); LoadProfile(seriesGPU, 1); - int auto_apply = Program.config.getConfig("auto_apply_" + Program.config.getConfig("performance_mode")); + int auto_apply = Program.config.getConfigPerf("auto_apply"); checkAuto.Checked = (auto_apply == 1); @@ -277,15 +286,19 @@ namespace GHelper private void ButtonReset_Click(object? sender, EventArgs e) { + LoadProfile(seriesCPU, 0, 1); LoadProfile(seriesGPU, 1, 1); checkAuto.Checked = false; - Program.config.setConfig("auto_apply_" + Program.config.getConfig("performance_mode"), 0); + checkApplyPower.Checked = false; + + Program.config.setConfigPerf("auto_apply", 0); + Program.config.setConfigPerf("auto_apply_power", 0); Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, Program.config.getConfig("performance_mode")); - ResetApplyLabel(); + ApplyLabel(false); } private void ChartCPU_MouseUp(object? sender, MouseEventArgs e) diff --git a/GHelper.csproj b/GHelper.csproj index 6d3fb686..2aa07aa3 100644 --- a/GHelper.csproj +++ b/GHelper.csproj @@ -15,7 +15,7 @@ GHelper x64 False - 0.17 + 0.18 True diff --git a/Program.cs b/Program.cs index 2c10e7a3..fcd9ec26 100644 --- a/Program.cs +++ b/Program.cs @@ -99,13 +99,13 @@ namespace GHelper Debug.WriteLine(isPlugged.ToString()); - settingsForm.AutoGPUMode(isPlugged); - settingsForm.AutoScreen(isPlugged); + settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit")); settingsForm.AutoPerformance(isPlugged); + settingsForm.AutoScreen(isPlugged); + settingsForm.AutoGPUMode(isPlugged); settingsForm.SetMatrix(isPlugged); - settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit")); } private static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e) diff --git a/Settings.cs b/Settings.cs index 162cd282..cee2f175 100644 --- a/Settings.cs +++ b/Settings.cs @@ -176,9 +176,9 @@ namespace GHelper private void ButtonMatrix_Click(object? sender, EventArgs e) { - string fileName = ""; + string fileName = null; - Thread t = new Thread((ThreadStart)(() => + Thread t = new Thread(() => { OpenFileDialog of = new OpenFileDialog(); of.Filter = "Image Files (*.bmp;*.jpg;*.jpeg,*.png,*.gif)|*.BMP;*.JPG;*.JPEG;*.PNG;*.GIF"; @@ -187,18 +187,22 @@ namespace GHelper fileName = of.FileName; } return; - })); + }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); - Program.config.setConfig("matrix_picture", fileName); - SetMatrixPicture(fileName); - BeginInvoke(delegate + if (fileName is not null) { - comboMatrixRunning.SelectedIndex = 2; - }); + Program.config.setConfig("matrix_picture", fileName); + SetMatrixPicture(fileName); + BeginInvoke(delegate + { + comboMatrixRunning.SelectedIndex = 2; + }); + } + } @@ -307,7 +311,7 @@ namespace GHelper if (fans == null || fans.Text == "") { fans = new Fans(); - Debug.WriteLine("Starting fans"); + //Debug.WriteLine("Starting fans"); } if (fans.Visible) @@ -684,6 +688,20 @@ namespace GHelper } } + public void SetPower() + { + int limit_total = Program.config.getConfigPerf("limit_total"); + int limit_cpu = Program.config.getConfigPerf("limit_cpu"); + + Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA0, limit_total); + Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA1, limit_total); + Program.wmi.DeviceSet(ASUSWmi.PPT_CPUB0, limit_cpu); + + Debug.WriteLine(limit_total.ToString() + ", " + limit_cpu.ToString()); + + + } + public void SetPerformanceMode(int PerformanceMode = ASUSWmi.PerformanceBalanced, bool notify = false) { @@ -714,16 +732,21 @@ namespace GHelper Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode); - if (Program.config.getConfig("auto_apply_" + PerformanceMode) == 1) + if (Program.config.getConfigPerf("auto_apply") == 1) { Program.wmi.SetFanCurve(0, Program.config.getFanConfig(0)); Program.wmi.SetFanCurve(1, Program.config.getFanConfig(1)); } + if (Program.config.getConfigPerf("auto_apply_power") == 1) + { + SetPower(); + } + if (fans != null && fans.Text != "") { - fans.LoadFans(); - fans.ResetApplyLabel(); + fans.InitFans(); + fans.InitPower(); } if (notify && (oldMode != PerformanceMode)) @@ -969,7 +992,7 @@ namespace GHelper } } - public void SetBatteryChargeLimit(int limit = 100) + public void SetBatteryChargeLimit(int limit) { if (limit < 40 || limit > 100) return;