Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #63 from darosultan/GlaiveSupport
Browse files Browse the repository at this point in the history
Merged glaive support into own branch
  • Loading branch information
DarthAffe authored Sep 30, 2017
2 parents 220953b + c364d4b commit c93f53d
Show file tree
Hide file tree
Showing 6 changed files with 559 additions and 386 deletions.
8 changes: 7 additions & 1 deletion CUE.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<DocumentationFile>bin\CUE.NET.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="HidSharp, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\HidSharp.1.5\lib\net35\HidSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
Expand Down Expand Up @@ -68,6 +71,7 @@
<Compile Include="Devices\Generic\EventArgs\UpdatingEventArgs.cs" />
<Compile Include="Devices\Generic\LedUpateRequest.cs" />
<Compile Include="Devices\Keyboard\Enums\BrushCalculationMode.cs" />
<Compile Include="Devices\Mouse\GlaiveMouse.cs" />
<Compile Include="Effects\AbstractLedGroupEffect.cs" />
<Compile Include="Effects\AbstractBrushEffect.cs" />
<Compile Include="Effects\AbstractEffectTarget.cs" />
Expand Down Expand Up @@ -132,7 +136,9 @@
<Compile Include="CueSDK.cs" />
<Compile Include="Devices\ICueDevice.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildProjectDirectory)\CUE.NET.targets" />
</Project>
11 changes: 10 additions & 1 deletion CueSDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using CUE.NET.Devices.Mousemat;
using CUE.NET.Exceptions;
using CUE.NET.Native;
using System;

namespace CUE.NET
{
Expand Down Expand Up @@ -79,6 +80,7 @@ public static partial class CueSDK
/// </summary>
public static CorsairMouse MouseSDK { get; private set; }


/// <summary>
/// Gets the managed representation of a headset managed by the CUE-SDK.
/// Note that currently only one connected headset is supported.
Expand Down Expand Up @@ -197,7 +199,14 @@ public static void Initialize(bool exclusiveAccess = false)
device = KeyboardSDK = new CorsairKeyboard(new CorsairKeyboardDeviceInfo(nativeDeviceInfo));
break;
case CorsairDeviceType.Mouse:
device = MouseSDK = new CorsairMouse(new CorsairMouseDeviceInfo(nativeDeviceInfo));
if(info.Model.ToLower().Contains("glaive"))
{
device = MouseSDK = new GlaiveMouse(new CorsairMouseDeviceInfo(nativeDeviceInfo));
}
else
{
device = MouseSDK = new CorsairMouse(new CorsairMouseDeviceInfo(nativeDeviceInfo));
}
break;
case CorsairDeviceType.Headset:
device = HeadsetSDK = new CorsairHeadset(new CorsairHeadsetDeviceInfo(nativeDeviceInfo));
Expand Down
2 changes: 1 addition & 1 deletion Devices/Generic/AbstractCueDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ protected virtual void Render(ILedGroup ledGroup)
catch (Exception ex) { OnException(ex); }
}

private void UpdateLeds(ICollection<LedUpateRequest> updateRequests)
protected virtual void UpdateLeds(ICollection<LedUpateRequest> updateRequests)
{
updateRequests = updateRequests.Where(x => x.Color != CorsairColor.Transparent).ToList();

Expand Down
139 changes: 139 additions & 0 deletions Devices/Mouse/GlaiveMouse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using CUE.NET.Devices.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using HidSharp;
using System.Drawing;
using CUE.NET.Devices.Generic.Enums;

namespace CUE.NET.Devices.Mouse
{
public class GlaiveMouse : CorsairMouse
{
private const int vid = 0x1b1c;
private const int pid = 0x1b34;

private HidDevice dev;
private HidStream stream;

private Color bars;
private Color front;
private Color logo;

private bool initialized = false;

public GlaiveMouse(CorsairMouseDeviceInfo info) : base(info)
{ }

public static GlaiveMouse FromCorsairMouse(CorsairMouse mouse)
{
return new GlaiveMouse(mouse.MouseDeviceInfo);
}

public override void Initialize()
{
var loader = new HidDeviceLoader();
dev = loader.GetDeviceOrDefault(vid, pid);
if (!dev.TryOpen(out stream)) throw new Exception("Glaive mouse init error!");

initialized = true;

base.Initialize();
}

protected override void UpdateLeds(ICollection<LedUpateRequest> updateRequests)
{
updateRequests = updateRequests.Where(x => x.Color != CorsairColor.Transparent).ToList();

OnLedsUpdating(updateRequests);

if (updateRequests.Any()) // CUE seems to crash if 'CorsairSetLedsColors' is called with a zero length array
{
//int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
//IntPtr ptr = Marshal.AllocHGlobal(structSize * updateRequests.Count);
//IntPtr addPtr = new IntPtr(ptr.ToInt64());
//foreach (LedUpateRequest ledUpdateRequest in updateRequests)
//{
// _CorsairLedColor color = new _CorsairLedColor
// {
// ledId = (int)ledUpdateRequest.LedId,
// r = ledUpdateRequest.Color.R,
// g = ledUpdateRequest.Color.G,
// b = ledUpdateRequest.Color.B
// };

// Marshal.StructureToPtr(color, addPtr, false);
// addPtr = new IntPtr(addPtr.ToInt64() + structSize);
//}
//_CUESDK.CorsairSetLedsColors(updateRequests.Count, ptr);
//Marshal.FreeHGlobal(ptr);

foreach (LedUpateRequest ledUpdateRequest in updateRequests)
{
switch(ledUpdateRequest.LedId)
{
case CorsairLedId.B1:
logo = Color.FromArgb(ledUpdateRequest.Color.R, ledUpdateRequest.Color.G, ledUpdateRequest.Color.B);
break;
case CorsairLedId.B2:
front = Color.FromArgb(ledUpdateRequest.Color.R, ledUpdateRequest.Color.G, ledUpdateRequest.Color.B);
break;
case CorsairLedId.B3:
bars = Color.FromArgb(ledUpdateRequest.Color.R, ledUpdateRequest.Color.G, ledUpdateRequest.Color.B);
break;
default:
break;
}
}

HidUpdate();
}

OnLedsUpdated(updateRequests);
}

private void HidUpdate()
{
if (initialized)
{
byte[] buff = new byte[65];
buff[1] = 7;
buff[2] = 34;
buff[3] = 4;
buff[4] = 1;



//dpi indicator (no idea why but this crap doesnt work)
buff[5] = 3;
//if (dpiIndicator == 1 || dpiIndicator == 2 || dpiIndicator == 4)
//buff[6] = 255;
//if (dpiIndicator >= 2)
buff[7] = 255;
//if (dpiIndicator == 2 || dpiIndicator == 5)
buff[8] = 255;

//bars rgb
buff[9] = 6;
buff[10] = bars.R;
buff[11] = bars.G;
buff[12] = bars.B;

//front rgb
buff[13] = 1;
buff[14] = front.R;
buff[15] = front.G;
buff[16] = front.B;

//logo rgb
buff[17] = 2;
buff[18] = logo.R;
buff[19] = logo.G;
buff[20] = logo.B;

stream.Write(buff);
}
else throw new Exception("not initialized");
}
}
}
Loading

0 comments on commit c93f53d

Please sign in to comment.