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 973ddac + 8d89a04 commit 76f93a6
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 30 deletions.
4 changes: 4 additions & 0 deletions app/ASUSWmi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class ASUSWmi
public const uint DevsGPUFanCurve = 0x00110025;
public const uint DevsMidFanCurve = 0x00110032;

public const int Temp_CPU = 0x00120094;
public const int Temp_GPU = 0x00120097;


public const int PPT_TotalA0 = 0x001200A0; // Total PPT on 2022 and CPU PPT on 2021
public const int PPT_EDCA1 = 0x001200A1; // CPU EDC
public const int PPT_TDCA2 = 0x001200A2; // CPU TDC
Expand Down
2 changes: 1 addition & 1 deletion app/Aura.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static void ApplyBrightness(int brightness)
{
HidDevice[] HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray();

byte[] msg = { 0x5a, 0xba, 0xc5, 0xc4, (byte)brightness };
byte[] msg = { 0x5d, 0xba, 0xc5, 0xc4, (byte)brightness };

foreach (HidDevice device in HidDeviceList)
if (device.IsConnected && device.Description.Contains("HID"))
Expand Down
1 change: 1 addition & 0 deletions app/ControlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static class ControlHelper
static bool _invert = false;
static bool _darkTheme = false;


static float _scale = 1;

static Color formBack;
Expand Down
42 changes: 37 additions & 5 deletions app/HardwareMonitor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using GHelper;
using GHelper.Gpu;

public static class HardwareMonitor
Expand All @@ -9,16 +10,43 @@ public static class HardwareMonitor
public static float? batteryDischarge = -1;
public static int? gpuTemp = null;

public static string? cpuFan;
public static string? gpuFan;
public static string? midFan;

private static string FormatFan(int fan)
{
// fix for old models
if (fan < 0)
{
fan += 65536;
if (fan <= 0 || fan > 100) return null; //nothing reasonable
}

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
}

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
{
var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true);
cpuTemp = ct.NextValue() - 273;
ct.Dispose();
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");
Expand All @@ -37,8 +65,12 @@ public static void ReadSensors()

try
{
gpuTemp = GpuTemperatureProvider?.GetCurrentTemperature();
} catch (Exception ex) {
gpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_GPU);
if (gpuTemp < 0)
gpuTemp = GpuTemperatureProvider?.GetCurrentTemperature();

}
catch (Exception ex) {
gpuTemp = null;
Logger.WriteLine("Failed reading GPU temp");
Logger.WriteLine(ex.ToString());
Expand Down
42 changes: 19 additions & 23 deletions app/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public SettingsForm()

Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(5));
await Task.Delay(TimeSpan.FromSeconds(1));
CheckForUpdatesAsync();
});

Expand Down Expand Up @@ -828,26 +828,12 @@ private void ButtonEco_Click(object? sender, EventArgs e)
}


private static string FormatFan(int fan)
{
if (fan < 0) return null;

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
}

private static void RefreshSensors(bool force = false)
{

if (!force && Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastRefresh) < 2000) return;
lastRefresh = DateTimeOffset.Now.ToUnixTimeMilliseconds();

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

string cpuTemp = "";
string gpuTemp = "";
string battery = "";
Expand All @@ -867,12 +853,16 @@ private static void RefreshSensors(bool force = false)

Program.settingsForm.BeginInvoke(delegate
{
Program.settingsForm.labelCPUFan.Text = "CPU" + cpuTemp + cpuFan;
Program.settingsForm.labelGPUFan.Text = "GPU" + gpuTemp + gpuFan;
if (midFan is not null) Program.settingsForm.labelMidFan.Text = "Mid" + midFan;
Program.settingsForm.labelCPUFan.Text = "CPU" + cpuTemp + HardwareMonitor.cpuFan;
Program.settingsForm.labelGPUFan.Text = "GPU" + gpuTemp + HardwareMonitor.gpuFan;
if (HardwareMonitor.midFan is not null)
Program.settingsForm.labelMidFan.Text = "Mid" + HardwareMonitor.midFan;

Program.settingsForm.labelBattery.Text = battery;

Program.trayIcon.Text = "CPU" + cpuTemp + cpuFan + "\n" + "GPU" + gpuTemp + gpuFan + ((battery.Length > 0) ? ("\n" + battery) : "");
Program.trayIcon.Text = "CPU" + cpuTemp + HardwareMonitor.cpuFan + "\n"
+ "GPU" + gpuTemp + HardwareMonitor.gpuFan +
((battery.Length > 0) ? ("\n" + battery) : "");

});
}
Expand Down Expand Up @@ -1035,9 +1025,11 @@ public void AutoKeyboard()
if (Program.config.getConfig("keyboard_auto") != 1) return;

if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)
Program.wmi.DeviceSet(ASUSWmi.UniversalControl, ASUSWmi.KB_Light_Up);
Aura.ApplyBrightness(3);
//Program.wmi.DeviceSet(ASUSWmi.UniversalControl, ASUSWmi.KB_Light_Up);
else
Program.wmi.DeviceSet(ASUSWmi.UniversalControl, ASUSWmi.KB_Light_Down);
Aura.ApplyBrightness(0);
//Program.wmi.DeviceSet(ASUSWmi.UniversalControl, ASUSWmi.KB_Light_Down);


}
Expand Down Expand Up @@ -1119,6 +1111,9 @@ public int InitGPUMode()
int eco = Program.wmi.DeviceGet(ASUSWmi.GPUEco);
int mux = Program.wmi.DeviceGet(ASUSWmi.GPUMux);

//Logger.WriteLine("Eco flag : " + eco);
//Logger.WriteLine("Mux flag : " + mux);

int GpuMode;

if (mux == 0)
Expand Down Expand Up @@ -1170,11 +1165,12 @@ public void SetEcoGPU(int eco)
}

Program.wmi.DeviceSet(ASUSWmi.GPUEco, eco);
Logger.WriteLine("Setting Eco mode: " + eco);

Program.settingsForm.BeginInvoke(delegate
{
InitGPUMode();
HardwareMonitor.RecreateGpuTemperatureProviderWithDelay();
Thread.Sleep(500);
InitGPUMode();
AutoScreen();
});
});
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [G-Helper (GHelper)](https://github.com/seerge/g-helper)
# [G-Helper](https://github.com/seerge/g-helper)

[![Github all releases](https://img.shields.io/github/downloads/seerge/g-helper/total.svg)](https://GitHub.com/seerge/g-helper/releases/) [![GitHub release](https://img.shields.io/github/release/seerge/g-helper.svg)](https://GitHub.com/seerge/g-helper/releases/) [![GitHub stars](https://img.shields.io/github/stars/seerge/g-helper.svg?style=social&label=Star)](https://GitHub.com/seerge/g-helper/stargazers/)

Expand All @@ -16,6 +16,7 @@ A small utility that allows you to do almost everything you could do with Armour
### [: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 76f93a6

Please sign in to comment.