From 96184d12200cda348a39343fe7abfbf3604fcf9f Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 6 Jun 2018 20:47:05 +0200 Subject: [PATCH] Fixed a problem with syncbacked leds kept in the synced state forever --- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 13 ++++++++ RGB.NET.Core/Leds/Led.cs | 32 +++++++++++++++---- .../Mainboard/AsusMainboardRGBDevice.cs | 2 +- .../Generic/CorsairRGBDevice.cs | 2 +- RGB.NET.Devices.Debug/DebugRGBDevice.cs | 5 ++- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index fe14e69..f9ceed4 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -131,6 +131,19 @@ namespace RGB.NET.Core return led; } + /// + /// Applies the give to the ignoring internal workflows regarding locks and update-requests. + /// This should be only used for syncbacks! + /// + /// The the should be aplied to. + /// The to apply. + protected virtual void SetLedColorWithoutRequest(Led led, Color color) + { + if (led == null) return; + + led.InternalColor = color; + } + /// /// Applies the given layout. /// diff --git a/RGB.NET.Core/Leds/Led.cs b/RGB.NET.Core/Leds/Led.cs index 13187db..d38185e 100644 --- a/RGB.NET.Core/Leds/Led.cs +++ b/RGB.NET.Core/Leds/Led.cs @@ -57,13 +57,14 @@ namespace RGB.NET.Core /// /// Indicates whether the is about to change it's color. /// - public bool IsDirty => RequestedColor != _color; + public bool IsDirty => RequestedColor.HasValue; - private Color _requestedColor = Color.Transparent; + private Color? _requestedColor; /// /// Gets a copy of the the LED should be set to on the next update. + /// Null if there is no update-request for the next update. /// - public Color RequestedColor + public Color? RequestedColor { get => _requestedColor; private set @@ -85,10 +86,25 @@ namespace RGB.NET.Core set { if (!IsLocked) - RequestedColor += value; + { + if (RequestedColor.HasValue) + RequestedColor += value; + else + RequestedColor = value; + } + } } + /// + /// Gets or set the ignoring all workflows regarding locks and update-requests. /> + /// + internal Color InternalColor + { + get => _color; + set => SetProperty(ref _color, value); + } + private bool _isLocked; /// /// Gets or sets if the color of this LED can be changed. @@ -143,7 +159,11 @@ namespace RGB.NET.Core /// internal void Update() { - _color = RequestedColor; + if (!RequestedColor.HasValue) return; + + _color = RequestedColor.Value; + RequestedColor = null; + // ReSharper disable once ExplicitCallerInfoArgument OnPropertyChanged(nameof(Color)); } @@ -154,7 +174,7 @@ namespace RGB.NET.Core internal void Reset() { _color = Color.Transparent; - RequestedColor = Color.Transparent; + RequestedColor = null; IsLocked = false; // ReSharper disable once ExplicitCallerInfoArgument diff --git a/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs b/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs index f1609b6..26fecdb 100644 --- a/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs @@ -45,7 +45,7 @@ namespace RGB.NET.Devices.Asus { byte[] colorData = _AsusSDK.GetMbColor(DeviceInfo.Handle); for (int i = 0; i < LedMapping.Count; i++) - LedMapping[LedId.Mainboard1 + i].Color = new Color(colorData[(i * 3)], colorData[(i * 3) + 2], colorData[(i * 3) + 1]); + SetLedColorWithoutRequest(LedMapping[LedId.Mainboard1 + i], new Color(colorData[(i * 3)], colorData[(i * 3) + 2], colorData[(i * 3) + 1])); } /// diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs index 4c098b1..22ad483 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs @@ -114,7 +114,7 @@ namespace RGB.NET.Devices.Corsair for (int i = 0; i < LedMapping.Count; i++) { _CorsairLedColor ledColor = (_CorsairLedColor)Marshal.PtrToStructure(readPtr, typeof(_CorsairLedColor)); - this[(CorsairLedId)ledColor.ledId].Color = new Color(ledColor.r, ledColor.g, ledColor.b); + SetLedColorWithoutRequest(this[(CorsairLedId)ledColor.ledId], new Color(ledColor.r, ledColor.g, ledColor.b)); readPtr = new IntPtr(readPtr.ToInt64() + structSize); } diff --git a/RGB.NET.Devices.Debug/DebugRGBDevice.cs b/RGB.NET.Devices.Debug/DebugRGBDevice.cs index 45005d3..4c71688 100644 --- a/RGB.NET.Devices.Debug/DebugRGBDevice.cs +++ b/RGB.NET.Devices.Debug/DebugRGBDevice.cs @@ -51,11 +51,10 @@ namespace RGB.NET.Devices.Debug foreach (KeyValuePair value in syncBackValues) { Led led = ((IRGBDevice)this)[value.Key]; - if (led != null) - led.Color = value.Value; + SetLedColorWithoutRequest(led, value.Value); } } - catch {/* ics that's not my fault ... */} + catch {/* idc that's not my fault ... */} } ///