mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Changed update-Pprameter away from dictionary
This commit is contained in:
parent
9c8d67740d
commit
2222808c23
@ -2,7 +2,6 @@
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
// ReSharper disable VirtualMemberNeverOverridden.Global
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@ -16,7 +17,7 @@ namespace RGB.NET.Core
|
||||
|
||||
private readonly object _dataLock = new();
|
||||
private readonly IDeviceUpdateTrigger _updateTrigger;
|
||||
private Dictionary<TIdentifier, TData>? _currentDataSet;
|
||||
private readonly Dictionary<TIdentifier, TData> _currentDataSet = new();
|
||||
|
||||
#endregion
|
||||
|
||||
@ -45,17 +46,25 @@ namespace RGB.NET.Core
|
||||
/// <param name="customData"><see cref="CustomUpdateData"/> provided by the trigger.</param>
|
||||
protected virtual void OnUpdate(object? sender, CustomUpdateData customData)
|
||||
{
|
||||
Dictionary<TIdentifier, TData> dataSet;
|
||||
(TIdentifier, TData)[] dataSet;
|
||||
lock (_dataLock)
|
||||
{
|
||||
if (_currentDataSet == null) return;
|
||||
if (_currentDataSet.Count == 0) return;
|
||||
|
||||
dataSet = _currentDataSet;
|
||||
_currentDataSet = null;
|
||||
dataSet = ArrayPool<(TIdentifier, TData)>.Shared.Rent(_currentDataSet.Count);
|
||||
Span<(TIdentifier, TData)> data = new Span<(TIdentifier, TData)>(dataSet).Slice(0, _currentDataSet.Count);
|
||||
|
||||
int i = 0;
|
||||
foreach ((TIdentifier key, TData value) in _currentDataSet)
|
||||
data[i++] = (key, value);
|
||||
|
||||
_currentDataSet.Clear();
|
||||
}
|
||||
|
||||
if (dataSet.Count != 0)
|
||||
if (dataSet.Length != 0)
|
||||
Update(dataSet);
|
||||
|
||||
ArrayPool<(TIdentifier, TData)>.Shared.Return(dataSet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -69,26 +78,22 @@ namespace RGB.NET.Core
|
||||
/// Performs the update this queue is responsible for.
|
||||
/// </summary>
|
||||
/// <param name="dataSet">The set of data that needs to be updated.</param>
|
||||
protected abstract void Update(Dictionary<TIdentifier, TData> dataSet);
|
||||
protected abstract void Update(in ReadOnlySpan<(TIdentifier key, TData color)> dataSet);
|
||||
|
||||
/// <summary>
|
||||
/// Sets or merges the provided data set in the current dataset and notifies the trigger that there is new data available.
|
||||
/// </summary>
|
||||
/// <param name="dataSet">The set of data.</param>
|
||||
// ReSharper disable once MemberCanBeProtected.Global
|
||||
public virtual void SetData(Dictionary<TIdentifier, TData> dataSet)
|
||||
public virtual void SetData(IEnumerable<(TIdentifier, TData)> dataSet)
|
||||
{
|
||||
if (dataSet.Count == 0) return;
|
||||
IList<(TIdentifier, TData)> data = dataSet.ToList();
|
||||
if (data.Count == 0) return;
|
||||
|
||||
lock (_dataLock)
|
||||
{
|
||||
if (_currentDataSet == null)
|
||||
_currentDataSet = dataSet;
|
||||
else
|
||||
{
|
||||
foreach ((TIdentifier key, TData value) in dataSet)
|
||||
_currentDataSet[key] = value;
|
||||
}
|
||||
foreach ((TIdentifier key, TData value) in data)
|
||||
_currentDataSet[key] = value;
|
||||
}
|
||||
|
||||
_updateTrigger.TriggerHasData();
|
||||
@ -100,7 +105,7 @@ namespace RGB.NET.Core
|
||||
public virtual void Reset()
|
||||
{
|
||||
lock (_dataLock)
|
||||
_currentDataSet = null;
|
||||
_currentDataSet.Clear();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -135,7 +140,7 @@ namespace RGB.NET.Core
|
||||
/// Calls <see cref="UpdateQueue{TIdentifier,TData}.SetData"/> for a data set created out of the provided list of <see cref="Led"/>.
|
||||
/// </summary>
|
||||
/// <param name="leds"></param>
|
||||
public void SetData(IEnumerable<Led> leds) => SetData(leds.ToDictionary(x => x.CustomData ?? x.Id, x => x.Color));
|
||||
public void SetData(IEnumerable<Led> leds) => SetData(leds.Select(x => (x.CustomData ?? x.Id, x.Color)));
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using AuraServiceLib;
|
||||
using RGB.NET.Core;
|
||||
|
||||
@ -43,7 +43,7 @@ namespace RGB.NET.Devices.Asus
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
if (Device == null) return;
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.CoolerMaster.Native;
|
||||
|
||||
@ -28,7 +28,7 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
: base(updateTrigger)
|
||||
{
|
||||
this._deviceIndex = deviceIndex;
|
||||
|
||||
|
||||
_deviceMatrix = new _CoolerMasterColorMatrix();
|
||||
_deviceMatrix.KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS];
|
||||
}
|
||||
@ -38,12 +38,12 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
{
|
||||
(int row, int column) = ((int, int))data.Key;
|
||||
_deviceMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(data.Value.GetR(), data.Value.GetG(), data.Value.GetB());
|
||||
(int row, int column) = ((int, int))key;
|
||||
_deviceMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(color.GetR(), color.GetG(), color.GetB());
|
||||
}
|
||||
|
||||
_CoolerMasterSDK.SetAllLedColor(_deviceMatrix, _deviceIndex);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Corsair.Native;
|
||||
@ -36,26 +35,26 @@ namespace RGB.NET.Devices.Corsair
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
|
||||
IntPtr ptr = Marshal.AllocHGlobal(structSize * dataSet.Count);
|
||||
IntPtr ptr = Marshal.AllocHGlobal(structSize * dataSet.Length);
|
||||
IntPtr addPtr = new(ptr.ToInt64());
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
{
|
||||
_CorsairLedColor color = new()
|
||||
{
|
||||
ledId = (int)data.Key,
|
||||
r = data.Value.GetR(),
|
||||
g = data.Value.GetG(),
|
||||
b = data.Value.GetB()
|
||||
_CorsairLedColor corsairColor = new()
|
||||
{
|
||||
ledId = (int)key,
|
||||
r = color.GetR(),
|
||||
g = color.GetG(),
|
||||
b = color.GetB()
|
||||
};
|
||||
|
||||
Marshal.StructureToPtr(color, addPtr, false);
|
||||
Marshal.StructureToPtr(corsairColor, addPtr, false);
|
||||
addPtr = new IntPtr(addPtr.ToInt64() + structSize);
|
||||
}
|
||||
|
||||
_CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Count, ptr);
|
||||
_CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Length, ptr);
|
||||
_CUESDK.CorsairSetLedsColorsFlushBuffer();
|
||||
Marshal.FreeHGlobal(ptr);
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
using RGB.NET.Core;
|
||||
|
||||
@ -52,15 +51,15 @@ namespace RGB.NET.Devices.DMX.E131
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
DataPacket.SetSequenceNumber(GetNextSequenceNumber());
|
||||
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
{
|
||||
LedChannelMapping mapping = (LedChannelMapping)data.Key;
|
||||
LedChannelMapping mapping = (LedChannelMapping)key;
|
||||
foreach ((int channel, Func<Color, byte> getValue) in mapping)
|
||||
DataPacket.SetChannel(channel, getValue(data.Value));
|
||||
DataPacket.SetChannel(channel, getValue(color));
|
||||
}
|
||||
|
||||
_socket.Send(DataPacket, DataPacket.Length);
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Logitech.Native;
|
||||
|
||||
@ -27,9 +25,9 @@ namespace RGB.NET.Devices.Logitech
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
Color color = dataSet.Values.First();
|
||||
Color color = dataSet[0].color;
|
||||
|
||||
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.DeviceRGB);
|
||||
_LogitechGSDK.LogiLedSetLighting((int)Math.Round(color.R * 100),
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Logitech.Native;
|
||||
|
||||
@ -33,27 +32,27 @@ namespace RGB.NET.Devices.Logitech
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
|
||||
|
||||
Array.Clear(_bitmap, 0, _bitmap.Length);
|
||||
bool usesBitmap = false;
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
{
|
||||
(LedId id, LogitechLedId customData) = ((LedId, LogitechLedId))data.Key;
|
||||
(LedId id, LogitechLedId customData) = ((LedId, LogitechLedId))key;
|
||||
|
||||
// DarthAffe 26.03.2017: This is only needed since update by name doesn't work as expected for all keys ...
|
||||
if (BitmapMapping.BitmapOffset.TryGetValue(id, out int bitmapOffset))
|
||||
{
|
||||
BitmapMapping.SetColor(_bitmap, bitmapOffset, data.Value);
|
||||
BitmapMapping.SetColor(_bitmap, bitmapOffset, color);
|
||||
usesBitmap = true;
|
||||
}
|
||||
else
|
||||
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)customData,
|
||||
(int)Math.Round(data.Value.R * 100),
|
||||
(int)Math.Round(data.Value.G * 100),
|
||||
(int)Math.Round(data.Value.B * 100));
|
||||
(int)MathF.Round(color.R * 100),
|
||||
(int)MathF.Round(color.G * 100),
|
||||
(int)MathF.Round(color.B * 100));
|
||||
}
|
||||
|
||||
if (usesBitmap)
|
||||
|
||||
@ -13,12 +13,12 @@ namespace RGB.NET.Devices.Logitech
|
||||
#region Constants
|
||||
|
||||
private static readonly Dictionary<RGBDeviceType, LogitechDeviceType> DEVICE_TYPE_MAPPING = new()
|
||||
{
|
||||
{RGBDeviceType.Keyboard, LogitechDeviceType.Keyboard},
|
||||
{RGBDeviceType.Mouse, LogitechDeviceType.Mouse},
|
||||
{RGBDeviceType.Headset, LogitechDeviceType.Headset},
|
||||
{RGBDeviceType.Mousepad, LogitechDeviceType.Mousemat},
|
||||
{RGBDeviceType.Speaker, LogitechDeviceType.Speaker}
|
||||
{
|
||||
{ RGBDeviceType.Keyboard, LogitechDeviceType.Keyboard },
|
||||
{ RGBDeviceType.Mouse, LogitechDeviceType.Mouse },
|
||||
{ RGBDeviceType.Headset, LogitechDeviceType.Headset },
|
||||
{ RGBDeviceType.Mousepad, LogitechDeviceType.Mousemat },
|
||||
{ RGBDeviceType.Speaker, LogitechDeviceType.Speaker }
|
||||
};
|
||||
|
||||
#endregion
|
||||
@ -48,17 +48,17 @@ namespace RGB.NET.Devices.Logitech
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.All);
|
||||
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
{
|
||||
int zone = (int)data.Key;
|
||||
int zone = (int)key;
|
||||
_LogitechGSDK.LogiLedSetLightingForTargetZone(_deviceType, zone,
|
||||
(int)Math.Round(data.Value.R * 100),
|
||||
(int)Math.Round(data.Value.G * 100),
|
||||
(int)Math.Round(data.Value.B * 100));
|
||||
(int)MathF.Round(color.R * 100),
|
||||
(int)MathF.Round(color.G * 100),
|
||||
(int)MathF.Round(color.B * 100));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Msi.Native;
|
||||
|
||||
@ -34,10 +34,10 @@ namespace RGB.NET.Devices.Msi
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
_MsiSDK.SetLedColor(_deviceType, (int)data.Key, data.Value.GetR(), data.Value.GetG(), data.Value.GetB());
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
_MsiSDK.SetLedColor(_deviceType, (int)key, color.GetR(), color.GetG(), color.GetB());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
using Sanford.Multimedia.Midi;
|
||||
|
||||
@ -26,10 +25,10 @@ namespace RGB.NET.Devices.Novation
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ShortMessage CreateMessage(KeyValuePair<object, Color> data)
|
||||
protected override ShortMessage CreateMessage(object key, in Color color)
|
||||
{
|
||||
(byte mode, byte id) = ((byte, byte))data.Key;
|
||||
return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(data.Value)));
|
||||
(byte mode, byte id) = ((byte, byte))key;
|
||||
return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(color)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -38,9 +37,9 @@ namespace RGB.NET.Devices.Novation
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to convert.</param>
|
||||
/// <returns>The novation-representation of the <see cref="Color"/>.</returns>
|
||||
protected virtual int ConvertColor(Color color)
|
||||
protected virtual int ConvertColor(in Color color)
|
||||
{
|
||||
(double hue, double saturation, double value) = color.GetHSV();
|
||||
(double hue, double _, double value) = color.GetHSV();
|
||||
|
||||
if ((hue >= 330) || (hue < 30))
|
||||
return (int)Math.Ceiling(value * 3); // red with brightness 1, 2 or 3
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
using Sanford.Multimedia.Midi;
|
||||
|
||||
@ -37,10 +36,10 @@ namespace RGB.NET.Devices.Novation
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
SendMessage(CreateMessage(data));
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
SendMessage(CreateMessage(key, color));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -59,7 +58,7 @@ namespace RGB.NET.Devices.Novation
|
||||
/// </summary>
|
||||
/// <param name="data">The data set to create the message from.</param>
|
||||
/// <returns>The message created out of the data set.</returns>
|
||||
protected abstract ShortMessage? CreateMessage(KeyValuePair<object, Color> data);
|
||||
protected abstract ShortMessage? CreateMessage(object key, in Color color);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
using Sanford.Multimedia.Midi;
|
||||
|
||||
@ -152,12 +151,12 @@ namespace RGB.NET.Devices.Novation
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ShortMessage? CreateMessage(KeyValuePair<object, Color> data)
|
||||
protected override ShortMessage? CreateMessage(object key, in Color color)
|
||||
{
|
||||
(byte mode, byte id) = ((byte, byte))data.Key;
|
||||
(byte mode, byte id) = ((byte, byte))key;
|
||||
if (mode == 0x00) return null;
|
||||
|
||||
return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(data.Value)));
|
||||
return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(color)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -166,7 +165,7 @@ namespace RGB.NET.Devices.Novation
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to convert.</param>
|
||||
/// <returns>The novation-representation of the <see cref="Color"/>.</returns>
|
||||
protected virtual int ConvertColor(Color color)
|
||||
protected virtual int ConvertColor(in Color color)
|
||||
{
|
||||
int bestVelocity = 0;
|
||||
double bestMatchDistance = double.MaxValue;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
@ -27,15 +26,15 @@ namespace RGB.NET.Devices.Razer
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet)
|
||||
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.CHROMALINK_MAX_LEDS];
|
||||
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
colors[(int)data.Key] = new _Color(data.Value);
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
colors[(int)key] = new _Color(color);
|
||||
|
||||
_ChromaLinkCustomEffect effectParams = new()
|
||||
{ Color = colors };
|
||||
{ Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
|
||||
@ -35,7 +34,7 @@ namespace RGB.NET.Devices.Razer
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
IntPtr effectParams = CreateEffectParams(dataSet);
|
||||
Guid effectId = Guid.NewGuid();
|
||||
@ -71,7 +70,7 @@ namespace RGB.NET.Devices.Razer
|
||||
/// </summary>
|
||||
/// <param name="dataSet">The data to be updated.</param>
|
||||
/// <returns>An <see cref="IntPtr"/> pointing to the effect parameter struct.</returns>
|
||||
protected abstract IntPtr CreateEffectParams(Dictionary<object, Color> dataSet);
|
||||
protected abstract IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
@ -27,16 +26,16 @@ namespace RGB.NET.Devices.Razer
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet)
|
||||
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.HEADSET_MAX_LEDS];
|
||||
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
colors[(int)data.Key] = new _Color(data.Value);
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
colors[(int)key] = new _Color(color);
|
||||
|
||||
_HeadsetCustomEffect effectParams = new()
|
||||
{ Color = colors };
|
||||
|
||||
{ Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
@ -27,15 +26,14 @@ namespace RGB.NET.Devices.Razer
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet)
|
||||
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.KEYBOARD_MAX_LEDS];
|
||||
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
colors[(int)data.Key] = new _Color(data.Value);
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
colors[(int)key] = new _Color(color);
|
||||
|
||||
_KeyboardCustomEffect effectParams = new()
|
||||
{ Color = colors };
|
||||
_KeyboardCustomEffect effectParams = new() { Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
@ -27,15 +26,14 @@ namespace RGB.NET.Devices.Razer
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet)
|
||||
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS];
|
||||
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
colors[(int)data.Key] = new _Color(data.Value);
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
colors[(int)key] = new _Color(color);
|
||||
|
||||
_KeypadCustomEffect effectParams = new()
|
||||
{ Color = colors };
|
||||
_KeypadCustomEffect effectParams = new() { Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
@ -27,15 +26,14 @@ namespace RGB.NET.Devices.Razer
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet)
|
||||
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.MOUSE_MAX_LEDS];
|
||||
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
colors[(int)data.Key] = new _Color(data.Value);
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
colors[(int)key] = new _Color(color);
|
||||
|
||||
_MouseCustomEffect effectParams = new()
|
||||
{ Color = colors };
|
||||
_MouseCustomEffect effectParams = new() { Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
@ -27,15 +26,14 @@ namespace RGB.NET.Devices.Razer
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet)
|
||||
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.MOUSEPAD_MAX_LEDS];
|
||||
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
colors[(int)data.Key] = new _Color(data.Value);
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
colors[(int)key] = new _Color(color);
|
||||
|
||||
_MousepadCustomEffect effectParams = new()
|
||||
{ Color = colors };
|
||||
_MousepadCustomEffect effectParams = new() { Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.SteelSeries.API;
|
||||
@ -44,8 +44,8 @@ namespace RGB.NET.Devices.SteelSeries
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
=> SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.Select(x => (((SteelSeriesLedId)x.Key).GetAPIName(), x.Value.ToIntArray())).Where(x => x.Item1 != null).ToList()!);
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
=> SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.ToArray().Select(x => (((SteelSeriesLedId)x.key).GetAPIName(), x.color.ToIntArray())).Where(x => x.Item1 != null).ToList()!);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -50,9 +50,9 @@ namespace RGB.NET.Devices.WS281X.Arduino
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IEnumerable<byte[]> GetCommands(Dictionary<object, Color> dataSet)
|
||||
protected override IEnumerable<byte[]> GetCommands(IList<(object key, Color color)> dataSet)
|
||||
{
|
||||
foreach (IGrouping<int, ((int channel, int key), Color Value)> channelData in dataSet.Select(x => (((int channel, int key))x.Key, x.Value))
|
||||
foreach (IGrouping<int, ((int channel, int key), Color Value)> channelData in dataSet.Select(x => (((int channel, int key))x.key, x.color))
|
||||
.GroupBy(x => x.Item1.channel))
|
||||
{
|
||||
int channel = channelData.Key;
|
||||
|
||||
@ -36,7 +36,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IEnumerable<string> GetCommands(Dictionary<object, Color> dataSet)
|
||||
protected override IEnumerable<string> GetCommands(IList<(object key, Color color)> dataSet)
|
||||
{
|
||||
foreach ((object key, Color value) in dataSet)
|
||||
yield return $"pix {(int)key} {value.AsRGBHexString(false)}";
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.WS281X
|
||||
@ -56,9 +57,9 @@ namespace RGB.NET.Devices.WS281X
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
foreach (TData command in GetCommands(dataSet))
|
||||
foreach (TData command in GetCommands(dataSet.ToArray()))
|
||||
{
|
||||
SerialConnection.ReadTo(Prompt);
|
||||
SendCommand(command);
|
||||
@ -70,7 +71,7 @@ namespace RGB.NET.Devices.WS281X
|
||||
/// </summary>
|
||||
/// <param name="dataSet">The set of data that needs to be updated.</param>
|
||||
/// <returns>The commands to be sent.</returns>
|
||||
protected abstract IEnumerable<TData> GetCommands(Dictionary<object, Color> dataSet);
|
||||
protected abstract IEnumerable<TData> GetCommands(IList<(object key, Color color)> dataSet);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a command as a string followed by a line-break to the device.
|
||||
|
||||
@ -77,10 +77,9 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
foreach (IGrouping<int, ((int channel, int key), Color Value)> channelData in dataSet.Select(x => (((int channel, int key))x.Key, x.Value))
|
||||
.GroupBy(x => x.Item1.channel))
|
||||
foreach (IGrouping<int, ((int channel, int key), Color color)> channelData in dataSet.ToArray().Select(x => (((int channel, int key))x.key, x.color)).GroupBy(x => x.Item1.channel))
|
||||
{
|
||||
byte[] buffer = GetBuffer(channelData);
|
||||
_sendDataAction(buffer);
|
||||
@ -98,7 +97,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
|
||||
_udpClient?.Send(buffer, buffer.Length);
|
||||
}
|
||||
|
||||
private byte[] GetBuffer(IGrouping<int, ((int channel, int key), Color Value)> data)
|
||||
private byte[] GetBuffer(IGrouping<int, ((int channel, int key) identifier, Color color)> data)
|
||||
{
|
||||
int channel = data.Key;
|
||||
byte[] buffer = _dataBuffer[channel];
|
||||
@ -106,8 +105,8 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
|
||||
buffer[0] = GetSequenceNumber(channel);
|
||||
buffer[1] = (byte)channel;
|
||||
int i = 2;
|
||||
foreach ((byte _, byte r, byte g, byte b) in data.OrderBy(x => x.Item1.key)
|
||||
.Select(x => x.Value.GetRGBBytes()))
|
||||
foreach ((byte _, byte r, byte g, byte b) in data.OrderBy(x => x.identifier.key)
|
||||
.Select(x => x.color.GetRGBBytes()))
|
||||
{
|
||||
buffer[i++] = r;
|
||||
buffer[i++] = g;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Wooting.Native;
|
||||
|
||||
@ -26,17 +26,17 @@ namespace RGB.NET.Devices.Wooting.Generic
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
{
|
||||
(int row, int column) = ((int, int))data.Key;
|
||||
_WootingSDK.ArraySetSingle((byte)row, (byte)column, data.Value.GetR(), data.Value.GetG(), data.Value.GetB());
|
||||
(int row, int column) = ((int, int))key;
|
||||
_WootingSDK.ArraySetSingle((byte)row, (byte)column, color.GetR(), color.GetG(), color.GetB());
|
||||
}
|
||||
|
||||
_WootingSDK.ArrayUpdateKeyboard();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user