From dfc3c0e5158d98190930cb804fc8518918d82947 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 28 May 2023 16:09:44 +0200 Subject: [PATCH] UI tweaks --- app/AsusACPI.cs | 3 +- app/AsusUSB.cs | 131 ++++++++++++++++++++++------------------- app/Fans.cs | 6 +- app/InputDispatcher.cs | 2 +- 4 files changed, 75 insertions(+), 67 deletions(-) diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs index 0baa2bf4..42a4c957 100644 --- a/app/AsusACPI.cs +++ b/app/AsusACPI.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Management; +using System.Management; using System.Runtime.InteropServices; public enum AsusFan diff --git a/app/AsusUSB.cs b/app/AsusUSB.cs index 5b3c6a8e..8467799e 100644 --- a/app/AsusUSB.cs +++ b/app/AsusUSB.cs @@ -1,5 +1,4 @@ using HidLibrary; -using Microsoft.Win32; using System.Text; namespace GHelper @@ -181,7 +180,7 @@ namespace GHelper foreach (HidDevice device in HidDeviceList) if (device.IsConnected && device.Capabilities.FeatureReportByteLength >= minFeatures - && device.Capabilities.InputReportByteLength >= minInput) + && device.Capabilities.InputReportByteLength >= minInput) yield return device; } @@ -248,33 +247,41 @@ namespace GHelper public static void ApplyBrightness(int brightness) { + if (AppConfig.ContainsModel("TUF")) Program.acpi.TUFKeyboardBrightness(brightness); - byte[] msg = { AURA_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness }; - var devices = GetHidDevices(deviceIds); - foreach (HidDevice device in devices) + Task.Run(async () => { - device.OpenDevice(); - device.WriteFeatureData(msg); - Logger.WriteLine("KB Backlight:" + BitConverter.ToString(msg)); - device.CloseDevice(); - } - // Backup payload for old models - if (AppConfig.ContainsModel("503")) - { - byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness }; + byte[] msg = { AURA_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness }; - var devicesBackup = GetHidDevices(deviceIds, 0); - foreach (HidDevice device in devicesBackup) + var devices = GetHidDevices(deviceIds); + foreach (HidDevice device in devices) { device.OpenDevice(); - device.WriteFeatureData(msgBackup); + device.WriteFeatureData(msg); + Logger.WriteLine("KB Backlight:" + BitConverter.ToString(msg)); device.CloseDevice(); } - } + + // Backup payload for old models + if (AppConfig.ContainsModel("503")) + { + byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness }; + + var devicesBackup = GetHidDevices(deviceIds, 0); + foreach (HidDevice device in devicesBackup) + { + device.OpenDevice(); + device.WriteFeatureData(msgBackup); + device.CloseDevice(); + } + } + + }); + } @@ -305,49 +312,6 @@ namespace GHelper } - public static int SetXGM(byte[] 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, 64)) - { - device.OpenDevice(); - Logger.WriteLine("XGM " + device.Attributes.ProductHexId + "|" + device.Capabilities.FeatureReportByteLength + ":" + BitConverter.ToString(msg)); - device.WriteFeatureData(payload); - device.CloseDevice(); - //return 1; - } - - return 0; - } - - public static void ApplyXGMLight(bool status) - { - SetXGM(new byte[] { 0x5e, 0xc5, status ? (byte)0x50 : (byte)0 }); - } - - - public static int ResetXGM() - { - return SetXGM(new byte[] { 0x5e, 0xd1, 0x02 }); - } - - public static int SetXGMFan(byte[] curve) - { - - if (AsusACPI.IsInvalidCurve(curve)) return -1; - - byte[] msg = new byte[19]; - Array.Copy(new byte[] { 0x5e, 0xd1, 0x01 }, msg, 3); - Array.Copy(curve, 0, msg, 3, curve.Length); - - return SetXGM(msg); - } - public static void ApplyAura() { @@ -393,6 +357,51 @@ namespace GHelper } + // Reference : thanks to https://github.com/RomanYazvinsky/ for initial discovery of XGM payloads + public static int SetXGM(byte[] 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, 300)) + { + device.OpenDevice(); + Logger.WriteLine("XGM " + device.Attributes.ProductHexId + "|" + device.Capabilities.FeatureReportByteLength + ":" + BitConverter.ToString(msg)); + device.WriteFeatureData(payload); + device.CloseDevice(); + //return 1; + } + + return 0; + } + + public static void ApplyXGMLight(bool status) + { + SetXGM(new byte[] { 0x5e, 0xc5, status ? (byte)0x50 : (byte)0 }); + } + + + public static int ResetXGM() + { + return SetXGM(new byte[] { 0x5e, 0xd1, 0x02 }); + } + + public static int SetXGMFan(byte[] curve) + { + + if (AsusACPI.IsInvalidCurve(curve)) return -1; + + byte[] msg = new byte[19]; + Array.Copy(new byte[] { 0x5e, 0xd1, 0x01 }, msg, 3); + Array.Copy(curve, 0, msg, 3, curve.Length); + + return SetXGM(msg); + } + + } } \ No newline at end of file diff --git a/app/Fans.cs b/app/Fans.cs index 96791dca..c36584ca 100644 --- a/app/Fans.cs +++ b/app/Fans.cs @@ -303,7 +303,7 @@ namespace GHelper } else { - MinimumSize = new Size(0, Program.settingsForm.Height); + Size = MinimumSize = new Size(0, Program.settingsForm.Height); Height = Program.settingsForm.Height; Top = Program.settingsForm.Top; } @@ -466,7 +466,7 @@ namespace GHelper chartMid.Visible = true; SetChart(chartMid, AsusFan.Mid); LoadProfile(seriesMid, AsusFan.Mid); - MinimumSize = new Size(0, chartCount * 400 + 200); + Size = MinimumSize = new Size(0, chartCount * 400 + 200); } else { @@ -481,7 +481,7 @@ namespace GHelper chartXGM.Visible = true; SetChart(chartXGM, AsusFan.XGM); LoadProfile(seriesXGM, AsusFan.XGM); - MinimumSize = new Size(0, chartCount * 400 + 200); + Size = MinimumSize = new Size(0, chartCount * 400 + 200); } else { diff --git a/app/InputDispatcher.cs b/app/InputDispatcher.cs index 23854f2c..c7a9d063 100644 --- a/app/InputDispatcher.cs +++ b/app/InputDispatcher.cs @@ -115,7 +115,7 @@ namespace GHelper AsusUSB.ApplyBrightness(AppConfig.getConfig("keyboard_brightness")); } - Debug.WriteLine(iddle.TotalSeconds); + //Debug.WriteLine(iddle.TotalSeconds); } public void Init()