mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-11 13:06:24 +00:00
Initial commit (simple but working version)
This commit is contained in:
1 parent
0a8c571244
commit
f07595b50c
30 files changed
+1098
No files matched your search
@@ -0,0 +1,24 @@
|
||||
namespace CUE.NET.Wrapper
|
||||
{
|
||||
public abstract class AbstractCueDevice : ICueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public CorsairDeviceInfo DeviceInfo { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
protected AbstractCueDevice(CorsairDeviceInfo info)
|
||||
{
|
||||
this.DeviceInfo = info;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using CUE.NET.Enums;
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Wrapper
|
||||
{
|
||||
public class CorsairDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Device type.
|
||||
/// </summary>
|
||||
public CorsairDeviceType Type { get; private set; }
|
||||
|
||||
//TODO DarthAffe 17.09.2015: This could be an Enum
|
||||
/// <summary>
|
||||
/// Device model (like “K95RGB”).
|
||||
/// </summary>
|
||||
public string Model { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Physical layout of the keyboard or mouse.
|
||||
/// </summary>
|
||||
public CorsairPhysicalLayout PhysicalLayout { get; private set; }
|
||||
|
||||
//TODO DarthAffe 17.09.2015: Would device-specific infos be useful?
|
||||
/// <summary>
|
||||
/// Logical layout of the keyboard as set in CUE settings.
|
||||
/// </summary>
|
||||
public CorsairLogicalLayout LogicalLayout { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Mask that describes device capabilities, formed as logical "or" of CorsairDeviceCaps enum values
|
||||
/// </summary>
|
||||
public int CapsMask { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public CorsairDeviceInfo(_CorsairDeviceInfo nativeInfo)
|
||||
{
|
||||
this.Type = nativeInfo.type;
|
||||
this.Model = nativeInfo.model == IntPtr.Zero ? null : Marshal.PtrToStringAuto(nativeInfo.model);
|
||||
this.PhysicalLayout = nativeInfo.physicalLayout;
|
||||
this.LogicalLayout = nativeInfo.logicalLayout;
|
||||
this.CapsMask = nativeInfo.capsMask;
|
||||
}
|
||||
|
||||
#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.Wrapper
|
||||
{
|
||||
/// <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 byte 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;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace CUE.NET.Wrapper
|
||||
{
|
||||
//TODO DarthAffe 18.09.2015: Implement
|
||||
public class CueHeadset : AbstractCueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public CueHeadset(CorsairDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using CUE.NET.Enums;
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Wrapper
|
||||
{
|
||||
public class CueKeyboard : AbstractCueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public CueKeyboard(CorsairDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public void SetKeyColor(char key, Color color)
|
||||
{
|
||||
CorsairLedId id = CUESDK.CorsairGetLedIdForKeyName(key);
|
||||
_CorsairLedColor ledColor = new _CorsairLedColor { ledId = id, r = color.R, g = color.G, b = color.B };
|
||||
|
||||
//TODO DarthAffe 18.09.2015: Generalize and move to base class
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(_CorsairLedColor)));
|
||||
Marshal.StructureToPtr(ledColor, ptr, true);
|
||||
CUESDK.CorsairSetLedsColors(1, ptr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace CUE.NET.Wrapper
|
||||
{
|
||||
//TODO DarthAffe 18.09.2015: Implement
|
||||
public class CueMouse : AbstractCueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public CueMouse(CorsairDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using CUE.NET.Enums;
|
||||
using CUE.NET.Exceptions;
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Wrapper
|
||||
{
|
||||
public static class CueSDK
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
|
||||
public static CorsairProtocolDetails ProtocolDetails { get; private set; }
|
||||
public static bool HasExclusiveAccess { get; private set; }
|
||||
public static CorsairError LastError => CUESDK.CorsairGetLastError();
|
||||
|
||||
public static CueKeyboard KeyboardSDK { get; private set; }
|
||||
public static CueMouse MouseSDK { get; private set; }
|
||||
public static CueHeadset HeadsetSDK { get; private set; }
|
||||
|
||||
// ReSharper restore UnusedAutoPropertyAccessor.Global
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public static void Initialize(bool exclusiveAccess = false)
|
||||
{
|
||||
if (ProtocolDetails != null)
|
||||
throw new WrapperException("CueSDK is already initialized.");
|
||||
|
||||
ProtocolDetails = new CorsairProtocolDetails(CUESDK.CorsairPerformProtocolHandshake());
|
||||
|
||||
CorsairError error = LastError;
|
||||
if (error != CorsairError.CE_Success)
|
||||
Throw(error);
|
||||
|
||||
if (exclusiveAccess)
|
||||
{
|
||||
if (!CUESDK.CorsairRequestControl(CorsairAccessMode.CAM_ExclusiveLightingControl))
|
||||
Throw(error);
|
||||
|
||||
HasExclusiveAccess = true;
|
||||
}
|
||||
|
||||
int deviceCount = CUESDK.CorsairGetDeviceCount();
|
||||
for (int i = 0; i < deviceCount; i++)
|
||||
{
|
||||
CorsairDeviceInfo info = new CorsairDeviceInfo((_CorsairDeviceInfo)Marshal.PtrToStructure(CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo)));
|
||||
switch (info.Type)
|
||||
{
|
||||
case CorsairDeviceType.CDT_Keyboard:
|
||||
KeyboardSDK = new CueKeyboard(info);
|
||||
break;
|
||||
case CorsairDeviceType.CDT_Mouse:
|
||||
MouseSDK = new CueMouse(info);
|
||||
break;
|
||||
case CorsairDeviceType.CDT_Headset:
|
||||
HeadsetSDK = new CueHeadset(info);
|
||||
break;
|
||||
|
||||
// ReSharper disable once RedundantCaseLabel
|
||||
case CorsairDeviceType.CDT_Unknown:
|
||||
default:
|
||||
throw new WrapperException("Unknown Device-Type");
|
||||
}
|
||||
|
||||
error = LastError;
|
||||
if (error != CorsairError.CE_Success)
|
||||
Throw(error);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Throw(CorsairError error)
|
||||
{
|
||||
ProtocolDetails = null;
|
||||
HasExclusiveAccess = false;
|
||||
KeyboardSDK = null;
|
||||
MouseSDK = null;
|
||||
HeadsetSDK = null;
|
||||
|
||||
throw new CUEException(error);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace CUE.NET.Wrapper
|
||||
{
|
||||
public interface ICueDevice
|
||||
{
|
||||
CorsairDeviceInfo DeviceInfo { get; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user