From 4ee97fdbc4651fe643c0079a4bafe3e578844263 Mon Sep 17 00:00:00 2001
From: Serge <5920850+seerge@users.noreply.github.com>
Date: Sun, 21 May 2023 17:42:15 +0200
Subject: [PATCH] XGM Fixes
---
app/AsusACPI.cs | 7 +-
app/AsusUSB.cs | 11 ++-
app/CustomControls.cs | 5 --
app/Fans.cs | 4 +-
app/GHelper.csproj | 2 +-
...{EventDispatcher.cs => InputDispatcher.cs} | 4 +-
app/Program.cs | 5 +-
app/Settings.cs | 74 +++++++++++++++----
8 files changed, 81 insertions(+), 31 deletions(-)
rename app/{EventDispatcher.cs => InputDispatcher.cs} (99%)
diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs
index 4e9ae38e..15189c2c 100644
--- a/app/AsusACPI.cs
+++ b/app/AsusACPI.cs
@@ -353,10 +353,14 @@ public class AsusACPI
}
+ public static bool IsInvalidCurve(byte[] curve)
+ {
+ return curve.Length != 16 || IsEmptyCurve(curve);
+ }
public static bool IsEmptyCurve(byte[] curve)
{
- return curve.Length != 16 || curve.All(singleByte => singleByte == 0);
+ return curve.All(singleByte => singleByte == 0);
}
public static byte[] FixFanCurve(byte[] curve)
@@ -397,6 +401,7 @@ public class AsusACPI
public bool IsXGConnected()
{
+ //return true;
return DeviceGet(GPUXGConnected) == 1;
}
diff --git a/app/AsusUSB.cs b/app/AsusUSB.cs
index 2a3d41dc..613f8c5a 100644
--- a/app/AsusUSB.cs
+++ b/app/AsusUSB.cs
@@ -288,13 +288,16 @@ namespace GHelper
public static int SetXGM(byte[] msg)
{
- Logger.WriteLine("XGM Payload :" + BitConverter.ToString(msg));
+ //Logger.WriteLine("XGM Payload :" + BitConverter.ToString(msg));
+
+ var payload = new byte[300];
+ Array.Copy(msg, payload, msg.Length);
foreach (HidDevice device in GetHidDevices(new int[] { 0x1970 }, 0))
{
device.OpenDevice();
- Logger.WriteLine("XGM " + device.Attributes.ProductHexId + device.Capabilities.FeatureReportByteLength + ":" + BitConverter.ToString(msg));
- device.WriteFeatureData(msg);
+ Logger.WriteLine("XGM " + device.Attributes.ProductHexId + "|" + device.Capabilities.FeatureReportByteLength + ":" + BitConverter.ToString(msg));
+ device.WriteFeatureData(payload);
device.CloseDevice();
return 1;
}
@@ -316,7 +319,7 @@ namespace GHelper
public static int SetXGMFan(byte[] curve)
{
- if (AsusACPI.IsEmptyCurve(curve)) return -1;
+ if (AsusACPI.IsInvalidCurve(curve)) return -1;
byte[] msg = new byte[19];
Array.Copy(new byte[] { 0x5e, 0xd1, 0x01 }, msg, 3);
diff --git a/app/CustomControls.cs b/app/CustomControls.cs
index 85e259c2..044527d6 100644
--- a/app/CustomControls.cs
+++ b/app/CustomControls.cs
@@ -30,11 +30,6 @@ namespace CustomControls
public bool darkTheme = false;
- public RForm()
- {
- DoubleBuffered = true;
- }
-
public static void InitColors(bool darkTheme)
{
if (darkTheme)
diff --git a/app/Fans.cs b/app/Fans.cs
index 4f1f7e83..435361a3 100644
--- a/app/Fans.cs
+++ b/app/Fans.cs
@@ -507,11 +507,11 @@ namespace GHelper
int mode = AppConfig.getConfig("performance_mode");
byte[] curve = AppConfig.getFanConfig(device);
- if (reset || AsusACPI.IsEmptyCurve(curve))
+ if (reset || AsusACPI.IsInvalidCurve(curve))
{
curve = Program.acpi.GetFanCurve(device, mode);
- if (AsusACPI.IsEmptyCurve(curve))
+ if (AsusACPI.IsInvalidCurve(curve))
curve = AppConfig.getDefaultCurve(device);
curve = AsusACPI.FixFanCurve(curve);
diff --git a/app/GHelper.csproj b/app/GHelper.csproj
index e70cf4fd..fbccab6a 100644
--- a/app/GHelper.csproj
+++ b/app/GHelper.csproj
@@ -16,7 +16,7 @@
AnyCPU
False
True
- 0.65
+ 0.66
diff --git a/app/EventDispatcher.cs b/app/InputDispatcher.cs
similarity index 99%
rename from app/EventDispatcher.cs
rename to app/InputDispatcher.cs
index 117bbd29..1de47a20 100644
--- a/app/EventDispatcher.cs
+++ b/app/InputDispatcher.cs
@@ -6,13 +6,13 @@ using Tools;
namespace GHelper
{
- public class EventDispatcher
+ public class InputDispatcher
{
private static bool isOptimizationRunning = OptimizationService.IsRunning();
private static nint windowHandle;
- public EventDispatcher(nint handle)
+ public InputDispatcher(nint handle)
{
windowHandle = handle;
diff --git a/app/Program.cs b/app/Program.cs
index 322c3a30..38ee9653 100644
--- a/app/Program.cs
+++ b/app/Program.cs
@@ -30,7 +30,7 @@ namespace GHelper
private static long lastTheme;
private static long lastAdmin;
- public static EventDispatcher eventDispatcher;
+ public static InputDispatcher inputDispatcher;
private static PowerLineStatus isPlugged = PowerLineStatus.Unknown;
@@ -75,7 +75,7 @@ namespace GHelper
trayIcon.MouseClick += TrayIcon_MouseClick;
- eventDispatcher = new EventDispatcher(ds);
+ inputDispatcher = new InputDispatcher(ds);
settingsForm.InitAura();
settingsForm.InitMatrix();
@@ -92,7 +92,6 @@ namespace GHelper
unRegPowerNotify = NativeMethods.RegisterPowerSettingNotification(ds, settingGuid.ConsoleDisplayState, NativeMethods.DEVICE_NOTIFY_WINDOW_HANDLE);
-
if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\') || action.Length > 0)
{
SettingsToggle(action);
diff --git a/app/Settings.cs b/app/Settings.cs
index 31f06539..a4e5fa53 100644
--- a/app/Settings.cs
+++ b/app/Settings.cs
@@ -115,6 +115,9 @@ namespace GHelper
buttonUltimate.MouseMove += ButtonUltimate_MouseHover;
buttonUltimate.MouseLeave += ButtonGPU_MouseLeave;
+ tableGPU.MouseMove += ButtonXGM_MouseMove;
+ tableGPU.MouseLeave += ButtonGPU_MouseLeave;
+
buttonXGM.Click += ButtonXGM_Click;
buttonScreenAuto.MouseMove += ButtonScreenAuto_MouseHover;
@@ -266,19 +269,40 @@ namespace GHelper
private void ButtonXGM_Click(object? sender, EventArgs e)
{
- if (Program.acpi.DeviceGet(AsusACPI.GPUXG) == 1)
- {
- Program.acpi.DeviceSet(AsusACPI.GPUXG, 0, "GPU XGM");
- }
- else
- {
- Program.acpi.DeviceSet(AsusACPI.GPUXG, 1, "GPU XGM");
- if (AppConfig.getConfigPerf("auto_apply") == 1)
- AsusUSB.SetXGMFan(AppConfig.getFanConfig(AsusFan.XGM));
- }
-
- InitXGM();
+ Task.Run(async () =>
+ {
+ BeginInvoke(delegate
+ {
+ ButtonEnabled(buttonOptimized, false);
+ ButtonEnabled(buttonEco, false);
+ ButtonEnabled(buttonStandard, false);
+ ButtonEnabled(buttonUltimate, false);
+ ButtonEnabled(buttonXGM, false);
+ });
+
+ if (Program.acpi.DeviceGet(AsusACPI.GPUXG) == 1)
+ {
+ Program.acpi.DeviceSet(AsusACPI.GPUXG, 0, "GPU XGM");
+ await Task.Delay(TimeSpan.FromSeconds(15));
+ }
+ else
+ {
+ Program.acpi.DeviceSet(AsusACPI.GPUXG, 1, "GPU XGM");
+ await Task.Delay(TimeSpan.FromSeconds(15));
+
+ if (AppConfig.getConfigPerf("auto_apply") == 1)
+ AsusUSB.SetXGMFan(AppConfig.getFanConfig(AsusFan.XGM));
+ }
+
+ BeginInvoke(delegate
+ {
+ InitGPUMode();
+ });
+
+
+ });
+
}
private void SliderBattery_ValueChanged(object? sender, EventArgs e)
@@ -440,6 +464,18 @@ namespace GHelper
labelTipGPU.Text = "";
}
+ private void ButtonXGM_MouseMove(object? sender, MouseEventArgs e)
+ {
+ if (sender is null) return;
+ TableLayoutPanel table = (TableLayoutPanel)sender;
+
+ if (!buttonXGM.Visible) return;
+
+ labelTipGPU.Text = buttonXGM.Bounds.Contains(table.PointToClient(Cursor.Position)) ?
+ "XGMobile toggle works only in Standard mode" : "";
+
+ }
+
private void ButtonOptimized_Click(object? sender, EventArgs e)
{
@@ -1331,8 +1367,13 @@ namespace GHelper
public void InitXGM()
{
+
buttonXGM.Enabled = buttonXGM.Visible = Program.acpi.IsXGConnected();
- buttonXGM.Activated = (Program.acpi.DeviceGet(AsusACPI.GPUXG) == 1);
+
+ int activated = Program.acpi.DeviceGet(AsusACPI.GPUXG);
+ if (activated < 0) return;
+
+ buttonXGM.Activated = (activated == 1);
if (buttonXGM.Activated)
{
@@ -1340,6 +1381,12 @@ namespace GHelper
ButtonEnabled(buttonEco, false);
ButtonEnabled(buttonStandard, false);
ButtonEnabled(buttonUltimate, false);
+ } else
+ {
+ ButtonEnabled(buttonOptimized, true);
+ ButtonEnabled(buttonEco, true);
+ ButtonEnabled(buttonStandard, true);
+ ButtonEnabled(buttonUltimate, true);
}
}
@@ -1431,6 +1478,7 @@ namespace GHelper
ButtonEnabled(buttonEco, false);
ButtonEnabled(buttonStandard, false);
ButtonEnabled(buttonUltimate, false);
+ ButtonEnabled(buttonXGM, false);
labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUChanging + " ...";