Improved the led update mechanism

This commit is contained in:
DarthAffe committed 2015-09-20 12:16:24 +02:00
1 parent 61b712d026
commit 4e1a1d11bd
9 files changed
+112 -45

No files matched your search

+13 -2
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using CUE.NET.Native;
@@ -35,9 +36,19 @@ namespace CUE.NET.Devices.Generic
return Leds[ledId];
}
public virtual void UpdateLeds(bool fullUpdate = false)
public virtual void UpdateLeds(bool forceUpdate = false)
{
IList<KeyValuePair<int, CorsairLed>> ledsToUpdate = (fullUpdate ? Leds : Leds.Where(x => x.Value.IsDirty)).ToList();
IList<KeyValuePair<int, CorsairLed>> ledsToUpdate = (forceUpdate ? Leds : Leds.Where(x => x.Value.IsDirty)).ToList();
foreach (CorsairLed led in Leds.Values)
led.Update();
UpdateLeds(ledsToUpdate);
}
private static void UpdateLeds(ICollection<KeyValuePair<int, CorsairLed>> ledsToUpdate)
{
ledsToUpdate = ledsToUpdate.Where(x => x.Value.Color != Color.Transparent).ToList();
if (!ledsToUpdate.Any())
return; // CUE seems to crash if 'CorsairSetLedsColors' is called with a zero length array
+22 -6
View File
@@ -6,21 +6,27 @@ namespace CUE.NET.Devices.Generic
{
#region Properties & Fields
public bool IsDirty { get; private set; } = false;
public bool IsDirty => RequestedColor != _color;
public bool IsUpdated { get; private set; }
private Color _color = Color.Black;
public Color RequestedColor { get; private set; } = Color.Transparent;
private Color _color = Color.Transparent;
public Color Color
{
get { return _color; }
set
{
if (_color != value)
IsDirty = true;
_color = value;
if (!IsLocked)
{
RequestedColor = value;
IsUpdated = true;
}
}
}
public bool IsLocked { get; set; } = false;
//TODO DarthAffe 19.09.2015: Add effects and stuff
#endregion
@@ -30,5 +36,15 @@ namespace CUE.NET.Devices.Generic
internal CorsairLed() { }
#endregion
#region Methods
internal void Update()
{
_color = RequestedColor;
IsUpdated = false;
}
#endregion
}
}
+1 -2
View File
@@ -13,8 +13,7 @@ namespace CUE.NET.Devices.Generic
/// Device type.
/// </summary>
public CorsairDeviceType Type { get; }
//TODO DarthAffe 17.09.2015: This could be an Enum
/// <summary>
/// Device model (like “K95RGB”).
/// </summary>