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 Nov 6, 2024
2 parents 3aee624 + fe30335 commit 72e431c
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# These are supported funding model platforms
custom: https://g-helper.com/support
2 changes: 1 addition & 1 deletion app/Ally/AllyControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ public static void ApplyMode(ControllerMode applyMode = ControllerMode.Auto, boo
if (init)
{
WakeUp();
InputDispatcher.SetBacklightAuto(true);
InputDispatcher.SetBacklightAuto();
}

AsusHid.WriteInput([AsusHid.INPUT_ID, 0xD1, 0x01, 0x01, (byte)_applyMode], "Controller");
Expand Down
2 changes: 1 addition & 1 deletion app/AnimeMatrix/AnimeMatrixDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public void PresentClock()
if (DateTime.Now.Second % 2 != 0) timeFormat = timeFormat.Replace(":", " ");

Clear();
Text(DateTime.Now.ToString(timeFormat), 15, 2, 25);
Text(DateTime.Now.ToString(timeFormat), 15, 7 - FullRows / 2, 25);
Text(DateTime.Now.ToString(dateFormat), 11.5F, 0, 14);
Present();

Expand Down
27 changes: 21 additions & 6 deletions app/Battery/BatteryControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,46 @@

namespace GHelper.Battery
{
internal class BatteryControl
public static class BatteryControl
{

static bool _chargeFull = AppConfig.Is("charge_full");
public static bool chargeFull
{
get
{
return _chargeFull;
}
set
{
AppConfig.Set("charge_full", value ? 1 : 0);
_chargeFull = value;
}
}

public static void ToggleBatteryLimitFull()
{
if (AppConfig.Is("charge_full")) SetBatteryChargeLimit();
if (chargeFull) SetBatteryChargeLimit();
else SetBatteryLimitFull();
}

public static void SetBatteryLimitFull()
{
AppConfig.Set("charge_full", 1);
chargeFull = true;
Program.acpi.DeviceSet(AsusACPI.BatteryLimit, 100, "BatteryLimit");
Program.settingsForm.VisualiseBatteryFull();
}

public static void UnSetBatteryLimitFull()
{
AppConfig.Set("charge_full", 0);
chargeFull = false;
Logger.WriteLine("Battery fully charged");
Program.settingsForm.Invoke(Program.settingsForm.VisualiseBatteryFull);
}

public static void AutoBattery(bool init = false)
{
if (AppConfig.Is("charge_full") && !init) SetBatteryLimitFull();
if (chargeFull && !init) SetBatteryLimitFull();
else SetBatteryChargeLimit();
}

Expand All @@ -46,7 +61,7 @@ public static void SetBatteryChargeLimit(int limit = -1)
Program.acpi.DeviceSet(AsusACPI.BatteryLimit, limit, "BatteryLimit");

AppConfig.Set("charge_limit", limit);
AppConfig.Set("charge_full", 0);
chargeFull = false;

Program.settingsForm.VisualiseBattery(limit);
}
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.197</AssemblyVersion>
<AssemblyVersion>0.198</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
4 changes: 1 addition & 3 deletions app/HardwareControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public static void ReadSensors()
if (fullCapacity > 0 && chargeCapacity > 0)
{
batteryCapacity = Math.Min(100, (decimal)chargeCapacity / (decimal)fullCapacity * 100);
if (batteryCapacity > 99) BatteryControl.UnSetBatteryLimitFull();
if (batteryCapacity > 99 && BatteryControl.chargeFull) BatteryControl.UnSetBatteryLimitFull();
if (chargeWatt)
{
batteryCharge = Math.Round((decimal)chargeCapacity / 1000, 1).ToString() + "Wh";
Expand All @@ -251,8 +251,6 @@ public static void ReadSensors()
batteryCharge = Math.Round(batteryCapacity, 1) + "%";
}
}


}

public static bool IsUsedGPU(int threshold = 10)
Expand Down
66 changes: 36 additions & 30 deletions app/Input/InputDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ public class InputDispatcher
{
System.Timers.Timer timer = new System.Timers.Timer(1000);
public static bool backlightActivity = true;
public static bool lidClose = false;

public static Keys keyProfile = Keys.F5;
public static Keys keyApp = Keys.F12;
public static Keys keyProfile = (Keys)AppConfig.Get("keybind_profile", (int)Keys.F5);
public static Keys keyApp = (Keys)AppConfig.Get("keybind_app", (int)Keys.F12);

public static Keys keyProfile0 = (Keys)AppConfig.Get("keybind_profile_0", (int)Keys.F17);
public static Keys keyProfile1 = (Keys)AppConfig.Get("keybind_profile_1", (int)Keys.F18);
public static Keys keyProfile2 = (Keys)AppConfig.Get("keybind_profile_2", (int)Keys.F16);
public static Keys keyProfile3 = (Keys)AppConfig.Get("keybind_profile_3", (int)Keys.F19);
public static Keys keyProfile4 = (Keys)AppConfig.Get("keybind_profile_4", (int)Keys.F20);

static ModeControl modeControl = Program.modeControl;
static ScreenControl screenControl = new ScreenControl();
Expand Down Expand Up @@ -101,10 +108,6 @@ public void RegisterKeys()
{
hook.UnregisterAll();

// CTRL + SHIFT + F5 to cycle profiles
if (AppConfig.Get("keybind_profile") != -1) keyProfile = (Keys)AppConfig.Get("keybind_profile");
if (AppConfig.Get("keybind_app") != -1) keyApp = (Keys)AppConfig.Get("keybind_app");

string actionM1 = AppConfig.GetString("m1");
string actionM2 = AppConfig.GetString("m2");

Expand All @@ -118,7 +121,6 @@ public void RegisterKeys()

if (!AppConfig.Is("skip_hotkeys"))
{

if (AppConfig.IsDUO())
{
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F7);
Expand All @@ -130,11 +132,11 @@ public void RegisterKeys()
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F14);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F15);

hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F16);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F17);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F18);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F19);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F20);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, keyProfile0);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, keyProfile1);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, keyProfile2);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, keyProfile3);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, keyProfile4);

