mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-13 09:08:34 +00:00
Added missing files from the last commit
This commit is contained in:
parent
6f2e77b797
commit
603c4f72fe
@ -50,8 +50,12 @@
|
|||||||
<Compile Include="Devices\Generic\Enums\CorsairAccessMode.cs" />
|
<Compile Include="Devices\Generic\Enums\CorsairAccessMode.cs" />
|
||||||
<Compile Include="Devices\Generic\Enums\CorsairDeviceCaps.cs" />
|
<Compile Include="Devices\Generic\Enums\CorsairDeviceCaps.cs" />
|
||||||
<Compile Include="Devices\Generic\Enums\CorsairDeviceType.cs" />
|
<Compile Include="Devices\Generic\Enums\CorsairDeviceType.cs" />
|
||||||
<Compile Include="Devices\Generic\ExceptionEventArgs.cs" />
|
<Compile Include="Devices\Generic\EventArgs\ExceptionEventArgs.cs" />
|
||||||
<Compile Include="Brushes\AbstractBrush.cs" />
|
<Compile Include="Brushes\AbstractBrush.cs" />
|
||||||
|
<Compile Include="Devices\Generic\EventArgs\LedsUpdatedEventArgs.cs" />
|
||||||
|
<Compile Include="Devices\Generic\EventArgs\LedsUpdatingEventArgs.cs" />
|
||||||
|
<Compile Include="Devices\Generic\EventArgs\UpdatedEventArgs.cs" />
|
||||||
|
<Compile Include="Devices\Generic\EventArgs\UpdatingEventArgs.cs" />
|
||||||
<Compile Include="Devices\Keyboard\Enums\BrushCalculationMode.cs" />
|
<Compile Include="Devices\Keyboard\Enums\BrushCalculationMode.cs" />
|
||||||
<Compile Include="Gradients\AbstractGradient.cs" />
|
<Compile Include="Gradients\AbstractGradient.cs" />
|
||||||
<Compile Include="Gradients\GradientStop.cs" />
|
<Compile Include="Gradients\GradientStop.cs" />
|
||||||
|
|||||||
@ -9,6 +9,7 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CUE.NET.Devices.Generic.Enums;
|
using CUE.NET.Devices.Generic.Enums;
|
||||||
|
using CUE.NET.Devices.Generic.EventArgs;
|
||||||
using CUE.NET.Effects;
|
using CUE.NET.Effects;
|
||||||
using CUE.NET.Native;
|
using CUE.NET.Native;
|
||||||
|
|
||||||
@ -73,6 +74,26 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event ExceptionEventHandler Exception;
|
public event ExceptionEventHandler Exception;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the device starts updating.
|
||||||
|
/// </summary>
|
||||||
|
public event UpdatingEventHandler Updating;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the device update is done.
|
||||||
|
/// </summary>
|
||||||
|
public event UpdatedEventHandler Updated;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the device starts to update the leds.
|
||||||
|
/// </summary>
|
||||||
|
public event LedsUpdatingEventHandler LedsUpdating;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the device updated the leds.
|
||||||
|
/// </summary>
|
||||||
|
public event LedsUpdatedEventHandler LedsUpdated;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@ -158,8 +179,11 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// Performs an update for all dirty keys, or all keys if flushLeds is set to true.
|
/// Performs an update for all dirty keys, or all keys if flushLeds is set to true.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="flushLeds">Specifies whether all keys (including clean ones) should be updated.</param>
|
/// <param name="flushLeds">Specifies whether all keys (including clean ones) should be updated.</param>
|
||||||
public virtual void Update(bool flushLeds = false)
|
public void Update(bool flushLeds = false)
|
||||||
{
|
{
|
||||||
|
OnUpdating();
|
||||||
|
|
||||||
|
DeviceUpdate();
|
||||||
UpdateEffects();
|
UpdateEffects();
|
||||||
|
|
||||||
IList<KeyValuePair<int, CorsairLed>> ledsToUpdate = (flushLeds ? Leds : Leds.Where(x => x.Value.IsDirty)).ToList();
|
IList<KeyValuePair<int, CorsairLed>> ledsToUpdate = (flushLeds ? Leds : Leds.Where(x => x.Value.IsDirty)).ToList();
|
||||||
@ -168,8 +192,16 @@ namespace CUE.NET.Devices.Generic
|
|||||||
led.Update();
|
led.Update();
|
||||||
|
|
||||||
UpdateLeds(ledsToUpdate);
|
UpdateLeds(ledsToUpdate);
|
||||||
|
|
||||||
|
OnUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Empty method which can be overwritten to perform device specific updates.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void DeviceUpdate()
|
||||||
|
{ }
|
||||||
|
|
||||||
private void UpdateEffects()
|
private void UpdateEffects()
|
||||||
{
|
{
|
||||||
List<IEffect> effectsToRemove = new List<IEffect>();
|
List<IEffect> effectsToRemove = new List<IEffect>();
|
||||||
@ -198,7 +230,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
effectsToRemove.Add(effect.Effect);
|
effectsToRemove.Add(effect.Effect);
|
||||||
}
|
}
|
||||||
// ReSharper disable once CatchAllClause
|
// ReSharper disable once CatchAllClause
|
||||||
catch (Exception ex) { ManageException(ex); }
|
catch (Exception ex) { OnException(ex); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,31 +244,35 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// <param name="effect">The effect to apply.</param>
|
/// <param name="effect">The effect to apply.</param>
|
||||||
protected abstract void ApplyEffect(IEffect effect);
|
protected abstract void ApplyEffect(IEffect effect);
|
||||||
|
|
||||||
private static void UpdateLeds(ICollection<KeyValuePair<int, CorsairLed>> ledsToUpdate)
|
private void UpdateLeds(ICollection<KeyValuePair<int, CorsairLed>> ledsToUpdate)
|
||||||
{
|
{
|
||||||
ledsToUpdate = ledsToUpdate.Where(x => x.Value.Color != Color.Transparent).ToList();
|
ledsToUpdate = ledsToUpdate.Where(x => x.Value.Color != Color.Transparent).ToList();
|
||||||
|
|
||||||
if (!ledsToUpdate.Any())
|
OnLedsUpdating(ledsToUpdate);
|
||||||
return; // CUE seems to crash if 'CorsairSetLedsColors' is called with a zero length array
|
|
||||||
|
|
||||||
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
|
if (ledsToUpdate.Any()) // CUE seems to crash if 'CorsairSetLedsColors' is called with a zero length array
|
||||||
IntPtr ptr = Marshal.AllocHGlobal(structSize * ledsToUpdate.Count);
|
|
||||||
IntPtr addPtr = new IntPtr(ptr.ToInt64());
|
|
||||||
foreach (KeyValuePair<int, CorsairLed> led in ledsToUpdate)
|
|
||||||
{
|
{
|
||||||
_CorsairLedColor color = new _CorsairLedColor
|
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
|
||||||
|
IntPtr ptr = Marshal.AllocHGlobal(structSize * ledsToUpdate.Count);
|
||||||
|
IntPtr addPtr = new IntPtr(ptr.ToInt64());
|
||||||
|
foreach (KeyValuePair<int, CorsairLed> led in ledsToUpdate)
|
||||||
{
|
{
|
||||||
ledId = led.Key,
|
_CorsairLedColor color = new _CorsairLedColor
|
||||||
r = led.Value.Color.R,
|
{
|
||||||
g = led.Value.Color.G,
|
ledId = led.Key,
|
||||||
b = led.Value.Color.B
|
r = led.Value.Color.R,
|
||||||
};
|
g = led.Value.Color.G,
|
||||||
|
b = led.Value.Color.B
|
||||||
|
};
|
||||||
|
|
||||||
Marshal.StructureToPtr(color, addPtr, false);
|
Marshal.StructureToPtr(color, addPtr, false);
|
||||||
addPtr = new IntPtr(addPtr.ToInt64() + structSize);
|
addPtr = new IntPtr(addPtr.ToInt64() + structSize);
|
||||||
|
}
|
||||||
|
_CUESDK.CorsairSetLedsColors(ledsToUpdate.Count, ptr);
|
||||||
|
Marshal.FreeHGlobal(ptr);
|
||||||
}
|
}
|
||||||
_CUESDK.CorsairSetLedsColors(ledsToUpdate.Count, ptr);
|
|
||||||
Marshal.FreeHGlobal(ptr);
|
OnLedsUpdated(ledsToUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -286,16 +322,6 @@ namespace CUE.NET.Devices.Generic
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the needed event-calls for an exception.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ex"></param>
|
|
||||||
/// <exception cref="System.Exception">A delegate callback throws an exception.</exception>
|
|
||||||
protected void ManageException(Exception ex)
|
|
||||||
{
|
|
||||||
Exception?.Invoke(this, new ExceptionEventArgs(ex));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resets all loaded LEDs back to default.
|
/// Resets all loaded LEDs back to default.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -305,6 +331,85 @@ namespace CUE.NET.Devices.Generic
|
|||||||
led.Reset();
|
led.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region EventCaller
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the needed event-calls for an exception.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ex">The exception previously thrown.</param>
|
||||||
|
protected virtual void OnException(Exception ex)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Exception?.Invoke(this, new ExceptionEventArgs(ex));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Well ... that's not my fault
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the needed event-calls before updating.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnUpdating()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Updating?.Invoke(this, new UpdatingEventArgs());
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Well ... that's not my fault
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the needed event-calls after an update.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnUpdated()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Updated?.Invoke(this, new UpdatedEventArgs());
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Well ... that's not my fault
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the needed event-calls before the leds are updated.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnLedsUpdating(ICollection<KeyValuePair<int, CorsairLed>> updatingLeds)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LedsUpdating?.Invoke(this, new LedsUpdatingEventArgs(updatingLeds));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Well ... that's not my fault
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the needed event-calls after the leds are updated.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnLedsUpdated(IEnumerable<KeyValuePair<int, CorsairLed>> updatedLeds)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LedsUpdated?.Invoke(this, new LedsUpdatedEventArgs(updatedLeds));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Well ... that's not my fault
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace CUE.NET.Devices.Generic
|
namespace CUE.NET.Devices.Generic.EventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents the information supplied with an Exception-event.
|
/// Represents the information supplied with an Exception-event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ExceptionEventArgs : EventArgs
|
public class ExceptionEventArgs : System.EventArgs
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
@ -1,8 +1,8 @@
|
|||||||
// ReSharper disable UnusedMemberInSuper.Global
|
// ReSharper disable UnusedMemberInSuper.Global
|
||||||
// ReSharper disable UnusedMember.Global
|
// ReSharper disable UnusedMember.Global
|
||||||
|
|
||||||
using CUE.NET.Devices.Generic;
|
|
||||||
using CUE.NET.Devices.Generic.Enums;
|
using CUE.NET.Devices.Generic.Enums;
|
||||||
|
using CUE.NET.Devices.Generic.EventArgs;
|
||||||
|
|
||||||
namespace CUE.NET.Devices
|
namespace CUE.NET.Devices
|
||||||
{
|
{
|
||||||
@ -13,6 +13,34 @@ namespace CUE.NET.Devices
|
|||||||
/// <param name="args">The arguments provided by the event.</param>
|
/// <param name="args">The arguments provided by the event.</param>
|
||||||
public delegate void ExceptionEventHandler(object sender, ExceptionEventArgs args);
|
public delegate void ExceptionEventHandler(object sender, ExceptionEventArgs args);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the event-handler of the Updating-event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">The sender of the event.</param>
|
||||||
|
/// <param name="args">The arguments provided by the event.</param>
|
||||||
|
public delegate void UpdatingEventHandler(object sender, UpdatingEventArgs args);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the event-handler of the Updated-event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">The sender of the event.</param>
|
||||||
|
/// <param name="args">The arguments provided by the event.</param>
|
||||||
|
public delegate void UpdatedEventHandler(object sender, UpdatedEventArgs args);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the event-handler of the LedsUpdating-event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">The sender of the event.</param>
|
||||||
|
/// <param name="args">The arguments provided by the event.</param>
|
||||||
|
public delegate void LedsUpdatingEventHandler(object sender, LedsUpdatingEventArgs args);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the event-handler of the LedsUpdated-event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">The sender of the event.</param>
|
||||||
|
/// <param name="args">The arguments provided by the event.</param>
|
||||||
|
public delegate void LedsUpdatedEventHandler(object sender, LedsUpdatedEventArgs args);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a generic cue device.
|
/// Represents a generic cue device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -33,12 +61,35 @@ namespace CUE.NET.Devices
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
float UpdateFrequency { get; set; }
|
float UpdateFrequency { get; set; }
|
||||||
|
|
||||||
// ReSharper disable once EventNeverSubscribedTo.Global
|
// ReSharper disable EventNeverSubscribedTo.Global
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when a catched exception is thrown inside the device.
|
/// Occurs when a catched exception is thrown inside the device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
event ExceptionEventHandler Exception;
|
event ExceptionEventHandler Exception;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the device starts updating.
|
||||||
|
/// </summary>
|
||||||
|
event UpdatingEventHandler Updating;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the device update is done.
|
||||||
|
/// </summary>
|
||||||
|
event UpdatedEventHandler Updated;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the device starts to update the leds.
|
||||||
|
/// </summary>
|
||||||
|
event LedsUpdatingEventHandler LedsUpdating;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the device updated the leds.
|
||||||
|
/// </summary>
|
||||||
|
event LedsUpdatedEventHandler LedsUpdated;
|
||||||
|
|
||||||
|
// ReSharper restore EventNeverSubscribedTo.Global
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform an update for all dirty keys, or all keys if flushLeds is set to true.
|
/// Perform an update for all dirty keys, or all keys if flushLeds is set to true.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user