From fd3a139c47a7cf863570953739773f1b7976343d Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 14 May 2023 10:28:48 +0200 Subject: [PATCH] Aura tweaks --- app/Aura.cs | 13 +++++++++---- app/Gpu/NvidiaGpuControl.cs | 4 ++-- app/HardwareControl.cs | 8 ++++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/Aura.cs b/app/Aura.cs index 3739c5f3..84977c28 100644 --- a/app/Aura.cs +++ b/app/Aura.cs @@ -161,13 +161,14 @@ namespace GHelper Color2 = Color.FromArgb(colorCode); } - private static IEnumerable GetHidDevices(int[] deviceIds) + + private static IEnumerable GetHidDevices(int[] deviceIds, int minInput = 18) { HidDevice[] HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray(); foreach (HidDevice device in HidDeviceList) if (device.IsConnected - && device.Capabilities.FeatureReportByteLength >= 64 - && device.Capabilities.InputReportByteLength >= 12) // + && device.Capabilities.FeatureReportByteLength > 0 + && device.Capabilities.InputReportByteLength >= minInput) // yield return device; } @@ -275,7 +276,11 @@ namespace GHelper byte[] msg = AuraMessage(Mode, Color1, Color2, _speed); var devices = GetHidDevices(deviceIds); - //if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); + if (devices.Count() == 0) + { + Logger.WriteLine("USB-KB : not found"); + GetHidDevices(deviceIds, 0); + } foreach (HidDevice device in devices) { diff --git a/app/Gpu/NvidiaGpuControl.cs b/app/Gpu/NvidiaGpuControl.cs index f757b1db..88f5f550 100644 --- a/app/Gpu/NvidiaGpuControl.cs +++ b/app/Gpu/NvidiaGpuControl.cs @@ -117,10 +117,10 @@ public class NvidiaGpuControl : IGpuControl { try { - string script = @"$device = Get-PnpDevice | Where-Object { $_.FriendlyName -imatch 'NVIDIA' -and $_.Class -eq 'Display' }; Disable-PnpDevice $device.InstanceId -Confirm:$false; Start-Sleep -Seconds 2; Enable-PnpDevice $device.InstanceId -Confirm:$false"; + string script = @"$device = Get-PnpDevice | Where-Object { $_.FriendlyName -imatch 'NVIDIA' -and $_.Class -eq 'Display' }; Disable-PnpDevice $device.InstanceId -Confirm:$false; Start-Sleep -Seconds 3; Enable-PnpDevice $device.InstanceId -Confirm:$false"; Logger.WriteLine(script); RunCMD("powershell", script); - Thread.Sleep(2000); + //Thread.Sleep(2000); return true; } catch (Exception ex ) diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs index 11906250..0c5e68cb 100644 --- a/app/HardwareControl.cs +++ b/app/HardwareControl.cs @@ -115,10 +115,14 @@ public static class HardwareControl public static bool IsUsedGPU(int threshold = 20) { - if (GetGpuUse() > threshold) + int use = GetGpuUse(); + Logger.WriteLine("GPU usage: " + use); + if (use > threshold) { Thread.Sleep(1000); - return (GetGpuUse() > threshold); + use = GetGpuUse(); + Logger.WriteLine("GPU usage: " + use); + return (use > threshold); } return false; }