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

Added device update modes and implemented syncback for corsair and asus

This commit is contained in:
Darth Affe 2017-12-06 15:41:23 +01:00
parent 5e59948d83
commit b700c84b8d
25 changed files with 130 additions and 31 deletions

View File

@ -40,6 +40,9 @@ namespace RGB.NET.Core
set => SetProperty(ref _location, value); set => SetProperty(ref _location, value);
} }
/// <inheritdoc />
public DeviceUpdateMode UpdateMode { get; set; } = DeviceUpdateMode.Sync;
/// <summary> /// <summary>
/// Gets a dictionary containing all <see cref="Led"/> of the <see cref="IRGBDevice"/>. /// Gets a dictionary containing all <see cref="Led"/> of the <see cref="IRGBDevice"/>.
/// </summary> /// </summary>
@ -69,7 +72,7 @@ namespace RGB.NET.Core
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
public virtual void Update(bool flushLeds = false) public virtual void Update(bool render = true, bool flushLeds = false)
{ {
// Device-specific updates // Device-specific updates
DeviceUpdate(); DeviceUpdate();
@ -79,9 +82,14 @@ namespace RGB.NET.Core
foreach (Led ledToUpdate in ledsToUpdate) foreach (Led ledToUpdate in ledsToUpdate)
ledToUpdate.Update(); ledToUpdate.Update();
UpdateLeds(ledsToUpdate); if (UpdateMode.HasFlag(DeviceUpdateMode.Sync))
UpdateLeds(ledsToUpdate);
} }
/// <inheritdoc />
public virtual void SyncBack()
{ }
/// <inheritdoc /> /// <inheritdoc />
public virtual void Dispose() public virtual void Dispose()
{ {

View File

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

View File

@ -28,6 +28,11 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
Size Size { get; } Size Size { get; }
/// <summary>
/// Gets or sets the <see cref="DeviceUpdateMode"/> of the <see cref="IRGBDevice"/>.
/// </summary>
DeviceUpdateMode UpdateMode { get; set; }
#endregion #endregion
#region Indexer #region Indexer
@ -60,9 +65,17 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Perform an update for all dirty <see cref="Led"/>, or all <see cref="Led"/> if flushLeds is set to true. /// Perform an update for all dirty <see cref="Led"/>, or all <see cref="Led"/> if flushLeds is set to true.
/// Only physically syncs the colors to the device if <paramref name="sync"/> is set to true.
/// </summary> /// </summary>
/// <param name="sync">Specifies whether the colors should be synced to the device or not.</param>
/// <param name="flushLeds">Specifies whether all <see cref="Led"/> (including clean ones) should be updated.</param> /// <param name="flushLeds">Specifies whether all <see cref="Led"/> (including clean ones) should be updated.</param>
void Update(bool flushLeds = false); void Update(bool sync = true, bool flushLeds = false);
/// <summary>
/// Synchronizes the internal state of the device to the real (physical) state.
/// This isn't supported by all devices! Check <see cref="IRGBDeviceInfo.SupportsSyncBack"/> to see if it's supported or not.
/// </summary>
void SyncBack();
/// <summary> /// <summary>
/// Adds the given <see cref="IRGBDeviceSpecialPart"/> to the device. /// Adds the given <see cref="IRGBDeviceSpecialPart"/> to the device.

View File

@ -29,6 +29,11 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
RGBDeviceLighting Lighting { get; } RGBDeviceLighting Lighting { get; }
/// <summary>
/// Gets a bool indicating, if the <see cref="IRGBDevice"/> supports SynBacks or not.
/// </summary>
bool SupportsSyncBack { get; }
/// <summary> /// <summary>
/// Gets the URI of an image of the <see cref="IRGBDevice"/> or null if there is no image. /// Gets the URI of an image of the <see cref="IRGBDevice"/> or null if there is no image.
/// </summary> /// </summary>

View File

@ -67,7 +67,8 @@ namespace RGB.NET.Core
if (!(obj is Point)) return false; if (!(obj is Point)) return false;
Point comparePoint = (Point)obj; 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));
} }
/// <summary> /// <summary>

View File

@ -76,7 +76,8 @@ namespace RGB.NET.Core
if (!(obj is Size)) return false; if (!(obj is Size)) return false;
Size compareSize = (Size)obj; 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));
} }
/// <summary> /// <summary>

View File

