using Windows.Devices.Lights;
using RGB.NET.Core;
namespace RGB.NET.Devices.DynamicLighting;
///
///
/// Represents a generic Dynamic Lighting-device.
///
public abstract class DynamicLightingRGBDevice : AbstractRGBDevice, IDynamicLightingRGBDevice
where TDeviceInfo : DynamicLightingRGBDeviceInfo
{
#region Properties & Fields
///
/// Gets the mapping of to the index of the led used to update the LEDs of this device.
///
protected LedMapping Mapping { get; private set; } = [];
///
/// Gets the reference led id.
///
protected abstract LedId ReferenceLedId { get; }
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The meta data for this device.
/// The queue used to update this device.
protected DynamicLightingRGBDevice(TDeviceInfo info, DynamicLightingDeviceUpdateQueue updateQueue)
: base(info, updateQueue) { }
#endregion
#region Methods
void IDynamicLightingRGBDevice.Initialize()
{
Mapping = CreateMapping();
InitializeLayout();
}
///
/// Initializes the LEDs of the device based on the data provided by the SDK.
///
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);
}
}
///
/// Creates a mapping for this device.
///
/// The mapping.
protected virtual LedMapping CreateMapping()
{
LedMapping mapping = [];
for (int i = 0; i < DeviceInfo.LedCount; i++)
mapping.Add(ReferenceLedId + i, i);
return mapping;
}
///
protected override object GetLedCustomData(LedId ledId) => Mapping.TryGetValue(ledId, out int index) ? index : 0;
#endregion
}