1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-13 00:58:31 +00:00

Compare commits

...

34 Commits

Author SHA1 Message Date
589bd12441
Update README.md 2021-08-05 23:27:28 +02:00
850eb66b3b
Merge pull request #70 from hmmwhatsthisdo/enablekeypresscallback_issue69
Add sanity-check to CueSDK.EnableKeypressHandler()
2018-04-22 16:45:09 +02:00
hmmwhatsthisdo
f3f7f498af Add sanity-check to CueSDK.EnableKeypressHandler() to ensure handlers are only enabled once. Resolves #69. 2018-04-22 06:27:10 -07:00
3b4649604f
Updated readme 2018-01-01 20:02:50 +01:00
83c67195fd Updated version number 2017-11-25 09:14:37 +01:00
811a296867 Added method to opt in to the keypress-callback since this prevents reinitializing 2017-11-25 09:12:57 +01:00
897162926a Updated changenotes and version number 2017-11-18 19:42:55 +01:00
8bcf64a9f9
Merge pull request #65 from DarthAffe/SdkUpdate
Sdk update
2017-11-18 18:27:27 +01:00
5091b33864 Added an event to get the key-change of special keys (G and M) 2017-11-18 12:29:03 +01:00
c4ac6f0e40 Added methods to use the new GetColor method 2017-11-18 11:17:25 +01:00
SpoinkyNL
6840813529 Updated SDK to 2.18.127
Added headset stand support
Added Glaive support
2017-11-13 21:59:33 +01:00
220953bfe7 Fixed an issue that prevents further reinitializing if an exception was thrown earlier 2017-08-13 08:22:18 +02:00
c786710b65 Correctly persisted update-rate in the ambilight example 2017-08-03 18:57:10 +02:00
63ef78f8fc Fixed missing LoadedArchitecture assignment 2017-07-16 12:11:57 +02:00
565e5ca1b2 Updated version number 2017-04-27 20:52:53 +02:00
86c9fb3860 Added an effect-list to the effect-target 2017-04-27 20:50:19 +02:00
33bd76ef0a Added two lists to modify the dative-dll-paths (#58) 2017-04-27 20:43:38 +02:00
5cc1748461 Fixed a bug in the SimpleDevTest and made it a bit more fancy 2017-04-27 20:42:38 +02:00
d17be4a976 Updated Ambilight-example version 2017-04-08 15:19:25 +02:00
0b92068fe6 Fixed DPI-scaling problem in the Ambilight-Example 2017-04-08 15:17:36 +02:00
295a56ca00 Updated CUE.NET package in ambilight example 2017-04-03 17:40:31 +02:00
34394caceb Updated version number 2017-03-18 09:50:51 +01:00
e6719c06a8 Updated SDK to 2.10.91 (this adds lightbar support) 2017-03-17 23:32:30 +01:00
7249da461f Updated version number 2017-02-01 19:47:26 +01:00
8781ce126e Added missing native-reload when calling IsSDKAvailable without initializing 2017-02-01 19:46:54 +01:00
0d5123aca1 Updated changenotes and version number 2017-01-28 14:19:05 +01:00
27562a4787 Added missing null-check while rendering groups 2017-01-28 12:16:46 +01:00
e0790cbc2a Added check for SDK-dll existance 2017-01-15 21:35:47 +01:00
28232a768b Improved performance of the LinearGradient 2017-01-15 14:30:41 +01:00
5e90779398 Fixed wrong region in RainbowGradient 2017-01-15 13:58:02 +01:00
7ef07ed99d Added ConicalGradientBrush 2017-01-15 13:57:44 +01:00
92fcbcff2a Fixed possible cache-issue in the RectangleKeyGroup 2017-01-08 10:51:10 +01:00
8a5581c660 Typo 2017-01-08 10:50:14 +01:00
8404985a55 Adjusted ambilight-example to take profit from the latest version 2017-01-05 20:21:02 +01:00
40 changed files with 876 additions and 82 deletions

View File

@ -0,0 +1,103 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable MemberCanBeProtected.Global
// ReSharper disable ReturnTypeCanBeEnumerable.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
// ReSharper disable UnusedMember.Global
using System;
using System.Drawing;
using CUE.NET.Devices.Generic;
using CUE.NET.Gradients;
namespace CUE.NET.Brushes
{
/// <summary>
/// Represents a brush drawing a conical gradient.
/// </summary>
public class ConicalGradientBrush : AbstractBrush, IGradientBrush
{
#region Properties & Fields
/// <summary>
/// Gets or sets the origin (radian-angle) the brush is drawn to. (default: -π/2)
/// </summary>
public float Origin { get; set; } = (float)Math.Atan2(-1, 0);
/// <summary>
/// Gets or sets the center point (as percentage in the range [0..1]) of the gradient drawn by the brush. (default: 0.5f, 0.5f)
/// </summary>
public PointF Center { get; set; } = new PointF(0.5f, 0.5f);
/// <summary>
/// Gets or sets the gradient drawn by the brush. If null it will default to full transparent.
/// </summary>
public IGradient Gradient { get; set; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="ConicalGradientBrush"/> class.
/// </summary>
public ConicalGradientBrush()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="ConicalGradientBrush"/> class.
/// </summary>
/// <param name="gradient">The gradient drawn by the brush.</param>
public ConicalGradientBrush(IGradient gradient)
{
this.Gradient = gradient;
}
/// <summary>
/// Initializes a new instance of the <see cref="ConicalGradientBrush"/> class.
/// </summary>
/// <param name="center">The center point (as percentage in the range [0..1]).</param>
/// <param name="gradient">The gradient drawn by the brush.</param>
public ConicalGradientBrush(PointF center, IGradient gradient)
{
this.Center = center;
this.Gradient = gradient;
}
/// <summary>
/// Initializes a new instance of the <see cref="ConicalGradientBrush"/> class.
/// </summary>
/// <param name="center">The center point (as percentage in the range [0..1]).</param>
/// <param name="origin">The origin (radian-angle) the brush is drawn to.</param>
/// <param name="gradient">The gradient drawn by the brush.</param>
public ConicalGradientBrush(PointF center, float origin, IGradient gradient)
{
this.Center = center;
this.Origin = origin;
this.Gradient = gradient;
}
#endregion
#region Methods
/// <summary>
/// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
/// </summary>
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
/// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
/// <returns>The color at the specified point.</returns>
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
{
float centerX = rectangle.Width * Center.X;
float centerY = rectangle.Height * Center.Y;
double angle = Math.Atan2(renderTarget.Point.Y - centerY, renderTarget.Point.X - centerX) - Origin;
if (angle < 0) angle += Math.PI * 2;
float offset = (float)(angle / (Math.PI * 2));
return Gradient.GetColor(offset);
}
#endregion
}
}

View File

@ -47,6 +47,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Brushes\ConicalGradientBrush.cs" />
<Compile Include="Brushes\IGradientBrush.cs" /> <Compile Include="Brushes\IGradientBrush.cs" />
<Compile Include="Brushes\ImageBrush.cs" /> <Compile Include="Brushes\ImageBrush.cs" />
<Compile Include="Brushes\ProfileBrush.cs" /> <Compile Include="Brushes\ProfileBrush.cs" />
@ -58,6 +59,7 @@
<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\Enums\CorsairKeyId.cs" />
<Compile Include="Devices\Generic\Enums\CorsairLedId.cs" /> <Compile Include="Devices\Generic\Enums\CorsairLedId.cs" />
<Compile Include="Devices\Generic\EventArgs\ExceptionEventArgs.cs" /> <Compile Include="Devices\Generic\EventArgs\ExceptionEventArgs.cs" />
<Compile Include="Brushes\AbstractBrush.cs" /> <Compile Include="Brushes\AbstractBrush.cs" />
@ -66,7 +68,12 @@
<Compile Include="Devices\Generic\EventArgs\UpdatedEventArgs.cs" /> <Compile Include="Devices\Generic\EventArgs\UpdatedEventArgs.cs" />
<Compile Include="Devices\Generic\EventArgs\UpdatingEventArgs.cs" /> <Compile Include="Devices\Generic\EventArgs\UpdatingEventArgs.cs" />
<Compile Include="Devices\Generic\LedUpateRequest.cs" /> <Compile Include="Devices\Generic\LedUpateRequest.cs" />
<Compile Include="Devices\HeadsetStand\CorsairHeadsetStand.cs" />
<Compile Include="Devices\HeadsetStand\CorsairHeadsetStandDeviceInfo.cs" />
<Compile Include="Devices\HeadsetStand\Enums\CorsairHeadsetStandLedId.cs" />
<Compile Include="Devices\Keyboard\Enums\BrushCalculationMode.cs" /> <Compile Include="Devices\Keyboard\Enums\BrushCalculationMode.cs" />
<Compile Include="Devices\Keyboard\Enums\CorsairKeyboardKeyId.cs" />
<Compile Include="Devices\Mouse\Enums\CorsairMouseKeyId.cs" />
<Compile Include="Effects\AbstractLedGroupEffect.cs" /> <Compile Include="Effects\AbstractLedGroupEffect.cs" />
<Compile Include="Effects\AbstractBrushEffect.cs" /> <Compile Include="Effects\AbstractBrushEffect.cs" />
<Compile Include="Effects\AbstractEffectTarget.cs" /> <Compile Include="Effects\AbstractEffectTarget.cs" />
@ -75,6 +82,7 @@
<Compile Include="Devices\Mousemat\CorsairMousematDeviceInfo.cs" /> <Compile Include="Devices\Mousemat\CorsairMousematDeviceInfo.cs" />
<Compile Include="Devices\Mousemat\Enums\CorsairMousematLedId.cs" /> <Compile Include="Devices\Mousemat\Enums\CorsairMousematLedId.cs" />
<Compile Include="Effects\MoveGradientEffect.cs" /> <Compile Include="Effects\MoveGradientEffect.cs" />
<Compile Include="EventArgs\KeyPressedEventArgs.cs" />
<Compile Include="Gradients\AbstractGradient.cs" /> <Compile Include="Gradients\AbstractGradient.cs" />
<Compile Include="Gradients\GradientStop.cs" /> <Compile Include="Gradients\GradientStop.cs" />
<Compile Include="Gradients\IGradient.cs" /> <Compile Include="Gradients\IGradient.cs" />

View File

@ -3,20 +3,19 @@
<metadata> <metadata>
<id>CUE.NET</id> <id>CUE.NET</id>
<title>CUE.NET</title> <title>CUE.NET</title>
<version>1.1.1.0</version> <version>1.2.0.1</version>
<authors>Darth Affe</authors> <authors>Darth Affe</authors>
<owners>Darth Affe</owners> <owners>Darth Affe</owners>
<projectUrl>https://github.com/DarthAffe/CUE.NET</projectUrl> <projectUrl>https://github.com/DarthAffe/CUE.NET</projectUrl>
<licenseUrl>https://raw.githubusercontent.com/DarthAffe/CUE.NET/master/LICENSE</licenseUrl> <licenseUrl>https://raw.githubusercontent.com/DarthAffe/CUE.NET/master/LICENSE</licenseUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Corsair HID SDK Wrapper</description> <description>Corsair HID SDK Wrapper</description>
<releaseNotes>- Added key-rectangle to BrushRenderTarget <releaseNotes>
- Added color-corrections for brushes (gamma is implemented by default) - Updated SDK to 2.18.127
- Added Gradient-Wrapping - Added methods to use the new GetColor method
- Added an new brush-effect to move gradients - Added an event to get the key-change of special keys (G and M)
- Fixed an reference-problem with colors assigned to more than one key - Fixed missing LoadedArchitecture assignment
- Added the associated device to CorsairLeds - Fixed an issue that prevents further reinitializing if an exception was thrown earlier
- Fixed some minor code issues
</releaseNotes> </releaseNotes>
<summary>C# (.NET) Wrapper library around the Corsair CUE-SDK</summary> <summary>C# (.NET) Wrapper library around the Corsair CUE-SDK</summary>
<copyright>Copyright © Wyrez 2017</copyright> <copyright>Copyright © Wyrez 2017</copyright>

127
CueSDK.cs
View File

@ -1,6 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -8,9 +9,11 @@ using CUE.NET.Devices;
using CUE.NET.Devices.Generic; using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Generic.Enums; using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Devices.Headset; using CUE.NET.Devices.Headset;
using CUE.NET.Devices.HeadsetStand;
using CUE.NET.Devices.Keyboard; using CUE.NET.Devices.Keyboard;
using CUE.NET.Devices.Mouse; using CUE.NET.Devices.Mouse;
using CUE.NET.Devices.Mousemat; using CUE.NET.Devices.Mousemat;
using CUE.NET.EventArgs;
using CUE.NET.Exceptions; using CUE.NET.Exceptions;
using CUE.NET.Native; using CUE.NET.Native;
@ -25,6 +28,18 @@ namespace CUE.NET
// ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable UnusedAutoPropertyAccessor.Global
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX86NativePaths { get; } = new List<string> { "x86/CUESDK_2015.dll", "x86/CUESDK.dll" };
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX64NativePaths { get; } = new List<string> { "x64/CUESDK_2015.dll", "x64/CUESDK.dll" };
/// <summary> /// <summary>
/// Indicates if the SDK is initialized and ready to use. /// Indicates if the SDK is initialized and ready to use.
/// </summary> /// </summary>
@ -74,13 +89,35 @@ namespace CUE.NET
public static CorsairHeadset HeadsetSDK { get; private set; } public static CorsairHeadset HeadsetSDK { get; private set; }
/// <summary> /// <summary>
/// Gets the managed representation of a moustmat managed by the CUE-SDK. /// Gets the managed representation of a mousemat managed by the CUE-SDK.
/// Note that currently only one connected mousemat is supported. /// Note that currently only one connected mousemat is supported.
/// </summary> /// </summary>
public static CorsairMousemat MousematSDK { get; private set; } public static CorsairMousemat MousematSDK { get; private set; }
/// <summary>
/// Gets the managed representation of a headset stand managed by the CUE-SDK.
/// Note that currently only one connected headset stand is supported.
/// </summary>
public static CorsairHeadsetStand HeadsetStandSDK { get; private set; }
// ReSharper restore UnusedAutoPropertyAccessor.Global // ReSharper restore UnusedAutoPropertyAccessor.Global
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void OnKeyPressedDelegate(IntPtr context, CorsairKeyId keyId, [MarshalAs(UnmanagedType.I1)] bool pressed);
private static OnKeyPressedDelegate _onKeyPressedDelegate;
#endregion
#region Events
/// <summary>
/// Occurs when the SDK reports that a key is pressed.
/// Notice that right now only G- (keyboard) and M- (mouse) keys are supported.
///
/// To enable this event <see cref="EnableKeypressCallback"/> needs to be called.
/// </summary>
public static event EventHandler<KeyPressedEventArgs> KeyPressed;
#endregion #endregion
#region Methods #region Methods
@ -88,7 +125,7 @@ namespace CUE.NET
/// <summary> /// <summary>
/// Checks if the SDK for the provided <see cref="CorsairDeviceType"/> is available or checks if CUE is installed and SDK supported enabled if null is provided. /// Checks if the SDK for the provided <see cref="CorsairDeviceType"/> is available or checks if CUE is installed and SDK supported enabled if null is provided.
/// </summary> /// </summary>
/// <param name="sdkType">The <see cref="CorsairDeviceType"/> to check or null to check for generall SDK availability.</param> /// <param name="sdkType">The <see cref="CorsairDeviceType"/> to check or null to check for general SDK availability.</param>
/// <returns>The availability of the provided <see cref="CorsairDeviceType"/>.</returns> /// <returns>The availability of the provided <see cref="CorsairDeviceType"/>.</returns>
public static bool IsSDKAvailable(CorsairDeviceType? sdkType = null) public static bool IsSDKAvailable(CorsairDeviceType? sdkType = null)
{ {
@ -108,12 +145,15 @@ namespace CUE.NET
return HeadsetSDK != null; return HeadsetSDK != null;
case CorsairDeviceType.Mousemat: case CorsairDeviceType.Mousemat:
return MousematSDK != null; return MousematSDK != null;
case CorsairDeviceType.HeadsetStand:
return HeadsetStandSDK != null;
default: default:
return true; return true;
} }
} }
else else
{ {
_CUESDK.Reload();
_CUESDK.CorsairPerformProtocolHandshake(); _CUESDK.CorsairPerformProtocolHandshake();
if (sdkType == null || sdkType == CorsairDeviceType.Unknown) if (sdkType == null || sdkType == CorsairDeviceType.Unknown)
@ -147,11 +187,13 @@ namespace CUE.NET
if (IsInitialized) if (IsInitialized)
throw new WrapperException("CueSDK is already initialized."); throw new WrapperException("CueSDK is already initialized.");
_CUESDK.Reload();
ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake()); ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake());
CorsairError error = LastError; CorsairError error = LastError;
if (error != CorsairError.Success) if (error != CorsairError.Success)
Throw(error); Throw(error, true);
if (ProtocolDetails.BreakingChanges) if (ProtocolDetails.BreakingChanges)
throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n" throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n"
@ -161,7 +203,7 @@ namespace CUE.NET
if (exclusiveAccess) if (exclusiveAccess)
{ {
if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl)) if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
Throw(LastError); Throw(LastError, true);
HasExclusiveAccess = true; HasExclusiveAccess = true;
} }
@ -190,6 +232,9 @@ namespace CUE.NET
case CorsairDeviceType.Mousemat: case CorsairDeviceType.Mousemat:
device = MousematSDK = new CorsairMousemat(new CorsairMousematDeviceInfo(nativeDeviceInfo)); device = MousematSDK = new CorsairMousemat(new CorsairMousematDeviceInfo(nativeDeviceInfo));
break; break;
case CorsairDeviceType.HeadsetStand:
device = HeadsetStandSDK = new CorsairHeadsetStand(new CorsairHeadsetStandDeviceInfo(nativeDeviceInfo));
break;
// ReSharper disable once RedundantCaseLabel // ReSharper disable once RedundantCaseLabel
case CorsairDeviceType.Unknown: case CorsairDeviceType.Unknown:
default: default:
@ -201,14 +246,45 @@ namespace CUE.NET
error = LastError; error = LastError;
if (error != CorsairError.Success) if (error != CorsairError.Success)
Throw(error); Throw(error, true);
} }
error = LastError;
if (error != CorsairError.Success)
Throw(error, false);
InitializedDevices = new ReadOnlyCollection<ICueDevice>(devices); InitializedDevices = new ReadOnlyCollection<ICueDevice>(devices);
IsInitialized = true; IsInitialized = true;
} }
/// <summary>
/// Enables the keypress-callback.
/// This method needs to be called to enable the <see cref="KeyPressed"/>-event.
///
/// WARNING: AFTER THIS METHOD IS CALLED IT'S NO LONGER POSSIBLE TO REINITIALIZE THE SDK!
/// </summary>
public static void EnableKeypressCallback()
{
if (!IsInitialized)
throw new WrapperException("CueSDK isn't initialized.");
if (_onKeyPressedDelegate != null)
return;
_onKeyPressedDelegate = OnKeyPressed;
_CUESDK.CorsairRegisterKeypressCallback(Marshal.GetFunctionPointerForDelegate(_onKeyPressedDelegate), IntPtr.Zero);
}
/// <summary>
/// Resets the colors of all devices back to the last saved color-data. (If there wasn't a manual save, that's the data from the time the SDK was initialized.)
/// </summary>
public static void Reset()
{
foreach (ICueDevice device in InitializedDevices)
device.RestoreColors();
}
/// <summary> /// <summary>
/// Reinitialize the CUE-SDK and temporarily hand back full control to CUE. /// Reinitialize the CUE-SDK and temporarily hand back full control to CUE.
/// </summary> /// </summary>
@ -226,10 +302,14 @@ namespace CUE.NET
if (!IsInitialized) if (!IsInitialized)
throw new WrapperException("CueSDK isn't initialized."); throw new WrapperException("CueSDK isn't initialized.");
if (_onKeyPressedDelegate != null)
throw new WrapperException("Keypress-Callback is enabled.");
KeyboardSDK?.ResetLeds(); KeyboardSDK?.ResetLeds();
MouseSDK?.ResetLeds(); MouseSDK?.ResetLeds();
HeadsetSDK?.ResetLeds(); HeadsetSDK?.ResetLeds();
MousematSDK?.ResetLeds(); MousematSDK?.ResetLeds();
HeadsetStandSDK?.ResetLeds();
_CUESDK.Reload(); _CUESDK.Reload();
@ -237,7 +317,7 @@ namespace CUE.NET
CorsairError error = LastError; CorsairError error = LastError;
if (error != CorsairError.Success) if (error != CorsairError.Success)
Throw(error); Throw(error, false);
if (ProtocolDetails.BreakingChanges) if (ProtocolDetails.BreakingChanges)
throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n" throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n"
@ -246,7 +326,7 @@ namespace CUE.NET
if (exclusiveAccess) if (exclusiveAccess)
if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl)) if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
Throw(LastError); Throw(LastError, false);
HasExclusiveAccess = exclusiveAccess; HasExclusiveAccess = exclusiveAccess;
int deviceCount = _CUESDK.CorsairGetDeviceCount(); int deviceCount = _CUESDK.CorsairGetDeviceCount();
@ -261,7 +341,7 @@ namespace CUE.NET
error = LastError; error = LastError;
if (error != CorsairError.Success) if (error != CorsairError.Success)
Throw(error); Throw(error, false);
} }
if (KeyboardSDK != null) if (KeyboardSDK != null)
@ -280,23 +360,38 @@ namespace CUE.NET
if (!reloadedDevices.ContainsKey(CorsairDeviceType.Mousemat) if (!reloadedDevices.ContainsKey(CorsairDeviceType.Mousemat)
|| MousematSDK.MousematDeviceInfo.Model != reloadedDevices[CorsairDeviceType.Mousemat].Model) || MousematSDK.MousematDeviceInfo.Model != reloadedDevices[CorsairDeviceType.Mousemat].Model)
throw new WrapperException("The previously loaded Mousemat got disconnected."); throw new WrapperException("The previously loaded Mousemat got disconnected.");
if (HeadsetStandSDK != null)
if (!reloadedDevices.ContainsKey(CorsairDeviceType.HeadsetStand)
|| HeadsetStandSDK.HeadsetStandDeviceInfo.Model != reloadedDevices[CorsairDeviceType.HeadsetStand].Model)
throw new WrapperException("The previously loaded Headset Stand got disconnected.");
error = LastError;
if (error != CorsairError.Success)
Throw(error, false);
IsInitialized = true; IsInitialized = true;
} }
private static void Throw(CorsairError error) private static void Throw(CorsairError error, bool reset)
{ {
ProtocolDetails = null; if (reset)
HasExclusiveAccess = false; {
KeyboardSDK = null; ProtocolDetails = null;
MouseSDK = null; HasExclusiveAccess = false;
HeadsetSDK = null; KeyboardSDK = null;
MousematSDK = null; MouseSDK = null;
IsInitialized = false; HeadsetSDK = null;
MousematSDK = null;
HeadsetStandSDK = null;
IsInitialized = false;
}
throw new CUEException(error); throw new CUEException(error);
} }
private static void OnKeyPressed(IntPtr context, CorsairKeyId keyId, bool pressed)
=> KeyPressed?.Invoke(null, new KeyPressedEventArgs(keyId, pressed));
#endregion #endregion
} }
} }

