using System; using System.Collections.Generic; 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 readonly Guid _deviceId; private Guid? _lastEffect; #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The update trigger used to update this queue. /// The id of the device updated by this queue. protected RazerUpdateQueue(IDeviceUpdateTrigger updateTrigger, Guid deviceId) : base(updateTrigger) { this._deviceId = deviceId; } #endregion #region Methods /// protected override void Update(Dictionary dataSet) { IntPtr effectParams = CreateEffectParams(dataSet); Guid effectId = Guid.NewGuid(); CreateEffect(effectParams, ref effectId); _RazerSDK.SetEffect(effectId); if (_lastEffect.HasValue) _RazerSDK.DeleteEffect(_lastEffect.Value); _lastEffect = effectId; } /// /// Creates the effect used to update this device. /// /// The parameters of the effect. /// The id this effect is created with. protected virtual void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateEffect(_deviceId, _Defines.EFFECT_ID, effectParams, ref 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 IntPtr CreateEffectParams(Dictionary dataSet); #endregion } }