From 3f21884af4c72b80c805d545fd5bbc03979662fc Mon Sep 17 00:00:00 2001 From: Sparronator9999 <86388887+Sparronator9999@users.noreply.github.com> Date: Tue, 30 Jul 2024 17:37:58 +1000 Subject: [PATCH] Actually implement the new extra options - Add laptop performance state configuration (different from Windows power plans) - Add Win/Fn key swap option --- Configs/MSI-GF63-Thin-11SC.xml | 40 +++++++++++++++++++++---- Docs/MSI EC Research.md | 8 +++-- YAMDCC.Config/KeySwapConf.cs | 31 +++++++++++++++++++ YAMDCC.Config/PerfMode.cs | 26 ++++++++++++++++ YAMDCC.Config/PerfModeConf.cs | 26 ++++++++++++++++ YAMDCC.Config/YAMDCC_Config.cs | 12 ++++++++ YAMDCC.GUI/MainWindow.Designer.cs | 50 +++++++++++++++---------------- YAMDCC.GUI/MainWindow.cs | 41 +++++++++++++++++++++++++ YAMDCC.Service/svcFanControl.cs | 29 ++++++++++++++---- 9 files changed, 224 insertions(+), 39 deletions(-) create mode 100644 YAMDCC.Config/KeySwapConf.cs create mode 100644 YAMDCC.Config/PerfMode.cs create mode 100644 YAMDCC.Config/PerfModeConf.cs diff --git a/Configs/MSI-GF63-Thin-11SC.xml b/Configs/MSI-GF63-Thin-11SC.xml index 059a93b..58006f2 100644 --- a/Configs/MSI-GF63-Thin-11SC.xml +++ b/Configs/MSI-GF63-Thin-11SC.xml @@ -265,16 +265,46 @@ 228 60 + + 210 + 2 + + + Maximum battery life + Optimises your laptop for maximum battery life. +Limits CPU power draw to 10W. +If set to default fan curve, uses an alternative fan curve. + 194 + + + Silent + Reduces the maximum fan speed to 60%. + 193 + + + Balanced + Balances battery life and performance. + 192 + + + High performance + Optimises your laptop for maximum performance. +Old (pre-alpha) versions of MSI Fan Control/YAMDCC set this setting. + 196 + + + + + 232 + false + 16 + 0 + Set fan mode to Advanced. Fixes fans not working at all with certain fan settings. 212 77 - - Set Performance Level to Turbo. Fixes fan speeds capped at ~60% due to the default setting. - 210 - 196 - diff --git a/Docs/MSI EC Research.md b/Docs/MSI EC Research.md index 0746990..2667359 100644 --- a/Docs/MSI EC Research.md +++ b/Docs/MSI EC Research.md @@ -111,9 +111,11 @@ Controls the performance level of the laptop: - `0xC4`: Turbo. The `MSI GF63 Thin 11SC.xml` config sets this value when loaded. - `0xC0`: High -- `0xC1`: Medium (default). Causes maximum fan speeds to be capped at 60%. -- `0xC2`: Low. Causes fan settings set by MSI Fan Control to be ignored,' - and a different default fan curve to be set (not in EC, as far as I know). +- `0xC1`: Medium (default on my machine). Causes maximum fan speeds to be capped at 60% (~3500 RPM). +- `0xC2`: Low: + - Limits CPU power draw to 10W while active (but not the dGPU power draw, funnily enough). + - Modifys some fan settings. This is still being studied, but appears to completely mess up + custom fan curves. ## `0xD3` Controls the keyboard backlight. The brightness level can be set using diff --git a/YAMDCC.Config/KeySwapConf.cs b/YAMDCC.Config/KeySwapConf.cs new file mode 100644 index 0000000..214b57a --- /dev/null +++ b/YAMDCC.Config/KeySwapConf.cs @@ -0,0 +1,31 @@ +using System.Xml.Serialization; + +namespace YAMDCC.Config +{ + public class KeySwapConf + { + /// + /// The register that controls the Win/Fn key swap state. + /// + [XmlElement] + public byte Reg; + + /// + /// Is the Win/Fn key swap feature enabled? + /// + [XmlElement] + public bool Enabled; + + /// + /// The value to turn on Win/Fn key swapping. + /// + [XmlElement] + public byte OnVal; + + /// + /// The value to turn off Win/Fn key swapping. + /// + [XmlElement] + public byte OffVal; + } +} diff --git a/YAMDCC.Config/PerfMode.cs b/YAMDCC.Config/PerfMode.cs new file mode 100644 index 0000000..3a4cd1b --- /dev/null +++ b/YAMDCC.Config/PerfMode.cs @@ -0,0 +1,26 @@ +using System.Xml.Serialization; + +namespace YAMDCC.Config +{ + public class PerfMode + { + /// + /// The name of the performance mode. + /// + [XmlElement] + public string Name; + + /// + /// The description of the performance mode. + /// + [XmlElement] + public string Desc; + + /// + /// The value to write to the EC register + /// when this performance mode is selected. + /// + [XmlElement] + public byte Value; + } +} diff --git a/YAMDCC.Config/PerfModeConf.cs b/YAMDCC.Config/PerfModeConf.cs new file mode 100644 index 0000000..66d2981 --- /dev/null +++ b/YAMDCC.Config/PerfModeConf.cs @@ -0,0 +1,26 @@ +using System.Xml.Serialization; + +namespace YAMDCC.Config +{ + public class PerfModeConf + { + /// + /// The register that controls the performance mode. + /// + [XmlElement] + public byte Reg; + + /// + /// The currently selected performance mode, as + /// an index of the available performance modes. + /// + [XmlElement] + public int ModeSel; + + /// + /// An array of possible performance modes for the laptop. + /// + [XmlArray] + public PerfMode[] PerfModes; + } +} diff --git a/YAMDCC.Config/YAMDCC_Config.cs b/YAMDCC.Config/YAMDCC_Config.cs index 154b2ff..7c9dd92 100644 --- a/YAMDCC.Config/YAMDCC_Config.cs +++ b/YAMDCC.Config/YAMDCC_Config.cs @@ -68,6 +68,18 @@ public sealed class YAMDCC_Config [XmlElement] public ChargeLimitConf ChargeLimitConf; + /// + /// The laptop's performance mode config. May be null. + /// + [XmlElement] + public PerfModeConf PerfModeConf; + + /// + /// The laptop's Win/Fn keyboard swap config. May be null. + /// + [XmlElement] + public KeySwapConf KeySwapConf; + /// /// A list of registers to write when applying a fan config. /// May be null, but if not null, must have diff --git a/YAMDCC.GUI/MainWindow.Designer.cs b/YAMDCC.GUI/MainWindow.Designer.cs index 215827c..0bfe187 100644 --- a/YAMDCC.GUI/MainWindow.Designer.cs +++ b/YAMDCC.GUI/MainWindow.Designer.cs @@ -147,45 +147,45 @@ private void InitializeComponent() // tsiLoadConf // this.tsiLoadConf.Name = "tsiLoadConf"; - this.tsiLoadConf.Size = new System.Drawing.Size(180, 22); + this.tsiLoadConf.Size = new System.Drawing.Size(154, 22); this.tsiLoadConf.Text = "Load config"; this.tsiLoadConf.Click += new System.EventHandler(this.tsiLoadConf_Click); // // tsiSaveConf // this.tsiSaveConf.Name = "tsiSaveConf"; - this.tsiSaveConf.Size = new System.Drawing.Size(180, 22); + this.tsiSaveConf.Size = new System.Drawing.Size(154, 22); this.tsiSaveConf.Text = "Save config"; this.tsiSaveConf.Click += new System.EventHandler(this.tsiSaveConf_Click); // // sep1 // this.sep1.Name = "sep1"; - this.sep1.Size = new System.Drawing.Size(177, 6); + this.sep1.Size = new System.Drawing.Size(151, 6); // // tsiApply // this.tsiApply.Name = "tsiApply"; - this.tsiApply.Size = new System.Drawing.Size(180, 22); + this.tsiApply.Size = new System.Drawing.Size(154, 22); this.tsiApply.Text = "Apply changes"; this.tsiApply.Click += new System.EventHandler(this.tsiApply_Click); // // tsiRevert // this.tsiRevert.Name = "tsiRevert"; - this.tsiRevert.Size = new System.Drawing.Size(180, 22); + this.tsiRevert.Size = new System.Drawing.Size(154, 22); this.tsiRevert.Text = "Revert changes"; this.tsiRevert.Click += new System.EventHandler(this.tsiRevert_Click); // // sep2 // this.sep2.Name = "sep2"; - this.sep2.Size = new System.Drawing.Size(177, 6); + this.sep2.Size = new System.Drawing.Size(151, 6); // // tsiExit // this.tsiExit.Name = "tsiExit"; - this.tsiExit.Size = new System.Drawing.Size(180, 22); + this.tsiExit.Size = new System.Drawing.Size(154, 22); this.tsiExit.Text = "Exit"; this.tsiExit.Click += new System.EventHandler(this.tsiExit_Click); // @@ -224,26 +224,26 @@ private void InitializeComponent() // tsiProfRename // this.tsiProfRename.Name = "tsiProfRename"; - this.tsiProfRename.Size = new System.Drawing.Size(180, 22); + this.tsiProfRename.Size = new System.Drawing.Size(178, 22); this.tsiProfRename.Text = "Change Name"; this.tsiProfRename.Click += new System.EventHandler(this.tsiProfRename_Click); // // tsiProfChangeDesc // this.tsiProfChangeDesc.Name = "tsiProfChangeDesc"; - this.tsiProfChangeDesc.Size = new System.Drawing.Size(180, 22); + this.tsiProfChangeDesc.Size = new System.Drawing.Size(178, 22); this.tsiProfChangeDesc.Text = "Change Description"; this.tsiProfChangeDesc.Click += new System.EventHandler(this.tsiProfChangeDesc_Click); // // sep3 // this.sep3.Name = "sep3"; - this.sep3.Size = new System.Drawing.Size(177, 6); + this.sep3.Size = new System.Drawing.Size(175, 6); // // tsiProfDel // this.tsiProfDel.Name = "tsiProfDel"; - this.tsiProfDel.Size = new System.Drawing.Size(180, 22); + this.tsiProfDel.Size = new System.Drawing.Size(178, 22); this.tsiProfDel.Text = "Delete"; this.tsiProfDel.Click += new System.EventHandler(this.tsiProfDel_Click); // @@ -291,14 +291,14 @@ private void InitializeComponent() // tsiAbout // this.tsiAbout.Name = "tsiAbout"; - this.tsiAbout.Size = new System.Drawing.Size(180, 22); + this.tsiAbout.Size = new System.Drawing.Size(141, 22); this.tsiAbout.Text = "About"; this.tsiAbout.Click += new System.EventHandler(this.tsiAbout_Click); // // tsiSource // this.tsiSource.Name = "tsiSource"; - this.tsiSource.Size = new System.Drawing.Size(180, 22); + this.tsiSource.Size = new System.Drawing.Size(141, 22); this.tsiSource.Text = "Source Code"; this.tsiSource.Click += new System.EventHandler(this.tsiSrc_Click); // @@ -448,14 +448,14 @@ private void InitializeComponent() this.cboFanSel.FormattingEnabled = true; this.cboFanSel.Location = new System.Drawing.Point(35, 3); this.cboFanSel.Name = "cboFanSel"; - this.cboFanSel.Size = new System.Drawing.Size(121, 23); + this.cboFanSel.Size = new System.Drawing.Size(120, 23); this.cboFanSel.TabIndex = 1; this.cboFanSel.SelectedIndexChanged += new System.EventHandler(this.cboFanSel_IndexChanged); // // lblProfSel // this.lblProfSel.AutoSize = true; - this.lblProfSel.Location = new System.Drawing.Point(162, 7); + this.lblProfSel.Location = new System.Drawing.Point(161, 7); this.lblProfSel.Margin = new System.Windows.Forms.Padding(3, 7, 0, 3); this.lblProfSel.Name = "lblProfSel"; this.lblProfSel.Size = new System.Drawing.Size(44, 15); @@ -467,16 +467,16 @@ private void InitializeComponent() this.cboProfSel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboProfSel.Enabled = false; this.cboProfSel.FormattingEnabled = true; - this.cboProfSel.Location = new System.Drawing.Point(209, 3); + this.cboProfSel.Location = new System.Drawing.Point(208, 3); this.cboProfSel.Name = "cboProfSel"; - this.cboProfSel.Size = new System.Drawing.Size(121, 23); + this.cboProfSel.Size = new System.Drawing.Size(120, 23); this.cboProfSel.TabIndex = 3; this.cboProfSel.SelectedIndexChanged += new System.EventHandler(this.cboProfSel_IndexChanged); // // btnProfAdd // this.btnProfAdd.Enabled = false; - this.btnProfAdd.Location = new System.Drawing.Point(336, 3); + this.btnProfAdd.Location = new System.Drawing.Point(334, 3); this.btnProfAdd.Margin = new System.Windows.Forms.Padding(3, 3, 0, 3); this.btnProfAdd.Name = "btnProfAdd"; this.btnProfAdd.Size = new System.Drawing.Size(23, 23); @@ -488,7 +488,7 @@ private void InitializeComponent() // btnProfDel // this.btnProfDel.Enabled = false; - this.btnProfDel.Location = new System.Drawing.Point(359, 3); + this.btnProfDel.Location = new System.Drawing.Point(357, 3); this.btnProfDel.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3); this.btnProfDel.Name = "btnProfDel"; this.btnProfDel.Size = new System.Drawing.Size(23, 23); @@ -604,8 +604,9 @@ private void InitializeComponent() this.numChgLim.Enabled = false; this.numChgLim.Location = new System.Drawing.Point(136, 3); this.numChgLim.Name = "numChgLim"; - this.numChgLim.Size = new System.Drawing.Size(60, 23); + this.numChgLim.Size = new System.Drawing.Size(50, 23); this.numChgLim.TabIndex = 3; + this.numChgLim.ValueChanged += new System.EventHandler(this.numChargeLim_Changed); // // lblPerfMode // @@ -624,15 +625,11 @@ private void InitializeComponent() this.cboPerfMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboPerfMode.Enabled = false; this.cboPerfMode.FormattingEnabled = true; - this.cboPerfMode.Items.AddRange(new object[] { - "Maximum battery life", - "Balanced", - "High performance", - "Turbo performance"}); this.cboPerfMode.Location = new System.Drawing.Point(136, 32); this.cboPerfMode.Name = "cboPerfMode"; - this.cboPerfMode.Size = new System.Drawing.Size(121, 23); + this.cboPerfMode.Size = new System.Drawing.Size(150, 23); this.cboPerfMode.TabIndex = 5; + this.cboPerfMode.SelectedIndexChanged += new System.EventHandler(this.cboPerfMode_SelectedIndexChanged); // // lblWinFnSwap // @@ -657,6 +654,7 @@ private void InitializeComponent() this.chkWinFnSwap.TabIndex = 7; this.chkWinFnSwap.Text = "Enabled"; this.chkWinFnSwap.UseVisualStyleBackColor = true; + this.chkWinFnSwap.CheckedChanged += new System.EventHandler(this.chkWinFnSwap_CheckedChanged); // // flwStats // diff --git a/YAMDCC.GUI/MainWindow.cs b/YAMDCC.GUI/MainWindow.cs index 3b0da7f..62c3584 100644 --- a/YAMDCC.GUI/MainWindow.cs +++ b/YAMDCC.GUI/MainWindow.cs @@ -537,6 +537,16 @@ private void numChargeLim_Changed(object sender, EventArgs e) Config.ChargeLimitConf.CurVal = (byte)numChgLim.Value; } + private void cboPerfMode_SelectedIndexChanged(object sender, EventArgs e) + { + Config.PerfModeConf.ModeSel = cboPerfMode.SelectedIndex; + } + + private void chkWinFnSwap_CheckedChanged(object sender, EventArgs e) + { + Config.KeySwapConf.Enabled = chkWinFnSwap.Checked; + } + private void btnRevert_Click(object sender, EventArgs e) { @@ -621,6 +631,37 @@ private void LoadConf(string configPath) numChgLim.Maximum = Math.Abs(cfg.MaxVal - cfg.MinVal); } + if (Config.PerfModeConf is null) + { + ttMain.SetToolTip(cboPerfMode, Strings.GetString("ttNotSupported")); + cboPerfMode.Enabled = lblPerfMode.Enabled = false; + } + else + { + PerfModeConf cfg = Config.PerfModeConf; + for (int i = 0; i < cfg.PerfModes.Length; i++) + { + cboPerfMode.Items.Add(cfg.PerfModes[i].Name); + } + + cboPerfMode.SelectedIndex = cfg.ModeSel; + ttMain.SetToolTip(cboPerfMode, cfg.PerfModes[cfg.ModeSel].Desc); + cboPerfMode.Enabled = lblPerfMode.Enabled = true; + } + + + if (Config.KeySwapConf is null) + { + ttMain.SetToolTip(chkWinFnSwap, Strings.GetString("ttNotSupported")); + chkWinFnSwap.Enabled = lblWinFnSwap.Enabled = false; + } + else + { + chkWinFnSwap.Checked = Config.KeySwapConf.Enabled; + ttMain.SetToolTip(chkWinFnSwap, "tooltip todo lol"); + chkWinFnSwap.Enabled = lblWinFnSwap.Enabled = true; + } + cboFanSel.Items.Clear(); for (int i = 0; i < Config.FanConfs.Length; i++) { diff --git a/YAMDCC.Service/svcFanControl.cs b/YAMDCC.Service/svcFanControl.cs index 05a3208..11cc917 100644 --- a/YAMDCC.Service/svcFanControl.cs +++ b/YAMDCC.Service/svcFanControl.cs @@ -114,7 +114,7 @@ protected override void OnStart(string[] args) Log.Info(Strings.GetString("svcStarted")); // Apply the fan curve and charging threshold: - ApplyCurve(); + ApplySettings(); } protected override void OnStop() @@ -144,7 +144,7 @@ protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus) case PowerBroadcastStatus.ResumeAutomatic: // Re-apply the fan curve after waking up from sleep: Log.Debug($"Re-applying fan curve..."); - ApplyCurve(); + ApplySettings(); break; } return true; @@ -185,7 +185,7 @@ private void IPCClientMessage(NamedPipeConnection