mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-10 20:46:24 +00:00
Reorganized project into a (hopefully) better structure
This commit is contained in:
1 parent
ce4e80c24b
commit
fc66ac0ceb
33 files changed
+111
-99
No files matched your search
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Devices.Generic
|
||||
{
|
||||
public abstract class AbstractCueDevice : ICueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public IDeviceInfo DeviceInfo { get; }
|
||||
|
||||
private Dictionary<int, CorsairLed> Leds { get; } = new Dictionary<int, CorsairLed>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
protected AbstractCueDevice(IDeviceInfo info)
|
||||
{
|
||||
this.DeviceInfo = info;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
protected CorsairLed GetLed(int ledId)
|
||||
{
|
||||
if (!this.Leds.ContainsKey(ledId))
|
||||
this.Leds.Add(ledId, new CorsairLed());
|
||||
|
||||
return this.Leds[ledId];
|
||||
}
|
||||
|
||||
public virtual void UpdateLeds(bool fullUpdate = false)
|
||||
{
|
||||
IList<KeyValuePair<int, CorsairLed>> ledsToUpdate = (fullUpdate ? this.Leds : this.Leds.Where(x => x.Value.IsDirty)).ToList();
|
||||
|
||||
if (!ledsToUpdate.Any())
|
||||
return; // CUE seems to crash if 'CorsairSetLedsColors' is called with a zero length array
|
||||
|
||||
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)
|
||||
{
|
||||
_CorsairLedColor color = new _CorsairLedColor
|
||||
{
|
||||
ledId = led.Key,
|
||||
r = led.Value.Color.R,
|
||||
g = led.Value.Color.G,
|
||||
b = led.Value.Color.B
|
||||
};
|
||||
|
||||
Marshal.StructureToPtr(color, addPtr, false);
|
||||
addPtr = new IntPtr(addPtr.ToInt64() + structSize);
|
||||
}
|
||||
_CUESDK.CorsairSetLedsColors(ledsToUpdate.Count, ptr);
|
||||
Marshal.FreeHGlobal(ptr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace CUE.NET.Devices.Generic
|
||||
{
|
||||
public class CorsairLed
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public bool IsDirty { get; private set; } = false;
|
||||
|
||||
private Color _color = Color.Black;
|
||||
public Color Color
|
||||
{
|
||||
get { return _color; }
|
||||
set
|
||||
{
|
||||
if (_color != value)
|
||||
IsDirty = true;
|
||||
|
||||
_color = value;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO DarthAffe 19.09.2015: Add effects and stuff
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal CorsairLed() { }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Devices.Generic
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed wrapper for CorsairProtocolDetails.
|
||||
/// </summary>
|
||||
public class CorsairProtocolDetails
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// String containing version of SDK(like “1.0.0.1”).
|
||||
/// Always contains valid value even if there was no CUE found.
|
||||
/// </summary>
|
||||
public string SdkVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// String containing version of CUE(like “1.0.0.1”) or NULL if CUE was not found.
|
||||
/// </summary>
|
||||
public string ServerVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Integer that specifies version of protocol that is implemented by current SDK.
|
||||
/// Numbering starts from 1.
|
||||
/// Always contains valid value even if there was no CUE found.
|
||||
/// </summary>
|
||||
public int SdkProtocolVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Integer that specifies version of protocol that is implemented by CUE.
|
||||
/// Numbering starts from 1.
|
||||
/// If CUE was not found then this value will be 0.
|
||||
/// </summary>
|
||||
public int ServerProtocolVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Boolean that specifies if there were breaking changes between version of protocol implemented by server and client.
|
||||
/// </summary>
|
||||
public bool BreakingChanges { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Internal constructor of managed CorsairProtocolDetails.
|
||||
/// </summary>
|
||||
/// <param name="nativeDetails">The native CorsairProtocolDetails-struct</param>
|
||||
internal CorsairProtocolDetails(_CorsairProtocolDetails nativeDetails)
|
||||
{
|
||||
this.SdkVersion = nativeDetails.sdkVersion == IntPtr.Zero ? null : Marshal.PtrToStringAuto(nativeDetails.sdkVersion);
|
||||
this.ServerVersion = nativeDetails.serverVersion == IntPtr.Zero ? null : Marshal.PtrToStringAuto(nativeDetails.serverVersion);
|
||||
this.SdkProtocolVersion = nativeDetails.sdkProtocolVersion;
|
||||
this.ServerProtocolVersion = nativeDetails.serverProtocolVersion;
|
||||
this.BreakingChanges = nativeDetails.breakingChanges != 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
namespace CUE.NET.Devices.Generic.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of available SDK access modes.
|
||||
/// </summary>
|
||||
public enum CorsairAccessMode
|
||||
{
|
||||
ExclusiveLightingControl = 0
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
|
||||
namespace CUE.NET.Devices.Generic.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of device capabilities
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum CorsairDeviceCaps
|
||||
{
|
||||
/// <summary>
|
||||
/// For devices that do not support any SDK functions
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// For devices that has controlled lighting
|
||||
/// </summary>
|
||||
Lighting = 1
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
namespace CUE.NET.Devices.Generic.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of available device types.
|
||||
/// </summary>
|
||||
public enum CorsairDeviceType
|
||||
{
|
||||
Unknown = 0,
|
||||
Mouse = 1,
|
||||
Keyboard = 2,
|
||||
Headset = 3
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
namespace CUE.NET.Devices.Generic.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// Shared list of all errors which could happen during calling of Corsair* functions.
|
||||
/// </summary>
|
||||
public enum CorsairError
|
||||
{
|
||||
/// <summary>
|
||||
/// If previously called function completed successfully.
|
||||
/// </summary>
|
||||
Success,
|
||||
|
||||
/// <summary>
|
||||
/// CUE is not running or was shut down or third-party control is disabled in CUE settings. (runtime error)
|
||||
/// </summary>
|
||||
ServerNotFound,
|
||||
|
||||
/// <summary>
|
||||
/// If some other client has or took over exclusive control. (runtime error)
|
||||
/// </summary>
|
||||
NoControl,
|
||||
|
||||
/// <summary>
|
||||
/// If developer did not perform protocol handshake. (developer error)
|
||||
/// </summary>
|
||||
ProtocolHandshakeMissing,
|
||||
|
||||
/// <summary>
|
||||
/// If developer is calling the function that is not supported by the server (either because protocol has broken by server or client or because the function is new and server is too old.
|
||||
/// Check CorsairProtocolDetails for details). (developer error)
|
||||
/// </summary>
|
||||
IncompatibleProtocol,
|
||||
|
||||
/// <summary>
|
||||
/// If developer supplied invalid arguments to the function (for specifics look at function descriptions). (developer error)
|
||||
/// </summary>
|
||||
InvalidArguments
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Devices.Generic
|
||||
{
|
||||
public class GenericDeviceInfo : IDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Device type.
|
||||
/// </summary>
|
||||
public CorsairDeviceType Type { get; }
|
||||
|
||||
//TODO DarthAffe 17.09.2015: This could be an Enum
|
||||
/// <summary>
|
||||
/// Device model (like “K95RGB”).
|
||||
/// </summary>
|
||||
public string Model { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Flags that describes device capabilities
|
||||
/// </summary>
|
||||
public CorsairDeviceCaps CapsMask { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Internal constructor of managed CorsairDeviceInfo.
|
||||
/// </summary>
|
||||
/// <param name="nativeInfo">The native CorsairDeviceInfo-struct</param>
|
||||
internal GenericDeviceInfo(_CorsairDeviceInfo nativeInfo)
|
||||
{
|
||||
this.Type = nativeInfo.type;
|
||||
this.Model = nativeInfo.model == IntPtr.Zero ? null : Marshal.PtrToStringAuto(nativeInfo.model);
|
||||
this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user