Added dynamic lighting device provider (not working)

This commit is contained in:
DarthAffe committed 2024-03-25 21:06:58 +01:00
1 parent a4bd797912
commit 768b1fddd0
38 files changed
+1758

No files matched your search

@@ -0,0 +1,34 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Dynamic Lighting Art-device.
/// </summary>
public sealed class DynamicLightingArtRGBDevice : DynamicLightingRGBDevice<DynamicLightingArtRGBDeviceInfo>, IArt
{
#region Properties & Fields
/// <inheritdoc/>
protected override LedId ReferenceLedId => LedId.Art1;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingArtRGBDevice" /> class.
/// </summary>
/// <param name="info">The meta data for this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal DynamicLightingArtRGBDevice(DynamicLightingArtRGBDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
}
@@ -0,0 +1,19 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingArtRGBDevice" />.
/// </summary>
public sealed class DynamicLightingArtRGBDeviceInfo : DynamicLightingRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
internal DynamicLightingArtRGBDeviceInfo(LampArrayInfo lampArrayInfo)
: base(RGBDeviceType.Art, lampArrayInfo)
{ }
#endregion
}
@@ -0,0 +1,34 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Dynamic Lighting Chassis-device.
/// </summary>
public sealed class DynamicLightingChassisRGBDevice : DynamicLightingRGBDevice<DynamicLightingChassisRGBDeviceInfo>, IChassis
{
#region Properties & Fields
/// <inheritdoc/>
protected override LedId ReferenceLedId => LedId.Chassis1;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingChassisRGBDevice" /> class.
/// </summary>
/// <param name="info">The meta data for this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal DynamicLightingChassisRGBDevice(DynamicLightingChassisRGBDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
}
@@ -0,0 +1,19 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingChassisRGBDevice" />.
/// </summary>
public sealed class DynamicLightingChassisRGBDeviceInfo : DynamicLightingRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
internal DynamicLightingChassisRGBDeviceInfo(LampArrayInfo lampArrayInfo)
: base(RGBDeviceType.Chassis, lampArrayInfo)
{ }
#endregion
}
@@ -0,0 +1,136 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System;
using System.Collections.Generic;
using System.Threading;
using RGB.NET.Core;
using Windows.Devices.Enumeration;
using Windows.Devices.Lights;
namespace RGB.NET.Devices.DynamicLighting;
internal record LampArrayInfo(string Id, string DisplayName, LampArray LampArray);
/// <inheritdoc />
/// <summary>
/// Represents a device provider responsible for Microsoft Dynamic Lighting devices.
/// </summary>
public sealed class DynamicLightingDeviceProvider : AbstractRGBDeviceProvider
{
#region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static DynamicLightingDeviceProvider? _instance;
/// <summary>
/// Gets the singleton <see cref="DynamicLightingDeviceProvider"/> instance.
/// </summary>
public static DynamicLightingDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new DynamicLightingDeviceProvider();
}
}
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="DynamicLightingDeviceProvider"/> class.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public DynamicLightingDeviceProvider()
{
lock (_lock)
{
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DynamicLightingDeviceProvider)}");
_instance = this;
}
}
#endregion
#region Methods
/// <inheritdoc />
protected override void InitializeSDK() { }
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> LoadDevices()
{
ManualResetEventSlim waitEvent = new(false);
List<LampArrayInfo> lampArrays = [];
DeviceWatcher? watcher = DeviceInformation.CreateWatcher(LampArray.GetDeviceSelector());
watcher.EnumerationCompleted += OnEnumerationCompleted;
watcher.Added += OnDeviceAdded;
watcher.Start();
waitEvent.Wait();
watcher.Stop();
watcher.EnumerationCompleted -= OnEnumerationCompleted;
watcher.Added -= OnDeviceAdded;
int updateTriggerId = 0;
foreach (LampArrayInfo lampArrayInfo in lampArrays)
{
IDynamicLightingRGBDevice? device = null;
try
{
device = CreateDevice(lampArrayInfo);
device.Initialize();
}
catch (Exception ex) { Throw(ex); }
if (device != null)
yield return device;
}
yield break;
IDynamicLightingRGBDevice CreateDevice(LampArrayInfo lampArrayInfo)
=> lampArrayInfo.LampArray.LampArrayKind switch
{
LampArrayKind.Undefined => new DynamicLightingUndefinedRGBDevice(new DynamicLightingUndefinedRGBDeviceInfo(lampArrayInfo), new DynamicLightingDeviceUpdateQueue(GetUpdateTrigger(updateTriggerId++, lampArrayInfo.LampArray.MinUpdateInterval.TotalSeconds), lampArrayInfo.LampArray)),
LampArrayKind.Keyboard => new DynamicLightingKeyboardRGBDevice(new DynamicLightingKeyboardRGBDeviceInfo(lampArrayInfo), new DynamicLightingDeviceUpdateQueue(GetUpdateTrigger(updateTriggerId++, lampArrayInfo.LampArray.MinUpdateInterval.TotalSeconds), lampArrayInfo.LampArray)),
LampArrayKind.Mouse => new DynamicLightingMouseRGBDevice(new DynamicLightingMouseRGBDeviceInfo(lampArrayInfo), new DynamicLightingDeviceUpdateQueue(GetUpdateTrigger(updateTriggerId++, lampArrayInfo.LampArray.MinUpdateInterval.TotalSeconds), lampArrayInfo.LampArray)),
LampArrayKind.GameController => new DynamicLightingGameControllerRGBDevice(new DynamicLightingGameControllerRGBDeviceInfo(lampArrayInfo), new DynamicLightingDeviceUpdateQueue(GetUpdateTrigger(updateTriggerId++, lampArrayInfo.LampArray.MinUpdateInterval.TotalSeconds), lampArrayInfo.LampArray)),
LampArrayKind.Peripheral => new DynamicLightingPeripheralRGBDevice(new DynamicLightingPeripheralRGBDeviceInfo(lampArrayInfo), new DynamicLightingDeviceUpdateQueue(GetUpdateTrigger(updateTriggerId++, lampArrayInfo.LampArray.MinUpdateInterval.TotalSeconds), lampArrayInfo.LampArray)),
LampArrayKind.Scene => new DynamicLightingSceneRGBDevice(new DynamicLightingSceneRGBDeviceInfo(lampArrayInfo), new DynamicLightingDeviceUpdateQueue(GetUpdateTrigger(updateTriggerId++, lampArrayInfo.LampArray.MinUpdateInterval.TotalSeconds), lampArrayInfo.LampArray)),
LampArrayKind.Notification => new DynamicLightingNotificationRGBDevice(new DynamicLightingNotificationRGBDeviceInfo(lampArrayInfo), new DynamicLightingDeviceUpdateQueue(GetUpdateTrigger(updateTriggerId++, lampArrayInfo.LampArray.MinUpdateInterval.TotalSeconds), lampArrayInfo.LampArray)),
LampArrayKind.Chassis => new DynamicLightingChassisRGBDevice(new DynamicLightingChassisRGBDeviceInfo(lampArrayInfo), new DynamicLightingDeviceUpdateQueue(GetUpdateTrigger(updateTriggerId++, lampArrayInfo.LampArray.MinUpdateInterval.TotalSeconds), lampArrayInfo.LampArray)),
LampArrayKind.Wearable => new DynamicLightingWearableRGBDevice(new DynamicLightingWearableRGBDeviceInfo(lampArrayInfo), new DynamicLightingDeviceUpdateQueue(GetUpdateTrigger(updateTriggerId++, lampArrayInfo.LampArray.MinUpdateInterval.TotalSeconds), lampArrayInfo.LampArray)),
LampArrayKind.Furniture => new DynamicLightingFurnitureRGBDevice(new DynamicLightingFurnitureRGBDeviceInfo(lampArrayInfo), new DynamicLightingDeviceUpdateQueue(GetUpdateTrigger(updateTriggerId++, lampArrayInfo.LampArray.MinUpdateInterval.TotalSeconds), lampArrayInfo.LampArray)),
LampArrayKind.Art => new DynamicLightingArtRGBDevice(new DynamicLightingArtRGBDeviceInfo(lampArrayInfo), new DynamicLightingDeviceUpdateQueue(GetUpdateTrigger(updateTriggerId++, lampArrayInfo.LampArray.MinUpdateInterval.TotalSeconds), lampArrayInfo.LampArray)),
_ => throw new ArgumentOutOfRangeException()
};
void OnEnumerationCompleted(DeviceWatcher sender, object o) => waitEvent.Set();
void OnDeviceAdded(DeviceWatcher sender, DeviceInformation args)
{
try { lampArrays.Add(new LampArrayInfo(args.Id, args.Name, LampArray.FromIdAsync(args.Id).GetAwaiter().GetResult())); }
catch (Exception ex) { Throw(ex); }
}
}
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
lock (_lock)
{
base.Dispose(disposing);
_instance = null;
}
}
#endregion
}
@@ -0,0 +1,34 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Dynamic Lighting Furniture-device.
/// </summary>
public sealed class DynamicLightingFurnitureRGBDevice : DynamicLightingRGBDevice<DynamicLightingFurnitureRGBDeviceInfo>, IFurniture
{
#region Properties & Fields
/// <inheritdoc/>
protected override LedId ReferenceLedId => LedId.Furniture1;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingFurnitureRGBDevice" /> class.
/// </summary>
/// <param name="info">The meta data for this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal DynamicLightingFurnitureRGBDevice(DynamicLightingFurnitureRGBDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
}
@@ -0,0 +1,19 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingFurnitureRGBDevice" />.
/// </summary>
public sealed class DynamicLightingFurnitureRGBDeviceInfo : DynamicLightingRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
internal DynamicLightingFurnitureRGBDeviceInfo(LampArrayInfo lampArrayInfo)
: base(RGBDeviceType.Furniture, lampArrayInfo)
{ }
#endregion
}
@@ -0,0 +1,34 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Dynamic Lighting GameController-device.
/// </summary>
public sealed class DynamicLightingGameControllerRGBDevice : DynamicLightingRGBDevice<DynamicLightingGameControllerRGBDeviceInfo>, IGameController
{
#region Properties & Fields
/// <inheritdoc/>
protected override LedId ReferenceLedId => LedId.GameController1;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingGameControllerRGBDevice" /> class.
/// </summary>
/// <param name="info">The meta data for this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal DynamicLightingGameControllerRGBDevice(DynamicLightingGameControllerRGBDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
}
@@ -0,0 +1,19 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingGameControllerRGBDevice" />.
/// </summary>
public sealed class DynamicLightingGameControllerRGBDeviceInfo : DynamicLightingRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
internal DynamicLightingGameControllerRGBDeviceInfo(LampArrayInfo lampArrayInfo)
: base(RGBDeviceType.GameController, lampArrayInfo)
{ }
#endregion
}
@@ -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,
};
}
@@ -0,0 +1,73 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System.Collections.Generic;
using System.Linq;
using Windows.System;
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Dynamic Lighting Keyboard-device.
/// </summary>
public sealed class DynamicLightingKeyboardRGBDevice : DynamicLightingRGBDevice<DynamicLightingKeyboardRGBDeviceInfo>, IKeyboard
{
#region Properties & Fields
/// <inheritdoc/>
protected override LedId ReferenceLedId => LedId.Keyboard_Programmable1;
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingKeyboardRGBDevice" /> class.
/// </summary>
/// <param name="info">The meta data for this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal DynamicLightingKeyboardRGBDevice(DynamicLightingKeyboardRGBDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
#region Methods
/// <inheritdoc/>
protected override LedMapping<int> CreateMapping()
{
LedMapping<int> ledMapping = [];
HashSet<int> indices = Enumerable.Range(0, DeviceInfo.LedCount).ToHashSet();
if (DeviceInfo.LampArray.SupportsVirtualKeys)
{
foreach ((VirtualKey virtualKey, LedId ledId) in LedMappings.KeyboardMapping)
{
int[] virtualKeyIndices = DeviceInfo.LampArray.GetIndicesForKey(virtualKey);
if (virtualKeyIndices.Length > 0)
{
int? index = virtualKeyIndices.FirstOrDefault(indices.Contains);
if (index != null)
{
ledMapping.Add(ledId, index.Value);
indices.Remove(index.Value);
}
}
}
}
LedId referenceLed = LedId.Keyboard_Custom1;
foreach (int index in indices.OrderBy(x => x))
ledMapping.Add(referenceLed++, index);
return ledMapping;
}
#endregion
}
@@ -0,0 +1,26 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDeviceInfo" />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingKeyboardRGBDevice" />.
/// </summary>
public sealed class DynamicLightingKeyboardRGBDeviceInfo : DynamicLightingRGBDeviceInfo, IKeyboardDeviceInfo
{
#region Properties & Fields
/// <inheritdoc/>
public KeyboardLayoutType Layout => KeyboardLayoutType.Unknown;
#endregion
#region Constructors
/// <inheritdoc />
internal DynamicLightingKeyboardRGBDeviceInfo(LampArrayInfo lampArrayInfo)
: base(RGBDeviceType.Keyboard, lampArrayInfo)
{ }
#endregion
}
@@ -0,0 +1,34 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Dynamic Lighting Mouse-device.
/// </summary>
public sealed class DynamicLightingMouseRGBDevice : DynamicLightingRGBDevice<DynamicLightingMouseRGBDeviceInfo>, IMouse
{
#region Properties & Fields
/// <inheritdoc/>
protected override LedId ReferenceLedId => LedId.Mouse1;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingMouseRGBDevice" /> class.
/// </summary>
/// <param name="info">The meta data for this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal DynamicLightingMouseRGBDevice(DynamicLightingMouseRGBDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
}
@@ -0,0 +1,19 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingMouseRGBDevice" />.
/// </summary>
public sealed class DynamicLightingMouseRGBDeviceInfo : DynamicLightingRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
internal DynamicLightingMouseRGBDeviceInfo(LampArrayInfo lampArrayInfo)
: base(RGBDeviceType.Mouse, lampArrayInfo)
{ }
#endregion
}
@@ -0,0 +1,34 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Dynamic Lighting Notification-device.
/// </summary>
public sealed class DynamicLightingNotificationRGBDevice : DynamicLightingRGBDevice<DynamicLightingNotificationRGBDeviceInfo>, IUnknownDevice
{
#region Properties & Fields
/// <inheritdoc/>
protected override LedId ReferenceLedId => LedId.Unknown1;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingNotificationRGBDevice" /> class.
/// </summary>
/// <param name="info">The meta data for this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal DynamicLightingNotificationRGBDevice(DynamicLightingNotificationRGBDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
}
@@ -0,0 +1,19 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingNotificationRGBDevice" />.
/// </summary>
public sealed class DynamicLightingNotificationRGBDeviceInfo : DynamicLightingRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
internal DynamicLightingNotificationRGBDeviceInfo(LampArrayInfo lampArrayInfo)
: base(RGBDeviceType.Unknown, lampArrayInfo)
{ }
#endregion
}
@@ -0,0 +1,34 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Dynamic Lighting Peripheral-device.
/// </summary>
public sealed class DynamicLightingPeripheralRGBDevice : DynamicLightingRGBDevice<DynamicLightingPeripheralRGBDeviceInfo>, IUnknownDevice
{
#region Properties & Fields
/// <inheritdoc/>
protected override LedId ReferenceLedId => LedId.Unknown1;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingPeripheralRGBDevice" /> class.
/// </summary>
/// <param name="info">The meta data for this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal DynamicLightingPeripheralRGBDevice(DynamicLightingPeripheralRGBDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
}
@@ -0,0 +1,19 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingPeripheralRGBDevice" />.
/// </summary>
public sealed class DynamicLightingPeripheralRGBDeviceInfo : DynamicLightingRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
internal DynamicLightingPeripheralRGBDeviceInfo(LampArrayInfo lampArrayInfo)
: base(RGBDeviceType.Unknown, lampArrayInfo)
{ }
#endregion
}
@@ -0,0 +1,9 @@
[RGB.NET](https://github.com/DarthAffe/RGB.NET) Device-Provider-Package for Microsoft Dynamic Lighting-Devices.
## Usage
This provider follows the default pattern and does not require additional setup.
```csharp
surface.Load(DynamicLightingDeviceProvider.Instance);
```
@@ -0,0 +1,64 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-windows10.0.17763.0;net7.0-windows10.0.17763.0</TargetFrameworks>
<SupportedOSPlatformVersion>10.0.17763.0</SupportedOSPlatformVersion>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<Authors>Darth Affe</Authors>
<Company>Wyrez</Company>
<Language>en-US</Language>
<NeutralLanguage>en-US</NeutralLanguage>
<Title>RGB.NET.Devices.DynamicLighting</Title>
<AssemblyName>RGB.NET.Devices.DynamicLighting</AssemblyName>
<AssemblyTitle>RGB.NET.Devices.DynamicLighting</AssemblyTitle>
<PackageId>RGB.NET.Devices.DynamicLighting</PackageId>
<RootNamespace>RGB.NET.Devices.DynamicLighting</RootNamespace>
<Description>Microsoft Dynamic Lighting-Device-Implementations of RGB.NET</Description>
<Summary>Microsoft Dynamic Lighting-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals</Summary>
<Copyright>Copyright © Darth Affe 2024</Copyright>
<PackageCopyright>Copyright © Darth Affe 2024</PackageCopyright>
<PackageIcon>icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageProjectUrl>https://github.com/DarthAffe/RGB.NET</PackageProjectUrl>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<RepositoryType>Github</RepositoryType>
<RepositoryUrl>https://github.com/DarthAffe/RGB.NET</RepositoryUrl>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes></PackageReleaseNotes>
<Version>0.0.1</Version>
<AssemblyVersion>0.0.1</AssemblyVersion>
<FileVersion>0.0.1</FileVersion>
<OutputPath>..\bin\</OutputPath>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSource>True</IncludeSource>
<IncludeSymbols>True</IncludeSymbols>
<DebugType>portable</DebugType>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DefineConstants>TRACE;DEBUG</DefineConstants>
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<Optimize>true</Optimize>
<NoWarn>$(NoWarn);CS1591;CS1572;CS1573</NoWarn>
<DefineConstants>RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Content Include="..\Resources\icon.png" Link="icon.png" Pack="true" PackagePath="\" />
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,13 @@
<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/=chassis/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=furniture/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=gamecontroller/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=keyboard/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mouse/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=notification/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=peripheral/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=scene/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=undefined/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=wearable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=art/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generic/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
@@ -0,0 +1,34 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Dynamic Lighting Scene-device.
/// </summary>
public sealed class DynamicLightingSceneRGBDevice : DynamicLightingRGBDevice<DynamicLightingSceneRGBDeviceInfo>, IUnknownDevice
{
#region Properties & Fields
/// <inheritdoc/>
protected override LedId ReferenceLedId => LedId.Unknown1;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingSceneRGBDevice" /> class.
/// </summary>
/// <param name="info">The meta data for this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal DynamicLightingSceneRGBDevice(DynamicLightingSceneRGBDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
}
@@ -0,0 +1,19 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingSceneRGBDevice" />.
/// </summary>
public sealed class DynamicLightingSceneRGBDeviceInfo : DynamicLightingRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
internal DynamicLightingSceneRGBDeviceInfo(LampArrayInfo lampArrayInfo)
: base(RGBDeviceType.Unknown, lampArrayInfo)
{ }
#endregion
}
@@ -0,0 +1,34 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Dynamic Lighting Undefined-device.
/// </summary>
public sealed class DynamicLightingUndefinedRGBDevice : DynamicLightingRGBDevice<DynamicLightingUndefinedRGBDeviceInfo>, IUnknownDevice
{
#region Properties & Fields
/// <inheritdoc/>
protected override LedId ReferenceLedId => LedId.Unknown1;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingUndefinedRGBDevice" /> class.
/// </summary>
/// <param name="info">The meta data for this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal DynamicLightingUndefinedRGBDevice(DynamicLightingUndefinedRGBDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
}
@@ -0,0 +1,19 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingUndefinedRGBDevice" />.
/// </summary>
public sealed class DynamicLightingUndefinedRGBDeviceInfo : DynamicLightingRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
internal DynamicLightingUndefinedRGBDeviceInfo(LampArrayInfo lampArrayInfo)
: base(RGBDeviceType.Unknown, lampArrayInfo)
{ }
#endregion
}
@@ -0,0 +1,34 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc cref="DynamicLightingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Dynamic Lighting Wearable-device.
/// </summary>
public sealed class DynamicLightingWearableRGBDevice : DynamicLightingRGBDevice<DynamicLightingWearableRGBDeviceInfo>, IWearable
{
#region Properties & Fields
/// <inheritdoc/>
protected override LedId ReferenceLedId => LedId.Wearable1;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingWearableRGBDevice" /> class.
/// </summary>
/// <param name="info">The meta data for this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal DynamicLightingWearableRGBDevice(DynamicLightingWearableRGBDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
}
@@ -0,0 +1,19 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.DynamicLighting.DynamicLightingWearableRGBDevice" />.
/// </summary>
public sealed class DynamicLightingWearableRGBDeviceInfo : DynamicLightingRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
internal DynamicLightingWearableRGBDeviceInfo(LampArrayInfo lampArrayInfo)
: base(RGBDeviceType.Wearable, lampArrayInfo)
{ }
#endregion
}