using System; using RGB.NET.Core; using RGB.NET.Devices.Razer.Native; namespace RGB.NET.Devices.Razer; /// /// Represents a basic update-queue performing updates for razer devices. /// public abstract class RazerUpdateQueue : UpdateQueue { #region Properties & Fields private Guid? _lastEffect; #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The update trigger used to update this queue. protected RazerUpdateQueue(IDeviceUpdateTrigger updateTrigger) : base(updateTrigger) { } #endregion #region Methods /// protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { nint effectParams = CreateEffectParams(dataSet); Guid effectId = Guid.NewGuid(); CreateEffect(effectParams, ref effectId); _RazerSDK.SetEffect(effectId); if (_lastEffect.HasValue) _RazerSDK.DeleteEffect(_lastEffect.Value); _lastEffect = effectId; return true; } catch (Exception ex) { RazerDeviceProvider.Instance.Throw(ex); } return false; } /// /// Creates the effect used to update this device. /// /// The parameters of the effect. /// The id this effect is created with. protected abstract void CreateEffect(nint effectParams, ref Guid effectId); /// public override void Reset() { if (_lastEffect.HasValue) { _RazerSDK.DeleteEffect(_lastEffect.Value); _lastEffect = null; } } /// /// Creates the device-specific effect parameters for the led-update. /// /// The data to be updated. /// An pointing to the effect parameter struct. protected abstract nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet); #endregion }