diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs
index 305e1a2..feefc99 100644
--- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs
+++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs
@@ -40,6 +40,9 @@ namespace RGB.NET.Core
set => SetProperty(ref _location, value);
}
+ ///
+ public DeviceUpdateMode UpdateMode { get; set; } = DeviceUpdateMode.Sync;
+
///
/// Gets a dictionary containing all of the .
///
@@ -69,7 +72,7 @@ namespace RGB.NET.Core
#region Methods
///
- public virtual void Update(bool flushLeds = false)
+ public virtual void Update(bool render = true, bool flushLeds = false)
{
// Device-specific updates
DeviceUpdate();
@@ -79,9 +82,14 @@ namespace RGB.NET.Core
foreach (Led ledToUpdate in ledsToUpdate)
ledToUpdate.Update();
- UpdateLeds(ledsToUpdate);
+ if (UpdateMode.HasFlag(DeviceUpdateMode.Sync))
+ UpdateLeds(ledsToUpdate);
}
+ ///
+ public virtual void SyncBack()
+ { }
+
///
public virtual void Dispose()
{
diff --git a/RGB.NET.Core/Devices/DeviceUpdateMode.cs b/RGB.NET.Core/Devices/DeviceUpdateMode.cs
new file mode 100644
index 0000000..5f958b9
--- /dev/null
+++ b/RGB.NET.Core/Devices/DeviceUpdateMode.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace RGB.NET.Core
+{
+ [Flags]
+ public enum DeviceUpdateMode
+ {
+ None = 0,
+
+ Sync = 1 << 0,
+ SyncBack = 1 << 1,
+
+ NoUpdate = 1 << 0xFF
+ }
+}
diff --git a/RGB.NET.Core/Devices/IRGBDevice.cs b/RGB.NET.Core/Devices/IRGBDevice.cs
index 1c971b6..b766b65 100644
--- a/RGB.NET.Core/Devices/IRGBDevice.cs
+++ b/RGB.NET.Core/Devices/IRGBDevice.cs
@@ -28,6 +28,11 @@ namespace RGB.NET.Core
///
Size Size { get; }
+ ///
+ /// Gets or sets the of the .
+ ///
+ DeviceUpdateMode UpdateMode { get; set; }
+
#endregion
#region Indexer
@@ -60,9 +65,17 @@ namespace RGB.NET.Core
///
/// Perform an update for all dirty , or all if flushLeds is set to true.
+ /// Only physically syncs the colors to the device if is set to true.
///
+ /// Specifies whether the colors should be synced to the device or not.
/// Specifies whether all (including clean ones) should be updated.
- void Update(bool flushLeds = false);
+ void Update(bool sync = true, bool flushLeds = false);
+
+ ///
+ /// Synchronizes the internal state of the device to the real (physical) state.
+ /// This isn't supported by all devices! Check to see if it's supported or not.
+ ///
+ void SyncBack();
///
/// Adds the given to the device.
diff --git a/RGB.NET.Core/Devices/IRGBDeviceInfo.cs b/RGB.NET.Core/Devices/IRGBDeviceInfo.cs
index 23dbeb2..718f889 100644
--- a/RGB.NET.Core/Devices/IRGBDeviceInfo.cs
+++ b/RGB.NET.Core/Devices/IRGBDeviceInfo.cs
@@ -29,6 +29,11 @@ namespace RGB.NET.Core
///
RGBDeviceLighting Lighting { get; }
+ ///
+ /// Gets a bool indicating, if the supports SynBacks or not.
+ ///
+ bool SupportsSyncBack { get; }
+
///
/// Gets the URI of an image of the or null if there is no image.
///
diff --git a/RGB.NET.Core/Positioning/Point.cs b/RGB.NET.Core/Positioning/Point.cs
index de28c22..58eb2d9 100644
--- a/RGB.NET.Core/Positioning/Point.cs
+++ b/RGB.NET.Core/Positioning/Point.cs
@@ -67,7 +67,8 @@ namespace RGB.NET.Core
if (!(obj is Point)) return false;
Point comparePoint = (Point)obj;
- return X.EqualsInTolerance(comparePoint.X) && Y.EqualsInTolerance(comparePoint.Y);
+ return ((double.IsNaN(X) && double.IsNaN(comparePoint.X)) || X.EqualsInTolerance(comparePoint.X))
+ && ((double.IsNaN(Y) && double.IsNaN(comparePoint.Y)) || Y.EqualsInTolerance(comparePoint.Y));
}
///
diff --git a/RGB.NET.Core/Positioning/Size.cs b/RGB.NET.Core/Positioning/Size.cs
index 2d967f8..d6b7c6f 100644
--- a/RGB.NET.Core/Positioning/Size.cs
+++ b/RGB.NET.Core/Positioning/Size.cs
@@ -76,7 +76,8 @@ namespace RGB.NET.Core
if (!(obj is Size)) return false;
Size compareSize = (Size)obj;
- return Width.EqualsInTolerance(compareSize.Width) && Height.EqualsInTolerance(compareSize.Height);
+ return ((double.IsNaN(Width) && double.IsNaN(compareSize.Width)) || Width.EqualsInTolerance(compareSize.Width))
+ && ((double.IsNaN(Height) && double.IsNaN(compareSize.Height)) || Height.EqualsInTolerance(compareSize.Height));
}
///
diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj
index 429140a..722ec5e 100644
--- a/RGB.NET.Core/RGB.NET.Core.csproj
+++ b/RGB.NET.Core/RGB.NET.Core.csproj
@@ -58,6 +58,7 @@
+
diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs
index 435f2dd..2d2a2c7 100644
--- a/RGB.NET.Core/RGBSurface.cs
+++ b/RGB.NET.Core/RGBSurface.cs
@@ -67,7 +67,7 @@ namespace RGB.NET.Core
#region Methods
///
- /// Perform an update for all dirty , or all , if flushLeds is set to true.
+ /// Perform a full update for all devices. Updates only dirty by default, or all , if flushLeds is set to true.
///
/// Specifies whether all , (including clean ones) should be updated.
public void Update(bool flushLeds = false)
@@ -76,6 +76,11 @@ namespace RGB.NET.Core
{
OnUpdating();
+ foreach (IRGBDevice device in Devices)
+ if (device.UpdateMode.HasFlag(DeviceUpdateMode.SyncBack) && device.DeviceInfo.SupportsSyncBack)
+ try { device.SyncBack(); }
+ catch (Exception ex) { OnException(ex); }
+
lock (_ledGroups)
{
// Render brushes
@@ -85,8 +90,9 @@ namespace RGB.NET.Core
}
foreach (IRGBDevice device in Devices)
- try { device.Update(flushLeds); }
- catch (Exception ex) { OnException(ex); }
+ if (!device.UpdateMode.HasFlag(DeviceUpdateMode.NoUpdate))
+ try { device.Update(flushLeds); }
+ catch (Exception ex) { OnException(ex); }
OnUpdated();
}
diff --git a/RGB.NET.Devices.Asus/Dram/AsusDramRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/Dram/AsusDramRGBDeviceInfo.cs
index 26739b9..ac9f411 100644
--- a/RGB.NET.Devices.Asus/Dram/AsusDramRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Asus/Dram/AsusDramRGBDeviceInfo.cs
@@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
///
public class AsusDramRGBDeviceInfo : AsusRGBDeviceInfo
{
+ #region Properties & Fields
+
+ ///
+ public override bool SupportsSyncBack => true;
+
+ #endregion
+
#region Constructors
///
diff --git a/RGB.NET.Devices.Asus/Enum/AsusLedIds.cs b/RGB.NET.Devices.Asus/Enum/AsusLedIds.cs
index 9b43f63..67c9d7e 100644
--- a/RGB.NET.Devices.Asus/Enum/AsusLedIds.cs
+++ b/RGB.NET.Devices.Asus/Enum/AsusLedIds.cs
@@ -13,11 +13,11 @@ namespace RGB.NET.Devices.Asus
//TODO DarthAffe 07.10.2017: Create useful Ids for all devices
- MainboardAudio1 = 0x01,
- MainboardAudio2 = 0x02,
- MainboardAudio3 = 0x03,
- MainboardAudio4 = 0x04,
- MainboardRGBStrip1 = 0x05,
+ MainboardLed1 = 0x01,
+ MainboardLed2 = 0x02,
+ MainboardLed3 = 0x03,
+ MainboardLed4 = 0x04,
+ MainboardLed5 = 0x05,
GraphicsCardLed1 = 0x11,
diff --git a/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs
index 95faa34..bcf2c39 100644
--- a/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs
@@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Asus
///
/// Represents a generic information for a Corsair-.
///
- public class AsusRGBDeviceInfo : IRGBDeviceInfo
+ public abstract class AsusRGBDeviceInfo : IRGBDeviceInfo
{
#region Properties & Fields
@@ -26,6 +26,9 @@ namespace RGB.NET.Devices.Asus
///
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
+ ///
+ public abstract bool SupportsSyncBack { get; }
+
///
/// Gets the index of the .
///
@@ -42,7 +45,7 @@ namespace RGB.NET.Devices.Asus
/// The handle of the .
/// The manufacturer-name of the .
/// The model-name of the .
- internal AsusRGBDeviceInfo(RGBDeviceType deviceType, IntPtr handle, string manufacturer = "Unknown", string model = "Generic Asus-Device")
+ internal AsusRGBDeviceInfo(RGBDeviceType deviceType, IntPtr handle, string manufacturer = "Asus", string model = "Generic Asus-Device")
{
this.DeviceType = deviceType;
this.Handle = handle;
diff --git a/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDeviceInfo.cs
index 5506668..2547d3f 100644
--- a/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDeviceInfo.cs
@@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
///
public class AsusGraphicsCardRGBDeviceInfo : AsusRGBDeviceInfo
{
+ #region Properties & Fields
+
+ ///
+ public override bool SupportsSyncBack => false;
+
+ #endregion
+
#region Constructors
///
diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs
index 350ffa3..ec3b1d3 100644
--- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs
@@ -11,7 +11,10 @@ namespace RGB.NET.Devices.Asus
public class AsusKeyboardRGBDeviceInfo : AsusRGBDeviceInfo
{
#region Properties & Fields
-
+
+ ///
+ public override bool SupportsSyncBack => false;
+
///
/// Gets the physical layout of the keyboard.
///
diff --git a/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs b/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs
index 67d0423..6b91f5a 100644
--- a/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs
+++ b/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs
@@ -30,13 +30,21 @@ namespace RGB.NET.Devices.Asus
//TODO DarthAffe 07.10.2017: Look for a good default layout
int ledCount = _AsusSDK.GetMbLedCount(DeviceInfo.Handle);
for (int i = 0; i < ledCount; i++)
- InitializeLed(new AsusLedId(this, AsusLedIds.MainboardAudio1 + i, i), new Rectangle(i * 40, 0, 40, 8));
+ InitializeLed(new AsusLedId(this, AsusLedIds.MainboardLed1 + i, i), new Rectangle(i * 40, 0, 40, 8));
//TODO DarthAffe 07.10.2017: We don'T know the model, how to save layouts and images?
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Mainboards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"),
null, PathHelper.GetAbsolutePath(@"Images\Asus\Mainboards"));
}
+ ///
+ public override void SyncBack()
+ {
+ byte[] colorData = _AsusSDK.GetMbColor(DeviceInfo.Handle);
+ for (int i = 0; i < LedMapping.Count; i++)
+ LedMapping[new AsusLedId(this, AsusLedIds.MainboardLed1 + i)].Color = new Color(colorData[(i * 3)], colorData[(i * 3) + 2], colorData[(i * 3) + 1]);
+ }
+
///
protected override void ApplyColorData() => _AsusSDK.SetMbColor(DeviceInfo.Handle, ColorData);
diff --git a/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDeviceInfo.cs
index bcfda88..732813e 100644
--- a/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDeviceInfo.cs
@@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
///
public class AsusMainboardRGBDeviceInfo : AsusRGBDeviceInfo
{
+ #region Properties & Fields
+
+ ///
+ public override bool SupportsSyncBack => true;
+
+ #endregion
+
#region Constructors
///
diff --git a/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDeviceInfo.cs
index 9e82924..d83f79b 100644
--- a/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDeviceInfo.cs
@@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
///
public class AsusMouseRGBDeviceInfo : AsusRGBDeviceInfo
{
+ #region Properties & Fields
+
+ ///
+ public override bool SupportsSyncBack => false;
+
+ #endregion
+
#region Constructors
///
diff --git a/RGB.NET.Devices.Asus/Native/_AsusSDK.cs b/RGB.NET.Devices.Asus/Native/_AsusSDK.cs
index 642f1a1..e4e881c 100644
--- a/RGB.NET.Devices.Asus/Native/_AsusSDK.cs
+++ b/RGB.NET.Devices.Asus/Native/_AsusSDK.cs
@@ -191,7 +191,7 @@ namespace RGB.NET.Devices.Asus.Native
internal static byte[] GetMbColor(IntPtr handle)
{
- int count = _getDramColorPointer(handle, IntPtr.Zero, 0);
+ int count = _getMbColorPointer(handle, IntPtr.Zero, 0);
byte[] colors = new byte[count];
IntPtr readColorsPtr = Marshal.AllocHGlobal(colors.Length);
_getMbColorPointer(handle, readColorsPtr, colors.Length);
diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDeviceInfo.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDeviceInfo.cs
index c08ad0b..25d67e9 100644
--- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDeviceInfo.cs
@@ -27,6 +27,9 @@ namespace RGB.NET.Devices.CoolerMaster
///
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
+ ///
+ public bool SupportsSyncBack => false;
+
///
/// Gets the of the .
///
diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs
index 2cbf7c3..c2fadf5 100644
--- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs
+++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs
@@ -127,11 +127,8 @@ namespace RGB.NET.Devices.Corsair
}
}
- ///
- /// Reads the current color-data from the device
- ///
- /// A dictionary mapping the to the current .
- protected Dictionary GetColors()
+ ///
+ public override void SyncBack()
{
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
IntPtr ptr = Marshal.AllocHGlobal(structSize * LedMapping.Count);
@@ -145,18 +142,15 @@ namespace RGB.NET.Devices.Corsair
_CUESDK.CorsairGetLedsColors(LedMapping.Count, ptr);
IntPtr readPtr = ptr;
- Dictionary colorData = new Dictionary();
for (int i = 0; i < LedMapping.Count; i++)
{
_CorsairLedColor ledColor = (_CorsairLedColor)Marshal.PtrToStructure(readPtr, typeof(_CorsairLedColor));
- colorData.Add((CorsairLedIds)ledColor.ledId, new Color(ledColor.r, ledColor.g, ledColor.b));
+ LedMapping[new CorsairLedId(this, (CorsairLedIds)ledColor.ledId)].Color = new Color(ledColor.r, ledColor.g, ledColor.b);
readPtr = new IntPtr(readPtr.ToInt64() + structSize);
}
Marshal.FreeHGlobal(ptr);
-
- return colorData;
}
#endregion
diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs
index b6cccbf..446dc4f 100644
--- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs
@@ -35,6 +35,9 @@ namespace RGB.NET.Devices.Corsair
///
public Uri Image { get; protected set; }
+ ///
+ public bool SupportsSyncBack => true;
+
///
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
diff --git a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs
index f6474f0..8e02dd2 100644
--- a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs
+++ b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs
@@ -34,10 +34,7 @@ namespace RGB.NET.Devices.Corsair
///
protected override void InitializeLayout()
{
- _CorsairLedPositions nativeLedPositions =
- (_CorsairLedPositions)
- Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex),
- typeof(_CorsairLedPositions));
+ _CorsairLedPositions nativeLedPositions = (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex), typeof(_CorsairLedPositions));
int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
IntPtr ptr = nativeLedPositions.pLedPosition;
diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings
index 0ba3335..12c37b7 100644
--- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings
+++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings
@@ -1,4 +1,5 @@
+ True
True
True
False
diff --git a/RGB.NET.Devices.Logitech/Generic/LogitechRGBDeviceInfo.cs b/RGB.NET.Devices.Logitech/Generic/LogitechRGBDeviceInfo.cs
index 262967c..b5370dd 100644
--- a/RGB.NET.Devices.Logitech/Generic/LogitechRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Logitech/Generic/LogitechRGBDeviceInfo.cs
@@ -38,6 +38,9 @@ namespace RGB.NET.Devices.Logitech
}
}
+ ///
+ public bool SupportsSyncBack => false;
+
///
/// Gets a flag that describes device capabilities. ()
///
diff --git a/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs b/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs
index 89b12e0..450f5b8 100644
--- a/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs
@@ -28,6 +28,9 @@ namespace RGB.NET.Devices.Msi
///
public Uri Image { get; protected set; }
+ ///
+ public bool SupportsSyncBack => false;
+
///
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
diff --git a/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs b/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs
index 6179ea4..31f848e 100644
--- a/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs
@@ -26,6 +26,9 @@ namespace RGB.NET.Devices.Novation
///
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
+ ///
+ public bool SupportsSyncBack => false;
+
///
/// Gets the of the .
///