mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-11 21:16:24 +00:00
Separated keyboard, mouse and headset
This commit is contained in:
1 parent
a4a81cf3c3
commit
575804c8bf
31 files changed
+528
-405
No files matched your search
@@ -8,13 +8,13 @@ namespace CUE.NET.Wrapper
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public CorsairDeviceInfo DeviceInfo { get; }
|
||||
public IDeviceInfo DeviceInfo { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
protected AbstractCueDevice(CorsairDeviceInfo info)
|
||||
protected AbstractCueDevice(IDeviceInfo info)
|
||||
{
|
||||
this.DeviceInfo = info;
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
// 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 CorsairDeviceCaps CapsMask { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Internal constructor of managed CorsairDeviceInfo.
|
||||
/// </summary>
|
||||
/// <param name="nativeInfo">The native CorsairDeviceInfo-struct</param>
|
||||
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 = (CorsairDeviceCaps)nativeInfo.capsMask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
namespace CUE.NET.Wrapper
|
||||
{
|
||||
//TODO DarthAffe 18.09.2015: Implement
|
||||
public class CueMouse : AbstractCueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal CueMouse(CorsairDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+19
-15
@@ -4,6 +4,9 @@ using System.Runtime.InteropServices;
|
||||
using CUE.NET.Enums;
|
||||
using CUE.NET.Exceptions;
|
||||
using CUE.NET.Native;
|
||||
using CUE.NET.Wrapper.Headset;
|
||||
using CUE.NET.Wrapper.Keyboard;
|
||||
using CUE.NET.Wrapper.Mouse;
|
||||
|
||||
namespace CUE.NET.Wrapper
|
||||
{
|
||||
@@ -17,9 +20,9 @@ namespace CUE.NET.Wrapper
|
||||
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; }
|
||||
public static CorsairKeyboard KeyboardSDK { get; private set; }
|
||||
public static CorsairMouse MouseSDK { get; private set; }
|
||||
public static CorsairHeadset HeadsetSDK { get; private set; }
|
||||
|
||||
// ReSharper restore UnusedAutoPropertyAccessor.Global
|
||||
|
||||
@@ -35,7 +38,7 @@ namespace CUE.NET.Wrapper
|
||||
ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake());
|
||||
|
||||
CorsairError error = LastError;
|
||||
if (error != CorsairError.CE_Success)
|
||||
if (error != CorsairError.Success)
|
||||
Throw(error);
|
||||
|
||||
if (ProtocolDetails.BreakingChanges)
|
||||
@@ -45,7 +48,7 @@ namespace CUE.NET.Wrapper
|
||||
|
||||
if (exclusiveAccess)
|
||||
{
|
||||
if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.CAM_ExclusiveLightingControl))
|
||||
if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
|
||||
Throw(error);
|
||||
|
||||
HasExclusiveAccess = true;
|
||||
@@ -54,30 +57,31 @@ namespace CUE.NET.Wrapper
|
||||
int deviceCount = _CUESDK.CorsairGetDeviceCount();
|
||||
for (int i = 0; i < deviceCount; i++)
|
||||
{
|
||||
CorsairDeviceInfo info = new CorsairDeviceInfo((_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo)));
|
||||
if (!info.CapsMask.HasFlag(CorsairDeviceCaps.CDC_Lighting))
|
||||
_CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo));
|
||||
GenericDeviceInfo info = new GenericDeviceInfo(nativeDeviceInfo);
|
||||
if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting))
|
||||
continue; // Everything that doesn't support lighting control is useless
|
||||
|
||||
switch (info.Type)
|
||||
{
|
||||
case CorsairDeviceType.CDT_Keyboard:
|
||||
KeyboardSDK = new CueKeyboard(info);
|
||||
case CorsairDeviceType.Keyboard:
|
||||
KeyboardSDK = new CorsairKeyboard(new CorsairKeyboardDeviceInfo(nativeDeviceInfo));
|
||||
break;
|
||||
case CorsairDeviceType.CDT_Mouse:
|
||||
MouseSDK = new CueMouse(info);
|
||||
case CorsairDeviceType.Mouse:
|
||||
MouseSDK = new CorsairMouse(new CorsairMouseDeviceInfo(nativeDeviceInfo));
|
||||
break;
|
||||
case CorsairDeviceType.CDT_Headset:
|
||||
HeadsetSDK = new CueHeadset(info);
|
||||
case CorsairDeviceType.Headset:
|
||||
HeadsetSDK = new CorsairHeadset(new CorsairHeadsetDeviceInfo(nativeDeviceInfo));
|
||||
break;
|
||||
|
||||
// ReSharper disable once RedundantCaseLabel
|
||||
case CorsairDeviceType.CDT_Unknown:
|
||||
case CorsairDeviceType.Unknown:
|
||||
default:
|
||||
throw new WrapperException("Unknown Device-Type");
|
||||
}
|
||||
|
||||
error = LastError;
|
||||
if (error != CorsairError.CE_Success)
|
||||
if (error != CorsairError.Success)
|
||||
Throw(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using CUE.NET.Enums;
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Wrapper
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace CUE.NET.Wrapper
|
||||
namespace CUE.NET.Wrapper.Headset
|
||||
{
|
||||
//TODO DarthAffe 18.09.2015: Implement
|
||||
public class CueHeadset : AbstractCueDevice
|
||||
public class CorsairHeadset : AbstractCueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal CueHeadset(CorsairDeviceInfo info)
|
||||
internal CorsairHeadset(CorsairHeadsetDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Wrapper.Headset
|
||||
{
|
||||
public class CorsairHeadsetDeviceInfo : GenericDeviceInfo
|
||||
{
|
||||
public CorsairHeadsetDeviceInfo(_CorsairDeviceInfo nativeInfo)
|
||||
: base(nativeInfo)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,6 @@
|
||||
{
|
||||
public interface ICueDevice
|
||||
{
|
||||
CorsairDeviceInfo DeviceInfo { get; }
|
||||
IDeviceInfo DeviceInfo { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using CUE.NET.Enums;
|
||||
|
||||
namespace CUE.NET.Wrapper
|
||||
{
|
||||
public interface IDeviceInfo
|
||||
{
|
||||
CorsairDeviceType Type { get; }
|
||||
|
||||
//TODO DarthAffe 17.09.2015: This could be an Enum
|
||||
/// <summary>
|
||||
/// Device model (like “K95RGB”).
|
||||
/// </summary>
|
||||
string Model { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Flags that describes device capabilities
|
||||
/// </summary>
|
||||
CorsairDeviceCaps CapsMask { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,23 @@
|
||||
using System.Drawing;
|
||||
using CUE.NET.Enums;
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Wrapper
|
||||
namespace CUE.NET.Wrapper.Keyboard
|
||||
{
|
||||
public class CueKeyboard : AbstractCueDevice
|
||||
public class CorsairKeyboard : AbstractCueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public CorsairKeyboardDeviceInfo KeyboardDeviceInfo { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal CueKeyboard(CorsairDeviceInfo info)
|
||||
internal CorsairKeyboard(CorsairKeyboardDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
{
|
||||
this.KeyboardDeviceInfo = info;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -22,7 +25,7 @@ namespace CUE.NET.Wrapper
|
||||
|
||||
public void SetKeyColor(char key, Color color)
|
||||
{
|
||||
CorsairLedId id = _CUESDK.CorsairGetLedIdForKeyName(key);
|
||||
int id = _CUESDK.CorsairGetLedIdForKeyName(key);
|
||||
_CorsairLedColor ledColor = new _CorsairLedColor { ledId = id, r = color.R, g = color.G, b = color.B };
|
||||
SetKeyColors(ledColor);
|
||||
}
|
||||
@@ -32,7 +35,7 @@ namespace CUE.NET.Wrapper
|
||||
_CorsairLedColor[] ledColors = new _CorsairLedColor[keys.Length];
|
||||
for (int i = 0; i < keys.Length; i++)
|
||||
{
|
||||
CorsairLedId id = _CUESDK.CorsairGetLedIdForKeyName(keys[i]);
|
||||
int id = _CUESDK.CorsairGetLedIdForKeyName(keys[i]);
|
||||
ledColors[i] = new _CorsairLedColor { ledId = id, r = color.R, g = color.G, b = color.B };
|
||||
}
|
||||
SetKeyColors(ledColors);
|
||||
@@ -0,0 +1,40 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
|
||||
using CUE.NET.Enums.Keyboard;
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Wrapper.Keyboard
|
||||
{
|
||||
public class CorsairKeyboardDeviceInfo : GenericDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Physical layout of the keyboard.
|
||||
/// </summary>
|
||||
public CorsairPhysicalKeyboardLayout PhysicalLayout { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Logical layout of the keyboard as set in CUE settings.
|
||||
/// </summary>
|
||||
public CorsairLogicalKeyboardLayout LogicalLayout { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Internal constructor of managed CorsairDeviceInfo.
|
||||
/// </summary>
|
||||
/// <param name="nativeInfo">The native CorsairDeviceInfo-struct</param>
|
||||
internal CorsairKeyboardDeviceInfo(_CorsairDeviceInfo nativeInfo)
|
||||
: base(nativeInfo)
|
||||
{
|
||||
this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout;
|
||||
this.LogicalLayout = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace CUE.NET.Wrapper.Mouse
|
||||
{
|
||||
//TODO DarthAffe 18.09.2015: Implement
|
||||
public class CorsairMouse : AbstractCueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public CorsairMouseDeviceInfo MouseDeviceInfo { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal CorsairMouse(CorsairMouseDeviceInfo info)
|
||||
: base(info)
|
||||
{
|
||||
this.MouseDeviceInfo = info;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
|
||||
using CUE.NET.Enums.Mouse;
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Wrapper.Mouse
|
||||
{
|
||||
public class CorsairMouseDeviceInfo : GenericDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Physical layout of the mouse.
|
||||
/// </summary>
|
||||
public CorsairPhysicalMouseLayout PhysicalLayout { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Internal constructor of managed CorsairDeviceInfo.
|
||||
/// </summary>
|
||||
/// <param name="nativeInfo">The native CorsairDeviceInfo-struct</param>
|
||||
internal CorsairMouseDeviceInfo(_CorsairDeviceInfo nativeInfo)
|
||||
: base(nativeInfo)
|
||||
{
|
||||
this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user