mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Updated the Corsair-Headset-DeviceProvider to benefit from CUE.NET 1.0.3
This commit is contained in:
parent
7ed9114805
commit
841207225d
@ -1,12 +1,10 @@
|
|||||||
using System;
|
using System.Linq;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Artemis.Utilities;
|
using Artemis.Utilities;
|
||||||
using CUE.NET;
|
using CUE.NET;
|
||||||
using CUE.NET.Devices.Generic.Enums;
|
using CUE.NET.Devices.Generic.Enums;
|
||||||
using CUE.NET.Exceptions;
|
|
||||||
using Ninject.Extensions.Logging;
|
using Ninject.Extensions.Logging;
|
||||||
|
|
||||||
namespace Artemis.DeviceProviders.Corsair
|
namespace Artemis.DeviceProviders.Corsair
|
||||||
@ -24,8 +22,8 @@ namespace Artemis.DeviceProviders.Corsair
|
|||||||
public override bool TryEnable()
|
public override bool TryEnable()
|
||||||
{
|
{
|
||||||
CanUse = CanInitializeSdk();
|
CanUse = CanInitializeSdk();
|
||||||
if (CanUse)
|
if (CanUse && !CueSDK.IsInitialized)
|
||||||
CueSDK.HeadsetSDK.UpdateMode = UpdateMode.Manual;
|
CueSDK.Initialize();
|
||||||
|
|
||||||
Logger.Debug("Attempted to enable Corsair headset. CanUse: {0}", CanUse);
|
Logger.Debug("Attempted to enable Corsair headset. CanUse: {0}", CanUse);
|
||||||
return CanUse;
|
return CanUse;
|
||||||
@ -33,7 +31,7 @@ namespace Artemis.DeviceProviders.Corsair
|
|||||||
|
|
||||||
public override void Disable()
|
public override void Disable()
|
||||||
{
|
{
|
||||||
if (CueSDK.ProtocolDetails != null)
|
if (CueSDK.IsInitialized)
|
||||||
CueSDK.Reinitialize();
|
CueSDK.Reinitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +41,7 @@ namespace Artemis.DeviceProviders.Corsair
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var leds = CueSDK.HeadsetSDK.Leds.Count();
|
var leds = CueSDK.HeadsetSDK.Leds.Count();
|
||||||
var rect = new Rect(new Size(leds*20, leds*20));
|
var rect = new Rect(new Size(leds * 20, leds * 20));
|
||||||
var img = brush.Dispatcher.Invoke(() =>
|
var img = brush.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
var visual = new DrawingVisual();
|
var visual = new DrawingVisual();
|
||||||
@ -58,37 +56,22 @@ namespace Artemis.DeviceProviders.Corsair
|
|||||||
{
|
{
|
||||||
corsairLed.Color = ledIndex == 0
|
corsairLed.Color = ledIndex == 0
|
||||||
? img.GetPixel(0, 0)
|
? img.GetPixel(0, 0)
|
||||||
: img.GetPixel((ledIndex + 1)*20 - 1, (ledIndex + 1)*20 - 1);
|
: img.GetPixel((ledIndex + 1) * 20 - 1, (ledIndex + 1) * 20 - 1);
|
||||||
ledIndex++;
|
ledIndex++;
|
||||||
}
|
}
|
||||||
CueSDK.HeadsetSDK.Update(true);
|
|
||||||
|
CueSDK.HeadsetSDK.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CanInitializeSdk()
|
private static bool CanInitializeSdk()
|
||||||
{
|
{
|
||||||
// If already initialized, return result right away
|
|
||||||
if (CueSDK.ProtocolDetails != null)
|
|
||||||
return CueSDK.HeadsetSDK != null;
|
|
||||||
|
|
||||||
// Else try to enable the SDK
|
|
||||||
for (var tries = 0; tries < 9; tries++)
|
for (var tries = 0; tries < 9; tries++)
|
||||||
{
|
{
|
||||||
if (CueSDK.ProtocolDetails != null)
|
if (CueSDK.IsSDKAvailable(CorsairDeviceType.Headset))
|
||||||
break;
|
return true;
|
||||||
|
Thread.Sleep(2000);
|
||||||
try
|
|
||||||
{
|
|
||||||
CueSDK.Initialize();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
Thread.Sleep(2000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
if (CueSDK.ProtocolDetails == null)
|
|
||||||
return false;
|
|
||||||
return CueSDK.HeadsetSDK != null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user