Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,16 @@ public static bool IsForceMiniled()
{
return ContainsModel("G834JYR") || ContainsModel("G834JZR") || ContainsModel("G634JZR") || ContainsModel("G835LW") || Is("force_miniled");
}
public static int GetFanUnifiedMode()
{
return Get("fan_unified_mode", 0);
}

public static void SetFanUnifiedMode(int mode)
{
Set("fan_unified_mode", mode);
}

public static bool SaveDimming()
{
return Is("save_dimming");
Expand All @@ -766,6 +776,4 @@ public static bool IsAutoStatusLed()
{
return Is("auto_status_led");
}


}
41 changes: 35 additions & 6 deletions app/Fans.Designer.cs

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

61 changes: 56 additions & 5 deletions app/Fans.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GHelper.Fan;
using GHelper.Fan;
using GHelper.Gpu.NVidia;
using GHelper.Mode;
using GHelper.UI;
Expand Down Expand Up @@ -136,6 +136,10 @@ public Fans()
checkApplyFans.Click += CheckApplyFans_Click;
checkApplyPower.Click += CheckApplyPower_Click;

comboFanUnified.Items.AddRange(new String[] { "Disabled", "GPU Priority", "CPU Priority" });
comboFanUnified.SelectedIndex = AppConfig.GetFanUnifiedMode();
comboFanUnified.SelectedIndexChanged += ComboFanUnified_SelectedIndexChanged;

trackGPUClockLimit.Minimum = NvidiaGpuControl.MinClockLimit;
trackGPUClockLimit.Maximum = NvidiaGpuControl.MaxClockLimit;

Expand Down Expand Up @@ -866,14 +870,18 @@ private void CheckApplyPower_Click(object? sender, EventArgs e)

}

private void ComboFanUnified_SelectedIndexChanged(object? sender, EventArgs e)
{
AppConfig.SetFanUnifiedMode(comboFanUnified.SelectedIndex);
modeControl.AutoFans(true);
}

private void CheckApplyFans_Click(object? sender, EventArgs e)
{
if (sender is null) return;
CheckBox chk = (CheckBox)sender;

AppConfig.SetMode("auto_apply", chk.Checked ? 1 : 0);
modeControl.SetPerformanceMode();

modeControl.AutoFans(true);
}

public void InitAxis()
Expand Down Expand Up @@ -945,6 +953,7 @@ public void InitPower()

}

checkApplyFans.Checked = AppConfig.IsMode("auto_apply");
checkApplyPower.Checked = AppConfig.IsMode("auto_apply_power");

int limit_total = AppConfig.GetMode("limit_total", AsusACPI.DefaultTotal);
Expand Down Expand Up @@ -1372,6 +1381,48 @@ private void AdjustAllLevels(int index, double curXVal, double curYVal, Series s
}
}

}
public static int GetFanSpeedForTemperature(int temp, byte[] curve)
{
int fanSpeed = 0;

for (int i = 0; i < 8; i++)
{
if (curve[i] == 0) continue;

if (temp >= curve[i])
{
fanSpeed = curve[i + 8];
}
else
{
break;
}
}

return fanSpeed;
}

public static byte[] CreateFlatFanCurve(int fanSpeed, byte[]? standardCurve)
{
if (fanSpeed < 0) fanSpeed = 0;
if (fanSpeed > 100) fanSpeed = 100;
byte speed = (byte)fanSpeed;

if (standardCurve is null || standardCurve.Length != 16) {
// Fallback to default temps if something is wrong
standardCurve = new byte[] { 20, 30, 40, 50, 60, 70, 80, 90, 0, 0, 0, 0, 0, 0, 0, 0 };
}

byte[] flatCurve = new byte[16];
// Copy temperature points
Array.Copy(standardCurve, 0, flatCurve, 0, 8);
// Set all speed points to the target speed
for (int i = 8; i < 16; i++) {
flatCurve[i] = speed;
}

return flatCurve;
}

}
}
75 changes: 70 additions & 5 deletions app/Mode/ModeControl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using GHelper.Gpu.NVidia;
using GHelper.Gpu.NVidia;
using GHelper.Helpers;
using GHelper.USB;
using GHelper.Gpu;
using Ryzen;