hook.RegisterHotKey(ModifierKeys.Control, Keys.VolumeDown);
hook.RegisterHotKey(ModifierKeys.Control, Keys.VolumeUp);
Expand Down Expand Up @@ -425,6 +427,12 @@ public void KeyPressed(object sender, KeyPressedEventArgs e)
if (e.Modifier == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt))
{
if (e.Key == keyProfile) modeControl.CyclePerformanceMode(true);

if (e.Key == keyProfile0) modeControl.SetPerformanceMode(0, true);
if (e.Key == keyProfile1) modeControl.SetPerformanceMode(1, true);
if (e.Key == keyProfile2) modeControl.SetPerformanceMode(2, true);
if (e.Key == keyProfile3) modeControl.SetPerformanceMode(3, true);
if (e.Key == keyProfile4) modeControl.SetPerformanceMode(4, true);

switch (e.Key)
{
Expand Down Expand Up @@ -457,21 +465,6 @@ public void KeyPressed(object sender, KeyPressedEventArgs e)
Program.toast.RunToast(Properties.Strings.StandardMode);
Program.settingsForm.gpuControl.SetGPUMode(AsusACPI.GPUModeStandard);
break;
case Keys.F16:
modeControl.SetPerformanceMode(2, true);
break;
case Keys.F17:
modeControl.SetPerformanceMode(0, true);
break;
case Keys.F18:
modeControl.SetPerformanceMode(1, true);
break;
case Keys.F19:
modeControl.SetPerformanceMode(3, true);
break;
case Keys.F20:
modeControl.SetPerformanceMode(4, true);
break;
}
}

Expand Down Expand Up @@ -748,6 +741,7 @@ static void HandleEvent(int EventID)
KeyProcess("fne");
return;
case 174: // FN+F5
case 153: // FN+F5 OLD MODELS
case 157: // Zenbook DUO FN+F
modeControl.CyclePerformanceMode(Control.ModifierKeys == Keys.Shift);
return;
Expand Down Expand Up @@ -879,10 +873,22 @@ public static int GetBacklight()
return Math.Max(Math.Min(3, backlight), 0);
}

public static void SetBacklightAuto(bool init = false)
public static void AutoKeyboard()
{
if (AppConfig.HasTabletMode()) TabletMode();
if (lidClose || AppConfig.Is("skip_aura")) return;

Aura.Init();
Aura.ApplyPower();
Aura.ApplyAura();
SetBacklightAuto();
}


public static void SetBacklightAuto()
{
if (init) Aura.Init();
Aura.ApplyBrightness(GetBacklight(), "Auto", init);
if (lidClose) return;
Aura.ApplyBrightness(GetBacklight(), "Auto");
}

