mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Added device update modes and implemented syncback for corsair and asus
This commit is contained in:
parent
5e59948d83
commit
b700c84b8d
@ -40,6 +40,9 @@ namespace RGB.NET.Core
|
||||
set => SetProperty(ref _location, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public DeviceUpdateMode UpdateMode { get; set; } = DeviceUpdateMode.Sync;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dictionary containing all <see cref="Led"/> of the <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
@ -69,7 +72,7 @@ namespace RGB.NET.Core
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void SyncBack()
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Dispose()
|
||||
{
|
||||
|
||||
15
RGB.NET.Core/Devices/DeviceUpdateMode.cs
Normal file
15
RGB.NET.Core/Devices/DeviceUpdateMode.cs
Normal 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
|
||||
}
|
||||
}
|
||||
@ -28,6 +28,11 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
Size Size { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="DeviceUpdateMode"/> of the <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
DeviceUpdateMode UpdateMode { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexer
|
||||
@ -60,9 +65,17 @@ namespace RGB.NET.Core
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <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>
|
||||
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>
|
||||
/// Adds the given <see cref="IRGBDeviceSpecialPart"/> to the device.
|
||||
|
||||
@ -29,6 +29,11 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
RGBDeviceLighting Lighting { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a bool indicating, if the <see cref="IRGBDevice"/> supports SynBacks or not.
|
||||
/// </summary>
|
||||
bool SupportsSyncBack { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URI of an image of the <see cref="IRGBDevice"/> or null if there is no image.
|
||||
/// </summary>
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -58,6 +58,7 @@
|
||||
<Compile Include="Decorators\IDecorator.cs" />
|
||||
<Compile Include="Decorators\ILedGroupDecorator.cs" />
|
||||
<Compile Include="Devices\AbstractRGBDevice.cs" />
|
||||
<Compile Include="Devices\DeviceUpdateMode.cs" />
|
||||
<Compile Include="Devices\IRGBDeviceSpecialPart.cs" />
|
||||
<Compile Include="Devices\Layout\LedImage.cs" />
|
||||
<Compile Include="Devices\Layout\LedImageLayout.cs" />
|
||||
|
||||
@ -67,7 +67,7 @@ namespace RGB.NET.Core
|
||||
#region Methods
|
||||
|
||||
/// <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>
|
||||
/// <param name="flushLeds">Specifies whether all <see cref="Led"/>, (including clean ones) should be updated.</param>
|
||||
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();
|
||||
}
|
||||
|
||||
@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
|
||||
/// </summary>
|
||||
public class AsusDramRGBDeviceInfo : AsusRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool SupportsSyncBack => true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -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,
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Asus
|
||||
/// <summary>
|
||||
/// Represents a generic information for a Corsair-<see cref="T:RGB.NET.Core.IRGBDevice" />.
|
||||
/// </summary>
|
||||
public class AsusRGBDeviceInfo : IRGBDeviceInfo
|
||||
public abstract class AsusRGBDeviceInfo : IRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@ -26,6 +26,9 @@ namespace RGB.NET.Devices.Asus
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract bool SupportsSyncBack { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index of the <see cref="AsusRGBDevice{TDeviceInfo}"/>.
|
||||
/// </summary>
|
||||
@ -42,7 +45,7 @@ namespace RGB.NET.Devices.Asus
|
||||
/// <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="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.Handle = handle;
|
||||
|
||||
@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
|
||||
/// </summary>
|
||||
public class AsusGraphicsCardRGBDeviceInfo : AsusRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool SupportsSyncBack => false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -11,7 +11,10 @@ namespace RGB.NET.Devices.Asus
|
||||
public class AsusKeyboardRGBDeviceInfo : AsusRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool SupportsSyncBack => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the physical layout of the keyboard.
|
||||
/// </summary>
|
||||
|
||||
@ -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"));
|
||||
}
|
||||
|
||||
/// <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 />
|
||||
protected override void ApplyColorData() => _AsusSDK.SetMbColor(DeviceInfo.Handle, ColorData);
|
||||
|
||||
|
||||
@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
|
||||
/// </summary>
|
||||
public class AsusMainboardRGBDeviceInfo : AsusRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool SupportsSyncBack => true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -9,6 +9,13 @@ namespace RGB.NET.Devices.Asus
|
||||
/// </summary>
|
||||
public class AsusMouseRGBDeviceInfo : AsusRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool SupportsSyncBack => false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -27,6 +27,9 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SupportsSyncBack => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CoolerMasterDevicesIndexes"/> of the <see cref="CoolerMasterRGBDevice{TDeviceInfo}"/>.
|
||||
/// </summary>
|
||||
|
||||
@ -127,11 +127,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the current color-data from the device
|
||||
/// </summary>
|
||||
/// <returns>A dictionary mapping the <see cref="CorsairLedIds"/> to the current <see cref="Color"/>.</returns>
|
||||
protected Dictionary<CorsairLedIds, Color> GetColors()
|
||||
/// <inheritdoc cref="IRGBDevice.SyncBack" />
|
||||
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<CorsairLedIds, Color> colorData = new Dictionary<CorsairLedIds, Color>();
|
||||
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
|
||||
|
||||
@ -35,6 +35,9 @@ namespace RGB.NET.Devices.Corsair
|
||||
/// <inheritdoc />
|
||||
public Uri Image { get; protected set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SupportsSyncBack => true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
|
||||
|
||||
|
||||
@ -34,10 +34,7 @@ namespace RGB.NET.Devices.Corsair
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
|
||||
@ -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">
|
||||
<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/=mousepad/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=native/@EntryIndexedValue">False</s:Boolean>
|
||||
|
||||
@ -38,6 +38,9 @@ namespace RGB.NET.Devices.Logitech
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SupportsSyncBack => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a flag that describes device capabilities. (<see cref="LogitechDeviceCaps" />)
|
||||
/// </summary>
|
||||
|
||||
@ -28,6 +28,9 @@ namespace RGB.NET.Devices.Msi
|
||||
/// <inheritdoc />
|
||||
public Uri Image { get; protected set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SupportsSyncBack => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
|
||||
|
||||
|
||||
@ -26,6 +26,9 @@ namespace RGB.NET.Devices.Novation
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SupportsSyncBack => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="NovationColorCapabilities"/> of the <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user