Skip to content

Commit

Permalink
Merge branch 'main' into cpu-auto-tdp
Browse files Browse the repository at this point in the history
  • Loading branch information
IceStormNG committed Oct 15, 2024
2 parents 40a9750 + f6f15aa commit 63f57da
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public static bool IsInvertedFNLock()

public static bool IsOLED()
{
return ContainsModel("OLED") || IsSlash() || ContainsModel("M7600") || ContainsModel("UX64") || ContainsModel("UX34") || ContainsModel("UX53") || ContainsModel("K360") || ContainsModel("X150") || ContainsModel("M350") || ContainsModel("K650") || ContainsModel("UM53") || ContainsModel("K660") || ContainsModel("UX84") || ContainsModel("M650") || ContainsModel("M550") || ContainsModel("K340") || ContainsModel("K350") || ContainsModel("M140") || ContainsModel("UM340") || ContainsModel("S540") || ContainsModel("M7400") || ContainsModel("N650") || ContainsModel("HN7306") || ContainsModel("H7606") || ContainsModel("UX5406") || ContainsModel("UM5606");
return ContainsModel("OLED") || IsSlash() || ContainsModel("M7600") || ContainsModel("UX64") || ContainsModel("UX34") || ContainsModel("UX53") || ContainsModel("K360") || ContainsModel("X150") || ContainsModel("M350") || ContainsModel("K650") || ContainsModel("UM53") || ContainsModel("K660") || ContainsModel("UX84") || ContainsModel("M650") || ContainsModel("M550") || ContainsModel("K340") || ContainsModel("K350") || ContainsModel("M140") || ContainsModel("UM340") || ContainsModel("S540") || ContainsModel("M7400") || ContainsModel("N650") || ContainsModel("HN7306") || ContainsModel("H7606") || ContainsModel("UX5406") || ContainsModel("M5606");
}

public static bool IsNoOverdrive()
Expand Down Expand Up @@ -707,7 +707,7 @@ public static bool IsDynamicLighting()

public static bool IsForceMiniled()
{
return ContainsModel("G834JYR") || Is("force_miniled");
return ContainsModel("G834JYR") || ContainsModel("G834JZR") || Is("force_miniled");
}

public static bool SaveDimming()
Expand Down
15 changes: 11 additions & 4 deletions app/Display/ScreenControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ public class ScreenControl
{

public const int MAX_REFRESH = 1000;
public static int MIN_RATE = AppConfig.Get("min_rate", 60);
public static int MAX_RATE = AppConfig.Get("max_rate");

public static int GetMaxRate(string? laptopScreen)
{
if (MAX_RATE > 0) return MAX_RATE;
else return ScreenNative.GetMaxRefreshRate(laptopScreen);
}

public void AutoScreen(bool force = false)
{
Expand All @@ -15,7 +22,7 @@ public void AutoScreen(bool force = false)
if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)
SetScreen(MAX_REFRESH, 1);
else
SetScreen(60, 0);
SetScreen(MIN_RATE, 0);
}
else
{
Expand All @@ -29,7 +36,7 @@ public void ToggleScreenRate()
var refreshRate = ScreenNative.GetRefreshRate(laptopScreen);
if (refreshRate < 0) return;

ScreenNative.SetRefreshRate(laptopScreen, refreshRate > 60 ? 60 : ScreenNative.GetMaxRefreshRate(laptopScreen));
ScreenNative.SetRefreshRate(laptopScreen, refreshRate > MIN_RATE ? MIN_RATE : GetMaxRate(laptopScreen));
InitScreen();
}

Expand All @@ -43,7 +50,7 @@ public void SetScreen(int frequency = -1, int overdrive = -1, int miniled = -1)

if (frequency >= MAX_REFRESH)
{
frequency = ScreenNative.GetMaxRefreshRate(laptopScreen);
frequency = GetMaxRate(laptopScreen);
}