public static void SetBacklight(int delta, bool force = false)
Expand Down
4 changes: 3 additions & 1 deletion app/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using GHelper.Input;
using GHelper.Mode;
using GHelper.Peripherals;
using GHelper.USB;
using Microsoft.Win32;
using Ryzen;
using System.Diagnostics;
Expand Down Expand Up @@ -262,9 +263,10 @@ public static bool SetAutoModes(bool powerChanged = false, bool init = false)
}
else
{
settingsForm.AutoKeyboard();
InputDispatcher.AutoKeyboard();
}

XGM.InitLight();
VisualControl.InitBrightness();

return true;
Expand Down
24 changes: 3 additions & 21 deletions app/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,14 @@ protected override void WndProc(ref Message m)
{
case 0:
Logger.WriteLine("Lid Closed");
InputDispatcher.lidClose = AniMatrixControl.lidClose = true;
Aura.ApplyBrightness(0, "Lid");
AniMatrixControl.lidClose = true;
matrixControl.SetLidMode();
break;
case 1:
Logger.WriteLine("Lid Open");
InputDispatcher.lidClose = AniMatrixControl.lidClose = false;
Aura.ApplyBrightness(InputDispatcher.GetBacklight(), "Lid");
AniMatrixControl.lidClose = false;
matrixControl.SetLidMode();
break;
}
Expand Down Expand Up @@ -1580,24 +1580,6 @@ public void SetModeLabel(string modeText)
}


public void AutoKeyboard()
{

if (!AppConfig.Is("skip_aura"))
{
Aura.ApplyPower();
Aura.ApplyAura();
}

InputDispatcher.SetBacklightAuto(true);

if (Program.acpi.IsXGConnected())
XGM.Light(AppConfig.Is("xmg_light"));

if (AppConfig.HasTabletMode()) InputDispatcher.TabletMode();

}


public void VisualizeXGM(int GPUMode = -1)
{
Expand Down Expand Up @@ -1825,7 +1807,7 @@ public void VisualiseBattery(int limit)

public void VisualiseBatteryFull()
{
if (AppConfig.Is("charge_full"))
if (BatteryControl.chargeFull)
{
buttonBatteryFull.BackColor = colorStandard;
buttonBatteryFull.ForeColor = SystemColors.ControlLightLight;
Expand Down
5 changes: 5 additions & 0 deletions app/USB/Aura.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ private static void ApplyAllyPower(AuraPower flags)
AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xD1, 0x09, 0x01, power }, "Aura");
}

public static void ApplyPowerOff()
{
AsusHid.Write(AuraPowerMessage(new AuraPower()));
}

public static void ApplyPower()
{

Expand Down
4 changes: 4 additions & 0 deletions app/USB/XGM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public static void Light(bool status)
Write(new byte[] { 0x5e, 0xc5, status ? (byte)0x50 : (byte)0 });
}

public static void InitLight()
{
if (Program.acpi.IsXGConnected()) Light(AppConfig.Is("xmg_light"));
}

public static void Reset()
{
Expand Down
4 changes: 1 addition & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
[![GitHub release](https://img.shields.io/github/release/seerge/g-helper)](https://GitHub.com/seerge/g-helper/releases/)
[![Github all releases](https://img.shields.io/github/downloads/seerge/g-helper/total)](https://GitHub.com/seerge/g-helper/releases/) [![GitHub stars](https://img.shields.io/github/stars/seerge/g-helper.svg?style=social)](https://GitHub.com/seerge/g-helper/stargazers/) <sup>[中文版点这里](https://github.com/seerge/g-helper/blob/main/docs/README.zh-CN.md)</sup> <sup>[日本語はこちら](https://github.com/seerge/g-helper/blob/main/docs/README.ja-JP.md)</sup>

Small and lightweight Armoury Crate alternative for Asus laptops offering almost same functionality without extra load and unnecessary services.

Works with all popular models, such as ROG Zephyrus G14, G15, G16, M16, Flow X13, Flow X16, Flow Z13, DUO, TUF Series, Strix or Scar Series, ProArt, Vivobook, Zenbook, ROG Ally or Ally X and many more!
Small and lightweight Armoury Crate alternative for Asus laptops offering almost same functionality with a much smaller footprint. Works with all popular models, such as ROG Zephyrus G14, G15, G16, M16, Flow X13, Flow X16, Flow Z13, DUO, TUF Series, Strix or Scar Series, ProArt, Vivobook, Zenbook, ROG Ally or Ally X and many more!

# [:floppy_disk:Download](https://github.com/seerge/g-helper/releases/latest/download/GHelper.zip)
**⭐ If you like the app - please spread the word about it online**
Expand Down

0 comments on commit 72e431c

Please sign in to comment.