@ -58,6 +58,7 @@
<Compile Include="Decorators\IDecorator.cs" /> <Compile Include="Decorators\IDecorator.cs" />
<Compile Include="Decorators\ILedGroupDecorator.cs" /> <Compile Include="Decorators\ILedGroupDecorator.cs" />
<Compile Include="Devices\AbstractRGBDevice.cs" /> <Compile Include="Devices\AbstractRGBDevice.cs" />
<Compile Include="Devices\DeviceUpdateMode.cs" />
<Compile Include="Devices\IRGBDeviceSpecialPart.cs" /> <Compile Include="Devices\IRGBDeviceSpecialPart.cs" />
<Compile Include="Devices\Layout\LedImage.cs" /> <Compile Include="Devices\Layout\LedImage.cs" />
<Compile Include="Devices\Layout\LedImageLayout.cs" /> <Compile Include="Devices\Layout\LedImageLayout.cs" />

View File

@ -67,7 +67,7 @@ namespace RGB.NET.Core
#region Methods #region Methods
/// <summary> /// <summary>
/// Perform an update for all dirty <see cref="Led"/>, or all <see cref="Led"/>, if flushLeds is set to true. /// Perform a full update for all devices. Updates only dirty <see cref="Led"/> by default, or all <see cref="Led"/>, if flushLeds is set to true.
/// </summary> /// </summary>
/// <param name="flushLeds">Specifies whether all <see cref="Led"/>, (including clean ones) should be updated.</param> /// <param name="flushLeds">Specifies whether all <see cref="Led"/>, (including clean ones) should be updated.</param>
public void Update(bool flushLeds = false) public void Update(bool flushLeds = false)
@ -76,6 +76,11 @@ namespace RGB.NET.Core
{ {
OnUpdating(); 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) lock (_ledGroups)
{ {
// Render brushes // Render brushes
@ -85,8 +90,9 @@ namespace RGB.NET.Core
} }
foreach (IRGBDevice device in Devices) foreach (IRGBDevice device in Devices)
try { device.Update(flushLeds); } if (!device.UpdateMode.HasFlag(DeviceUpdateMode.NoUpdate))
catch (Exception ex) { OnException(ex); } try { device.Update(flushLeds); }
catch (Exception ex) { OnException(ex); }
OnUpdated(); OnUpdated();
} }

View File

