Skip to content

Commit

Permalink
Add per-profile performance mode toggle
Browse files Browse the repository at this point in the history
- Remove support for inequal number of fan profiles per fan config

Closes #37
  • Loading branch information
Sparronator9999 committed Feb 15, 2025
1 parent 3079885 commit 0d48cc6
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 260 deletions.
17 changes: 17 additions & 0 deletions YAMDCC.Config/FanCurveConf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ public sealed class FanCurveConf
[XmlElement]
public string Desc { get; set; }

/// <summary>
/// The <see cref="PerfMode"/> to use with this fan profile,
/// as an index of the available performance modes.
/// </summary>
/// <remarks>
/// <para>
/// This setting is ignored if this <see cref="FanCurveConf"/>
/// is not for the first fan in the computer.
/// </para>
/// <para>
/// Set to -1 to use the default performance mode
/// (as set by <see cref="PerfModeConf.ModeSel"/>).
/// </para>
/// </remarks>
[XmlElement]
public int PerfModeSel { get; set; } = -1;

/// <summary>
/// The fan speeds and associated up and down thresholds.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions YAMDCC.Config/PerfModeConf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public sealed class PerfModeConf
public byte Reg { get; set; }

/// <summary>
/// The currently selected performance mode, as
/// an index of the available performance modes.
/// The default performance mode, as an index of the available
/// performance modes, when not overriden by a <see cref="FanCurveConf"/>.
/// </summary>
[XmlElement]
public int ModeSel { get; set; }
Expand Down
22 changes: 20 additions & 2 deletions YAMDCC.Config/YAMDCC_Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ private bool IsValid()
return false;
}

// all fans must have same number of fan profiles now
if (!FansHaveSameProfCount())
{
return false;
}

// YAMDCC doesn't handle MinSpeed lower than MaxSpeed,
// so return false if MinSpeed is lower or equal to MaxSpeed:
if (cfg.MinSpeed >= cfg.MaxSpeed)
Expand All @@ -270,7 +276,7 @@ private bool IsValid()
// and fan curve registers
// - there are the same amount of up threshold registers
// as down threshold registers
// - there is one more fan curve register than up/down threshold registers
// - there is one more fan profile register than up/down threshold registers
// - there is at least one fan profile to apply (first should be Default)
if (cfg.UpThresholdRegs?.Length < 1 ||
cfg.UpThresholdRegs?.Length != cfg.DownThresholdRegs?.Length ||
Expand All @@ -286,7 +292,7 @@ private bool IsValid()
if (string.IsNullOrEmpty(curveCfg.Name) ||
string.IsNullOrEmpty(curveCfg.Desc) ||
// there should be exactly one temperature threshold
// per fan curve register; if there isn't, return false
// per fan proffile register; if there isn't, return false
curveCfg.TempThresholds?.Count != cfg.FanCurveRegs.Length)
{
return false;
Expand Down Expand Up @@ -415,4 +421,16 @@ private bool IsValid()
// expected to be nonzero.
return true;
}

private bool FansHaveSameProfCount()
{
for (int i = 0; i < FanConfs.Count - 1; i++)
{
if (FanConfs[i].FanCurveConfs.Count != FanConfs[i + 1].FanCurveConfs.Count)
{
return false;
}
}
return true;
}
}
312 changes: 163 additions & 149 deletions YAMDCC.ConfigEditor/MainForm.Designer.cs

Large diffs are not rendered by default.

115 changes: 29 additions & 86 deletions YAMDCC.ConfigEditor/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public MainForm()
tsiProfAdd.ToolTipText = Strings.GetString("ttProfAdd");
tsiProfRen.ToolTipText = Strings.GetString("ttProfRen");
tsiProfChangeDesc.ToolTipText = Strings.GetString("ttProfChangeDesc");
tsiSwitchAll.ToolTipText = Strings.GetString("ttSwitchAll");
tsiECtoConf.ToolTipText = Strings.GetString("ttECtoConf");
tsiProfDel.ToolTipText = Strings.GetString("ttProfDel");
tsiECMon.ToolTipText = Strings.GetString("ttECMon");
Expand Down Expand Up @@ -409,26 +408,6 @@ private void ProfChangeDesc(object sender, EventArgs e)
}
}

private void SwitchAllToggle(object sender, EventArgs e)
{
if (!tsiSwitchAll.Checked)
{
if (FansHaveSameProfCount())
{
tsiSwitchAll.Checked = true;
}
else
{
Utils.ShowError("All fans must have the same number of fan profiles.");
}
}
else
{
tsiSwitchAll.Checked = false;
}

}

