mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Compare commits
No commits in common. "8555d6b9616495f21b97a7a5c7833085bf07449f" and "4b5d076953f33d5e88f2845e7c4a926d2a23f44d" have entirely different histories.
8555d6b961
...
4b5d076953
@ -42,7 +42,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractRGBDeviceProvider" /> class.
|
||||
/// </summary>
|
||||
@ -157,6 +157,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
|
||||
/// <returns>The newly created update trigger.</returns>
|
||||
protected virtual IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new DeviceUpdateTrigger(updateRateHardLimit);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resets the device provider and disposes all devices and update triggers.
|
||||
/// </summary>
|
||||
|
||||
@ -40,16 +40,4 @@ public static class CustomUpdateDataExtension
|
||||
customUpdateData[CustomUpdateDataIndex.UPDATE_DEVICES] = value;
|
||||
return customUpdateData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="CustomUpdateDataIndex.HEARTBEAT"/>-Parameter to the given value.
|
||||
/// </summary>
|
||||
/// <param name="customUpdateData">The update-data to modify.</param>
|
||||
/// <param name="value">The value to set.</param>
|
||||
/// <returns>The modified update-data.</returns>
|
||||
public static CustomUpdateData Heartbeat(this CustomUpdateData customUpdateData, bool value = true)
|
||||
{
|
||||
customUpdateData[CustomUpdateDataIndex.HEARTBEAT] = value;
|
||||
return customUpdateData;
|
||||
}
|
||||
}
|
||||
@ -24,11 +24,6 @@ public static class CustomUpdateDataIndex
|
||||
/// default: true
|
||||
/// </summary>
|
||||
public const string UPDATE_DEVICES = "updateDevices";
|
||||
|
||||
/// <summary>
|
||||
/// Used by <see cref="DeviceUpdateTrigger"/> to indicate heatbeat updates.
|
||||
/// </summary>
|
||||
public const string HEARTBEAT = "heartbeat";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -53,20 +52,9 @@ public class DeviceUpdateTrigger : AbstractUpdateTrigger, IDeviceUpdateTrigger
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time in ms after which a refresh-request is sent even if no changes are made in the meantime to prevent the target from timing out or similar problems.
|
||||
/// To disable heartbeats leave it at 0.
|
||||
/// </summary>
|
||||
public int HeartbeatTimer { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double LastUpdateTime { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the timestamp of the last update.
|
||||
/// </summary>
|
||||
protected long LastUpdateTimestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the event to trigger when new data is available (<see cref="TriggerHasData"/>).
|
||||
/// </summary>
|
||||
@ -157,14 +145,6 @@ public class DeviceUpdateTrigger : AbstractUpdateTrigger, IDeviceUpdateTrigger
|
||||
while (!UpdateToken.IsCancellationRequested)
|
||||
if (HasDataEvent.WaitOne(Timeout))
|
||||
LastUpdateTime = TimerHelper.Execute(() => OnUpdate(), UpdateFrequency * 1000);
|
||||
else if ((HeartbeatTimer > 0) && (LastUpdateTimestamp > 0) && (TimerHelper.GetElapsedTime(LastUpdateTimestamp) > HeartbeatTimer))
|
||||
OnUpdate(new CustomUpdateData().Heartbeat());
|
||||
}
|
||||
|
||||
protected override void OnUpdate(CustomUpdateData? updateData = null)
|
||||
{
|
||||
base.OnUpdate(updateData);
|
||||
LastUpdateTimestamp = Stopwatch.GetTimestamp();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -57,15 +57,14 @@ public class DMXDeviceProvider : AbstractRGBDeviceProvider
|
||||
/// <inheritdoc />
|
||||
protected override IEnumerable<IRGBDevice> LoadDevices()
|
||||
{
|
||||
for (int i = 0; i < DeviceDefinitions.Count; i++)
|
||||
foreach (IDMXDeviceDefinition dmxDeviceDefinition in DeviceDefinitions)
|
||||
{
|
||||
IDMXDeviceDefinition dmxDeviceDefinition = DeviceDefinitions[i];
|
||||
IRGBDevice? device = null;
|
||||
try
|
||||
{
|
||||
if (dmxDeviceDefinition is E131DMXDeviceDefinition e131DMXDeviceDefinition)
|
||||
if (e131DMXDeviceDefinition.Leds.Count > 0)
|
||||
device = new E131Device(new E131DeviceInfo(e131DMXDeviceDefinition), e131DMXDeviceDefinition.Leds, GetUpdateTrigger(i));
|
||||
device = new E131Device(new E131DeviceInfo(e131DMXDeviceDefinition), e131DMXDeviceDefinition.Leds, GetUpdateTrigger(0));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -77,14 +76,5 @@ public class DMXDeviceProvider : AbstractRGBDeviceProvider
|
||||
}
|
||||
}
|
||||
|
||||
protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit)
|
||||
{
|
||||
DeviceUpdateTrigger updateTrigger = new(updateRateHardLimit);
|
||||
if ((DeviceDefinitions[id] is E131DMXDeviceDefinition e131DMXDeviceDefinition))
|
||||
updateTrigger.HeartbeatTimer = e131DMXDeviceDefinition.HeartbeatTimer;
|
||||
|
||||
return updateTrigger;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -57,12 +57,6 @@ public class E131DMXDeviceDefinition : IDMXDeviceDefinition
|
||||
/// </summary>
|
||||
public Dictionary<LedId, List<(int channel, Func<Color, byte> getValueFunc)>> Leds { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// The time in ms after which the device is updated even if no changes are made in the meantime to prevent the target from timing out or similar problems.
|
||||
/// To disable heartbeats leave it at 0.
|
||||
/// </summary>
|
||||
public int HeartbeatTimer { get; set; } = 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
@ -50,14 +50,6 @@ public class E131UpdateQueue : UpdateQueue
|
||||
|
||||
#region Methods
|
||||
|
||||
protected override void OnUpdate(object? sender, CustomUpdateData customData)
|
||||
{
|
||||
if (customData[CustomUpdateDataIndex.HEARTBEAT] as bool? ?? false)
|
||||
Update(Array.Empty<(object key, Color color)>());
|
||||
else
|
||||
base.OnUpdate(sender, customData);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
|
||||
@ -14,7 +14,7 @@ internal class SteelSeriesDeviceUpdateQueue : UpdateQueue
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly string _deviceType;
|
||||
private string _deviceType;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -37,7 +37,7 @@ internal class SteelSeriesDeviceUpdateQueue : UpdateQueue
|
||||
|
||||
protected override void OnUpdate(object? sender, CustomUpdateData customData)
|
||||
{
|
||||
if (customData[CustomUpdateDataIndex.HEARTBEAT] as bool? ?? false)
|
||||
if (customData["refresh"] as bool? ?? false)
|
||||
SteelSeriesSDK.SendHeartbeat();
|
||||
else
|
||||
base.OnUpdate(sender, customData);
|
||||
|
||||
@ -0,0 +1,80 @@
|
||||
// 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
|
||||
}
|
||||
@ -12,12 +12,6 @@ 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;
|
||||
@ -127,7 +121,7 @@ public class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new DeviceUpdateTrigger(updateRateHardLimit) { HeartbeatTimer = HEARTBEAT_TIMER };
|
||||
protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new SteelSeriesDeviceUpdateTrigger(updateRateHardLimit);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user