From 41caaefc97ae061d7b1d35a628e193cd25199045 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Tue, 9 May 2023 16:05:57 +0200 Subject: [PATCH] Improved aura logging --- app/Aura.cs | 23 ++++++++++++++--------- app/Gpu/NvidiaGpuControl.cs | 4 ++-- app/Settings.cs | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/Aura.cs b/app/Aura.cs index 3921a441..7fc09698 100644 --- a/app/Aura.cs +++ b/app/Aura.cs @@ -1,6 +1,7 @@ using HidLibrary; using OSD; using System.Diagnostics; +using System.Windows.Forms; namespace GHelper { @@ -197,15 +198,16 @@ namespace GHelper { byte[] msg = { 0x5d, 0xba, 0xc5, 0xc4, (byte)brightness }; - foreach (HidDevice device in GetHidDevices(new int[] { 0x19b6 })) + var devices = GetHidDevices(new int[] { 0x19b6 }); + if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); + + foreach (HidDevice device in devices) { device.OpenDevice(); device.Write(msg); device.CloseDevice(); } - Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); - if (Program.config.ContainsModel("TUF")) Program.wmi.TUFKeyboardBrightness(brightness); } @@ -216,18 +218,18 @@ namespace GHelper byte[] msg = AuraDev19b6Extensions.ToBytes(flags.ToArray()); - Debug.WriteLine(BitConverter.ToString(msg)); - foreach (HidDevice device in GetHidDevices(new int[] { 0x19b6 })) + var devices = GetHidDevices(new int[] { 0x19b6 }); + if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); + + foreach (HidDevice device in devices) { device.OpenDevice(); device.Write(msg); device.CloseDevice(); } - Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); - - //if (Program.config.ContainsModel("TUF")) + if (Program.config.ContainsModel("TUF")) Program.wmi.TUFKeyboardPower( flags.Contains(AuraDev19b6.AwakeKeyb), flags.Contains(AuraDev19b6.BootKeyb), @@ -273,7 +275,10 @@ namespace GHelper byte[] msg = AuraMessage(Mode, Color1, Color2, _speed); - foreach (HidDevice device in GetHidDevices(deviceIds)) + var devices = GetHidDevices(deviceIds); + if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); + + foreach (HidDevice device in devices) { device.OpenDevice(); device.Write(msg); diff --git a/app/Gpu/NvidiaGpuControl.cs b/app/Gpu/NvidiaGpuControl.cs index 8c859aa7..6629a5de 100644 --- a/app/Gpu/NvidiaGpuControl.cs +++ b/app/Gpu/NvidiaGpuControl.cs @@ -4,6 +4,7 @@ using NvAPIWrapper.Native.GPU; using NvAPIWrapper.Native.GPU.Structures; using NvAPIWrapper.Native.Interfaces.GPU; using System.Diagnostics; +using System.Management; using static NvAPIWrapper.Native.GPU.Structures.PerformanceStates20InfoV1; namespace GHelper.Gpu; @@ -46,7 +47,6 @@ public class NvidiaGpuControl : IGpuControl } - public void GetClocks(out int core, out int memory, out string gpu) { PhysicalGPU internalGpu = _internalGpu!; @@ -86,7 +86,7 @@ public class NvidiaGpuControl : IGpuControl var coreClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Graphics, new PerformanceStates20ParameterDelta(core * 1000)); var memoryClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Memory, new PerformanceStates20ParameterDelta(memory * 1000)); - PerformanceStates20ClockEntryV1[] clocks = { coreClock , memoryClock}; + PerformanceStates20ClockEntryV1[] clocks = { coreClock, memoryClock }; PerformanceStates20BaseVoltageEntryV1[] voltages = { }; PerformanceState20[] performanceStates = { new PerformanceState20(PerformanceStateId.P0_3DPerformance, clocks, voltages) }; diff --git a/app/Settings.cs b/app/Settings.cs index 71b8a384..6cc2b9a4 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -948,7 +948,7 @@ namespace GHelper SetGPUMode(ASUSWmi.GPUModeEco); } - public void RefreshSensors(bool force = false) + public async void RefreshSensors(bool force = false) { if (!force && Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastRefresh) < 2000) return;