View File

@ -29,6 +29,8 @@ namespace CUE.NET.Devices.Generic
private static DateTime _lastUpdate = DateTime.Now; private static DateTime _lastUpdate = DateTime.Now;
private Dictionary<CorsairLedId, CorsairColor> _colorDataSave;
/// <summary> /// <summary>
/// Gets generic information provided by CUE for the device. /// Gets generic information provided by CUE for the device.
/// </summary> /// </summary>
@ -56,6 +58,7 @@ namespace CUE.NET.Devices.Generic
/// <summary> /// <summary>
/// Gets or sets the background brush of the keyboard. /// Gets or sets the background brush of the keyboard.
/// If this is null the last saved color-data is used as background.
/// </summary> /// </summary>
public IBrush Brush { get; set; } public IBrush Brush { get; set; }
@ -153,6 +156,7 @@ namespace CUE.NET.Devices.Generic
public virtual void Initialize() public virtual void Initialize()
{ {
DeviceRectangle = RectangleHelper.CreateRectangleFromRectangles((this).Select(x => x.LedRectangle)); DeviceRectangle = RectangleHelper.CreateRectangleFromRectangles((this).Select(x => x.LedRectangle));
SaveColors();
} }
/// <summary> /// <summary>
@ -187,19 +191,26 @@ 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 void Update(bool flushLeds = false) /// <param name="noRender">Only updates the hardware-leds skippin effects and the render-pass. Only use this if you know what that means!</param>
public void Update(bool flushLeds = false, bool noRender = false)
{ {
OnUpdating(); OnUpdating();
// Update effects if (!noRender)
foreach (ILedGroup ledGroup in LedGroups) {
ledGroup.UpdateEffects(); // Update effects
foreach (ILedGroup ledGroup in LedGroups)
ledGroup.UpdateEffects();
// Render brushes // Render brushes
Render(this); if (Brush != null)
foreach (ILedGroup ledGroup in LedGroups.OrderBy(x => x.ZIndex)) Render(this);
Render(ledGroup); else
ApplyColorData(_colorDataSave);
foreach (ILedGroup ledGroup in LedGroups.OrderBy(x => x.ZIndex))
Render(ledGroup);
}
// Device-specific updates // Device-specific updates
DeviceUpdate(); DeviceUpdate();
@ -226,8 +237,12 @@ namespace CUE.NET.Devices.Generic
// ReSharper disable once MemberCanBeMadeStatic.Local - idc // ReSharper disable once MemberCanBeMadeStatic.Local - idc
protected virtual void Render(ILedGroup ledGroup) protected virtual void Render(ILedGroup ledGroup)
{ {
if (ledGroup == null) return;
IList<CorsairLed> leds = ledGroup.GetLeds().ToList(); IList<CorsairLed> leds = ledGroup.GetLeds().ToList();
IBrush brush = ledGroup.Brush; IBrush brush = ledGroup.Brush;
if (brush == null) return;
try try
{ {
@ -289,6 +304,63 @@ namespace CUE.NET.Devices.Generic
OnLedsUpdated(updateRequests); OnLedsUpdated(updateRequests);
} }
/// <inheritdoc />
public void SyncColors()
{
Dictionary<CorsairLedId, CorsairColor> colorData = GetColors();
ApplyColorData(colorData);
Update(true, true);
}
/// <inheritdoc />
public void SaveColors()
{
_colorDataSave = GetColors();
}
/// <inheritdoc />
public void RestoreColors()
{
ApplyColorData(_colorDataSave);
Update(true, true);
}
private void ApplyColorData(Dictionary<CorsairLedId, CorsairColor> colorData)
{
if (colorData == null) return;
foreach (KeyValuePair<CorsairLedId, CorsairColor> corsairColor in _colorDataSave)
LedMapping[corsairColor.Key].Color = corsairColor.Value;
}
private Dictionary<CorsairLedId, CorsairColor> GetColors()
{
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
IntPtr ptr = Marshal.AllocHGlobal(structSize * LedMapping.Count);
IntPtr addPtr = new IntPtr(ptr.ToInt64());
foreach (KeyValuePair<CorsairLedId, CorsairLed> led in LedMapping)
{
_CorsairLedColor color = new _CorsairLedColor { ledId = (int)led.Value.Id };
Marshal.StructureToPtr(color, addPtr, false);
addPtr = new IntPtr(addPtr.ToInt64() + structSize);
}
_CUESDK.CorsairGetLedsColors(LedMapping.Count, ptr);
IntPtr readPtr = ptr;
Dictionary<CorsairLedId, CorsairColor> colorData = new Dictionary<CorsairLedId, CorsairColor>();
for (int i = 0; i < LedMapping.Count; i++)
{
_CorsairLedColor ledColor = (_CorsairLedColor)Marshal.PtrToStructure(readPtr, typeof(_CorsairLedColor));
colorData.Add((CorsairLedId)ledColor.ledId, new CorsairColor((byte)ledColor.r, (byte)ledColor.g, (byte)ledColor.b));
readPtr = new IntPtr(readPtr.ToInt64() + structSize);
}
Marshal.FreeHGlobal(ptr);
return colorData;
}
#endregion #endregion
#region LedGroup #region LedGroup
@ -341,6 +413,12 @@ namespace CUE.NET.Devices.Generic
#region Effects #region Effects
/// <summary>
/// Gets a list of all active effects of this target.
/// For this device this is always null.
/// </summary>
public IList<IEffect<ILedGroup>> Effects => null;
/// <summary> /// <summary>
/// NOT IMPLEMENTED: Effects can't be applied directly to the device. Add it to the Brush or create a ledgroup instead. /// NOT IMPLEMENTED: Effects can't be applied directly to the device. Add it to the Brush or create a ledgroup instead.
/// </summary> /// </summary>

View File

@ -15,6 +15,7 @@ namespace CUE.NET.Devices.Generic.Enums
Mouse = 1, Mouse = 1,
Keyboard = 2, Keyboard = 2,
Headset = 3, Headset = 3,
Mousemat = 4 Mousemat = 4,
HeadsetStand = 5
}; };
} }

