Skip to content

Commit

Permalink
Better EC firmware version support
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Sparronator9999 committed Feb 11, 2025
1 parent c3ee6b3 commit ebe8008
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 11 deletions.
23 changes: 23 additions & 0 deletions YAMDCC.Config/YAMDCC_Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ public sealed class YAMDCC_Config
[XmlElement]
public string Author { get; set; }

/// <summary>
/// Set to <see langword="true"/> if the EC supports reading
/// firmware version from registers <c>0xA0</c>-<c>0xBB</c>.
/// </summary>
/// <remarks>
/// If <see langword="false"/>, the <see cref="FirmVer"/>
/// and <see cref="FirmDate"/> properties are ignored.
/// </remarks>
[XmlElement]
public bool FirmVerSupported { get; set; }

/// <summary>
/// The EC firmware version of the laptop this config was made for.
/// </summary>
[XmlElement]
public string FirmVer { get; set; }

/// <summary>
/// The EC firmware date of the laptop this config was made for.
/// </summary>
[XmlElement]
public DateTime? FirmDate { get; set; }

/// <summary>
/// The list of <see cref="FanConf"/>s associated with the laptop.
/// </summary>
Expand Down
58 changes: 55 additions & 3 deletions YAMDCC.ConfigEditor/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 29 additions & 4 deletions YAMDCC.ConfigEditor/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,20 @@ private void IPCMessage(object sender, PipeMessageEventArgs<ServiceResponse, Ser
}
break;
}
case Response.FirmVer:
{
// no idea how the EcVer struct became a nested
// object array, but this works so keeping it
if (args[0] is object[] obj && obj.Length == 2 &&
obj[0] is string ver && obj[1] is DateTime date)
{
Config.FirmVer = ver;
Config.FirmDate = date;
txtFirmVer.Text = Config.FirmVer;
txtFirmDate.Text = $"{Config.FirmDate:G}";
}
break;
}
}
});
}
Expand Down Expand Up @@ -1004,6 +1018,11 @@ private void btnGetModel_Click(object sender, EventArgs e)
txtModel.Text = pcModel;
Config.Model = pcModel;
}

if (Config.FirmVerSupported)
{
SendSvcMessage(new ServiceCommand(Command.GetFirmVer));
}
}

private void FullBlastToggle(object sender, EventArgs e)
Expand Down Expand Up @@ -1106,9 +1125,17 @@ private void LoadConf(YAMDCC_Config cfg)
txtAuthor.Text = cfg.Author;
txtManufacturer.Text = cfg.Manufacturer;
txtModel.Text = cfg.Model;
if (cfg.FirmVerSupported)
{
txtFirmVer.Text = cfg.FirmVer;
txtFirmDate.Text = $"{cfg.FirmDate:G}";
}
else
{
txtFirmVer.Text = "(unknown)";
txtFirmDate.Text = "(unknown)";
}
txtAuthor.Enabled = true;
txtManufacturer.Enabled = true;
txtModel.Enabled = true;
btnGetModel.Enabled = true;

if (cfg.FullBlastConf is null)
Expand Down Expand Up @@ -1276,8 +1303,6 @@ private void DisableAll()
tbKeyLight.Enabled = false;

txtAuthor.Enabled = false;
txtManufacturer.Enabled = false;
txtModel.Enabled = false;
btnGetModel.Enabled = false;
}

Expand Down
6 changes: 6 additions & 0 deletions YAMDCC.ConfigEditor/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@
<metadata name="lblAuthor.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="lblFirmVer.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="lblFirmDate.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tblApply.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
Expand Down
14 changes: 14 additions & 0 deletions YAMDCC.IPC/EcInfo.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
11 changes: 11 additions & 0 deletions YAMDCC.IPC/ServiceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ public enum Command
/// maximum brightness value (minus offset).
/// </remarks>
SetKeyLightBright,
/// <summary>
/// Gets the EC firmware version and date for the current laptop.
/// </summary>
/// <remarks>
/// <para>This command does not take any data.</para>
/// <para>
/// The result is sent to the caller as a
/// <see cref="Response.FirmVer"/> message.
/// </para>
/// </remarks>
GetFirmVer,
}

/// <summary>
Expand Down
9 changes: 9 additions & 0 deletions YAMDCC.IPC/ServiceResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ public enum Response
/// </para>
/// </remarks>
KeyLightBright,
/// <summary>
/// The result of a <see cref="Command.GetFirmVer"/> command.
/// </summary>
/// <remarks>
/// This response's <see cref="ServiceResponse.Value"/> field
/// includes an <see cref="EcInfo"/> instance containing the
/// firmware version and date.
/// </remarks>
FirmVer,
}

/// <summary>
Expand Down
45 changes: 41 additions & 4 deletions YAMDCC.Service/FanControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +49,8 @@ internal sealed class FanControlService : ServiceBase
private readonly EC _EC;

private readonly Timer CooldownTimer = new(1000);

private EcInfo EcInfo;
#endregion

/// <summary>
Expand Down Expand Up @@ -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}");
}
}

Expand Down Expand Up @@ -309,6 +316,13 @@ private void IPCClientMessage(object sender, PipeMessageEventArgs<ServiceCommand
}
break;
}
case Command.GetFirmVer:
{
parseSuccess = true;
sendSuccessMsg = false;
cmdSuccess = GetFirmVer(id);
break;
}
default: // Unknown command
Log.Error(Strings.GetString("errBadCmd", cmd));
break;
Expand Down Expand Up @@ -650,6 +664,18 @@ private bool SetKeyLight(byte brightness)
return LogECWriteByte(klCfg.Reg, (byte)(brightness + klCfg.MinVal));
}

private bool GetFirmVer(int clientId)
{
if (Config is null || !Config.FirmVerSupported)
{
return false;
}

Log.Debug(Strings.GetString("svcGerFirmVer", clientId));
IPCServer.PushMessage(new ServiceResponse(Response.FirmVer, EcInfo), clientId);
return true;
}

private bool ECtoConf()
{
if (Config is null)
Expand Down Expand Up @@ -682,6 +708,17 @@ private bool ECtoConf()
Config.Model = pcModel;
}

if (Config.FirmVerSupported)
{
Config.FirmVer = EcInfo.Version;
Config.FirmDate = EcInfo.Date;
}
else
{
Config.FirmVer = null;
Config.FirmDate = null;
}

for (int i = 0; i < Config.FanConfs.Count; i++)
{
Log.Info(Strings.GetString("svcReadProfs", i + 1, Config.FanConfs.Count));
Expand Down
3 changes: 3 additions & 0 deletions YAMDCC.Service/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,7 @@ Please run 'YAMDCC.exe' instead.</value>
<data name="svcWriteFanMode" xml:space="preserve">
<value>Writing fan mode setting...</value>
</data>
<data name="svcGetFirmVer" xml:space="preserve">
<value>Sending firmware version to client {0}...</value>
</data>
</root>

0 comments on commit ebe8008

Please sign in to comment.