From e05e740bd249c8af1c9a28757acb989c152bb50f Mon Sep 17 00:00:00 2001 From: Daro Date: Mon, 6 Nov 2017 18:50:39 +0100 Subject: [PATCH] Switched from HidSharp to HidLibrary --- CUE.NET.csproj | 4 ++-- Devices/Mouse/GlaiveMouse.cs | 38 ++++-------------------------------- packages.config | 1 + 3 files changed, 7 insertions(+), 36 deletions(-) diff --git a/CUE.NET.csproj b/CUE.NET.csproj index 6987d5a..a7c5795 100644 --- a/CUE.NET.csproj +++ b/CUE.NET.csproj @@ -36,8 +36,8 @@ bin\CUE.NET.XML - - packages\HidSharp.1.5\lib\net35\HidSharp.dll + + packages\hidlibrary.3.2.46.0\lib\HidLibrary.dll diff --git a/Devices/Mouse/GlaiveMouse.cs b/Devices/Mouse/GlaiveMouse.cs index d4c67bb..44bb8cd 100644 --- a/Devices/Mouse/GlaiveMouse.cs +++ b/Devices/Mouse/GlaiveMouse.cs @@ -2,9 +2,9 @@ using System; using System.Collections.Generic; using System.Linq; -using HidSharp; using System.Drawing; using CUE.NET.Devices.Generic.Enums; +using HidLibrary; namespace CUE.NET.Devices.Mouse { @@ -14,7 +14,6 @@ namespace CUE.NET.Devices.Mouse private const int pid = 0x1b34; private HidDevice dev; - private HidStream stream; private Color bars; private Color front; @@ -32,9 +31,7 @@ namespace CUE.NET.Devices.Mouse 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!"); + dev = HidDevices.Enumerate(vid, pid).Where(s=>s.DevicePath.Contains(@"&mi_02#")).Single(); initialized = true; @@ -47,27 +44,8 @@ namespace CUE.NET.Devices.Mouse OnLedsUpdating(updateRequests); - if (updateRequests.Any()) // CUE seems to crash if 'CorsairSetLedsColors' is called with a zero length array + if (updateRequests.Any()) { - //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) @@ -101,16 +79,8 @@ namespace CUE.NET.Devices.Mouse 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 @@ -131,7 +101,7 @@ namespace CUE.NET.Devices.Mouse buff[19] = logo.G; buff[20] = logo.B; - stream.Write(buff); + dev.Write(buff); } else throw new Exception("not initialized"); } diff --git a/packages.config b/packages.config index c90f30a..ed5e1bd 100644 --- a/packages.config +++ b/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file