Compare commits

...

3 commits

Author SHA1 Message Date
Ell 9a5391573b 1.2.3 2022-01-19 12:14:21 +01:00
Ell 1a123e5f27 added the ability to query whether certain lighting engines are supported 2022-01-19 12:12:36 +01:00
Ell 4b346e85bc replace lambdas with loops 2022-01-19 11:51:59 +01:00
8 changed files with 75 additions and 16 deletions

View file

@ -8,6 +8,11 @@ namespace Demo {
private static void Main(string[] args) {
IllumilibLighting.Initialize();
foreach (var type in Enum.GetValues<LightingType>()) {
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));

View file

@ -11,7 +11,8 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>Logo.png</PackageIcon>
<VersionPrefix>1.2.2</VersionPrefix>
<VersionPrefix>1.2.3</VersionPrefix>
<NoWarn>NU1701</NoWarn>
</PropertyGroup>
<ItemGroup>
@ -24,7 +25,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Colore" Version="6.0.0"/>
<PackageReference Include="CUESDK.NET" Version="3.0.361.2"/>
<PackageReference Include="Colore" Version="6.0.0" />
<PackageReference Include="CUESDK.NET" Version="3.0.361.2" />
</ItemGroup>
</Project>

View file

@ -18,7 +18,7 @@ namespace Illumilib {
/// </summary>
public const int KeyboardHeight = 6;
private static List<LightingSystem> systems;
private static Dictionary<LightingType, LightingSystem> systems;
/// <summary>
/// A property that returns whether Illumilib is currently initialized
/// </summary>
@ -33,10 +33,10 @@ namespace Illumilib {
public static bool Initialize() {
if (Initialized)
throw new InvalidOperationException("Illumilib has already been initialized");
systems = new List<LightingSystem>();
systems = new Dictionary<LightingType, LightingSystem>();
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,10 +47,21 @@ namespace Illumilib {
public static void Dispose() {
if (!Initialized)
return;
ForEach(s => s.Dispose());
foreach (var system in systems.Values)
system.Dispose();
systems = null;
}
/// <summary>
/// Returns whether the given <see cref="LightingType"/> has been initialized successfully and is enabled.
/// </summary>
/// <param name="type">The <see cref="LightingType"/> to query.</param>
/// <returns>Whether the given <see cref="LightingType"/> has been initialized and is enabled.</returns>
public static bool IsEnabled(LightingType type) {
EnsureInitialized();
return systems.ContainsKey(type);
}
/// <summary>
/// Sets the lighting for all keyboards and mice to the given color
/// </summary>
@ -58,7 +69,9 @@ namespace Illumilib {
/// <param name="g">The color's green value, between 0 and 1</param>
/// <param name="b">The color's blue value, between 0 and 1</param>
public static void SetAllLighting(float r, float g, float b) {
ForEach(s => s.SetAllLighting(r, g, b));
EnsureInitialized();
foreach (var system in systems.Values)
system.SetAllLighting(r, g, b);
}
/// <summary>
@ -68,7 +81,9 @@ namespace Illumilib {
/// <param name="g">The color's green value, between 0 and 1</param>
/// <param name="b">The color's blue value, between 0 and 1</param>
public static void SetKeyboardLighting(float r, float g, float b) {
ForEach(s => s.SetKeyboardLighting(r, g, b));
EnsureInitialized();
foreach (var system in systems.Values)
system.SetKeyboardLighting(r, g, b);
}
/// <summary>
@ -82,11 +97,13 @@ namespace Illumilib {
/// <param name="b">The color's blue value, between 0 and 1</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown if the positions are out of range in relation to <see cref="KeyboardWidth"/> and <see cref="KeyboardHeight"/></exception>
public static void SetKeyboardLighting(int x, int y, float r, float g, float b) {
EnsureInitialized();
if (x < 0 || x >= KeyboardWidth)
throw new ArgumentOutOfRangeException(nameof(x));
if (y < 0 || y >= KeyboardHeight)
throw new ArgumentOutOfRangeException(nameof(y));
ForEach(s => s.SetKeyboardLighting(x, y, r, g, b));
foreach (var system in systems.Values)
system.SetKeyboardLighting(x, y, r, g, b);
}
/// <summary>
@ -103,11 +120,13 @@ namespace Illumilib {
/// <param name="b">The color's blue value, between 0 and 1</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown if the positions are out of range in relation to <see cref="KeyboardWidth"/> and <see cref="KeyboardHeight"/></exception>
public static void SetKeyboardLighting(int x, int y, int width, int height, float r, float g, float b) {
EnsureInitialized();
if (x < 0 || x + width > KeyboardWidth)
throw new ArgumentOutOfRangeException(nameof(x));
if (y < 0 || y + height > KeyboardHeight)
throw new ArgumentOutOfRangeException(nameof(y));
ForEach(s => s.SetKeyboardLighting(x, y, width, height, r, g, b));
foreach (var system in systems.Values)
system.SetKeyboardLighting(x, y, width, height, r, g, b);
}
/// <summary>
@ -119,7 +138,9 @@ namespace Illumilib {
/// <param name="g">The color's green value, between 0 and 1</param>
/// <param name="b">The color's blue value, between 0 and 1</param>
public static void SetKeyboardLighting(KeyboardKeys key, float r, float g, float b) {
ForEach(s => s.SetKeyboardLighting(key, r, g, b));
EnsureInitialized();
foreach (var system in systems.Values)
system.SetKeyboardLighting(key, r, g, b);
}
/// <summary>
@ -129,14 +150,14 @@ namespace Illumilib {
/// <param name="g">The color's green value, between 0 and 1</param>
/// <param name="b">The color's blue value, between 0 and 1</param>
public static void SetMouseLighting(float r, float g, float b) {
ForEach(s => s.SetMouseLighting(r, g, b));
EnsureInitialized();
foreach (var system in systems.Values)
system.SetMouseLighting(r, g, b);
}
private static void ForEach(Action<LightingSystem> action) {
private static void EnsureInitialized() {
if (!Initialized)
throw new InvalidOperationException("Illumilib has not been initialized yet");
foreach (var system in systems)
action(system);
}
}

24
Illumilib/LightingType.cs Normal file
View file

@ -0,0 +1,24 @@
using Illumilib.System;
namespace Illumilib {
/// <summary>
/// An enumeration of possible lighting engines that Illumilib currently supports.
/// To query whether a lighting type is available, see <see cref="IllumilibLighting.IsEnabled"/>.
/// </summary>
public enum LightingType {
/// <summary>
/// The logitech lighting type, controlled by <see cref="LogitechLighting"/>.
/// </summary>
Logitech,
/// <summary>
/// The corsair lighting type, controlled by <see cref="CorsairLighting"/>.
/// </summary>
Corsair,
/// <summary>
/// The razer lighting type, controlled by <see cref="RazerLighting"/>.
/// </summary>
Razer
}
}

View file

@ -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() {

View file

@ -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();

View file

@ -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;

View file

@ -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;