if (frequency > 0 && frequency != refreshRate)
Expand Down Expand Up @@ -151,7 +158,7 @@ public void InitScreen()
{
var laptopScreen = ScreenNative.FindLaptopScreen();
int frequency = ScreenNative.GetRefreshRate(laptopScreen);
int maxFrequency = ScreenNative.GetMaxRefreshRate(laptopScreen);
int maxFrequency = GetMaxRate(laptopScreen);

if (maxFrequency > 0) AppConfig.Set("max_frequency", maxFrequency);
else maxFrequency = AppConfig.Get("max_frequency");
Expand Down
40 changes: 33 additions & 7 deletions app/Display/VisualControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GHelper.Helpers;
using Microsoft.Win32;
using System.Management;

namespace GHelper.Display
Expand Down Expand Up @@ -37,6 +38,7 @@ public enum SplendidCommand : int
Cinema = 25,
Vivid = 13,
Eyecare = 17,
Disabled = 18,
}
public static class VisualControl
{
Expand Down Expand Up @@ -99,15 +101,15 @@ public static Dictionary<SplendidGamut, string> GetGamutModes()
foreach (FileInfo icm in icms)
{
//Logger.WriteLine(icm.FullName);

if (icm.Name.Contains("sRGB"))
{
try
{
_modes.Add(isVivo ? SplendidGamut.VivoSRGB : SplendidGamut.sRGB, "Gamut: sRGB");
Logger.WriteLine(icm.FullName + " sRGB");
}
catch
catch
{
}
}
Expand Down Expand Up @@ -175,7 +177,8 @@ public static Dictionary<SplendidCommand, string> GetVisualModes()
{ SplendidCommand.FPS, "FPS"},
{ SplendidCommand.Cinema, "Cinema"},
{ SplendidCommand.Vivid, "Vivid" },
{ SplendidCommand.Eyecare, "Eyecare"}
{ SplendidCommand.Eyecare, "Eyecare"},
{ SplendidCommand.Disabled, "Disabled"}
};
}

Expand Down Expand Up @@ -205,6 +208,20 @@ public static Dictionary<int, string> GetEyeCares()
};
}

const string GameVisualKey = @"HKEY_CURRENT_USER\Software\ASUS\ARMOURY CRATE Service\GameVisual";
const string GameVisualValue = "ActiveGVStatus";

public static bool IsEnabled()
{
var status = (int?)Registry.GetValue(GameVisualKey, GameVisualValue, 1);
return status > 0;
}

public static void SetRegStatus(int status = 1)
{
Registry.SetValue(GameVisualKey, GameVisualValue, status, RegistryValueKind.DWord);
}

