Jump to content
Corsair Community

CUE-SDK C# Wrapper (CUE.NET)


Darth Affe

Recommended Posts

Current version: 1.2.0

 

You'll always find the latest release on nuget https://www.nuget.org/packages/CUE.NET/ or (sometimes older) releases at https://github.com/DarthAffe/CUE.NET/releases/latest and the source at https://github.com/DarthAffe/CUE.NET

This is considered done now and will be no longer actively developed (only bugfixes if needed).

CUE.NET will be superseded by RGB.NET. Feel free to join the discord-channel if you're interested what's happening there :)

 

Features:

  • Full Control over the LEDs of your SDK-supported Corsair-Devices through a C#-API
     
  • Reading, saving and restoring colors on the keyboard
     
  • By-key-access to every supported led or grouping in regions/lists
     
  • Comprehensive render-engine based on brushes to allow easy drawing over multiple leds.
     
  • Effect-engine to animate brushes or groups of leds
     
  • Capture special key-pressed (including G- (keyboard) and M- (mouse) keys)

Link to comment
Share on other sites

  • Replies 52
  • Created
  • Last Reply
Hey goomonster3,

 

I just committed a small example of what's possible for now.

This is rudimentary, but I'm going to bring it into some structure now.

 

Sweet! Thank you a lot - I am gonna try and do some stuff with your "ported" c# sdk now :D. Keep up the good work - loads of developers will appreciate it later when this gets noticed!

Link to comment
Share on other sites

I've just created an release tag for a version which seems to work quite well.

As said until now it's nothing too fancy but for anyone who wants to utilize the api it should be a good place to start.

 

Link: https://github.com/DarthAffe/CUE.NET/releases/tag/v0.1.0

 

Like before I appreciate ideas of what to add, help with other devices than my K95 (the only device it's tested until now) or someone who checks my spelling and grammar to let the documentation (well, or code-comments) be understandable :p

Link to comment
Share on other sites

  • 2 weeks later...

Hey! I'd like to know how far along you might be on the development of support for mice and headsets! If you're still working on it, I could pitch in. I'm using your wrapper in my program, now, and I'd love to extend my effects to all the devices through SDK.

 

Let me know here or in a PM if you'd like to work together on what's left, please! :)

Link to comment
Share on other sites

  • 1 month later...

I'm noticing that the SDK detects my keyboard but the keys collection contains zero elements. I have a Corsair K95 under Windows 10 with latest CUE Engine, driver and firmware.

 

using Version 0.2.0.0 of CUE.NET and tries .NET 4.5 and 4.6.

 

-- CODE --

CueSDK.Initialize();

Console.WriteLine("Initialized with " + CueSDK.LoadedArchitecture + "-SDK");

 

CorsairKeyboard keyboard = CueSDK.KeyboardSDK;

 

Console.WriteLine(keyboard.DeviceInfo.Model);

Console.WriteLine(keyboard.DeviceInfo.Type.ToString());

Console.WriteLine(keyboard.DeviceInfo.CapsMask.ToString());

 

if (keyboard == null)

throw new Exception("Keyboard not found");

 

keyboard['A'].Led.Color = Color.Red;

keyboard[CorsairKeyboardKeyId.B].Led.Color = Color.Green;

keyboard.Update();

 

End's with an uninitialized object exception when I try to touch keyboard['A'] and if I output the contents of the keys collection I have a count of zero. It does however report the K95 keyboard properly after I initialize. Help? I'm trying to write a program to do something really cool with the LED's and serve it as a #Codegasm episode on http://barnnerd.com

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
  • 2 weeks later...

Quick stupid question.. I'm writting an alert program that's going to run in the background.. I got everything working .. except this..

 

Basically what I do is flash lights (Brush color, Brush black.. etc) .. then at the end of that "flash" function I'd like the keyboard to revert back to the profile that's running before the flashing begain (like it does when you close the program) .. I am not opening it exclusive.. and I know the problem is that it's ujsing a black brush.

 