View File

@ -0,0 +1,46 @@
// ReSharper disable InconsistentNaming
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
namespace CUE.NET.Devices.Generic.Enums
{
/// <summary>
/// Contains list of all KeyIds available for all corsair devices.
/// </summary>
public enum CorsairKeyId
{
Invalid = 0,
G1 = 1,
G2 = 2,
G3 = 3,
G4 = 4,
G5 = 5,
G6 = 6,
G7 = 7,
G8 = 8,
G9 = 9,
G10 = 10,
G11 = 11,
G12 = 12,
G13 = 13,
G14 = 14,
G15 = 15,
G16 = 16,
G17 = 17,
G18 = 18,
M1 = 19,
M2 = 20,
M3 = 21,
M4 = 22,
M5 = 23,
M6 = 24,
M7 = 25,
M8 = 26,
M9 = 27,
M10 = 28,
M11 = 29,
M12 = 30,
}
}

View File

@ -162,6 +162,8 @@ namespace CUE.NET.Devices.Generic.Enums
B2 = 149, B2 = 149,
B3 = 150, B3 = 150,
B4 = 151, B4 = 151,
B5 = 189,
B6 = 190,
LeftLogo = 152, LeftLogo = 152,
RightLogo = 153, RightLogo = 153,
@ -182,6 +184,36 @@ namespace CUE.NET.Devices.Generic.Enums
Zone12 = 166, Zone12 = 166,
Zone13 = 167, Zone13 = 167,
Zone14 = 168, Zone14 = 168,
Zone15 = 169 Zone15 = 169,
Lightbar1 = 170,
Lightbar2 = 171,
Lightbar3 = 172,
Lightbar4 = 173,
Lightbar5 = 174,
Lightbar6 = 175,
Lightbar7 = 176,
Lightbar8 = 177,
Lightbar9 = 178,
Lightbar10 = 179,
Lightbar11 = 180,
Lightbar12 = 181,
Lightbar13 = 182,
Lightbar14 = 183,
Lightbar15 = 184,
Lightbar16 = 185,
Lightbar17 = 186,
Lightbar18 = 187,
Lightbar19 = 188,
HeadsetStandZone1 = 191,
HeadsetStandZone2 = 192,
HeadsetStandZone3 = 193,
HeadsetStandZone4 = 194,
HeadsetStandZone5 = 195,
HeadsetStandZone6 = 196,
HeadsetStandZone7 = 197,
HeadsetStandZone8 = 198,
HeadsetStandZone9 = 199,
} }
} }

