1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Changed SteelSeries devices to use the core heartbeat functionality

This commit is contained in:
Darth Affe 2022-11-05 21:11:41 +01:00
parent ca8bc67f03
commit b12d0dc631
3 changed files with 9 additions and 83 deletions

View File

@ -14,7 +14,7 @@ internal class SteelSeriesDeviceUpdateQueue : UpdateQueue
{
#region Properties & Fields
private string _deviceType;
private readonly string _deviceType;
#endregion
@ -37,7 +37,7 @@ internal class SteelSeriesDeviceUpdateQueue : UpdateQueue
protected override void OnUpdate(object? sender, CustomUpdateData customData)
{
if (customData["refresh"] as bool? ?? false)
if (customData[CustomUpdateDataIndex.HEARTBEAT] as bool? ?? false)
SteelSeriesSDK.SendHeartbeat();
else
base.OnUpdate(sender, customData);

View File

@ -1,80 +0,0 @@
// ReSharper disable MemberCanBePrivate.Global
using System.Diagnostics;
using System.Threading;
using RGB.NET.Core;
namespace RGB.NET.Devices.SteelSeries;
/// <summary>
/// Represents an update-trigger used to update SteelSeries devices
/// </summary>
public class SteelSeriesDeviceUpdateTrigger : DeviceUpdateTrigger
{
#region Constants
private static readonly long FLUSH_TIMER = 5 * 1000 * (long)(Stopwatch.Frequency / 1000.0); // flush the device every 5 seconds to prevent timeouts
#endregion
#region Properties & Fields
private long _lastUpdateTimestamp;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="SteelSeriesDeviceUpdateTrigger"/> class.
/// </summary>
public SteelSeriesDeviceUpdateTrigger()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="SteelSeriesDeviceUpdateTrigger"/> class.
/// </summary>
/// <param name="updateRateHardLimit">The hard limit of the update rate of this trigger.</param>
public SteelSeriesDeviceUpdateTrigger(double updateRateHardLimit)
: base(updateRateHardLimit)
{ }
#endregion
#region Methods
/// <inheritdoc />
protected override void UpdateLoop()
{
OnStartup();
while (!UpdateToken.IsCancellationRequested)
{
if (HasDataEvent.WaitOne(Timeout))
{
long preUpdateTicks = Stopwatch.GetTimestamp();
OnUpdate();
if (UpdateFrequency > 0)
{
double lastUpdateTime = ((_lastUpdateTimestamp - preUpdateTicks) / (Stopwatch.Frequency / 1000.0));
int sleep = (int)((UpdateFrequency * 1000.0) - lastUpdateTime);
if (sleep > 0)
Thread.Sleep(sleep);
}
}
else if ((_lastUpdateTimestamp > 0) && ((Stopwatch.GetTimestamp() - _lastUpdateTimestamp) > FLUSH_TIMER))
OnUpdate(new CustomUpdateData(("refresh", true)));
}
}
/// <inheritdoc />
protected override void OnUpdate(CustomUpdateData? updateData = null)
{
base.OnUpdate(updateData);
_lastUpdateTimestamp = Stopwatch.GetTimestamp();
}
#endregion
}

View File

@ -12,6 +12,12 @@ namespace RGB.NET.Devices.SteelSeries;
/// </summary>
public class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
{
#region Constants
private static readonly int HEARTBEAT_TIMER = 5000; // flush the device every 5 seconds to prevent timeouts
#endregion
#region Properties & Fields
private static SteelSeriesDeviceProvider? _instance;
@ -121,7 +127,7 @@ public class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
}
/// <inheritdoc />
protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new SteelSeriesDeviceUpdateTrigger(updateRateHardLimit);
protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new DeviceUpdateTrigger(updateRateHardLimit) { HeartbeatTimer = HEARTBEAT_TIMER };
/// <inheritdoc />
public override void Dispose()