private void ECtoConf(object sender, EventArgs e)
{
if (Utils.ShowInfo(Strings.GetString("dlgECtoConfStart"),
Expand Down Expand Up @@ -746,21 +725,18 @@ private void ProfSelChanged(object sender, EventArgs e)
FanConf cfg = Config.FanConfs[cboFanSel.SelectedIndex];
FanCurveConf curveCfg = cfg.FanCurveConfs[cboProfSel.SelectedIndex];

if (tsiSwitchAll.Checked)
for (int i = 0; i < Config.FanConfs.Count; i++)
{
for (int i = 0; i < Config.FanConfs.Count; i++)
{
Config.FanConfs[i].CurveSel = cboProfSel.SelectedIndex;
}
}
else
{
cfg.CurveSel = cboProfSel.SelectedIndex;
Config.FanConfs[i].CurveSel = cboProfSel.SelectedIndex;
}

ttMain.SetToolTip(cboProfSel, Strings.GetString(
"ttProfSel", cfg.FanCurveConfs[cfg.CurveSel].Desc));

cboProfPerfMode.SelectedIndex = Config.FanConfs[0]
.FanCurveConfs[cboProfSel.SelectedIndex].PerfModeSel + 1;
cboProfPerfMode.Enabled = true;

bool enable = curveCfg.Name != "Default";
for (int i = 0; i < numFanSpds.Length; i++)
{
Expand All @@ -784,27 +760,15 @@ private void ProfSelChanged(object sender, EventArgs e)
tsiProfDel.Enabled = enable;
}

private void ProfAdd(object sender, EventArgs e)
private void ProfPerfModeChanged(object sender, EventArgs e)
{
if (tsiSwitchAll.Checked)
{
bool switchAll = tsiSwitchAll.Checked;
tsiSwitchAll.Checked = false;
ProfAdd(0, cboFanSel.Items.Count);
tsiSwitchAll.Checked = switchAll;
}
else
{
ProfAdd(cboFanSel.SelectedIndex, cboFanSel.SelectedIndex + 1);
}

if (!FansHaveSameProfCount())
{
tsiSwitchAll.Checked = false;
}
int i = cboProfPerfMode.SelectedIndex;
Config.FanConfs[0].FanCurveConfs[cboProfSel.SelectedIndex].PerfModeSel = i - 1;
//ttMain.SetToolTip(cboPerfMode,
// Strings.GetString("ttPerfMode", Config.PerfModeConf.PerfModes[i].Desc));
}

private void ProfAdd(int start, int end)
private void ProfAdd(object sender, EventArgs e)
{
FanConf cfg = Config.FanConfs[cboFanSel.SelectedIndex];

Expand All @@ -814,7 +778,7 @@ private void ProfAdd(int start, int end)

if (dlg.ShowDialog() == DialogResult.OK)
{
for (int i = start; i < end; i++)
for (int i = 0; i < cboFanSel.Items.Count; i++)
{
cfg = Config.FanConfs[i];

Expand Down Expand Up @@ -874,32 +838,17 @@ private void btnProfAdd_KeyPress(object sender, KeyPressEventArgs e)

private void ProfDel(object sender, EventArgs e)
{
if (tsiSwitchAll.Checked)
{
ProfDel(0, cboFanSel.Items.Count);
}
else
{
ProfDel(cboFanSel.SelectedIndex, cboFanSel.SelectedIndex + 1);
}

if (!FansHaveSameProfCount())
{
tsiSwitchAll.Checked = false;
}
}
FanConf cfg = Config.FanConfs[cboFanSel.SelectedIndex];
FanCurveConf curveCfg = cfg.FanCurveConfs[cfg.CurveSel];

private void ProfDel(int start, int end)
{
for (int i = start; i < end; i++)
if (curveCfg.Name != "Default" && Utils.ShowWarning(
Strings.GetString("dlgProfDel", curveCfg.Name),
$"Delete fan profile? ({cfg.Name})") == DialogResult.Yes)
{
FanConf cfg = Config.FanConfs[i];
FanCurveConf curveCfg = cfg.FanCurveConfs[cfg.CurveSel];

if (curveCfg.Name != "Default" && Utils.ShowWarning(
Strings.GetString("dlgProfDel", curveCfg.Name),
$"Delete fan profile? ({cfg.Name})") == DialogResult.Yes)
for (int i = 0; i < cboFanSel.Items.Count; i++)
{
cfg = Config.FanConfs[i];

// Remove the fan profile from the config's list
cfg.FanCurveConfs.RemoveAt(cfg.CurveSel);
cfg.CurveSel -= 1;
Expand Down Expand Up @@ -969,6 +918,9 @@ private void PerfModeChange(object sender, EventArgs e)
Config.PerfModeConf.ModeSel = i;
ttMain.SetToolTip(cboPerfMode,
Strings.GetString("ttPerfMode", Config.PerfModeConf.PerfModes[i].Desc));

PerfModeConf pCfg = Config.PerfModeConf;
cboProfPerfMode.Items[0] = $"Default ({pCfg.PerfModes[pCfg.ModeSel].Name})";
}

private void WinFnSwapToggle(object sender, EventArgs e)
Expand Down Expand Up @@ -1118,7 +1070,6 @@ private void LoadConf(string confPath)
private void LoadConf(YAMDCC_Config cfg)
{
DisableAll();
tsiSwitchAll.Checked = FansHaveSameProfCount();

tsiSaveConf.Enabled = true;

Expand Down Expand Up @@ -1172,16 +1123,20 @@ private void LoadConf(YAMDCC_Config cfg)
}

cboPerfMode.Items.Clear();
cboProfPerfMode.Items.Clear();

if (cfg.PerfModeConf is null)
{
ttMain.SetToolTip(cboPerfMode, Strings.GetString("ttNotSupported"));
}
else
{
PerfModeConf perfModeConf = cfg.PerfModeConf;
cboProfPerfMode.Items.Add($"Default ({perfModeConf.PerfModes[perfModeConf.ModeSel].Name})");
for (int i = 0; i < perfModeConf.PerfModes.Count; i++)
{
cboPerfMode.Items.Add(perfModeConf.PerfModes[i].Name);
cboProfPerfMode.Items.Add(perfModeConf.PerfModes[i].Name);
}

cboPerfMode.SelectedIndex = perfModeConf.ModeSel;
Expand Down Expand Up @@ -1279,6 +1234,7 @@ private void DisableAll()
btnProfDel.Enabled = false;
cboFanSel.Enabled = false;
cboProfSel.Enabled = false;
cboProfPerfMode.Enabled = false;
if (tbFanSpds is not null)
{
for (int i = 0; i < tbFanSpds.Length; i++)
Expand Down Expand Up @@ -1315,19 +1271,6 @@ private void ToggleSvcCmds(bool enable)
btnRevert.Enabled = enable;
}

private bool FansHaveSameProfCount()
{
List<FanConf> cfgs = Config.FanConfs;
for (int i = 0; i < cfgs.Count - 1; i++)
{
if (cfgs[i].FanCurveConfs.Count != cfgs[i + 1].FanCurveConfs.Count)
{
return false;
}
}
return true;
}

private void UpdateStatus(StatusCode status, int data = 0)
{
if (AppStatus.Code == status)
Expand Down
5 changes: 1 addition & 4 deletions YAMDCC.ConfigEditor/MainForm.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -150,9 +150,6 @@
<metadata name="tabFanControl.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="flwFanSelect.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tabExtra.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
Expand Down
38 changes: 21 additions & 17 deletions YAMDCC.Service/FanControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ private bool ApplyConf()
}
}

// Write the fan curve to the appropriate registers for each fan:
// Write the fan profile to the appropriate registers for each fan:
int numFanConfs = Config.FanConfs.Count;
for (int i = 0; i < numFanConfs; i++)
{
Expand All @@ -468,27 +468,32 @@ private bool ApplyConf()
}
}
}

// Write the performance mode
if (i == 0)
{
PerfModeConf pModeCfg = Config.PerfModeConf;
if (pModeCfg is not null)
{
Log.Info(Strings.GetString("svcWritePerfMode"));
int idx = curveCfg.PerfModeSel < 0
? pModeCfg.ModeSel
: curveCfg.PerfModeSel;

if (!LogECWriteByte(pModeCfg.Reg, pModeCfg.PerfModes[idx].Value))
{
success = false;
}
}
}
}

// Write the charge threshold:
ChargeLimitConf chgLimCfg = Config.ChargeLimitConf;
if (chgLimCfg is not null)
{
Log.Info(Strings.GetString("svcWriteChgLim"));
byte value = (byte)(chgLimCfg.MinVal + chgLimCfg.CurVal);
if (!LogECWriteByte(chgLimCfg.Reg, value))
{
success = false;
}
}

// Write the performance mode
PerfModeConf pModeCfg = Config.PerfModeConf;
if (pModeCfg is not null)
{
Log.Info(Strings.GetString("svcWritePerfMode"));
byte value = pModeCfg.PerfModes[pModeCfg.ModeSel].Value;
if (!LogECWriteByte(pModeCfg.Reg, value))
if (!LogECWriteByte(chgLimCfg.Reg, (byte)(chgLimCfg.MinVal + chgLimCfg.CurVal)))
{
success = false;
}
Expand All @@ -499,8 +504,7 @@ private bool ApplyConf()
if (fModeCfg is not null)
{
Log.Info(Strings.GetString("svcWriteFanMode"));
byte value = fModeCfg.FanModes[fModeCfg.ModeSel].Value;
if (!LogECWriteByte(fModeCfg.Reg, value))
if (!LogECWriteByte(fModeCfg.Reg, fModeCfg.FanModes[fModeCfg.ModeSel].Value))
{
success = false;
}
Expand Down

2 comments on commit 0d48cc6

@porkmanager
Copy link
Contributor

@porkmanager porkmanager commented on 0d48cc6 Feb 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as I expected. Thank you bro.
Few moments, with this feature, the UI becomes a bit complicated, and the Performance Mode in the "Extra" tab doesn't override(or it is disabled?) selected performance mode in the Fan control tab.
Edit.
Ah, i understood. I have not noticed that in the fan control tab in the Perf mode selector exist (default) option

@Sparronator9999
Copy link
Owner Author

@Sparronator9999 Sparronator9999 commented on 0d48cc6 Feb 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I made it so that you can set a default performance mode, then override it per-profile. This way the global performance mode stays compatible with older YAMDCC versions too :)

the UI becomes a bit complicated

There aren't many spots to put a per-profile performance mode setting without making it confusing to the user...

For example, if I put it next to the "Full blast" check box, it will remain visible on all tabs (including with the global performance mode!) and might cause confusion.

Please sign in to comment.