View File

@ -0,0 +1,91 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Exceptions;
using CUE.NET.Native;
namespace CUE.NET.Devices.HeadsetStand
{
/// <summary>
/// Represents the SDK for a corsair headset stand.
/// </summary>
public class CorsairHeadsetStand : AbstractCueDevice
{
#region Properties & Fields
/// <summary>
/// Gets specific information provided by CUE for the headset stand.
/// </summary>
public CorsairHeadsetStandDeviceInfo HeadsetStandDeviceInfo { get; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="CorsairHeadsetStand"/> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the headset stand</param>
internal CorsairHeadsetStand(CorsairHeadsetStandDeviceInfo info)
: base(info)
{
this.HeadsetStandDeviceInfo = info;
}
#endregion
#region Methods
/// <summary>
/// Initializes the headset stand.
/// </summary>
public override void Initialize()
{
int deviceCount = _CUESDK.CorsairGetDeviceCount();
// Get headset stand device index
int headsetStandIndex = -1;
for (int i = 0; i < deviceCount; i++)
{
_CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo));
GenericDeviceInfo info = new GenericDeviceInfo(nativeDeviceInfo);
if (info.Type != CorsairDeviceType.HeadsetStand)
continue;
headsetStandIndex = i;
break;
}
if (headsetStandIndex < 0)
throw new WrapperException("Can't determine headset stand device index");
_CorsairLedPositions nativeLedPositions = (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(headsetStandIndex), typeof(_CorsairLedPositions));
int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
IntPtr ptr = nativeLedPositions.pLedPosition;
// Put the positions in an array for sorting later on
List<_CorsairLedPosition> positions = new List<_CorsairLedPosition>();
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
{
_CorsairLedPosition ledPosition = (_CorsairLedPosition)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
ptr = new IntPtr(ptr.ToInt64() + structSize);
positions.Add(ledPosition);
}
// Sort for easy iteration by clients
foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.ledId))
InitializeLed(ledPosition.ledId, new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height));
base.Initialize();
}
#endregion
}
}

View File

@ -0,0 +1,26 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using CUE.NET.Devices.Generic;
using CUE.NET.Native;
namespace CUE.NET.Devices.HeadsetStand
{
/// <summary>
/// Represents specific information for a CUE headset stand.
/// </summary>
public class CorsairHeadsetStandDeviceInfo : GenericDeviceInfo
{
#region Constructors
/// <summary>
/// Internal constructor of managed <see cref="CorsairHeadsetStandDeviceInfo" />.
/// </summary>
/// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
internal CorsairHeadsetStandDeviceInfo(_CorsairDeviceInfo nativeInfo)
: base(nativeInfo)
{ }
#endregion
}
}

View File

@ -0,0 +1,26 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable InconsistentNaming
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
using CUE.NET.Devices.Generic.Enums;
namespace CUE.NET.Devices.HeadsetStand.Enums
{
/// <summary>
/// Contains list of all LEDs available for corsair headset stands.
/// </summary>
public static class CorsairHeadsetStandLedId
{
public const CorsairLedId Invalid = CorsairLedId.Invalid;
public const CorsairLedId HeadsetStandZone1 = CorsairLedId.HeadsetStandZone1;
public const CorsairLedId HeadsetStandZone2 = CorsairLedId.HeadsetStandZone2;
public const CorsairLedId HeadsetStandZone3 = CorsairLedId.HeadsetStandZone3;
public const CorsairLedId HeadsetStandZone4 = CorsairLedId.HeadsetStandZone4;
public const CorsairLedId HeadsetStandZone5 = CorsairLedId.HeadsetStandZone5;
public const CorsairLedId HeadsetStandZone6 = CorsairLedId.HeadsetStandZone6;
public const CorsairLedId HeadsetStandZone7 = CorsairLedId.HeadsetStandZone7;
public const CorsairLedId HeadsetStandZone8 = CorsairLedId.HeadsetStandZone8;
public const CorsairLedId HeadsetStandZone9 = CorsairLedId.HeadsetStandZone9;
}
}

View File

@ -140,10 +140,26 @@ namespace CUE.NET.Devices
void Initialize(); void Initialize();
/// <summary> /// <summary>
/// Perform 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>
void Update(bool flushLeds = false); /// <param name="noRender">Only updates the hardware-leds skippin effects and the render-pass. Only use this if you know what that means!</param>
void Update(bool flushLeds = false, bool noRender = false);
/// <summary>
/// Reads the currently active colors from the device and sync them with the internal state.
/// </summary>
void SyncColors();
/// <summary>
/// Saves the currently active colors from the device.
/// </summary>
void SaveColors();
/// <summary>
/// Restores the last saved colors.
/// </summary>
void RestoreColors();
/// <summary> /// <summary>
/// Attaches the given ledgroup. /// Attaches the given ledgroup.

