using CUE.NET;
using CUE.NET.Brushes;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Devices.Keyboard;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Exceptions;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows;
using System.ComponentModel;
using CUE.NET.Devices.Generic;
namespace RGBController2.Boards
{
public class CUEDeviceBoard : IBoard
{
private AbstractCueDevice _device;
private CorsairDeviceType _deviceType;
public CorsairDeviceType DeviceType
{
get { return _deviceType; }
set { _deviceType = value; }
}
private CorsairDeviceType[] _availableDevices;
public CorsairDeviceType[] AvailableDevices
{
get { return _availableDevices; }
}
private bool _connected;
public bool Connected
{
get { return _connected; }
}
///
/// Contructs oject to control Cue devices. Note: this does not connect to a device.
///
public CUEDeviceBoard()
{
List device = new List();
// Find which devices are available
if (CueSDK.IsSDKAvailable(CorsairDeviceType.Headset))
device.Add(CorsairDeviceType.Headset);
if (CueSDK.IsSDKAvailable(CorsairDeviceType.HeadsetStand))
device.Add(CorsairDeviceType.HeadsetStand);
if (CueSDK.IsSDKAvailable(CorsairDeviceType.Keyboard))
device.Add(CorsairDeviceType.Keyboard);
if (CueSDK.IsSDKAvailable(CorsairDeviceType.Mouse))
device.Add(CorsairDeviceType.Mouse);
if (CueSDK.IsSDKAvailable(CorsairDeviceType.Mousemat))
device.Add(CorsairDeviceType.Mousemat);
_availableDevices = device.ToArray();
_connected = false;
}
///
/// Connects to and initilises the given device.
///
/// The type of device to connect to
public void ConnectToDevice(CorsairDeviceType deviceType)
{
try
{
CueSDK.Initialize();
switch(deviceType)
{
case CorsairDeviceType.Headset:
_device = CueSDK.HeadsetSDK;
break;
case CorsairDeviceType.HeadsetStand:
_device = CueSDK.HeadsetStandSDK;
break;
case CorsairDeviceType.Keyboard:
_device = CueSDK.KeyboardSDK;
break;
case CorsairDeviceType.Mouse:
_device = CueSDK.MouseSDK;
break;
case CorsairDeviceType.Mousemat:
_device = CueSDK.MousematSDK;
break;
}
if (_device == null)
throw new WrapperException("No CUE device found");
_device.Brush = (CUE.NET.Brushes.SolidColorBrush)Color.Transparent; // This 'enables' manual color changes.
// Sets the device to blue, this should probally be changed to a different colour
SolidColorBrush solidColorBrush = new SolidColorBrush(Color.Blue);
_device.Brush = solidColorBrush;
_device.Update();
_connected = true;
}
catch (CUEException ex)
{
MessageBox.Show("CUE Exception! ErrorCode: " + Enum.GetName(typeof(CorsairError), ex.Error));
}
catch (WrapperException ex)
{
MessageBox.Show("Wrapper Exception! Message:" + ex.Message);
}
}
///
/// Sets all of the LEDs to the chosen RGB colour.
///
/// The red value
/// The green value
/// The blue value
public void SetAllLeds(byte red, byte green, byte blue)
{
if (Connected)
{
SolidColorBrush solidColorBrush = new SolidColorBrush(Color.FromArgb(255, (byte)red, (byte)green, (byte)blue));
_device.Brush = solidColorBrush;
_device.Update();
}
}
///
/// Turns off all of the LEDs for that device.
///
public void TurnOffAllLeds()
{
if (Connected)
{
SolidColorBrush solidColorBrush = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
_device.Brush = solidColorBrush;
_device.Update();
}
}
}
}