From 1a123e5f276bb9e8d3432836cbd065af0280944b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 19 Jan 2022 12:12:36 +0100 Subject: [PATCH] added the ability to query whether certain lighting engines are supported --- Demo/Program.cs | 5 +++++ Illumilib/Illumilib.csproj | 5 +++-- Illumilib/IllumilibLighting.cs | 30 ++++++++++++++++++---------- Illumilib/LightingType.cs | 24 ++++++++++++++++++++++ Illumilib/System/CorsairLighting.cs | 2 ++ Illumilib/System/LightingSystem.cs | 2 ++ Illumilib/System/LogitechLighting.cs | 2 ++ Illumilib/System/RazerLighting.cs | 2 ++ 8 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 Illumilib/LightingType.cs diff --git a/Demo/Program.cs b/Demo/Program.cs index 8dc5300..c7e6839 100644 --- a/Demo/Program.cs +++ b/Demo/Program.cs @@ -8,6 +8,11 @@ namespace Demo { private static void Main(string[] args) { IllumilibLighting.Initialize(); + foreach (var type in Enum.GetValues()) { + if (IllumilibLighting.IsEnabled(type)) + Console.WriteLine($"{type} lighting is enabled"); + } + Console.WriteLine("Setting all lights to blue"); IllumilibLighting.SetAllLighting(r: 0, g: 0, b: 1); Thread.Sleep(TimeSpan.FromSeconds(3)); diff --git a/Illumilib/Illumilib.csproj b/Illumilib/Illumilib.csproj index 507a512..d921b52 100644 --- a/Illumilib/Illumilib.csproj +++ b/Illumilib/Illumilib.csproj @@ -12,6 +12,7 @@ README.md Logo.png 1.2.2 + NU1701 @@ -24,7 +25,7 @@ - - + + diff --git a/Illumilib/IllumilibLighting.cs b/Illumilib/IllumilibLighting.cs index bb0390d..910d86c 100644 --- a/Illumilib/IllumilibLighting.cs +++ b/Illumilib/IllumilibLighting.cs @@ -18,7 +18,7 @@ namespace Illumilib { /// public const int KeyboardHeight = 6; - private static List systems; + private static Dictionary systems; /// /// A property that returns whether Illumilib is currently initialized /// @@ -33,10 +33,10 @@ namespace Illumilib { public static bool Initialize() { if (Initialized) throw new InvalidOperationException("Illumilib has already been initialized"); - systems = new List(); + systems = new Dictionary(); foreach (var system in new LightingSystem[] {new LogitechLighting(), new RazerLighting(), new CorsairLighting()}) { if (system.Initialize()) - systems.Add(system); + systems.Add(system.Type, system); } return systems.Count > 0; } @@ -47,11 +47,21 @@ namespace Illumilib { public static void Dispose() { if (!Initialized) return; - foreach (var system in systems) + foreach (var system in systems.Values) system.Dispose(); systems = null; } + /// + /// Returns whether the given has been initialized successfully and is enabled. + /// + /// The to query. + /// Whether the given has been initialized and is enabled. + public static bool IsEnabled(LightingType type) { + EnsureInitialized(); + return systems.ContainsKey(type); + } + /// /// Sets the lighting for all keyboards and mice to the given color /// @@ -60,7 +70,7 @@ namespace Illumilib { /// The color's blue value, between 0 and 1 public static void SetAllLighting(float r, float g, float b) { EnsureInitialized(); - foreach (var system in systems) + foreach (var system in systems.Values) system.SetAllLighting(r, g, b); } @@ -72,7 +82,7 @@ namespace Illumilib { /// The color's blue value, between 0 and 1 public static void SetKeyboardLighting(float r, float g, float b) { EnsureInitialized(); - foreach (var system in systems) + foreach (var system in systems.Values) system.SetKeyboardLighting(r, g, b); } @@ -92,7 +102,7 @@ namespace Illumilib { throw new ArgumentOutOfRangeException(nameof(x)); if (y < 0 || y >= KeyboardHeight) throw new ArgumentOutOfRangeException(nameof(y)); - foreach (var system in systems) + foreach (var system in systems.Values) system.SetKeyboardLighting(x, y, r, g, b); } @@ -115,7 +125,7 @@ namespace Illumilib { throw new ArgumentOutOfRangeException(nameof(x)); if (y < 0 || y + height > KeyboardHeight) throw new ArgumentOutOfRangeException(nameof(y)); - foreach (var system in systems) + foreach (var system in systems.Values) system.SetKeyboardLighting(x, y, width, height, r, g, b); } @@ -129,7 +139,7 @@ namespace Illumilib { /// The color's blue value, between 0 and 1 public static void SetKeyboardLighting(KeyboardKeys key, float r, float g, float b) { EnsureInitialized(); - foreach (var system in systems) + foreach (var system in systems.Values) system.SetKeyboardLighting(key, r, g, b); } @@ -141,7 +151,7 @@ namespace Illumilib { /// The color's blue value, between 0 and 1 public static void SetMouseLighting(float r, float g, float b) { EnsureInitialized(); - foreach (var system in systems) + foreach (var system in systems.Values) system.SetMouseLighting(r, g, b); } diff --git a/Illumilib/LightingType.cs b/Illumilib/LightingType.cs new file mode 100644 index 0000000..d6aea10 --- /dev/null +++ b/Illumilib/LightingType.cs @@ -0,0 +1,24 @@ +using Illumilib.System; + +namespace Illumilib { + /// + /// An enumeration of possible lighting engines that Illumilib currently supports. + /// To query whether a lighting type is available, see . + /// + public enum LightingType { + + /// + /// The logitech lighting type, controlled by . + /// + Logitech, + /// + /// The corsair lighting type, controlled by . + /// + Corsair, + /// + /// The razer lighting type, controlled by . + /// + Razer + + } +} \ No newline at end of file diff --git a/Illumilib/System/CorsairLighting.cs b/Illumilib/System/CorsairLighting.cs index 19d732d..c0d4493 100644 --- a/Illumilib/System/CorsairLighting.cs +++ b/Illumilib/System/CorsairLighting.cs @@ -5,6 +5,8 @@ using Corsair.CUE.SDK; namespace Illumilib.System { internal class CorsairLighting : LightingSystem { + public override LightingType Type => LightingType.Corsair; + private DeviceInfo[] devices; public override bool Initialize() { diff --git a/Illumilib/System/LightingSystem.cs b/Illumilib/System/LightingSystem.cs index d4e7fcc..e372211 100644 --- a/Illumilib/System/LightingSystem.cs +++ b/Illumilib/System/LightingSystem.cs @@ -3,6 +3,8 @@ namespace Illumilib.System { internal abstract class LightingSystem : IDisposable { + public abstract LightingType Type { get; } + public abstract bool Initialize(); public abstract void Dispose(); diff --git a/Illumilib/System/LogitechLighting.cs b/Illumilib/System/LogitechLighting.cs index 50f3751..64d739e 100644 --- a/Illumilib/System/LogitechLighting.cs +++ b/Illumilib/System/LogitechLighting.cs @@ -3,6 +3,8 @@ namespace Illumilib.System { internal class LogitechLighting : LightingSystem { + public override LightingType Type => LightingType.Logitech; + private readonly byte[] bitmap = new byte[LogitechGsdk.LogiLedBitmapSize]; private bool bitmapDirty; diff --git a/Illumilib/System/RazerLighting.cs b/Illumilib/System/RazerLighting.cs index 1dfb97f..a567bf8 100644 --- a/Illumilib/System/RazerLighting.cs +++ b/Illumilib/System/RazerLighting.cs @@ -5,6 +5,8 @@ using Colore.Effects.Keyboard; namespace Illumilib.System { internal class RazerLighting : LightingSystem { + public override LightingType Type => LightingType.Razer; + private IChroma chroma; private CustomKeyboardEffect effect = new CustomKeyboardEffect(Color.Black); private bool effectOutdated;