Skip to content

Commit

Permalink
Merge branch 'seerge:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
HamzaYslmn authored Mar 29, 2023
2 parents 76f93a6 + a7a7170 commit 8e8e2af
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 45 deletions.
2 changes: 2 additions & 0 deletions app/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public string getParamName(int device, string paramName = "fan_profile")

if (device == 1)
name = "gpu";
else if (device == 2)
name = "mid";
else
name = "cpu";

Expand Down
20 changes: 17 additions & 3 deletions app/Aura.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,30 @@ public static Dictionary<int, string> GetSpeeds()
{ 2, "Hızlı" }
};
}
public static Dictionary<int, string> GetModes()
{
return new Dictionary<int, string>

static Dictionary<int, string> _modes = new Dictionary<int, string>
{
{ 0, "Sabit" },
{ 1, "Nefes" },
{ 2, "Renk Geçişi" },
{ 3, "GökKuşağı" },
{ 10, "Flaş" },
};

public static Dictionary<int, string> GetModes()
{
if (Program.config.ContainsModel("TUF"))
{
_modes.Remove(3);
}

if (Program.config.ContainsModel("401"))
{
_modes.Remove(2);
_modes.Remove(3);
}

return _modes;
}


Expand Down
12 changes: 3 additions & 9 deletions app/Fans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static string ChartPercToRPM(int percentage, string unit = "")
{
if (percentage == 0) return "OFF";

return (200 * Math.Round((float)(MinRPM + (MaxRPM - MinRPM) * percentage * 0.01) / 200)).ToString() + unit;
return (200 * Math.Round((float)(MinRPM*100 + (MaxRPM - MinRPM) * percentage) / 200)).ToString() + unit;
}

void SetChart(Chart chart, int device)
Expand Down Expand Up @@ -89,14 +89,8 @@ public Fans()
InitializeComponent();
InitTheme();

MinRPM = 1800;

if (Program.config.ContainsModel("401"))
MaxRPM = 7200;
else if (Program.config.ContainsModel("503"))
MaxRPM = 6800;
else
MaxRPM = 5800;
MinRPM = 18;
MaxRPM = HardwareMonitor.GetFanMax();



Expand Down
2 changes: 1 addition & 1 deletion app/GHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PlatformTarget>x64</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.42</AssemblyVersion>
<AssemblyVersion>0.43</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
63 changes: 38 additions & 25 deletions app/HardwareMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ public static class HardwareMonitor
public static string? gpuFan;
public static string? midFan;

public static int GetFanMax()
{
int max = 58;
if (Program.config.ContainsModel("401")) max = 72;
else if (Program.config.ContainsModel("503")) max = 68;

return Math.Max(max, Program.config.getConfig("fan_max"));
}

public static void SetFanMax(int fan)
{
Program.config.setConfig("fan_max", fan);
}
private static string FormatFan(int fan)
{
// fix for old models
Expand All @@ -23,51 +36,40 @@ private static string FormatFan(int fan)
if (fan <= 0 || fan > 100) return null; //nothing reasonable
}

int fanMax = GetFanMax();
if (fan > fanMax) SetFanMax(fan);

if (Program.config.getConfig("fan_rpm") == 1)
return " Fan: " + (fan * 100).ToString() + "RPM";
else
return " Fan: " + Math.Min(Math.Round(fan / 0.6), 100).ToString() + "%"; // relatively to 6000 rpm
return " Fan: " + Math.Min(Math.Round((float)fan/fanMax*100), 100).ToString() + "%"; // relatively to 6000 rpm
}

public static void ReadSensors()
{
cpuTemp = -1;
batteryDischarge = -1;

cpuFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.CPU_Fan));
gpuFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.GPU_Fan));
midFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.Mid_Fan));

try
{
cpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_CPU);
if (cpuTemp < 0)
{
var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true);
cpuTemp = ct.NextValue() - 273;
ct.Dispose();
}
} catch
{
Logger.WriteLine("Failed reading CPU temp");
}
cpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_CPU);
gpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_GPU);

try
if (cpuTemp < 0) try
{
var cb = new PerformanceCounter("Power Meter", "Power", "Power Meter (0)", true);
batteryDischarge = cb.NextValue() / 1000;
cb.Dispose();

var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true);
cpuTemp = ct.NextValue() - 273;
ct.Dispose();
} catch
{
Logger.WriteLine("Failed reading Battery discharge");
Logger.WriteLine("Failed reading CPU temp");
}

try
if (gpuTemp < 0) try
{
gpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_GPU);
if (gpuTemp < 0)
gpuTemp = GpuTemperatureProvider?.GetCurrentTemperature();
if (GpuTemperatureProvider is null) RecreateGpuTemperatureProvider();
gpuTemp = GpuTemperatureProvider?.GetCurrentTemperature();

}
catch (Exception ex) {
Expand All @@ -76,6 +78,17 @@ public static void ReadSensors()
Logger.WriteLine(ex.ToString());
}

try
{
var cb = new PerformanceCounter("Power Meter", "Power", "Power Meter (0)", true);
batteryDischarge = cb.NextValue() / 1000;
cb.Dispose();

}
catch
{
Logger.WriteLine("Failed reading Battery discharge");
}
}

public static void RecreateGpuTemperatureProviderWithDelay() {
Expand Down
5 changes: 1 addition & 4 deletions app/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ public static void Main()

Application.EnableVisualStyles();

SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);

var ds = settingsForm.Handle;

trayIcon.MouseClick += TrayIcon_MouseClick;


wmi.SubscribeToEvents(WatcherEventArrived);

settingsForm.InitGPUMode();
Expand All @@ -75,10 +72,10 @@ public static void Main()
settingsForm.SetStartupCheck(Startup.IsScheduled());

SetAutoModes();
HardwareMonitor.RecreateGpuTemperatureProvider();

// Subscribing for system power change events
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;


if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\'))
Expand Down
4 changes: 2 additions & 2 deletions app/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public SettingsForm()
sliderBattery.ValueChanged += SliderBattery_ValueChanged;
Program.trayIcon.MouseMove += TrayIcon_MouseMove;

aTimer = new System.Timers.Timer(500);
aTimer = new System.Timers.Timer(1000);
aTimer.Elapsed += OnTimedEvent;

// Subscribing for monitor power on events
Expand Down Expand Up @@ -878,7 +878,7 @@ private void SettingsForm_VisibleChanged(object? sender, EventArgs e)
this.Top = Screen.FromControl(this).WorkingArea.Height - 10 - this.Height;
this.Activate();

aTimer.Interval = 300;
//aTimer.Interval = 300;
aTimer.Enabled = true;

//RefreshSensors();
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ A small utility that allows you to do almost everything you could do with Armour
1. Seamless and automatic GPU switching (without asking you to close all apps, etc)
2. All performance modes can be fully customized (with fan curves and PPTs)
3. Very lightweight and consumes almost no resources, doesn't install any services. Just a single exe to run
4. Simple and clean UI with easy access to all settings
4. Simple and clean native UI with easy access to all settings

### [:floppy_disk: Download latest release](https://github.com/seerge/g-helper/releases/latest/download/GHelper.zip)

If you like this app, please [star :star: it on Github](https://github.com/seerge/g-helper) and spread a word about it!

If you post about app - please include a link. Thanks.

![Screenshot 2023-03-29 122524](https://user-images.githubusercontent.com/5920850/228505505-c3682509-a9e4-4cac-a5fd-e10d30c477cd.png)
Expand Down

0 comments on commit 8e8e2af

Please sign in to comment.