XGM Fixes

This commit is contained in:
Serge
2023-05-21 17:42:15 +02:00
parent 34075b67d4
commit 4ee97fdbc4
8 changed files with 81 additions and 31 deletions

View File

@@ -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) 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) public static byte[] FixFanCurve(byte[] curve)
@@ -397,6 +401,7 @@ public class AsusACPI
public bool IsXGConnected() public bool IsXGConnected()
{ {
//return true;
return DeviceGet(GPUXGConnected) == 1; return DeviceGet(GPUXGConnected) == 1;
} }

View File

@@ -288,13 +288,16 @@ namespace GHelper
public static int SetXGM(byte[] msg) 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)) foreach (HidDevice device in GetHidDevices(new int[] { 0x1970 }, 0))
{ {
device.OpenDevice(); device.OpenDevice();
Logger.WriteLine("XGM " + device.Attributes.ProductHexId + device.Capabilities.FeatureReportByteLength + ":" + BitConverter.ToString(msg)); Logger.WriteLine("XGM " + device.Attributes.ProductHexId + "|" + device.Capabilities.FeatureReportByteLength + ":" + BitConverter.ToString(msg));
device.WriteFeatureData(msg); device.WriteFeatureData(payload);
device.CloseDevice(); device.CloseDevice();
return 1; return 1;
} }
@@ -316,7 +319,7 @@ namespace GHelper
public static int SetXGMFan(byte[] curve) public static int SetXGMFan(byte[] curve)
{ {
if (AsusACPI.IsEmptyCurve(curve)) return -1; if (AsusACPI.IsInvalidCurve(curve)) return -1;
byte[] msg = new byte[19]; byte[] msg = new byte[19];
Array.Copy(new byte[] { 0x5e, 0xd1, 0x01 }, msg, 3); Array.Copy(new byte[] { 0x5e, 0xd1, 0x01 }, msg, 3);

View File

@@ -30,11 +30,6 @@ namespace CustomControls
public bool darkTheme = false; public bool darkTheme = false;
public RForm()
{
DoubleBuffered = true;
}
public static void InitColors(bool darkTheme) public static void InitColors(bool darkTheme)
{ {
if (darkTheme) if (darkTheme)

View File

@@ -507,11 +507,11 @@ namespace GHelper
int mode = AppConfig.getConfig("performance_mode"); int mode = AppConfig.getConfig("performance_mode");
byte[] curve = AppConfig.getFanConfig(device); byte[] curve = AppConfig.getFanConfig(device);
if (reset || AsusACPI.IsEmptyCurve(curve)) if (reset || AsusACPI.IsInvalidCurve(curve))
{ {
curve = Program.acpi.GetFanCurve(device, mode); curve = Program.acpi.GetFanCurve(device, mode);
if (AsusACPI.IsEmptyCurve(curve)) if (AsusACPI.IsInvalidCurve(curve))
curve = AppConfig.getDefaultCurve(device); curve = AppConfig.getDefaultCurve(device);
curve = AsusACPI.FixFanCurve(curve); curve = AsusACPI.FixFanCurve(curve);

View File

@@ -16,7 +16,7 @@
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly> <ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.65</AssemblyVersion> <AssemblyVersion>0.66</AssemblyVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@@ -6,13 +6,13 @@ using Tools;
namespace GHelper namespace GHelper
{ {
public class EventDispatcher public class InputDispatcher
{ {
private static bool isOptimizationRunning = OptimizationService.IsRunning(); private static bool isOptimizationRunning = OptimizationService.IsRunning();
private static nint windowHandle; private static nint windowHandle;
public EventDispatcher(nint handle) public InputDispatcher(nint handle)
{ {
windowHandle = handle; windowHandle = handle;

View File

@@ -30,7 +30,7 @@ namespace GHelper
private static long lastTheme; private static long lastTheme;
private static long lastAdmin; private static long lastAdmin;
public static EventDispatcher eventDispatcher; public static InputDispatcher inputDispatcher;
private static PowerLineStatus isPlugged = PowerLineStatus.Unknown; private static PowerLineStatus isPlugged = PowerLineStatus.Unknown;
@@ -75,7 +75,7 @@ namespace GHelper
trayIcon.MouseClick += TrayIcon_MouseClick; trayIcon.MouseClick += TrayIcon_MouseClick;
eventDispatcher = new EventDispatcher(ds); inputDispatcher = new InputDispatcher(ds);
settingsForm.InitAura(); settingsForm.InitAura();
settingsForm.InitMatrix(); settingsForm.InitMatrix();
@@ -92,7 +92,6 @@ namespace GHelper
unRegPowerNotify = NativeMethods.RegisterPowerSettingNotification(ds, settingGuid.ConsoleDisplayState, NativeMethods.DEVICE_NOTIFY_WINDOW_HANDLE); unRegPowerNotify = NativeMethods.RegisterPowerSettingNotification(ds, settingGuid.ConsoleDisplayState, NativeMethods.DEVICE_NOTIFY_WINDOW_HANDLE);
if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\') || action.Length > 0) if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\') || action.Length > 0)
{ {
SettingsToggle(action); SettingsToggle(action);

View File

@@ -115,6 +115,9 @@ namespace GHelper
buttonUltimate.MouseMove += ButtonUltimate_MouseHover; buttonUltimate.MouseMove += ButtonUltimate_MouseHover;
buttonUltimate.MouseLeave += ButtonGPU_MouseLeave; buttonUltimate.MouseLeave += ButtonGPU_MouseLeave;
tableGPU.MouseMove += ButtonXGM_MouseMove;
tableGPU.MouseLeave += ButtonGPU_MouseLeave;
buttonXGM.Click += ButtonXGM_Click; buttonXGM.Click += ButtonXGM_Click;
buttonScreenAuto.MouseMove += ButtonScreenAuto_MouseHover; buttonScreenAuto.MouseMove += ButtonScreenAuto_MouseHover;
@@ -266,19 +269,40 @@ namespace GHelper
private void ButtonXGM_Click(object? sender, EventArgs e) 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) Task.Run(async () =>
AsusUSB.SetXGMFan(AppConfig.getFanConfig(AsusFan.XGM)); {
} BeginInvoke(delegate
{
InitXGM(); 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) private void SliderBattery_ValueChanged(object? sender, EventArgs e)
@@ -440,6 +464,18 @@ namespace GHelper
labelTipGPU.Text = ""; 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) private void ButtonOptimized_Click(object? sender, EventArgs e)
{ {
@@ -1331,8 +1367,13 @@ namespace GHelper
public void InitXGM() public void InitXGM()
{ {
buttonXGM.Enabled = buttonXGM.Visible = Program.acpi.IsXGConnected(); 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) if (buttonXGM.Activated)
{ {
@@ -1340,6 +1381,12 @@ namespace GHelper
ButtonEnabled(buttonEco, false); ButtonEnabled(buttonEco, false);
ButtonEnabled(buttonStandard, false); ButtonEnabled(buttonStandard, false);
ButtonEnabled(buttonUltimate, 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(buttonEco, false);
ButtonEnabled(buttonStandard, false); ButtonEnabled(buttonStandard, false);
ButtonEnabled(buttonUltimate, false); ButtonEnabled(buttonUltimate, false);
ButtonEnabled(buttonXGM, false);
labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUChanging + " ..."; labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUChanging + " ...";