From cbd99bd75f736afae7397f03116d8729d758417e Mon Sep 17 00:00:00 2001 From: Aytackydln Date: Mon, 30 Sep 2024 20:14:32 +0200 Subject: [PATCH] flush device leds after device unlock --- .../Devices/RGBNet/RgbNetDevice.cs | 7 +++++++ .../Devices/RGBNet/RgbNetDeviceUpdater.cs | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Project-Aurora/AuroraDeviceManager/Devices/RGBNet/RgbNetDevice.cs b/Project-Aurora/AuroraDeviceManager/Devices/RGBNet/RgbNetDevice.cs index f0d987874..4cb4f52ee 100644 --- a/Project-Aurora/AuroraDeviceManager/Devices/RGBNet/RgbNetDevice.cs +++ b/Project-Aurora/AuroraDeviceManager/Devices/RGBNet/RgbNetDevice.cs @@ -5,6 +5,7 @@ using Common; using Common.Devices; using Common.Devices.RGBNet; +using Microsoft.Win32; using RGB.NET.Core; namespace AuroraDeviceManager.Devices.RGBNet; @@ -27,6 +28,12 @@ public abstract class RgbNetDevice : DefaultDevice protected RgbNetDevice() { _updater = new RgbNetDeviceUpdater(DeviceKeyRemap, false); + SystemEvents.SessionSwitch += (_, _) => + { + _updater.Flush(); + Thread.Sleep(3000); + _updater.Flush(); + }; } protected RgbNetDevice(bool needsLayout) diff --git a/Project-Aurora/AuroraDeviceManager/Devices/RGBNet/RgbNetDeviceUpdater.cs b/Project-Aurora/AuroraDeviceManager/Devices/RGBNet/RgbNetDeviceUpdater.cs index d97edf055..9ba29f4a3 100644 --- a/Project-Aurora/AuroraDeviceManager/Devices/RGBNet/RgbNetDeviceUpdater.cs +++ b/Project-Aurora/AuroraDeviceManager/Devices/RGBNet/RgbNetDeviceUpdater.cs @@ -8,6 +8,13 @@ namespace AuroraDeviceManager.Devices.RGBNet; public class RgbNetDeviceUpdater(ConcurrentDictionary> deviceKeyRemap, bool needsLayout) { + private bool _flush; + + internal void Flush() + { + _flush = true; + } + internal void UpdateDevice(IReadOnlyDictionary keyColors, IRGBDevice device) { if (needsLayout) @@ -19,7 +26,8 @@ internal void UpdateDevice(IReadOnlyDictionary keyColor UpdateStraight(keyColors, device); } - device.Update(); + device.Update(_flush); + _flush = false; } private static void UpdateReverse(IReadOnlyDictionary keyColors, IRGBDevice device) @@ -93,7 +101,7 @@ private void UpdateStraight(IReadOnlyDictionary keyColo private static void UpdateLed(Led led, SimpleColor color) { - led.Color = new RGB.NET.Core.Color( + led.Color = new Color( color.A, color.R, color.G, @@ -103,7 +111,7 @@ private static void UpdateLed(Led led, SimpleColor color) private static void UpdateLedCalibrated(Led led, SimpleColor color, SimpleColor calibration) { - led.Color = new RGB.NET.Core.Color( + led.Color = new Color( (byte)(color.A * calibration.A / 255), (byte)(color.R * calibration.R / 255), (byte)(color.G * calibration.G / 255),