View File

@ -0,0 +1,36 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable InconsistentNaming
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
using CUE.NET.Devices.Generic.Enums;
namespace CUE.NET.Devices.Keyboard.Enums
{
/// <summary>
/// Contains list of all LEDs available for corsair keyboards.
/// </summary>
public static class CorsairKeyboardKeyId
{
public const CorsairKeyId Invalid = CorsairKeyId.Invalid;
public const CorsairKeyId G1 = CorsairKeyId.G1;
public const CorsairKeyId G2 = CorsairKeyId.G2;
public const CorsairKeyId G3 = CorsairKeyId.G3;
public const CorsairKeyId G4 = CorsairKeyId.G4;
public const CorsairKeyId G5 = CorsairKeyId.G5;
public const CorsairKeyId G6 = CorsairKeyId.G6;
public const CorsairKeyId G7 = CorsairKeyId.G7;
public const CorsairKeyId G8 = CorsairKeyId.G8;
public const CorsairKeyId G9 = CorsairKeyId.G9;
public const CorsairKeyId G10 = CorsairKeyId.G10;
public const CorsairKeyId G11 = CorsairKeyId.G11;
public const CorsairKeyId G12 = CorsairKeyId.G12;
public const CorsairKeyId G13 = CorsairKeyId.G13;
public const CorsairKeyId G14 = CorsairKeyId.G14;
public const CorsairKeyId G15 = CorsairKeyId.G15;
public const CorsairKeyId G16 = CorsairKeyId.G16;
public const CorsairKeyId G17 = CorsairKeyId.G17;
public const CorsairKeyId G18 = CorsairKeyId.G18;
}
}

View File

@ -161,5 +161,24 @@ namespace CUE.NET.Devices.Keyboard.Enums
public const CorsairLedId International4 = CorsairLedId.International4; public const CorsairLedId International4 = CorsairLedId.International4;
public const CorsairLedId Fn = CorsairLedId.Fn; public const CorsairLedId Fn = CorsairLedId.Fn;
public const CorsairLedId Logo = CorsairLedId.Logo; public const CorsairLedId Logo = CorsairLedId.Logo;
public const CorsairLedId Lightbar1 = CorsairLedId.Lightbar1;
public const CorsairLedId Lightbar2 = CorsairLedId.Lightbar2;
public const CorsairLedId Lightbar3 = CorsairLedId.Lightbar3;
public const CorsairLedId Lightbar4 = CorsairLedId.Lightbar4;
public const CorsairLedId Lightbar5 = CorsairLedId.Lightbar5;
public const CorsairLedId Lightbar6 = CorsairLedId.Lightbar6;
public const CorsairLedId Lightbar7 = CorsairLedId.Lightbar7;
public const CorsairLedId Lightbar8 = CorsairLedId.Lightbar8;
public const CorsairLedId Lightbar9 = CorsairLedId.Lightbar9;
public const CorsairLedId Lightbar10 = CorsairLedId.Lightbar10;
public const CorsairLedId Lightbar11 = CorsairLedId.Lightbar11;
public const CorsairLedId Lightbar12 = CorsairLedId.Lightbar12;
public const CorsairLedId Lightbar13 = CorsairLedId.Lightbar13;
public const CorsairLedId Lightbar14 = CorsairLedId.Lightbar14;
public const CorsairLedId Lightbar15 = CorsairLedId.Lightbar15;
public const CorsairLedId Lightbar16 = CorsairLedId.Lightbar16;
public const CorsairLedId Lightbar17 = CorsairLedId.Lightbar17;
public const CorsairLedId Lightbar18 = CorsairLedId.Lightbar18;
public const CorsairLedId Lightbar19 = CorsairLedId.Lightbar19;
} }
} }

View File

