1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Fixed a problem with syncbacked leds kept in the synced state forever

This commit is contained in:
Darth Affe 2018-06-06 20:47:05 +02:00
parent 9e44b8f9e5
commit 96184d1220
5 changed files with 43 additions and 11 deletions

View File

@ -131,6 +131,19 @@ namespace RGB.NET.Core
return led;
}
/// <summary>
/// Applies the give <see cref="Color"/> to the <see cref="Led"/> ignoring internal workflows regarding locks and update-requests.
/// This should be only used for syncbacks!
/// </summary>
/// <param name="led">The <see cref="Led"/> the <see cref="Color"/> should be aplied to.</param>
/// <param name="color">The <see cref="Color"/> to apply.</param>
protected virtual void SetLedColorWithoutRequest(Led led, Color color)
{
if (led == null) return;
led.InternalColor = color;
}
/// <summary>
/// Applies the given layout.
/// </summary>

View File

@ -57,13 +57,14 @@ namespace RGB.NET.Core
/// <summary>
/// Indicates whether the <see cref="Led" /> is about to change it's color.
/// </summary>
public bool IsDirty => RequestedColor != _color;
public bool IsDirty => RequestedColor.HasValue;
private Color _requestedColor = Color.Transparent;
private Color? _requestedColor;
/// <summary>
/// Gets a copy of the <see cref="Core.Color"/> the LED should be set to on the next update.
/// Null if there is no update-request for the next update.
/// </summary>
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;
}
}
}
/// <summary>
/// Gets or set the <see cref="Color"/> ignoring all workflows regarding locks and update-requests. />
/// </summary>
internal Color InternalColor
{
get => _color;
set => SetProperty(ref _color, value);
}
private bool _isLocked;
/// <summary>
/// Gets or sets if the color of this LED can be changed.
@ -143,7 +159,11 @@ namespace RGB.NET.Core
/// </summary>
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

View File

@ -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]));
}
/// <inheritdoc />

View File

@ -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);
}

View File

@ -51,11 +51,10 @@ namespace RGB.NET.Devices.Debug
foreach (KeyValuePair<LedId, Color> 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 ... */}
}
/// <inheritdoc />