@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
/// </summary> /// </summary>
public class AsusDramRGBDeviceInfo : AsusRGBDeviceInfo public class AsusDramRGBDeviceInfo : AsusRGBDeviceInfo
{ {
#region Properties & Fields
/// <inheritdoc />
public override bool SupportsSyncBack => true;
#endregion
#region Constructors #region Constructors
/// <inheritdoc /> /// <inheritdoc />

View File

@ -13,11 +13,11 @@ namespace RGB.NET.Devices.Asus
//TODO DarthAffe 07.10.2017: Create useful Ids for all devices //TODO DarthAffe 07.10.2017: Create useful Ids for all devices
MainboardAudio1 = 0x01, MainboardLed1 = 0x01,
MainboardAudio2 = 0x02, MainboardLed2 = 0x02,
MainboardAudio3 = 0x03, MainboardLed3 = 0x03,
MainboardAudio4 = 0x04, MainboardLed4 = 0x04,
MainboardRGBStrip1 = 0x05, MainboardLed5 = 0x05,
GraphicsCardLed1 = 0x11, GraphicsCardLed1 = 0x11,

View File

@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Asus
/// <summary> /// <summary>
/// Represents a generic information for a Corsair-<see cref="T:RGB.NET.Core.IRGBDevice" />. /// Represents a generic information for a Corsair-<see cref="T:RGB.NET.Core.IRGBDevice" />.
/// </summary> /// </summary>
public class AsusRGBDeviceInfo : IRGBDeviceInfo public abstract class AsusRGBDeviceInfo : IRGBDeviceInfo
{ {
#region Properties & Fields #region Properties & Fields
@ -26,6 +26,9 @@ namespace RGB.NET.Devices.Asus
/// <inheritdoc /> /// <inheritdoc />
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key; public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
/// <inheritdoc />
public abstract bool SupportsSyncBack { get; }
/// <summary> /// <summary>
/// Gets the index of the <see cref="AsusRGBDevice{TDeviceInfo}"/>. /// Gets the index of the <see cref="AsusRGBDevice{TDeviceInfo}"/>.
/// </summary> /// </summary>
@ -42,7 +45,7 @@ namespace RGB.NET.Devices.Asus
/// <param name="handle">The handle of the <see cref="IRGBDevice"/>.</param> /// <param name="handle">The handle of the <see cref="IRGBDevice"/>.</param>
/// <param name="manufacturer">The manufacturer-name of the <see cref="IRGBDevice"/>.</param> /// <param name="manufacturer">The manufacturer-name of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The model-name of the <see cref="IRGBDevice"/>.</param> /// <param name="model">The model-name of the <see cref="IRGBDevice"/>.</param>
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.DeviceType = deviceType;
this.Handle = handle; this.Handle = handle;

View File

@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
/// </summary> /// </summary>
public class AsusGraphicsCardRGBDeviceInfo : AsusRGBDeviceInfo public class AsusGraphicsCardRGBDeviceInfo : AsusRGBDeviceInfo
{ {
#region Properties & Fields
/// <inheritdoc />
public override bool SupportsSyncBack => false;
#endregion
#region Constructors #region Constructors
/// <inheritdoc /> /// <inheritdoc />

View File

@ -11,7 +11,10 @@ namespace RGB.NET.Devices.Asus
public class AsusKeyboardRGBDeviceInfo : AsusRGBDeviceInfo public class AsusKeyboardRGBDeviceInfo : AsusRGBDeviceInfo
{ {
#region Properties & Fields #region Properties & Fields
/// <inheritdoc />
public override bool SupportsSyncBack => false;
/// <summary> /// <summary>
/// Gets the physical layout of the keyboard. /// Gets the physical layout of the keyboard.
/// </summary> /// </summary>

View File

@ -30,13 +30,21 @@ namespace RGB.NET.Devices.Asus
//TODO DarthAffe 07.10.2017: Look for a good default layout //TODO DarthAffe 07.10.2017: Look for a good default layout
int ledCount = _AsusSDK.GetMbLedCount(DeviceInfo.Handle); int ledCount = _AsusSDK.GetMbLedCount(DeviceInfo.Handle);
for (int i = 0; i < ledCount; i++) 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? //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"), ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Mainboards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"),
null, PathHelper.GetAbsolutePath(@"Images\Asus\Mainboards")); null, PathHelper.GetAbsolutePath(@"Images\Asus\Mainboards"));
} }
/// <inheritdoc />
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]);
}
/// <inheritdoc /> /// <inheritdoc />
protected override void ApplyColorData() => _AsusSDK.SetMbColor(DeviceInfo.Handle, ColorData); protected override void ApplyColorData() => _AsusSDK.SetMbColor(DeviceInfo.Handle, ColorData);

View File

@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
/// </summary> /// </summary>
public class AsusMainboardRGBDeviceInfo : AsusRGBDeviceInfo public class AsusMainboardRGBDeviceInfo : AsusRGBDeviceInfo
{ {
#region Properties & Fields
/// <inheritdoc />
public override bool SupportsSyncBack => true;
#endregion
#region Constructors #region Constructors
/// <inheritdoc /> /// <inheritdoc />

View File

@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
/// </summary> /// </summary>
public class AsusMouseRGBDeviceInfo : AsusRGBDeviceInfo public class AsusMouseRGBDeviceInfo : AsusRGBDeviceInfo
{ {
#region Properties & Fields
/// <inheritdoc />
public override bool SupportsSyncBack => false;
#endregion
#region Constructors #region Constructors
/// <inheritdoc /> /// <inheritdoc />

View File

@ -191,7 +191,7 @@ namespace RGB.NET.Devices.Asus.Native
internal static byte[] GetMbColor(IntPtr handle) 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]; byte[] colors = new byte[count];
IntPtr readColorsPtr = Marshal.AllocHGlobal(colors.Length); IntPtr readColorsPtr = Marshal.AllocHGlobal(colors.Length);
_getMbColorPointer(handle, readColorsPtr, colors.Length); _getMbColorPointer(handle, readColorsPtr, colors.Length);

View File

@ -27,6 +27,9 @@ namespace RGB.NET.Devices.CoolerMaster
/// <inheritdoc /> /// <inheritdoc />
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key; public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
/// <inheritdoc />
public bool SupportsSyncBack => false;
/// <summary> /// <summary>
/// Gets the <see cref="CoolerMasterDevicesIndexes"/> of the <see cref="CoolerMasterRGBDevice{TDeviceInfo}"/>. /// Gets the <see cref="CoolerMasterDevicesIndexes"/> of the <see cref="CoolerMasterRGBDevice{TDeviceInfo}"/>.
/// </summary> /// </summary>

View File

@ -127,11 +127,8 @@ namespace RGB.NET.Devices.Corsair
} }
} }
/// <summary> /// <inheritdoc cref="IRGBDevice.SyncBack" />
/// Reads the current color-data from the device public override void SyncBack()
/// </summary>
/// <returns>A dictionary mapping the <see cref="CorsairLedIds"/> to the current <see cref="Color"/>.</returns>
protected Dictionary<CorsairLedIds, Color> GetColors()
{ {
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor)); int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
IntPtr ptr = Marshal.AllocHGlobal(structSize * LedMapping.Count); IntPtr ptr = Marshal.AllocHGlobal(structSize * LedMapping.Count);
@ -145,18 +142,15 @@ namespace RGB.NET.Devices.Corsair
_CUESDK.CorsairGetLedsColors(LedMapping.Count, ptr); _CUESDK.CorsairGetLedsColors(LedMapping.Count, ptr);
IntPtr readPtr = ptr; IntPtr readPtr = ptr;
Dictionary<CorsairLedIds, Color> colorData = new Dictionary<CorsairLedIds, Color>();
for (int i = 0; i < LedMapping.Count; i++) for (int i = 0; i < LedMapping.Count; i++)
{ {
_CorsairLedColor ledColor = (_CorsairLedColor)Marshal.PtrToStructure(readPtr, typeof(_CorsairLedColor)); _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); readPtr = new IntPtr(readPtr.ToInt64() + structSize);
} }
Marshal.FreeHGlobal(ptr); Marshal.FreeHGlobal(ptr);
return colorData;
} }
#endregion #endregion