I've tried to use a transparent brush to see if that would work.. but no dice.. is there a way ( or do you know of a way ) that will release control of the keyboard back to CUE so the profile will continue to run as it did before, or a way to just "reset" the keyboard?

Link to comment
Share on other sites

No, at the moment there is no way to get any kind of information about CUE through the SDK.

That's why currently (as far as I know) there are only two ways to release control of the keyboard back to CUE (and it seems that you know of both):

1. Close the application (this is quite obvious^^)

2. Run your application in shared access mode (this is default). CUE should regain access as soon as it updates something. (That's why a CUE-profile containing only background lights will never get control back.)

 

The profile loading option I introduced with the last update allows some kind of workaround to this problem, but you need to know to which profile you'd like to revert to (the default-profile is the only 'variable' thing, since it's possible to get this out of the CUE-config file).

 

EDIT: Just as I wrote this I came up with something that might work: Actually it should be possible to reset the connection to the SDK (to reset the keyboard to CUE settings) without losing internal states. I'll investigate this over the weekend - sometimes things are too easy to be recognized^^

Link to comment
Share on other sites

  • 4 weeks later...
I just added the possibility to reinitialize - this should solve your problem.

https://github.com/DarthAffe/CUE.NET/releases/tag/v1.0.2

 

Just update to the latest version (nuget-packages are updated too).

 

Sorry for the late response, I didn't get notified of a change.. .. I will need to fix that.. I will pull down the pre-release nuget and see if it works :) thanks for your help!

 

UPDATE: This works perfectly.. :) I'm using it for a monitoring program that flashes the keyboard when I have PRTG issues.. and this worked great! I appreciate it!

Link to comment
Share on other sites

  • 2 months later...
  • 3 months later...
  • 3 months later...

Hey, the wiki is currently really outdated - sorry for that but I'm just to lazy to work on it ...

 

I created a short example (consisting of two files) - whole project is attached too:

 

Program.cs

using System;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using CUE.NET;
using CUE.NET.Brushes;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Devices.Keyboard;
using CUE.NET.Exceptions;
using CUE.NET.Gradients;
using CUE.NET.Groups;

