mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-11-11 13:06:24 +00:00
Added dynamic lighting device provider (not working)
This commit is contained in:
1 parent
a4bd797912
commit
768b1fddd0
38 files changed
+1758
No files matched your search
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using Windows.Devices.Lights;
|
||||
using RGB.NET.Core;
|
||||
using System.Linq;
|
||||
|
||||
namespace RGB.NET.Devices.DynamicLighting;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents the update-queue performing updates for dynamic lightning devices.
|
||||
/// </summary>
|
||||
public sealed class DynamicLightingDeviceUpdateQueue : UpdateQueue
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private bool _isDisposed = false;
|
||||
|
||||
private readonly LampArray _lampArray;
|
||||
private readonly int[] _indices;
|
||||
private readonly Windows.UI.Color[] _colors;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DynamicLightingDeviceUpdateQueue"/> class.
|
||||
/// </summary>
|
||||
/// <param name="updateTrigger">The update trigger used by this queue.</param>
|
||||
/// <param name="lampArray">The lamp array to update.</param>
|
||||
internal DynamicLightingDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, LampArray lampArray)
|
||||
: base(updateTrigger)
|
||||
{
|
||||
this._lampArray = lampArray;
|
||||
|
||||
_colors = new Windows.UI.Color[lampArray.LampCount];
|
||||
_indices = Enumerable.Range(0, lampArray.LampCount).ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_isDisposed) throw new ObjectDisposedException(nameof(DynamicLightingDeviceUpdateQueue));
|
||||
if (!_lampArray.IsConnected) return false;
|
||||
|
||||
// ReSharper disable once ForCanBeConvertedToForeach - Prevent a possible allocation of an enumerator
|
||||
for (int i = 0; i < dataSet.Length; i++)
|
||||
{
|
||||
(object key, Color color) = dataSet[i];
|
||||
(byte a, byte r, byte g, byte b) = color.GetRGBBytes();
|
||||
_colors[(int)key] = Windows.UI.Color.FromArgb(a, r, g, b);
|
||||
}
|
||||
|
||||
_lampArray.SetColorsForIndices(_colors, _indices);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DynamicLightingDeviceProvider.Instance.Throw(ex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
|
||||
_isDisposed = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using Windows.Devices.Lights;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.DynamicLighting;
|
||||
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
|
||||
/// <summary>
|
||||
/// Represents a generic Dynamic Lighting-device.
|
||||
/// </summary>
|
||||
public abstract class DynamicLightingRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, IDynamicLightingRGBDevice
|
||||
where TDeviceInfo : DynamicLightingRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapping of <see cref="LedId"/> to the index of the led used to update the LEDs of this device.
|
||||
/// </summary>
|
||||
protected LedMapping<int> Mapping { get; private set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reference led id.
|
||||
/// </summary>
|
||||
protected abstract LedId ReferenceLedId { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DynamicLightingRGBDevice{TDeviceInfo}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The meta data for this device.</param>
|
||||
/// <param name="updateQueue">The queue used to update this device.</param>
|
||||
protected DynamicLightingRGBDevice(TDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
|
||||
: base(info, updateQueue) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
void IDynamicLightingRGBDevice.Initialize()
|
||||
{
|
||||
Mapping = CreateMapping();
|
||||
InitializeLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the LEDs of the device based on the data provided by the SDK.
|
||||
/// </summary>
|
||||
protected virtual void InitializeLayout()
|
||||
{
|
||||
for (int i = 0; i < DeviceInfo.LedCount; i++)
|
||||
{
|
||||
LampInfo lampInfo = DeviceInfo.LampArray.GetLampInfo(i);
|
||||
|
||||
LedId ledId = Mapping.TryGetValue(i, out LedId id) ? id : LedId.Invalid;
|
||||
Rectangle rectangle = new(new Point(lampInfo.Position.X, lampInfo.Position.Y), new Size(10, 10));
|
||||
AddLed(ledId, rectangle.Location, rectangle.Size);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a mapping for this device.
|
||||
/// </summary>
|
||||
/// <returns>The mapping.</returns>
|
||||
protected virtual LedMapping<int> CreateMapping()
|
||||
{
|
||||
LedMapping<int> mapping = [];
|
||||
for (int i = 0; i < DeviceInfo.LedCount; i++)
|
||||
mapping.Add(ReferenceLedId + i, i);
|
||||
|
||||
return mapping;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override object GetLedCustomData(LedId ledId) => Mapping.TryGetValue(ledId, out int index) ? index : 0;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using Windows.Devices.Lights;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.DynamicLighting;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a DynamicLighting-<see cref="T:RGB.NET.Core.IRGBDevice" />.
|
||||
/// </summary>
|
||||
public class DynamicLightingRGBDeviceInfo : IRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceType DeviceType { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string DeviceName { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Manufacturer => "Dynamic Lighting";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Model { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the unique ID of the device
|
||||
/// </summary>
|
||||
public string DeviceId { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public object? LayoutMetadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of LEDs this device contains.
|
||||
/// </summary>
|
||||
public int LedCount { get; }
|
||||
|
||||
internal LampArray LampArray { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="DynamicLightingRGBDeviceInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="lampArrayInfo">The low level information for this device.</param>
|
||||
internal DynamicLightingRGBDeviceInfo(RGBDeviceType deviceType, LampArrayInfo lampArrayInfo)
|
||||
{
|
||||
this.DeviceType = deviceType;
|
||||
|
||||
LampArray = lampArrayInfo.LampArray;
|
||||
DeviceId = lampArrayInfo.Id;
|
||||
Model = lampArrayInfo.DisplayName;
|
||||
LedCount = lampArrayInfo.LampArray.LampCount;
|
||||
|
||||
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.DynamicLighting;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a DynamicLighting RGB-device.
|
||||
/// </summary>
|
||||
public interface IDynamicLightingRGBDevice : IRGBDevice
|
||||
{
|
||||
internal void Initialize();
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System.Collections.Generic;
|
||||
using Windows.System;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.DynamicLighting;
|
||||
|
||||
internal static class LedMappings
|
||||
{
|
||||
public static Dictionary<VirtualKey, LedId> KeyboardMapping = new()
|
||||
{
|
||||
[VirtualKey.Back] = LedId.Keyboard_Backspace,
|
||||
[VirtualKey.Tab] = LedId.Keyboard_Tab,
|
||||
[VirtualKey.Enter] = LedId.Keyboard_Enter,
|
||||
[VirtualKey.Pause] = LedId.Keyboard_PauseBreak,
|
||||
[VirtualKey.CapitalLock] = LedId.Keyboard_CapsLock,
|
||||
[VirtualKey.Escape] = LedId.Keyboard_Escape,
|
||||
[VirtualKey.Space] = LedId.Keyboard_Space,
|
||||
[VirtualKey.PageUp] = LedId.Keyboard_PageUp,
|
||||
[VirtualKey.PageDown] = LedId.Keyboard_PageDown,
|
||||
[VirtualKey.End] = LedId.Keyboard_End,
|
||||
[VirtualKey.Home] = LedId.Keyboard_Home,
|
||||
[VirtualKey.Left] = LedId.Keyboard_ArrowLeft,
|
||||
[VirtualKey.Up] = LedId.Keyboard_ArrowUp,
|
||||
[VirtualKey.Right] = LedId.Keyboard_ArrowRight,
|
||||
[VirtualKey.Down] = LedId.Keyboard_ArrowDown,
|
||||
[VirtualKey.Print] = LedId.Keyboard_PrintScreen,
|
||||
[VirtualKey.Insert] = LedId.Keyboard_Insert,
|
||||
[VirtualKey.Delete] = LedId.Keyboard_Delete,
|
||||
[VirtualKey.Number0] = LedId.Keyboard_0,
|
||||
[VirtualKey.Number1] = LedId.Keyboard_1,
|
||||
[VirtualKey.Number2] = LedId.Keyboard_2,
|
||||
[VirtualKey.Number3] = LedId.Keyboard_3,
|
||||
[VirtualKey.Number4] = LedId.Keyboard_4,
|
||||
[VirtualKey.Number5] = LedId.Keyboard_5,
|
||||
[VirtualKey.Number6] = LedId.Keyboard_6,
|
||||
[VirtualKey.Number7] = LedId.Keyboard_7,
|
||||
[VirtualKey.Number8] = LedId.Keyboard_8,
|
||||
[VirtualKey.Number9] = LedId.Keyboard_9,
|
||||
[VirtualKey.A] = LedId.Keyboard_A,
|
||||
[VirtualKey.B] = LedId.Keyboard_B,
|
||||
[VirtualKey.C] = LedId.Keyboard_C,
|
||||
[VirtualKey.D] = LedId.Keyboard_D,
|
||||
[VirtualKey.E] = LedId.Keyboard_E,
|
||||
[VirtualKey.F] = LedId.Keyboard_F,
|
||||
[VirtualKey.G] = LedId.Keyboard_G,
|
||||
[VirtualKey.H] = LedId.Keyboard_H,
|
||||
[VirtualKey.I] = LedId.Keyboard_I,
|
||||
[VirtualKey.J] = LedId.Keyboard_J,
|
||||
[VirtualKey.K] = LedId.Keyboard_K,
|
||||
[VirtualKey.L] = LedId.Keyboard_L,
|
||||
[VirtualKey.M] = LedId.Keyboard_M,
|
||||
[VirtualKey.N] = LedId.Keyboard_N,
|
||||
[VirtualKey.O] = LedId.Keyboard_O,
|
||||
[VirtualKey.P] = LedId.Keyboard_P,
|
||||
[VirtualKey.Q] = LedId.Keyboard_Q,
|
||||
[VirtualKey.R] = LedId.Keyboard_R,
|
||||
[VirtualKey.S] = LedId.Keyboard_S,
|
||||
[VirtualKey.T] = LedId.Keyboard_T,
|
||||
[VirtualKey.U] = LedId.Keyboard_U,
|
||||
[VirtualKey.V] = LedId.Keyboard_V,
|
||||
[VirtualKey.W] = LedId.Keyboard_W,
|
||||
[VirtualKey.X] = LedId.Keyboard_X,
|
||||
[VirtualKey.Y] = LedId.Keyboard_Y,
|
||||
[VirtualKey.Z] = LedId.Keyboard_Z,
|
||||
[VirtualKey.LeftWindows] = LedId.Keyboard_LeftGui,
|
||||
[VirtualKey.RightWindows] = LedId.Keyboard_RightGui,
|
||||
[VirtualKey.Application] = LedId.Keyboard_Application,
|
||||
[VirtualKey.NumberPad0] = LedId.Keyboard_Num0,
|
||||
[VirtualKey.NumberPad1] = LedId.Keyboard_Num1,
|
||||
[VirtualKey.NumberPad2] = LedId.Keyboard_Num2,
|
||||
[VirtualKey.NumberPad3] = LedId.Keyboard_Num3,
|
||||
[VirtualKey.NumberPad4] = LedId.Keyboard_Num4,
|
||||
[VirtualKey.NumberPad5] = LedId.Keyboard_Num5,
|
||||
[VirtualKey.NumberPad6] = LedId.Keyboard_Num6,
|
||||
[VirtualKey.NumberPad7] = LedId.Keyboard_Num7,
|
||||
[VirtualKey.NumberPad8] = LedId.Keyboard_Num8,
|
||||
[VirtualKey.NumberPad9] = LedId.Keyboard_Num9,
|
||||
[VirtualKey.Multiply] = LedId.Keyboard_NumAsterisk,
|
||||
[VirtualKey.Add] = LedId.Keyboard_NumPlus,
|
||||
[VirtualKey.Subtract] = LedId.Keyboard_NumMinus,
|
||||
[VirtualKey.Decimal] = LedId.Keyboard_NumComma,
|
||||
[VirtualKey.Divide] = LedId.Keyboard_NumSlash,
|
||||
[VirtualKey.F1] = LedId.Keyboard_F1,
|
||||
[VirtualKey.F2] = LedId.Keyboard_F2,
|
||||
[VirtualKey.F3] = LedId.Keyboard_F3,
|
||||
[VirtualKey.F4] = LedId.Keyboard_F4,
|
||||
[VirtualKey.F5] = LedId.Keyboard_F5,
|
||||
[VirtualKey.F6] = LedId.Keyboard_F6,
|
||||
[VirtualKey.F7] = LedId.Keyboard_F7,
|
||||
[VirtualKey.F8] = LedId.Keyboard_F8,
|
||||
[VirtualKey.F9] = LedId.Keyboard_F9,
|
||||
[VirtualKey.F10] = LedId.Keyboard_F10,
|
||||
[VirtualKey.F11] = LedId.Keyboard_F11,
|
||||
[VirtualKey.F12] = LedId.Keyboard_F12,
|
||||
[VirtualKey.NumberKeyLock] = LedId.Keyboard_NumLock,
|
||||
[VirtualKey.Scroll] = LedId.Keyboard_ScrollLock,
|
||||
[VirtualKey.LeftShift] = LedId.Keyboard_LeftShift,
|
||||
[VirtualKey.RightShift] = LedId.Keyboard_RightShift,
|
||||
[VirtualKey.LeftControl] = LedId.Keyboard_LeftCtrl,
|
||||
[VirtualKey.RightControl] = LedId.Keyboard_RightCtrl,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user