View File

@ -35,6 +35,9 @@ namespace RGB.NET.Devices.Corsair
/// <inheritdoc /> /// <inheritdoc />
public Uri Image { get; protected set; } public Uri Image { get; protected set; }
/// <inheritdoc />
public bool SupportsSyncBack => true;
/// <inheritdoc /> /// <inheritdoc />
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key; public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;

View File

@ -34,10 +34,7 @@ namespace RGB.NET.Devices.Corsair
/// <inheritdoc /> /// <inheritdoc />
protected override void InitializeLayout() protected override void InitializeLayout()
{ {
_CorsairLedPositions nativeLedPositions = _CorsairLedPositions nativeLedPositions = (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex), typeof(_CorsairLedPositions));
(_CorsairLedPositions)
Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex),
typeof(_CorsairLedPositions));
int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
IntPtr ptr = nativeLedPositions.pLedPosition; IntPtr ptr = nativeLedPositions.pLedPosition;

View File

@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=headsetstand/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=libs/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=libs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mousepad/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mousepad/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=native/@EntryIndexedValue">False</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=native/@EntryIndexedValue">False</s:Boolean>

View File

@ -38,6 +38,9 @@ namespace RGB.NET.Devices.Logitech
} }
} }
/// <inheritdoc />
public bool SupportsSyncBack => false;
/// <summary> /// <summary>
/// Gets a flag that describes device capabilities. (<see cref="LogitechDeviceCaps" />) /// Gets a flag that describes device capabilities. (<see cref="LogitechDeviceCaps" />)
/// </summary> /// </summary>

View File

@ -28,6 +28,9 @@ namespace RGB.NET.Devices.Msi
/// <inheritdoc /> /// <inheritdoc />
public Uri Image { get; protected set; } public Uri Image { get; protected set; }
/// <inheritdoc />
public bool SupportsSyncBack => false;
/// <inheritdoc /> /// <inheritdoc />
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key; public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;

View File

@ -26,6 +26,9 @@ namespace RGB.NET.Devices.Novation
/// <inheritdoc /> /// <inheritdoc />
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key; public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
/// <inheritdoc />
public bool SupportsSyncBack => false;
/// <summary> /// <summary>
/// Gets the <see cref="NovationColorCapabilities"/> of the <see cref="IRGBDevice"/>. /// Gets the <see cref="NovationColorCapabilities"/> of the <see cref="IRGBDevice"/>.
/// </summary> /// </summary>