public static void SetGamut(int mode = -1)
{
if (skipGamut) return;
Expand Down Expand Up @@ -235,7 +252,7 @@ public static void SetGamut(int mode = -1)
public static void SetVisual(SplendidCommand mode = SplendidCommand.Default, int whiteBalance = DefaultColorTemp, bool init = false)
{
if (mode == SplendidCommand.None) return;
if ((mode == SplendidCommand.Default || mode == SplendidCommand.VivoNormal) && init) return; // Skip default setting on init
if ((mode == SplendidCommand.Disabled || mode == SplendidCommand.Default || mode == SplendidCommand.VivoNormal) && init) return; // Skip default setting on init

if (!forceVisual && ScreenCCD.GetHDRStatus(true)) return;
if (!forceVisual && ScreenNative.GetRefreshRate(ScreenNative.FindLaptopScreen(true)) < 0) return;
Expand All @@ -245,12 +262,16 @@ public static void SetVisual(SplendidCommand mode = SplendidCommand.Default, int

if (whiteBalance != DefaultColorTemp && !init) ProcessHelper.RunAsAdmin();

int? balance;
int? balance = null;
int command = 0;

switch (mode)
{
case SplendidCommand.Disabled:
command = 2;
break;
case SplendidCommand.Eyecare:
balance = 2;
balance = 4;
break;
case SplendidCommand.VivoNormal:
case SplendidCommand.VivoVivid:
Expand All @@ -264,7 +285,7 @@ public static void SetVisual(SplendidCommand mode = SplendidCommand.Default, int
break;
}

var result = RunSplendid(mode, 0, balance);
int result = RunSplendid(mode, command, balance);
if (result == 0) return;
if (result == -1)
{
Expand Down Expand Up @@ -321,6 +342,11 @@ private static int RunSplendid(SplendidCommand command, int? param1 = null, int?
var result = ProcessHelper.RunCMD(splendid, (int)command + " " + param1 + " " + param2);
if (result.Contains("file not exist") || (result.Length == 0 && !isVivo)) return 1;
if (result.Contains("return code: -1")) return -1;
if (result.Contains("Visual is disabled"))
{
SetRegStatus(1);
return 1;
}
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion app/GHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.195</AssemblyVersion>
<AssemblyVersion>0.196</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
26 changes: 24 additions & 2 deletions app/HardwareControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class HardwareControl
public static decimal? fullCapacity;
public static decimal? chargeCapacity;


public static string? batteryCharge;

public static string? cpuFan;
public static string? gpuFan;
Expand All @@ -34,6 +34,20 @@ public static class HardwareControl

static long lastUpdate;

static bool _chargeWatt = AppConfig.Is("charge_watt");
public static bool chargeWatt
{
get
{
return _chargeWatt;
}
set
{
AppConfig.Set("charge_watt", value ? 1 : 0);
_chargeWatt = value;
}
}

private static int GetGpuUse()
{
try
Expand Down Expand Up @@ -226,8 +240,16 @@ public static void ReadSensors()

if (fullCapacity > 0 && chargeCapacity > 0)
{
batteryCapacity = Math.Min(100, ((decimal)chargeCapacity / (decimal)fullCapacity) * 100);
batteryCapacity = Math.Min(100, (decimal)chargeCapacity / (decimal)fullCapacity * 100);
if (batteryCapacity > 99) BatteryControl.UnSetBatteryLimitFull();
if (chargeWatt)
{
batteryCharge = Math.Round((decimal)chargeCapacity / 1000, 1).ToString() + "Wh";
}
else
{
batteryCharge = Math.Round(batteryCapacity, 1) + "%";
}
}


Expand Down
8 changes: 8 additions & 0 deletions app/Input/KeyboardListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class KeyboardListener
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
Action<int> _handler;

static int retry = 0;

public KeyboardListener(Action<int> KeyHandler)
{
_handler = KeyHandler;
Expand Down Expand Up @@ -67,6 +69,12 @@ private void Listen()
catch (Exception ex)
{
Logger.WriteLine($"Listener exited: {ex.Message}");
if (retry++ < 2)
{
Thread.Sleep(300);
Logger.WriteLine($"Restarting listener {retry}");
Listen();
}
}

}
Expand Down
25 changes: 18 additions & 7 deletions app/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public SettingsForm()

labelCharge.MouseEnter += PanelBattery_MouseEnter;
labelCharge.MouseLeave += PanelBattery_MouseLeave;
labelBattery.Click += LabelBattery_Click;

buttonPeripheral1.Click += ButtonPeripheral_Click;
buttonPeripheral2.Click += ButtonPeripheral_Click;
Expand Down Expand Up @@ -288,6 +289,12 @@ public SettingsForm()
InitVisual();
}

private void LabelBattery_Click(object? sender, EventArgs e)
{
HardwareControl.chargeWatt = !HardwareControl.chargeWatt;
RefreshSensors(true);
}

private void ButtonDonate_Click(object? sender, EventArgs e)
{
AppConfig.Set("donate_click", 1);
Expand Down Expand Up @@ -881,7 +888,7 @@ private void Button120Hz_MouseHover(object? sender, EventArgs e)

private void Button60Hz_MouseHover(object? sender, EventArgs e)
{
labelTipScreen.Text = Properties.Strings.MinRefreshTooltip;
labelTipScreen.Text = Properties.Strings.MinRefreshTooltip.Replace("60", ScreenControl.MIN_RATE.ToString());
}

private void ButtonScreen_MouseLeave(object? sender, EventArgs e)
Expand All @@ -891,7 +898,7 @@ private void ButtonScreen_MouseLeave(object? sender, EventArgs e)

private void ButtonScreenAuto_MouseHover(object? sender, EventArgs e)
{
labelTipScreen.Text = Properties.Strings.AutoRefreshTooltip;
labelTipScreen.Text = Properties.Strings.AutoRefreshTooltip.Replace("60", ScreenControl.MIN_RATE.ToString());
}

private void ButtonUltimate_MouseHover(object? sender, EventArgs e)
Expand Down Expand Up @@ -1246,7 +1253,7 @@ private void Button120Hz_Click(object? sender, EventArgs e)
private void Button60Hz_Click(object? sender, EventArgs e)
{
AppConfig.Set("screen_auto", 0);
screenControl.SetScreen(60, 0);
screenControl.SetScreen(ScreenControl.MIN_RATE, 0);
}


Expand Down Expand Up @@ -1277,16 +1284,18 @@ public void VisualiseScreen(bool screenEnabled, bool screenAuto, int frequency,
{
buttonScreenAuto.Activated = true;
}
else if (frequency == 60)
else if (frequency == ScreenControl.MIN_RATE)
{
button60Hz.Activated = true;
}
else if (frequency > 60)
else if (frequency > ScreenControl.MIN_RATE)
{
button120Hz.Activated = true;
}

if (maxFrequency > 60)
button60Hz.Text = ScreenControl.MIN_RATE + "Hz";

if (maxFrequency > ScreenControl.MIN_RATE)
{
button120Hz.Text = maxFrequency.ToString() + "Hz" + (overdriveSetting ? " + OD" : "");
panelScreen.Visible = true;
Expand Down Expand Up @@ -1459,7 +1468,9 @@ public async void RefreshSensors(bool force = false)
cpuTemp = ": " + Math.Round((decimal)HardwareControl.cpuTemp).ToString() + "°C";

if (HardwareControl.batteryCapacity > 0)
charge = Properties.Strings.BatteryCharge + ": " + Math.Round(HardwareControl.batteryCapacity, 1) + "% ";
{
charge = Properties.Strings.BatteryCharge + ": " + HardwareControl.batteryCharge;
}

if (HardwareControl.batteryRate < 0)
battery = Properties.Strings.Discharging + ": " + Math.Round(-(decimal)HardwareControl.batteryRate, 1).ToString() + "W";
Expand Down

0 comments on commit 63f57da

Please sign in to comment.