mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-12 16:58:29 +00:00
Merge pull request #22 from DarthAffe/Development
Merged exception-handling to fix #9
This commit is contained in:
commit
62fba47519
@ -45,6 +45,7 @@
|
||||
<Compile Include="Devices\Generic\Enums\CorsairAccessMode.cs" />
|
||||
<Compile Include="Devices\Generic\Enums\CorsairDeviceCaps.cs" />
|
||||
<Compile Include="Devices\Generic\Enums\CorsairDeviceType.cs" />
|
||||
<Compile Include="Devices\Generic\OnExceptionEventArgs.cs" />
|
||||
<Compile Include="Devices\Keyboard\Brushes\AbstractBrush.cs" />
|
||||
<Compile Include="Devices\Keyboard\Brushes\Gradient\AbstractGradient.cs" />
|
||||
<Compile Include="Devices\Keyboard\Brushes\Gradient\GradientStop.cs" />
|
||||
|
||||
@ -39,6 +39,12 @@ namespace CUE.NET.Devices.Generic
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event OnExceptionEventHandler OnException;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
protected AbstractCueDevice(IDeviceInfo info)
|
||||
@ -142,6 +148,11 @@ namespace CUE.NET.Devices.Generic
|
||||
Marshal.FreeHGlobal(ptr);
|
||||
}
|
||||
|
||||
protected void ManageException(Exception ex)
|
||||
{
|
||||
OnException?.Invoke(this, new OnExceptionEventArgs(ex));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
22
Devices/Generic/OnExceptionEventArgs.cs
Normal file
22
Devices/Generic/OnExceptionEventArgs.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace CUE.NET.Devices.Generic
|
||||
{
|
||||
public class OnExceptionEventArgs : EventArgs
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public Exception Exception { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public OnExceptionEventArgs(Exception exception)
|
||||
{
|
||||
this.Exception = exception;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,21 @@
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
|
||||
namespace CUE.NET.Devices
|
||||
{
|
||||
public delegate void OnExceptionEventHandler(object sender, OnExceptionEventArgs args);
|
||||
|
||||
public interface ICueDevice
|
||||
{
|
||||
|
||||
IDeviceInfo DeviceInfo { get; }
|
||||
|
||||
UpdateMode UpdateMode { get; set; }
|
||||
|
||||
float UpdateFrequency { get; set; }
|
||||
|
||||
event OnExceptionEventHandler OnException;
|
||||
|
||||
void Update(bool flushLeds = false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,22 +97,26 @@ namespace CUE.NET.Devices.Keyboard
|
||||
long currentTicks = DateTime.Now.Ticks;
|
||||
foreach (EffectTimeContainer effect in _effects)
|
||||
{
|
||||
float deltaTime;
|
||||
if (effect.TicksAtLastUpdate < 0)
|
||||
try
|
||||
{
|
||||
float deltaTime;
|
||||
if (effect.TicksAtLastUpdate < 0)
|
||||
{
|
||||
effect.TicksAtLastUpdate = currentTicks;
|
||||
deltaTime = 0f;
|
||||
}
|
||||
else
|
||||
deltaTime = (currentTicks - effect.TicksAtLastUpdate) / 10000000f;
|
||||
|
||||
effect.TicksAtLastUpdate = currentTicks;
|
||||
deltaTime = 0f;
|
||||
effect.Effect.Update(deltaTime);
|
||||
|
||||
ApplyBrush((effect.Effect.KeyList ?? this).ToList(), effect.Effect.EffectBrush);
|
||||
|
||||
if (effect.Effect.IsDone)
|
||||
effectsToRemove.Add(effect.Effect);
|
||||
}
|
||||
else
|
||||
deltaTime = (currentTicks - effect.TicksAtLastUpdate) / 10000000f;
|
||||
|
||||
effect.TicksAtLastUpdate = currentTicks;
|
||||
effect.Effect.Update(deltaTime);
|
||||
|
||||
ApplyBrush((effect.Effect.KeyList ?? this).ToList(), effect.Effect.EffectBrush);
|
||||
|
||||
if (effect.Effect.IsDone)
|
||||
effectsToRemove.Add(effect.Effect);
|
||||
catch (Exception ex) { ManageException(ex); }
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,9 +140,13 @@ namespace CUE.NET.Devices.Keyboard
|
||||
// ReSharper disable once MemberCanBeMadeStatic.Local - idc
|
||||
private void ApplyBrush(ICollection<CorsairKey> keys, IBrush brush)
|
||||
{
|
||||
RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(keys.Select(x => x.KeyRectangle));
|
||||
foreach (CorsairKey key in keys)
|
||||
key.Led.Color = brush.GetColorAtPoint(brushRectangle, key.KeyRectangle.GetCenter());
|
||||
try
|
||||
{
|
||||
RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(keys.Select(x => x.KeyRectangle));
|
||||
foreach (CorsairKey key in keys)
|
||||
key.Led.Color = brush.GetColorAtPoint(brushRectangle, key.KeyRectangle.GetCenter());
|
||||
}
|
||||
catch (Exception ex) { ManageException(ex); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user