@ -2,10 +2,16 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using CUE.NET.Devices.Generic; using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Devices.Mouse.Enums; using CUE.NET.Devices.Mouse.Enums;
using CUE.NET.Exceptions; using CUE.NET.Exceptions;
using CUE.NET.Native;
namespace CUE.NET.Devices.Mouse namespace CUE.NET.Devices.Mouse
{ {
@ -44,6 +50,14 @@ namespace CUE.NET.Devices.Mouse
/// </summary> /// </summary>
public override void Initialize() public override void Initialize()
{ {
// Glaive is a special flake that doesn't follow the default layout
if (MouseDeviceInfo.Model == "GLAIVE RGB")
{
InitializeLed(CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1)); // Logo
InitializeLed(CorsairMouseLedId.B2, new RectangleF(2, 0, 1, 1)); // Front
InitializeLed(CorsairMouseLedId.B5, new RectangleF(3, 0, 1, 1)); // Sides
return;
}
switch (MouseDeviceInfo.PhysicalLayout) switch (MouseDeviceInfo.PhysicalLayout)
{ {
case CorsairPhysicalMouseLayout.Zones1: case CorsairPhysicalMouseLayout.Zones1:

View File

@ -0,0 +1,30 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable InconsistentNaming
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
using CUE.NET.Devices.Generic.Enums;
namespace CUE.NET.Devices.Mouse.Enums
{
/// <summary>
/// Contains list of all LEDs available for corsair mice.
/// </summary>
public static class CorsairMouseKeyId
{
public const CorsairKeyId Invalid = CorsairKeyId.Invalid;
public const CorsairKeyId M1 = CorsairKeyId.M1;
public const CorsairKeyId M2 = CorsairKeyId.M2;
public const CorsairKeyId M3 = CorsairKeyId.M3;
public const CorsairKeyId M4 = CorsairKeyId.M4;
public const CorsairKeyId M5 = CorsairKeyId.M5;
public const CorsairKeyId M6 = CorsairKeyId.M6;
public const CorsairKeyId M7 = CorsairKeyId.M7;
public const CorsairKeyId M8 = CorsairKeyId.M8;
public const CorsairKeyId M9 = CorsairKeyId.M9;
public const CorsairKeyId M10 = CorsairKeyId.M10;
public const CorsairKeyId M11 = CorsairKeyId.M11;
public const CorsairKeyId M12 = CorsairKeyId.M12;
}
}

View File

@ -17,5 +17,7 @@ namespace CUE.NET.Devices.Mouse.Enums
public const CorsairLedId B2 = CorsairLedId.B2; public const CorsairLedId B2 = CorsairLedId.B2;
public const CorsairLedId B3 = CorsairLedId.B3; public const CorsairLedId B3 = CorsairLedId.B3;
public const CorsairLedId B4 = CorsairLedId.B4; public const CorsairLedId B4 = CorsairLedId.B4;
public const CorsairLedId B5 = CorsairLedId.B5;
public const CorsairLedId B6 = CorsairLedId.B6;
} }
} }

View File

@ -24,7 +24,7 @@ namespace CUE.NET.Effects
/// <summary> /// <summary>
/// Gets all <see cref="IEffect{T}" /> attached to this target. /// Gets all <see cref="IEffect{T}" /> attached to this target.
/// </summary> /// </summary>
protected IList<IEffect<T>> Effects => EffectTimes.Select(x => x.Effect).Cast<IEffect<T>>().ToList(); public IList<IEffect<T>> Effects => EffectTimes.Select(x => x.Effect).Cast<IEffect<T>>().ToList();
/// <summary> /// <summary>
/// Gets the strongly-typed target used for the effect. /// Gets the strongly-typed target used for the effect.

View File

@ -1,14 +1,25 @@
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System.Collections.Generic;
namespace CUE.NET.Effects namespace CUE.NET.Effects
{ {
/// <summary> /// <summary>
/// Represents a basic effect-target. /// Represents a basic effect-target.
/// </summary> /// </summary>
/// <typeparam name="T">The type this target represents.</typeparam> /// <typeparam name="T">The type this target represents.</typeparam>
public interface IEffectTarget<out T> public interface IEffectTarget<T>
where T : IEffectTarget<T> where T : IEffectTarget<T>
{ {
#region Properties & Fields
/// <summary>
/// Gets a list of all active effects of this target.
/// </summary>
IList<IEffect<T>> Effects { get; }
#endregion
#region Methods #region Methods
/// <summary> /// <summary>

View File

@ -0,0 +1,41 @@
// ReSharper disable MemberCanBePrivate.Global
using CUE.NET.Devices.Generic.Enums;
namespace CUE.NET.EventArgs
{
/// <summary>
/// Represents the data provided by the <see cref="CueSDK.KeyPressed"/>-event.
/// </summary>
public class KeyPressedEventArgs : System.EventArgs
{
#region Properties & Fields
/// <summary>
/// Gets the id of the key.
/// </summary>
public CorsairKeyId KeyId { get; }
/// <summary>
/// Gets the current status of the key (true = pressed, flase = released).
/// </summary>
public bool IsPressed { get; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="KeyPressedEventArgs"/> class.
/// </summary>
/// <param name="keyId">The id of the key.</param>
/// <param name="isPressed">The current status of the key (true = pressed, flase = released).</param>
public KeyPressedEventArgs(CorsairKeyId keyId, bool isPressed)
{
this.KeyId = keyId;
this.IsPressed = isPressed;
}
#endregion
}
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using CUE.NET.Brushes; using CUE.NET.Brushes;
using CUE.NET.ColorCorrection;
using CUE.NET.Devices.Generic; using CUE.NET.Devices.Generic;
using CUE.NET.Helper; using CUE.NET.Helper;
using Example_Ambilight_full.TakeAsIs; using Example_Ambilight_full.TakeAsIs;
@ -84,9 +85,8 @@ namespace Example_Ambilight_full
protected override CorsairColor FinalizeColor(CorsairColor color) protected override CorsairColor FinalizeColor(CorsairColor color)
{ {
//TODO DarthAffe 05.01.2017: Adopt example once the new version is released! // Apply our gamma-correction
//if (Math.Abs(Settings.Gamma - 1f) > float.Epsilon) ((GammaCorrection)Settings.Gamma).ApplyTo(color);
// ColorHelper.CorrectGamma(color, Settings.Gamma);
float lightness = (float)Math.Max((Settings.MinLightness / 100.0), (color.GetHSVValue() * ((double)Brightness < 0.0 ? 0.0f : ((double)Brightness > 1.0 ? 1f : Brightness)))); float lightness = (float)Math.Max((Settings.MinLightness / 100.0), (color.GetHSVValue() * ((double)Brightness < 0.0 ? 0.0f : ((double)Brightness > 1.0 ? 1f : Brightness))));
byte alpha = (byte)((double)color.A * ((double)Opacity < 0.0 ? 0.0 : ((double)Opacity > 1.0 ? 1.0 : (double)Opacity))); byte alpha = (byte)((double)color.A * ((double)Opacity < 0.0 ? 0.0 : ((double)Opacity > 1.0 ? 1.0 : (double)Opacity)));

View File

@ -1,5 +1,4 @@
using System; using System.Drawing;
using System.Drawing;
using CUE.NET; using CUE.NET;
using CUE.NET.Brushes; using CUE.NET.Brushes;
using CUE.NET.Devices.Generic.Enums; using CUE.NET.Devices.Generic.Enums;
@ -36,7 +35,7 @@ namespace Example_Ambilight_full
{ {
CueSDK.Initialize(); CueSDK.Initialize();
CueSDK.UpdateMode = UpdateMode.Continuous; CueSDK.UpdateMode = UpdateMode.Continuous;
CueSDK.UpdateFrequency = 1 / 20f; CueSDK.UpdateFrequency = 1f / _settings.UpdateRate;
SetAmbilightBrush(); SetAmbilightBrush();
_settings.AmbienceCreatorTypeChanged += (sender, args) => SetAmbilightBrush(); _settings.AmbienceCreatorTypeChanged += (sender, args) => SetAmbilightBrush();

View File

@ -22,8 +22,7 @@ namespace Example_Ambilight_full
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget) protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
{ {
//TODO DarthAffe 05.11.2016: The Key-Rectangle is missing in the render-target, I'll fix that with a future version of CUE.NET. Until then we consider the size of each key to be 10x10mm. float keyWidth = renderTarget.Rectangle.Width;
float keyWidth = 10;
int widthPixels = Math.Max(1, (int)(KeyWidthProportion * keyWidth)); int widthPixels = Math.Max(1, (int)(KeyWidthProportion * keyWidth));

View File

@ -22,9 +22,8 @@ namespace Example_Ambilight_full
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget) protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
{ {
//TODO DarthAffe 05.11.2016: The Key-Rectangle is missing in the render-target, I'll fix that with a future version of CUE.NET. Until then we consider the size of each key to be 10x10mm. float keyWidth = renderTarget.Rectangle.Width;
float keyWidth = 10; float keyHeight = renderTarget.Rectangle.Height;
float keyHeight = 10;
int widthPixels = Math.Max(1, (int)(KeyWidthProportion * keyWidth)); int widthPixels = Math.Max(1, (int)(KeyWidthProportion * keyWidth));
int heightPixels = Math.Max(1, (int)(KeyHeightProportion * keyHeight)); int heightPixels = Math.Max(1, (int)(KeyHeightProportion * keyHeight));

View File

@ -41,8 +41,8 @@
<ApplicationIcon>Resources\ambilight.ico</ApplicationIcon> <ApplicationIcon>Resources\ambilight.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="CUE.NET, Version=1.1.0.2, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="CUE.NET, Version=1.1.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\CUE.NET.1.1.0.2\lib\net45\CUE.NET.dll</HintPath> <HintPath>..\..\..\packages\CUE.NET.1.1.3.0\lib\net45\CUE.NET.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
@ -152,12 +152,12 @@
<Resource Include="Resources\ambilight.ico" /> <Resource Include="Resources\ambilight.ico" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\packages\CUE.NET.1.1.0.2\build\net45\CUE.NET.targets" Condition="Exists('..\..\..\packages\CUE.NET.1.1.0.2\build\net45\CUE.NET.targets')" /> <Import Project="..\..\..\packages\CUE.NET.1.1.3.0\build\net45\CUE.NET.targets" Condition="Exists('..\..\..\packages\CUE.NET.1.1.3.0\build\net45\CUE.NET.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\CUE.NET.1.1.0.2\build\net45\CUE.NET.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\CUE.NET.1.1.0.2\build\net45\CUE.NET.targets'))" /> <Error Condition="!Exists('..\..\..\packages\CUE.NET.1.1.3.0\build\net45\CUE.NET.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\CUE.NET.1.1.3.0\build\net45\CUE.NET.targets'))" />
</Target> </Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -49,5 +49,5 @@ using System.Windows;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.1")] [assembly: AssemblyVersion("1.0.1.3")]
[assembly: AssemblyFileVersion("1.0.1.1")] [assembly: AssemblyFileVersion("1.0.1.3")]

View File

@ -23,6 +23,7 @@ namespace Example_Ambilight_full.TakeAsIs
} }
} }
public int UpdateRate { get; set; } = 20;
public int OffsetLeft { get; set; } = 0; public int OffsetLeft { get; set; } = 0;
public int OffsetRight { get; set; } = 0; public int OffsetRight { get; set; } = 0;
public int OffsetTop { get; set; } = 0; public int OffsetTop { get; set; } = 0;

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Media; using System.Windows.Media;
using Microsoft.Win32;
using SharpDX; using SharpDX;
using SharpDX.Direct3D9; using SharpDX.Direct3D9;
@ -27,6 +28,14 @@ namespace Example_Ambilight_full.TakeAsIs.ScreenCapturing
Width = (int)System.Windows.SystemParameters.PrimaryScreenWidth; Width = (int)System.Windows.SystemParameters.PrimaryScreenWidth;
Height = (int)System.Windows.SystemParameters.PrimaryScreenHeight; Height = (int)System.Windows.SystemParameters.PrimaryScreenHeight;
//DarthAffe 08.04.2017: Fix for system using windows-scaling. The primary screen size is reported 'wrong'.
double scaling = GetScaling();
if (Math.Abs(scaling - 1.0) > 0.01)
{
Width = (int)(Width / scaling);
Height = (int)(Height / scaling);
}
PresentParameters presentParams = new PresentParameters(Width, Height) PresentParameters presentParams = new PresentParameters(Width, Height)
{ {
Windowed = true, Windowed = true,
@ -42,6 +51,19 @@ namespace Example_Ambilight_full.TakeAsIs.ScreenCapturing
#region Methods #region Methods
private double GetScaling()
{
try
{
int currentDpi = (int)Registry.GetValue("HKEY_CURRENT_USER\\Control Panel\\Desktop", "LogPixels", 96);
return 96.0 / currentDpi;
}
catch
{
return 1.0;
}
}
public byte[] CaptureScreen() public byte[] CaptureScreen()
{ {
_device.GetFrontBufferData(0, _surface); _device.GetFrontBufferData(0, _surface);

View File

@ -12,8 +12,12 @@ namespace Example_Ambilight_full.TakeAsIs.UI
public int UpdateRate public int UpdateRate
{ {
get { return (int)Math.Round(1f / CueSDK.UpdateFrequency); } get => (int)Math.Round(1f / CueSDK.UpdateFrequency);
set { CueSDK.UpdateFrequency = 1f / value; } set
{
Settings.UpdateRate = value;
CueSDK.UpdateFrequency = 1f / value;
}
} }
#endregion #endregion

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="CUE.NET" version="1.1.0.2" targetFramework="net45" /> <package id="CUE.NET" version="1.1.3.0" targetFramework="net45" />
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net45" /> <package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net45" />
<package id="MahApps.Metro" version="1.4.0-ALPHA026" targetFramework="net45" /> <package id="MahApps.Metro" version="1.4.0-ALPHA026" targetFramework="net45" />
<package id="SharpDX" version="3.1.1" targetFramework="net45" /> <package id="SharpDX" version="3.1.1" targetFramework="net45" />

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using CUE.NET; using CUE.NET;
using CUE.NET.Brushes; using CUE.NET.Brushes;
using CUE.NET.Devices; using CUE.NET.Devices;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Generic.Enums; using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Effects; using CUE.NET.Effects;
using CUE.NET.Exceptions; using CUE.NET.Exceptions;
@ -32,16 +33,62 @@ namespace SimpleDevTest
try try
{ {
bool test = CueSDK.IsSDKAvailable();
// Initialize CUE-SDK // Initialize CUE-SDK
CueSDK.Initialize(); CueSDK.Initialize();
Console.WriteLine("Initialized with " + CueSDK.LoadedArchitecture + "-SDK"); Console.WriteLine("Initialized with " + CueSDK.LoadedArchitecture + "-SDK");
CueSDK.EnableKeypressCallback();
CueSDK.KeyPressed += (sender, eventArgs) => Console.WriteLine($"Key {eventArgs.KeyId} {(eventArgs.IsPressed ? "pressed" : "released")}");
//CueSDK.KeyboardSDK.Brush = (SolidColorBrush)Color.Black;
//CueSDK.KeyboardSDK[CorsairLedId.Z].Color = Color.Red;
//CueSDK.KeyboardSDK[CorsairLedId.Z].IsLocked = true;
float thirdKeyboardWidth = CueSDK.KeyboardSDK.DeviceRectangle.Width / 3f;
ILedGroup left = new RectangleLedGroup(CueSDK.KeyboardSDK, new RectangleF(CueSDK.KeyboardSDK.DeviceRectangle.X, CueSDK.KeyboardSDK.DeviceRectangle.Y, thirdKeyboardWidth, CueSDK.KeyboardSDK.DeviceRectangle.Height));
ILedGroup mid = new RectangleLedGroup(CueSDK.KeyboardSDK, new RectangleF(CueSDK.KeyboardSDK.DeviceRectangle.X + thirdKeyboardWidth, CueSDK.KeyboardSDK.DeviceRectangle.Y, thirdKeyboardWidth, CueSDK.KeyboardSDK.DeviceRectangle.Height));
ILedGroup right = new RectangleLedGroup(CueSDK.KeyboardSDK, new RectangleF(CueSDK.KeyboardSDK.DeviceRectangle.X + thirdKeyboardWidth * 2, CueSDK.KeyboardSDK.DeviceRectangle.Y, thirdKeyboardWidth, CueSDK.KeyboardSDK.DeviceRectangle.Height));
//CueSDK.KeyboardSDK.Brush = new LinearGradientBrush(new LinearGradient(true, new GradientStop(0, Color.Blue), new GradientStop(0.5f, Color.Red))); //CueSDK.KeyboardSDK.Brush = new LinearGradientBrush(new LinearGradient(true, new GradientStop(0, Color.Blue), new GradientStop(0.5f, Color.Red)));
CueSDK.KeyboardSDK.Brush = new LinearGradientBrush(new RainbowGradient()); left.Brush = new ConicalGradientBrush(new PointF(0.6f, 0.7f), new RainbowGradient(360, 0));
CueSDK.KeyboardSDK.Brush.AddEffect(new MoveGradientEffect()); left.Brush.AddEffect(new MoveGradientEffect());
left.Brush.AddEffect(new FlashEffect { Attack = 2, Sustain = 1f, Release = 2, Interval = 1f });
mid.Brush = new ConicalGradientBrush(new PointF(0.5f, 0.3f), new RainbowGradient());
mid.Brush.AddEffect(new MoveGradientEffect());
mid.Brush.AddEffect(new FlashEffect { Attack = 2, Sustain = 1f, Release = 2, Interval = 1f });
right.Brush = new ConicalGradientBrush(new PointF(0.4f, 0.7f), new RainbowGradient(360, 0));
right.Brush.AddEffect(new MoveGradientEffect());
right.Brush.AddEffect(new FlashEffect { Attack = 2, Sustain = 1f, Release = 2, Interval = 1f });
//float halfKeyboardWidth = CueSDK.KeyboardSDK.DeviceRectangle.Width / 2f;
//ILedGroup left = new RectangleLedGroup(CueSDK.KeyboardSDK, new RectangleF(CueSDK.KeyboardSDK.DeviceRectangle.X, CueSDK.KeyboardSDK.DeviceRectangle.Y, halfKeyboardWidth, CueSDK.KeyboardSDK.DeviceRectangle.Height));
//ILedGroup right = new RectangleLedGroup(CueSDK.KeyboardSDK, new RectangleF(CueSDK.KeyboardSDK.DeviceRectangle.X + halfKeyboardWidth, CueSDK.KeyboardSDK.DeviceRectangle.Y, halfKeyboardWidth, CueSDK.KeyboardSDK.DeviceRectangle.Height));
////CueSDK.KeyboardSDK.Brush = new LinearGradientBrush(new LinearGradient(true, new GradientStop(0, Color.Blue), new GradientStop(0.5f, Color.Red)));
//left.Brush = new ConicalGradientBrush(new PointF(0.6f, 0.6f), new RainbowGradient(360, 0));
//left.Brush.AddEffect(new MoveGradientEffect());
//right.Brush = new ConicalGradientBrush(new PointF(0.4f, 0.6f), new RainbowGradient());
//right.Brush.AddEffect(new MoveGradientEffect());
CueSDK.UpdateMode = UpdateMode.Continuous; CueSDK.UpdateMode = UpdateMode.Continuous;
Wait(5);
CueSDK.UpdateMode = UpdateMode.Manual;
for (int i = 0; i < 100000; i++)
{
CueSDK.Reinitialize();
Console.WriteLine(i);
}
Console.WriteLine("done!");
Wait(5);
//IBrush rainbowBrush = new LinearGradientBrush(new RainbowGradient()); //IBrush rainbowBrush = new LinearGradientBrush(new RainbowGradient());
//rainbowBrush.AddEffect(new FlashEffect { Attack = 5f, Sustain = 1f, Decay = 0, Release = 5f, Interval = 1f }); //rainbowBrush.AddEffect(new FlashEffect { Attack = 5f, Sustain = 1f, Decay = 0, Release = 5f, Interval = 1f });
//rainbowBrush.AddEffect(new MoveRainbowEffect()); //rainbowBrush.AddEffect(new MoveRainbowEffect());

View File

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.1")] [assembly: AssemblyVersion("1.2.0.1")]
[assembly: AssemblyFileVersion("1.1.0.1")] [assembly: AssemblyFileVersion("1.2.0.1")]

View File

@ -1,5 +1,6 @@
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System.Collections.Generic;
using System.Linq; using System.Linq;
using CUE.NET.Devices.Generic; using CUE.NET.Devices.Generic;
@ -46,25 +47,26 @@ namespace CUE.NET.Gradients
/// <returns>The color at the specific offset.</returns> /// <returns>The color at the specific offset.</returns>
public override CorsairColor GetColor(float offset) public override CorsairColor GetColor(float offset)
{ {
if (!GradientStops.Any()) return CorsairColor.Transparent; if (GradientStops.Count == 0) return CorsairColor.Transparent;
if (GradientStops.Count == 1) return GradientStops.First().Color; if (GradientStops.Count == 1) return GradientStops.First().Color;
GradientStop gsBefore; GradientStop gsBefore;
GradientStop gsAfter; GradientStop gsAfter;
IList<GradientStop> orderedStops = GradientStops.OrderBy(x => x.Offset).ToList();
if (WrapGradient) if (WrapGradient)
{ {
gsBefore = GradientStops.Where(n => n.Offset <= offset).OrderBy(n => n.Offset).LastOrDefault(); gsBefore = orderedStops.LastOrDefault(n => n.Offset <= offset);
if (gsBefore == null) if (gsBefore == null)
{ {
GradientStop lastStop = GradientStops.OrderBy(n => n.Offset).Last(); GradientStop lastStop = orderedStops[orderedStops.Count - 1];
gsBefore = new GradientStop(lastStop.Offset - 1f, lastStop.Color); gsBefore = new GradientStop(lastStop.Offset - 1f, lastStop.Color);
} }
gsAfter = GradientStops.Where(n => n.Offset >= offset).OrderBy(n => n.Offset).FirstOrDefault(); gsAfter = orderedStops.FirstOrDefault(n => n.Offset >= offset);
if (gsAfter == null) if (gsAfter == null)
{ {
GradientStop firstStop = GradientStops.OrderBy(n => n.Offset).First(); GradientStop firstStop = orderedStops[0];
gsAfter = new GradientStop(firstStop.Offset + 1f, firstStop.Color); gsAfter = new GradientStop(firstStop.Offset + 1f, firstStop.Color);
} }
} }
@ -72,8 +74,8 @@ namespace CUE.NET.Gradients
{ {
offset = ClipOffset(offset); offset = ClipOffset(offset);
gsBefore = GradientStops.Where(n => n.Offset <= offset).OrderBy(n => n.Offset).Last(); gsBefore = orderedStops.Last(n => n.Offset <= offset);
gsAfter = GradientStops.Where(n => n.Offset >= offset).OrderBy(n => n.Offset).First(); gsAfter = orderedStops.First(n => n.Offset >= offset);
} }
float blendFactor = 0f; float blendFactor = 0f;

View File

@ -43,8 +43,6 @@ namespace CUE.NET.Gradients
#region Methods #region Methods
#endregion
/// <summary> /// <summary>
/// Gets the color on the rainbow at the given offset. /// Gets the color on the rainbow at the given offset.
/// </summary> /// </summary>
@ -58,5 +56,7 @@ namespace CUE.NET.Gradients
hue += 360; hue += 360;
return ColorHelper.ColorFromHSV(hue, 1f, 1f); return ColorHelper.ColorFromHSV(hue, 1f, 1f);
} }
#endregion
} }
} }

View File

@ -35,10 +35,19 @@ namespace CUE.NET.Groups
} }
} }
private float _minOverlayPercentage;
/// <summary> /// <summary>
/// Gets or sets the minimal percentage overlay a LED must have with the <see cref="Rectangle" /> to be taken into the ledgroup. /// Gets or sets the minimal percentage overlay a LED must have with the <see cref="Rectangle" /> to be taken into the ledgroup.
/// </summary> /// </summary>
public float MinOverlayPercentage { get; set; } public float MinOverlayPercentage
{
get { return _minOverlayPercentage; }
set
{
_minOverlayPercentage = value;
_ledCache = null;
}
}
#endregion #endregion

View File

@ -2,8 +2,12 @@
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using CUE.NET.Devices.Generic.Enums; using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Exceptions;
namespace CUE.NET.Native namespace CUE.NET.Native
{ {
@ -19,11 +23,6 @@ namespace CUE.NET.Native
/// </summary> /// </summary>
internal static string LoadedArchitecture { get; private set; } internal static string LoadedArchitecture { get; private set; }
static _CUESDK()
{
LoadCUESDK();
}
/// <summary> /// <summary>
/// Reloads the SDK. /// Reloads the SDK.
/// </summary> /// </summary>
@ -37,10 +36,24 @@ namespace CUE.NET.Native
{ {
if (_dllHandle != IntPtr.Zero) return; if (_dllHandle != IntPtr.Zero) return;
LoadedArchitecture = LoadedArchitecture = Environment.Is64BitProcess ? "x64" : "x86";
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll // HACK: Load library at runtime to support both, x86 and x64 with one managed dll
_dllHandle = LoadLibrary((LoadedArchitecture = Environment.Is64BitProcess ? "x64" : "x86") + "/CUESDK_2015.dll"); List<string> possiblePathList = Environment.Is64BitProcess ? CueSDK.PossibleX64NativePaths : CueSDK.PossibleX86NativePaths;
string dllPath = null;
foreach (string path in possiblePathList)
if (File.Exists(path))
{
dllPath = path;
break;
}
if (dllPath == null) throw new WrapperException($"Can't find the CUE-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
_dllHandle = LoadLibrary(dllPath);
_corsairSetLedsColorsPointer = (CorsairSetLedsColorsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairSetLedsColors"), typeof(CorsairSetLedsColorsPointer)); _corsairSetLedsColorsPointer = (CorsairSetLedsColorsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairSetLedsColors"), typeof(CorsairSetLedsColorsPointer));
_corsairGetLedsColorsPointer = (CorsairGetLedsColorsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedsColors"), typeof(CorsairGetLedsColorsPointer));
_corsairGetDeviceCountPointer = (CorsairGetDeviceCountPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceCount"), typeof(CorsairGetDeviceCountPointer)); _corsairGetDeviceCountPointer = (CorsairGetDeviceCountPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceCount"), typeof(CorsairGetDeviceCountPointer));
_corsairGetDeviceInfoPointer = (CorsairGetDeviceInfoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceInfo"), typeof(CorsairGetDeviceInfoPointer)); _corsairGetDeviceInfoPointer = (CorsairGetDeviceInfoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceInfo"), typeof(CorsairGetDeviceInfoPointer));
_corsairGetLedPositionsPointer = (CorsairGetLedPositionsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedPositions"), typeof(CorsairGetLedPositionsPointer)); _corsairGetLedPositionsPointer = (CorsairGetLedPositionsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedPositions"), typeof(CorsairGetLedPositionsPointer));
@ -50,6 +63,7 @@ namespace CUE.NET.Native
_corsairReleaseControlPointer = (CorsairReleaseControlPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairReleaseControl"), typeof(CorsairReleaseControlPointer)); _corsairReleaseControlPointer = (CorsairReleaseControlPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairReleaseControl"), typeof(CorsairReleaseControlPointer));
_corsairPerformProtocolHandshakePointer = (CorsairPerformProtocolHandshakePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairPerformProtocolHandshake"), typeof(CorsairPerformProtocolHandshakePointer)); _corsairPerformProtocolHandshakePointer = (CorsairPerformProtocolHandshakePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairPerformProtocolHandshake"), typeof(CorsairPerformProtocolHandshakePointer));
_corsairGetLastErrorPointer = (CorsairGetLastErrorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLastError"), typeof(CorsairGetLastErrorPointer)); _corsairGetLastErrorPointer = (CorsairGetLastErrorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLastError"), typeof(CorsairGetLastErrorPointer));
_corsairRegisterKeypressCallbackPointer = (CorsairRegisterKeypressCallbackPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairRegisterKeypressCallback"), typeof(CorsairRegisterKeypressCallbackPointer));
} }
private static void UnloadCUESDK() private static void UnloadCUESDK()
@ -77,6 +91,7 @@ namespace CUE.NET.Native
#region Pointers #region Pointers
private static CorsairSetLedsColorsPointer _corsairSetLedsColorsPointer; private static CorsairSetLedsColorsPointer _corsairSetLedsColorsPointer;
private static CorsairGetLedsColorsPointer _corsairGetLedsColorsPointer;
private static CorsairGetDeviceCountPointer _corsairGetDeviceCountPointer; private static CorsairGetDeviceCountPointer _corsairGetDeviceCountPointer;
private static CorsairGetDeviceInfoPointer _corsairGetDeviceInfoPointer; private static CorsairGetDeviceInfoPointer _corsairGetDeviceInfoPointer;
private static CorsairGetLedPositionsPointer _corsairGetLedPositionsPointer; private static CorsairGetLedPositionsPointer _corsairGetLedPositionsPointer;
@ -86,6 +101,7 @@ namespace CUE.NET.Native
private static CorsairReleaseControlPointer _corsairReleaseControlPointer; private static CorsairReleaseControlPointer _corsairReleaseControlPointer;
private static CorsairPerformProtocolHandshakePointer _corsairPerformProtocolHandshakePointer; private static CorsairPerformProtocolHandshakePointer _corsairPerformProtocolHandshakePointer;
private static CorsairGetLastErrorPointer _corsairGetLastErrorPointer; private static CorsairGetLastErrorPointer _corsairGetLastErrorPointer;
private static CorsairRegisterKeypressCallbackPointer _corsairRegisterKeypressCallbackPointer;
#endregion #endregion
@ -94,6 +110,9 @@ namespace CUE.NET.Native
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool CorsairSetLedsColorsPointer(int size, IntPtr ledsColors); private delegate bool CorsairSetLedsColorsPointer(int size, IntPtr ledsColors);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool CorsairGetLedsColorsPointer(int size, IntPtr ledsColors);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int CorsairGetDeviceCountPointer(); private delegate int CorsairGetDeviceCountPointer();
@ -121,6 +140,9 @@ namespace CUE.NET.Native
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate CorsairError CorsairGetLastErrorPointer(); private delegate CorsairError CorsairGetLastErrorPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool CorsairRegisterKeypressCallbackPointer(IntPtr callback, IntPtr context);
#endregion #endregion
// ReSharper disable EventExceptionNotDocumented // ReSharper disable EventExceptionNotDocumented
@ -133,6 +155,14 @@ namespace CUE.NET.Native
return _corsairSetLedsColorsPointer(size, ledsColors); return _corsairSetLedsColorsPointer(size, ledsColors);
} }
/// <summary>
/// CUE-SDK: get current color for the list of requested LEDs.
/// </summary>
internal static bool CorsairGetLedsColors(int size, IntPtr ledsColors)
{
return _corsairGetLedsColorsPointer(size, ledsColors);
}
/// <summary> /// <summary>
/// CUE-SDK: returns number of connected Corsair devices that support lighting control. /// CUE-SDK: returns number of connected Corsair devices that support lighting control.
/// </summary> /// </summary>
@ -206,6 +236,11 @@ namespace CUE.NET.Native
return _corsairGetLastErrorPointer(); return _corsairGetLastErrorPointer();
} }
internal static bool CorsairRegisterKeypressCallback(IntPtr callback, IntPtr context)
{
return _corsairRegisterKeypressCallbackPointer(callback, context);
}
// ReSharper restore EventExceptionNotDocumented // ReSharper restore EventExceptionNotDocumented
#endregion #endregion

View File

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.1.0")] [assembly: AssemblyVersion("1.2.0.1")]
[assembly: AssemblyFileVersion("1.1.1.0")] [assembly: AssemblyFileVersion("1.2.0.1")]

View File

@ -1,3 +1,6 @@
**CUE.NET is considered done now and will be no longer actively developed.
It is superseded by [RGB.NET](https://github.com/DarthAffe/RGB.NET). Feel free to join the [discord-channel](https://discord.gg/9kytURv) if you're interested what's happening there :)**
# CUE.NET # CUE.NET
C# (.NET) Wrapper library around the Corsair CUE-SDK C# (.NET) Wrapper library around the Corsair CUE-SDK

Binary file not shown.

Binary file not shown.