namespace GHelper.Mode
Expand All @@ -20,6 +21,7 @@ public class ModeControl

static System.Timers.Timer reapplyTimer = default!;
static System.Timers.Timer modeToggleTimer = default!;
static System.Timers.Timer? fanUnifiedTimer;

public ModeControl()
{
Expand Down Expand Up @@ -161,10 +163,70 @@ public void CyclePerformanceMode(bool back = false)

}

private void StopUnifiedFanControl()
{
if (fanUnifiedTimer is not null)
{
fanUnifiedTimer.Stop();
fanUnifiedTimer.Dispose();
fanUnifiedTimer = null;
}
}

private void UnifiedFanTimer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
int fanUnifiedMode = AppConfig.GetFanUnifiedMode();
if (fanUnifiedMode == 0) {
StopUnifiedFanControl();
AutoFans(true);
return;
}

byte[]? priorityCurve;
float? currentTempFloat;

if (fanUnifiedMode == 1) { // GPU Priority
priorityCurve = AppConfig.GetFanConfig(AsusFan.GPU);
currentTempFloat = HardwareControl.GetGPUTemp();
} else { // CPU Priority
priorityCurve = AppConfig.GetFanConfig(AsusFan.CPU);
currentTempFloat = HardwareControl.GetCPUTemp();
}

if (currentTempFloat is null) return;
int currentTemp = (int)currentTempFloat;

if (priorityCurve is null) return;

int fanSpeed = Fans.GetFanSpeedForTemperature(currentTemp, priorityCurve);

byte[] flatCurve = Fans.CreateFlatFanCurve(fanSpeed, priorityCurve);

Program.acpi.SetFanCurve(AsusFan.CPU, flatCurve);
Program.acpi.SetFanCurve(AsusFan.GPU, flatCurve);

}


public void AutoFans(bool force = false)
{
customFans = false;

StopUnifiedFanControl();

int fanUnifiedMode = AppConfig.GetFanUnifiedMode();

if (fanUnifiedMode > 0)
{
fanUnifiedTimer = new System.Timers.Timer(1000);
fanUnifiedTimer.Elapsed += UnifiedFanTimer_Elapsed;
fanUnifiedTimer.Start();
UnifiedFanTimer_Elapsed(null, null);
customFans = true;
SetModeLabel();
return;
}

if (AppConfig.IsMode("auto_apply") || force)
{

Expand All @@ -175,8 +237,11 @@ public void AutoFans(bool force = false)
xgmFan = true;
}

int cpuResult = Program.acpi.SetFanCurve(AsusFan.CPU, AppConfig.GetFanConfig(AsusFan.CPU));
int gpuResult = Program.acpi.SetFanCurve(AsusFan.GPU, AppConfig.GetFanConfig(AsusFan.GPU));
byte[]? cpuFanCurve = AppConfig.GetFanConfig(AsusFan.CPU);
byte[]? gpuFanCurve = AppConfig.GetFanConfig(AsusFan.GPU);

int cpuResult = Program.acpi.SetFanCurve(AsusFan.CPU, cpuFanCurve);
int gpuResult = Program.acpi.SetFanCurve(AsusFan.GPU, gpuFanCurve);

if (AppConfig.Is("mid_fan"))
Program.acpi.SetFanCurve(AsusFan.Mid, AppConfig.GetFanConfig(AsusFan.Mid));
Expand All @@ -185,8 +250,8 @@ public void AutoFans(bool force = false)
// Alternative way to set fan curve
if (cpuResult != 1 || gpuResult != 1)
{
cpuResult = Program.acpi.SetFanRange(AsusFan.CPU, AppConfig.GetFanConfig(AsusFan.CPU));
gpuResult = Program.acpi.SetFanRange(AsusFan.GPU, AppConfig.GetFanConfig(AsusFan.GPU));
cpuResult = Program.acpi.SetFanRange(AsusFan.CPU, cpuFanCurve);
gpuResult = Program.acpi.SetFanRange(AsusFan.GPU, gpuFanCurve);

// Something went wrong, resetting to default profile
if (cpuResult != 1 || gpuResult != 1)
Expand Down