From ebe800820dad0fe669810dda87813d34d5f050c9 Mon Sep 17 00:00:00 2001 From: Sparronator9999 <86388887+Sparronator9999@users.noreply.github.com> Date: Wed, 12 Feb 2025 09:32:56 +1100 Subject: [PATCH] Better EC firmware version support - Add firmware version/date to YAMDCC config (backwards-compatible change) - Only get EC firmware version/date if supported according to current config - Display EC firmware version that was used during EC-to-config or when "Get computer model..." button was pressed --- YAMDCC.Config/YAMDCC_Config.cs | 23 ++++++++++ YAMDCC.ConfigEditor/MainForm.Designer.cs | 58 ++++++++++++++++++++++-- YAMDCC.ConfigEditor/MainForm.cs | 33 ++++++++++++-- YAMDCC.ConfigEditor/MainForm.resx | 6 +++ YAMDCC.IPC/EcInfo.cs | 14 ++++++ YAMDCC.IPC/ServiceCommand.cs | 11 +++++ YAMDCC.IPC/ServiceResponse.cs | 9 ++++ YAMDCC.Service/FanControlService.cs | 45 ++++++++++++++++-- YAMDCC.Service/Strings.resx | 3 ++ 9 files changed, 191 insertions(+), 11 deletions(-) create mode 100644 YAMDCC.IPC/EcInfo.cs diff --git a/YAMDCC.Config/YAMDCC_Config.cs b/YAMDCC.Config/YAMDCC_Config.cs index 9a6f28d..0573c4f 100644 --- a/YAMDCC.Config/YAMDCC_Config.cs +++ b/YAMDCC.Config/YAMDCC_Config.cs @@ -66,6 +66,29 @@ public sealed class YAMDCC_Config [XmlElement] public string Author { get; set; } + /// + /// Set to if the EC supports reading + /// firmware version from registers 0xA0-0xBB. + /// + /// + /// If , the + /// and properties are ignored. + /// + [XmlElement] + public bool FirmVerSupported { get; set; } + + /// + /// The EC firmware version of the laptop this config was made for. + /// + [XmlElement] + public string FirmVer { get; set; } + + /// + /// The EC firmware date of the laptop this config was made for. + /// + [XmlElement] + public DateTime? FirmDate { get; set; } + /// /// The list of s associated with the laptop. /// diff --git a/YAMDCC.ConfigEditor/MainForm.Designer.cs b/YAMDCC.ConfigEditor/MainForm.Designer.cs index 359a149..5e346c4 100644 --- a/YAMDCC.ConfigEditor/MainForm.Designer.cs +++ b/YAMDCC.ConfigEditor/MainForm.Designer.cs @@ -70,6 +70,8 @@ private void InitializeComponent() System.Windows.Forms.Label lblAuthor; System.Windows.Forms.TableLayoutPanel tblApply; System.Windows.Forms.FlowLayoutPanel flwStats; + System.Windows.Forms.Label lblFirmVer; + System.Windows.Forms.Label lblFirmDate; this.tsiFile = new System.Windows.Forms.ToolStripMenuItem(); this.tsiLoadConf = new System.Windows.Forms.ToolStripMenuItem(); this.tsiSaveConf = new System.Windows.Forms.ToolStripMenuItem(); @@ -126,6 +128,8 @@ private void InitializeComponent() this.lblFanRPM = new System.Windows.Forms.Label(); this.lblTemp = new System.Windows.Forms.Label(); this.tblMain = new System.Windows.Forms.TableLayoutPanel(); + this.txtFirmVer = new System.Windows.Forms.TextBox(); + this.txtFirmDate = new System.Windows.Forms.TextBox(); menuStrip = new System.Windows.Forms.MenuStrip(); sep1 = new System.Windows.Forms.ToolStripSeparator(); sep2 = new System.Windows.Forms.ToolStripSeparator(); @@ -152,6 +156,8 @@ private void InitializeComponent() lblAuthor = new System.Windows.Forms.Label(); tblApply = new System.Windows.Forms.TableLayoutPanel(); flwStats = new System.Windows.Forms.FlowLayoutPanel(); + lblFirmVer = new System.Windows.Forms.Label(); + lblFirmDate = new System.Windows.Forms.Label(); menuStrip.SuspendLayout(); tcMain.SuspendLayout(); tabFanControl.SuspendLayout(); @@ -816,18 +822,24 @@ private void InitializeComponent() tblInfo.ColumnCount = 2; tblInfo.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); tblInfo.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + tblInfo.Controls.Add(this.txtFirmDate, 1, 4); tblInfo.Controls.Add(this.txtModel, 1, 2); tblInfo.Controls.Add(this.txtManufacturer, 1, 1); tblInfo.Controls.Add(lblModel, 0, 2); tblInfo.Controls.Add(lblManufacturer, 0, 1); tblInfo.Controls.Add(lblAuthor, 0, 0); tblInfo.Controls.Add(this.txtAuthor, 1, 0); - tblInfo.Controls.Add(this.btnGetModel, 1, 3); + tblInfo.Controls.Add(this.btnGetModel, 1, 5); + tblInfo.Controls.Add(lblFirmVer, 0, 3); + tblInfo.Controls.Add(lblFirmDate, 0, 4); + tblInfo.Controls.Add(this.txtFirmVer, 1, 3); tblInfo.Dock = System.Windows.Forms.DockStyle.Fill; tblInfo.Location = new System.Drawing.Point(3, 3); tblInfo.Margin = new System.Windows.Forms.Padding(0); tblInfo.Name = "tblInfo"; - tblInfo.RowCount = 4; + tblInfo.RowCount = 6; + tblInfo.RowStyles.Add(new System.Windows.Forms.RowStyle()); + tblInfo.RowStyles.Add(new System.Windows.Forms.RowStyle()); tblInfo.RowStyles.Add(new System.Windows.Forms.RowStyle()); tblInfo.RowStyles.Add(new System.Windows.Forms.RowStyle()); tblInfo.RowStyles.Add(new System.Windows.Forms.RowStyle()); @@ -897,7 +909,7 @@ private void InitializeComponent() // // btnGetModel // - this.btnGetModel.Location = new System.Drawing.Point(131, 90); + this.btnGetModel.Location = new System.Drawing.Point(131, 148); this.btnGetModel.Name = "btnGetModel"; this.btnGetModel.Size = new System.Drawing.Size(175, 25); this.btnGetModel.TabIndex = 6; @@ -1031,6 +1043,44 @@ private void InitializeComponent() this.tblMain.Size = new System.Drawing.Size(540, 416); this.tblMain.TabIndex = 1; // + // lblFirmVer + // + lblFirmVer.Anchor = System.Windows.Forms.AnchorStyles.Right; + lblFirmVer.AutoSize = true; + lblFirmVer.Location = new System.Drawing.Point(10, 94); + lblFirmVer.Name = "lblFirmVer"; + lblFirmVer.Size = new System.Drawing.Size(115, 15); + lblFirmVer.TabIndex = 7; + lblFirmVer.Text = "EC firmware version:"; + // + // lblFirmDate + // + lblFirmDate.Anchor = System.Windows.Forms.AnchorStyles.Right; + lblFirmDate.AutoSize = true; + lblFirmDate.Location = new System.Drawing.Point(25, 123); + lblFirmDate.Name = "lblFirmDate"; + lblFirmDate.Size = new System.Drawing.Size(100, 15); + lblFirmDate.TabIndex = 8; + lblFirmDate.Text = "EC firmware date:"; + // + // txtFirmVer + // + this.txtFirmVer.Dock = System.Windows.Forms.DockStyle.Fill; + this.txtFirmVer.Location = new System.Drawing.Point(131, 90); + this.txtFirmVer.Name = "txtFirmVer"; + this.txtFirmVer.ReadOnly = true; + this.txtFirmVer.Size = new System.Drawing.Size(386, 23); + this.txtFirmVer.TabIndex = 9; + // + // txtFirmDate + // + this.txtFirmDate.Dock = System.Windows.Forms.DockStyle.Fill; + this.txtFirmDate.Location = new System.Drawing.Point(131, 119); + this.txtFirmDate.Name = "txtFirmDate"; + this.txtFirmDate.ReadOnly = true; + this.txtFirmDate.Size = new System.Drawing.Size(386, 23); + this.txtFirmDate.TabIndex = 10; + // // MainForm // this.AcceptButton = this.btnApply; @@ -1137,5 +1187,7 @@ private void InitializeComponent() private System.Windows.Forms.TextBox txtManufacturer; private System.Windows.Forms.TextBox txtAuthor; private System.Windows.Forms.Button btnGetModel; + private System.Windows.Forms.TextBox txtFirmDate; + private System.Windows.Forms.TextBox txtFirmVer; } } diff --git a/YAMDCC.ConfigEditor/MainForm.cs b/YAMDCC.ConfigEditor/MainForm.cs index dc97c03..7b701c3 100644 --- a/YAMDCC.ConfigEditor/MainForm.cs +++ b/YAMDCC.ConfigEditor/MainForm.cs @@ -309,6 +309,20 @@ private void IPCMessage(object sender, PipeMessageEventArgs False + + False + + + False + False diff --git a/YAMDCC.IPC/EcInfo.cs b/YAMDCC.IPC/EcInfo.cs new file mode 100644 index 0000000..31bfc9e --- /dev/null +++ b/YAMDCC.IPC/EcInfo.cs @@ -0,0 +1,14 @@ +using MessagePack; +using System; + +namespace YAMDCC.IPC; + +[MessagePackObject] +public class EcInfo +{ + [Key(0)] + public string Version { get; set; } + + [Key(1)] + public DateTime Date { get; set; } +} diff --git a/YAMDCC.IPC/ServiceCommand.cs b/YAMDCC.IPC/ServiceCommand.cs index 951fcad..9f5e327 100644 --- a/YAMDCC.IPC/ServiceCommand.cs +++ b/YAMDCC.IPC/ServiceCommand.cs @@ -128,6 +128,17 @@ public enum Command /// maximum brightness value (minus offset). /// SetKeyLightBright, + /// + /// Gets the EC firmware version and date for the current laptop. + /// + /// + /// This command does not take any data. + /// + /// The result is sent to the caller as a + /// message. + /// + /// + GetFirmVer, } /// diff --git a/YAMDCC.IPC/ServiceResponse.cs b/YAMDCC.IPC/ServiceResponse.cs index a47c1ea..5869fd8 100644 --- a/YAMDCC.IPC/ServiceResponse.cs +++ b/YAMDCC.IPC/ServiceResponse.cs @@ -103,6 +103,15 @@ public enum Response /// /// KeyLightBright, + /// + /// The result of a command. + /// + /// + /// This response's field + /// includes an instance containing the + /// firmware version and date. + /// + FirmVer, } /// diff --git a/YAMDCC.Service/FanControlService.cs b/YAMDCC.Service/FanControlService.cs index bbf2ad9..b70a216 100644 --- a/YAMDCC.Service/FanControlService.cs +++ b/YAMDCC.Service/FanControlService.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Globalization; using System.IO; using System.IO.Pipes; using System.ServiceProcess; @@ -48,6 +49,8 @@ internal sealed class FanControlService : ServiceBase private readonly EC _EC; private readonly Timer CooldownTimer = new(1000); + + private EcInfo EcInfo; #endregion /// @@ -106,17 +109,21 @@ protected override void OnStart(string[] args) } Log.Info(Strings.GetString("drvLoadSuccess")); - if (Log.FileLevel == LogLevel.Debug) + + if (confLoaded && Config.FirmVerSupported) { + EcInfo = new(); if (_EC.ReadString(0xA0, 0xC, out string ecVer) && ecVer.Length == 0xC) { + EcInfo.Version = ecVer; Log.Debug($"EC firmware version: {ecVer}"); } if (_EC.ReadString(0xAC, 0x10, out string ecDate) && ecDate.Length == 0x10) { - Log.Debug("EC firmware date: " + - $"{ecDate.Substring(2, 2)}/{ecDate.Substring(0, 2)}/{ecDate.Substring(4, 4)} " + - $"{ecDate.Substring(8, 2)}:{ecDate.Substring(11, 2)}:{ecDate.Substring(14, 2)}"); + string temp = $"{ecDate.Substring(4, 4)}-{ecDate.Substring(0, 2)}-{ecDate.Substring(2, 2)}" + + $"T{ecDate.Substring(8, 2)}:{ecDate.Substring(11, 2)}:{ecDate.Substring(14, 2)}"; + EcInfo.Date = DateTime.ParseExact(temp, "s", CultureInfo.InvariantCulture); + Log.Debug($"EC firmware date: {EcInfo.Date:G}"); } } @@ -309,6 +316,13 @@ private void IPCClientMessage(object sender, PipeMessageEventArgs Writing fan mode setting... + + Sending firmware version to client {0}... + \ No newline at end of file