Skip to content

Commit

Permalink
flush device leds after device unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Sep 30, 2024
1 parent 410613a commit cbd99bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Common;
using Common.Devices;
using Common.Devices.RGBNet;
using Microsoft.Win32;
using RGB.NET.Core;

namespace AuroraDeviceManager.Devices.RGBNet;
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ namespace AuroraDeviceManager.Devices.RGBNet;

public class RgbNetDeviceUpdater(ConcurrentDictionary<IRGBDevice, Dictionary<LedId, DeviceKeys>> deviceKeyRemap, bool needsLayout)
{
private bool _flush;

internal void Flush()
{
_flush = true;
}

internal void UpdateDevice(IReadOnlyDictionary<DeviceKeys, SimpleColor> keyColors, IRGBDevice device)
{
if (needsLayout)
Expand All @@ -19,7 +26,8 @@ internal void UpdateDevice(IReadOnlyDictionary<DeviceKeys, SimpleColor> keyColor
UpdateStraight(keyColors, device);
}

device.Update();
device.Update(_flush);
_flush = false;
}

private static void UpdateReverse(IReadOnlyDictionary<DeviceKeys, SimpleColor> keyColors, IRGBDevice device)
Expand Down Expand Up @@ -93,7 +101,7 @@ private void UpdateStraight(IReadOnlyDictionary<DeviceKeys, SimpleColor> 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,
Expand All @@ -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),
Expand Down

0 comments on commit cbd99bd

Please sign in to comment.