using System;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Core.Layout;
namespace RGB.NET.Devices.Debug
{
///
///
/// Represents a debug device.
///
public class DebugRGBDevice : AbstractRGBDevice
{
#region Properties & Fields
///
public override DebugRGBDeviceInfo DeviceInfo { get; }
private Func> _syncBackFunc;
private Action> _updateLedsAction;
#endregion
#region Constructors
///
/// Internal constructor of .
///
internal DebugRGBDevice(string layoutPath, Func> syncBackFunc = null, Action> updateLedsAction = null)
{
this._syncBackFunc = syncBackFunc;
this._updateLedsAction = updateLedsAction;
DeviceLayout layout = DeviceLayout.Load(layoutPath);
DeviceInfo = new DebugRGBDeviceInfo(layout.Type, layout.Vendor, layout.Model, layout.Lighting, syncBackFunc != null);
}
#endregion
#region Methods
internal void Initialize(string layoutPath, string imageLayout) => ApplyLayoutFromFile(layoutPath, imageLayout, true);
///
public override void SyncBack()
{
try
{
Dictionary syncBackValues = _syncBackFunc?.Invoke();
if (syncBackValues == null) return;
foreach (KeyValuePair value in syncBackValues)
{
Led led = ((IRGBDevice)this)[value.Key];
if (led != null)
led.Color = value.Value;
}
}
catch {/* ics that's not my fault ... */}
}
///
protected override void UpdateLeds(IEnumerable ledsToUpdate) => _updateLedsAction?.Invoke(ledsToUpdate);
#endregion
}
}