namespace FlowingRainbow
{
   class Program
   {
       static void Main(string[] args)
       {
           try
           {
               CueSDK.Initialize();

               CorsairKeyboard keyboard = CueSDK.KeyboardSDK;
               if (keyboard == null)
               {
                   Console.WriteLine("Can't initialize keyboard ...");
                   Console.ReadKey();
                   return;
               }

               // I prefer to always add a solid black background to prevent "bleeding" colors if transparency is used.
               keyboard.Brush = (SolidColorBrush)Color.Black;

               // Create a ledGroup containing all the leds you want to brush (in this case the whole keyboard).
               ILedGroup rainbowLedGroup = new ListLedGroup(keyboard, keyboard);

               // Prepare to brushes (we want to toggle them) and add one to the group.
               LinearGradientBrush linearRainbowBrush = new LinearGradientBrush(new RainbowGradient());
               RadialGradientBrush radialRainbowBrush = new RadialGradientBrush(new RainbowGradient());
               rainbowLedGroup.Brush = linearRainbowBrush;

               // Add our custom effect to the brush to animate the rainbow.
               MovingRainbowEffect movingRainbowEffect = new MovingRainbowEffect();
               rainbowLedGroup.Brush.AddEffect(movingRainbowEffect);

               // Enable automatic updates to allow the effect to work (you might want to tune 'CueSDK.UpdateFrequency' too)
               CueSDK.UpdateMode = UpdateMode.Continuous;


               // We want a really fancy console-application :p
               Console.WriteLine("Change speed with 'w' and 's'");
               Console.WriteLine("Change direction with 'd'");
               Console.WriteLine("Change brush with 'b'");
               Console.WriteLine("Press ESC to exit ...");
               Console.WriteLine();

               Task.Factory.StartNew(
               () =>
               {
                   ConsoleKey key;
                   do
                   {
                       key = Console.ReadKey().Key;
                       switch (key)
                       {
                           case ConsoleKey.W:
                               movingRainbowEffect.Speed += 10f;
                               Console.WriteLine($"\rIncreasing speed to {movingRainbowEffect.Speed}");
                               break;
                           case ConsoleKey.S:
                               movingRainbowEffect.Speed -= 10f;
                               Console.WriteLine($"\rDecreasing speed to {movingRainbowEffect.Speed}");
                               break;
                           case ConsoleKey.D:
                               movingRainbowEffect.Direction = !movingRainbowEffect.Direction;
                               Console.WriteLine($"\rChanging direction to {movingRainbowEffect.Direction}");
                               break;
                           case ConsoleKey.B:
                               // We want to reuse our effect for both brushes so we need to set it free first
                               rainbowLedGroup.Brush.RemoveEffect(movingRainbowEffect);
                               // Swap the brush (this isn't good code, but this is an example :p
                               rainbowLedGroup.Brush = (rainbowLedGroup.Brush is LinearGradientBrush) ? (IBrush)radialRainbowBrush : linearRainbowBrush;
                               // Apply the effect the the other brush
                               rainbowLedGroup.Brush.AddEffect(movingRainbowEffect);
                               Console.WriteLine($"\rChanging brush to {rainbowLedGroup.Brush.GetType()}");
                               break;
                       }
                   } while (key != ConsoleKey.Escape);
                   Environment.Exit(0);
               });
           }
           catch (CUEException ex)
           {
               Console.WriteLine("CUE Exception! ErrorCode: " + Enum.GetName(typeof(CorsairError), ex.Error));
           }
           catch (WrapperException ex)
           {
               Console.WriteLine("Wrapper Exception! Message:" + ex.Message);
           }
           catch (Exception ex)
           {
               Console.WriteLine("Exception! Message:" + ex.Message);
           }
           while (true)
               Thread.Sleep(1000); // Don't exit after exception
       }
   }
}

 

MovingRainbowEffect.cs

using CUE.NET.Brushes;
using CUE.NET.Effects;
using CUE.NET.Gradients;

namespace FlowingRainbow
{
   public class MovingRainbowEffect : AbstractBrushEffect<IGradientBrush>
   {
       #region Properties & Fields

       public bool Direction { get; set; }
       public float Speed { get; set; } // 30 degree per second (see https://upload.wikimedia.org/wikipedia/commons/a/ad/HueScale.svg)

       #endregion

       #region Constructors

       public MovingRainbowEffect(float speed = 180f, bool direction = true)
       {
           this.Speed = speed;
           this.Direction = direction;
       }

       #endregion

       #region Methods

       public override void Update(float deltaTime)
       {
           // Our effect only works with rainbow-gradients
           RainbowGradient rainbowGradient = Brush.Gradient as RainbowGradient;
           if (rainbowGradient == null) return;

           // Calculate amount of movement we need to do considering the time since the last update, to be update-rate-independent.
           float movement = Speed * deltaTime;

           // Inverse our movement if we want move the rainbow in the other direction.
           if (!Direction)
               movement = -movement;

           // Move the whole gradient
           // Please notice, that this isn't good code since we're only increasing the value all the time. Like this we might get an overflow if the animation runs to long.
           // This should be prevented according to your specific use-case.
           rainbowGradient.StartHue += movement;
           rainbowGradient.EndHue += movement;
       }

       // Make sure that we only apply this effect if the brush has an rainbow gradient 
       public override bool CanBeAppliedTo(IBrush target)
       {
           return (target as IGradientBrush)?.Gradient is RainbowGradient;
       }

       #endregion
   }
}

FlowingRainbow.zip

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...