From 5830220a3d3d9fad34ae165584dc8116b44cba35 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Wed, 26 Jul 2023 23:57:20 +0200 Subject: [PATCH] Performance tweaks --- app/AsusUSB.cs | 62 +++++++++++++------------- app/HardwareControl.cs | 18 ++------ app/Peripherals/PeripheralsProvider.cs | 1 + app/Settings.Designer.cs | 1 + app/Settings.cs | 5 +-- 5 files changed, 38 insertions(+), 49 deletions(-) diff --git a/app/AsusUSB.cs b/app/AsusUSB.cs index 9cf3bbf6..2bb98e4d 100644 --- a/app/AsusUSB.cs +++ b/app/AsusUSB.cs @@ -75,8 +75,11 @@ namespace GHelper public static Color Color1 = Color.White; public static Color Color2 = Color.Black; + static bool isTuf = AppConfig.ContainsModel("Tuf"); + static bool isStrix = AppConfig.ContainsModel("Strix"); - static System.Timers.Timer timer = new System.Timers.Timer(1000); + + static System.Timers.Timer timer = new System.Timers.Timer(2000); static HidDevice? auraDevice = null; static AsusUSB() @@ -141,7 +144,7 @@ namespace GHelper public static Dictionary GetModes() { - if (AppConfig.ContainsModel("TUF")) + if (isTuf) { _modes.Remove(3); } @@ -185,7 +188,7 @@ namespace GHelper public static bool HasSecondColor() { - return (mode == 1 && !AppConfig.ContainsModel("TUF")); + return (mode == 1 && !isTuf); } public static int Speed @@ -289,8 +292,7 @@ namespace GHelper Task.Run(async () => { - if (AppConfig.ContainsModel("TUF")) - Program.acpi.TUFKeyboardBrightness(brightness); + if (isTuf) Program.acpi.TUFKeyboardBrightness(brightness); byte[] msg = { AURA_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness }; byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness }; @@ -390,7 +392,7 @@ namespace GHelper device.CloseDevice(); } - if (AppConfig.ContainsModel("TUF")) + if (isTuf) Program.acpi.TUFKeyboardPower( flags.Contains(AuraDev19b6.AwakeKeyb), flags.Contains(AuraDev19b6.BootKeyb), @@ -410,6 +412,7 @@ namespace GHelper device.OpenDevice(); if (device.ReadFeatureData(out byte[] data, AURA_HID_ID)) { + Logger.WriteLine("Aura Device:" + device.DevicePath); auraDevice = device; return; } @@ -422,36 +425,33 @@ namespace GHelper public static void ApplyColor(Color color) { - Task.Run(async () => + if (isTuf) { - if (AppConfig.ContainsModel("TUF")) - { - Program.acpi.TUFKeyboardRGB(0, color, 0); - return; - } + Program.acpi.TUFKeyboardRGB(0, color, 0); + return; + } - if (auraDevice is null || !auraDevice.IsConnected) GetAuraDevice(); - if (auraDevice is null || !auraDevice.IsConnected) return; + if (auraDevice is null || !auraDevice.IsConnected) GetAuraDevice(); + if (auraDevice is null || !auraDevice.IsConnected) return; - byte[] msg = new byte[40]; - int start = 9; + byte[] msg = new byte[40]; + int start = 9; - msg[0] = AURA_HID_ID; - msg[1] = 0xBC; - msg[2] = 1; - msg[3] = 1; - msg[4] = 0; + msg[0] = AURA_HID_ID; + msg[1] = 0xbc; + msg[2] = 1; + msg[3] = 1; + msg[4] = isStrix ? (byte)4 : (byte)0; - for (int i = 0; i < 10; i++) - { - msg[start + i * 3] = color.R; // R - msg[start + 1 + i * 3] = color.G; // G - msg[start + 2 + i * 3] = color.B; // B - } + for (int i = 0; i < 10; i++) + { + msg[start + i * 3] = color.R; // R + msg[start + 1 + i * 3] = color.G; // G + msg[start + 2 + i * 3] = color.B; // B + } - //Logger.WriteLine(BitConverter.ToString(msg)); - auraDevice.WriteFeatureData(msg); - }); + //Logger.WriteLine(BitConverter.ToString(msg)); + //auraDevice.Write(msg); } @@ -561,7 +561,7 @@ namespace GHelper if (AsusACPI.IsInvalidCurve(curve)) return -1; - InitXGM(); + //InitXGM(); byte[] msg = new byte[19]; Array.Copy(new byte[] { 0x5e, 0xd1, 0x01 }, msg, 3); diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs index 69f0147f..4d25b365 100644 --- a/app/HardwareControl.cs +++ b/app/HardwareControl.cs @@ -174,22 +174,12 @@ public static class HardwareControl public static float? GetCPUTemp() { - if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastUpdate) < 1000) return cpuTemp; - lastUpdate = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + var last = DateTimeOffset.Now.ToUnixTimeSeconds(); + if (Math.Abs(last - lastUpdate) < 2) return cpuTemp; + lastUpdate = last; cpuTemp = Program.acpi.DeviceGet(AsusACPI.Temp_CPU); - - if (cpuTemp < 0) try - { - using (var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true)) - { - cpuTemp = ct.NextValue() - 273; - } - } - catch (Exception ex) - { - Debug.WriteLine("Failed reading CPU temp :" + ex.Message); - } + //Debug.WriteLine(cpuTemp); return cpuTemp; } diff --git a/app/Peripherals/PeripheralsProvider.cs b/app/Peripherals/PeripheralsProvider.cs index 69bff958..86300411 100644 --- a/app/Peripherals/PeripheralsProvider.cs +++ b/app/Peripherals/PeripheralsProvider.cs @@ -139,6 +139,7 @@ namespace GHelper.Peripherals DetectMouse(new ChakramXWired()); DetectMouse(new GladiusIII()); DetectMouse(new GladiusIIIWired()); + UpdateSettingsView(); } public static void DetectMouse(AsusMouse am) diff --git a/app/Settings.Designer.cs b/app/Settings.Designer.cs index fdf98607..85182d13 100644 --- a/app/Settings.Designer.cs +++ b/app/Settings.Designer.cs @@ -1207,6 +1207,7 @@ namespace GHelper panelPeripherals.Padding = new Padding(20, 20, 20, 10); panelPeripherals.Size = new Size(827, 198); panelPeripherals.TabIndex = 4; + panelPeripherals.Visible = false; // // tableLayoutPeripherals // diff --git a/app/Settings.cs b/app/Settings.cs index b1394cad..13227154 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -236,6 +236,7 @@ namespace GHelper { screenControl.InitScreen(); gpuControl.InitXGM(); + PeripheralsProvider.RefreshBatteryForAllDevices(); updateControl.CheckForUpdates(); } } @@ -823,14 +824,11 @@ namespace GHelper battery = Properties.Strings.Charging + ": " + Math.Round((decimal)HardwareControl.batteryRate, 1).ToString() + "W"; - if (HardwareControl.gpuTemp > 0) { gpuTemp = $": {HardwareControl.gpuTemp}°C"; } - PeripheralsProvider.RefreshBatteryForAllDevices(); - Program.settingsForm.BeginInvoke(delegate { labelCPUFan.Text = "CPU" + cpuTemp + " " + HardwareControl.cpuFan; @@ -839,7 +837,6 @@ namespace GHelper labelMidFan.Text = "Mid " + HardwareControl.midFan; if (!batteryMouseOver) labelBattery.Text = battery; - VisualizePeripherals(); }); string trayTip = "CPU" + cpuTemp + " " + HardwareControl.cpuFan;