mirror of
https://github.com/Ellpeck/Illumilib.git
synced 2024-11-23 12:18:36 +01:00
code cleanup
This commit is contained in:
parent
e45344d211
commit
8f742b1eeb
8 changed files with 57 additions and 57 deletions
|
@ -6,7 +6,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Illumilib\Illumilib.csproj" />
|
<ProjectReference Include="..\Illumilib\Illumilib.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -14,49 +14,49 @@ namespace Demo {
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Setting all lights to blue");
|
Console.WriteLine("Setting all lights to blue");
|
||||||
IllumilibLighting.SetAllLighting(r: 0, g: 0, b: 1);
|
IllumilibLighting.SetAllLighting(0, 0, 1);
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(3));
|
Thread.Sleep(TimeSpan.FromSeconds(3));
|
||||||
IllumilibLighting.SetAllLighting(r: 0, g: 0, b: 0);
|
IllumilibLighting.SetAllLighting(0, 0, 0);
|
||||||
|
|
||||||
Console.WriteLine("Setting specific positions");
|
Console.WriteLine("Setting specific positions");
|
||||||
IllumilibLighting.SetKeyboardLighting(x: 6, y: 1, r: 1, g: 0, b: 1);
|
IllumilibLighting.SetKeyboardLighting(6, 1, 1, 0, 1);
|
||||||
IllumilibLighting.SetKeyboardLighting(x: 16, y: 5, r: 1, g: 0, b: 1);
|
IllumilibLighting.SetKeyboardLighting(16, 5, 1, 0, 1);
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(5));
|
Thread.Sleep(TimeSpan.FromSeconds(5));
|
||||||
IllumilibLighting.SetKeyboardLighting(r: 0, g: 0, b: 0);
|
IllumilibLighting.SetKeyboardLighting(0, 0, 0);
|
||||||
IllumilibLighting.SetKeyboardLighting(x: 8, y: 2, width: 2, height: 2, r: 0, g: 1, b: 0);
|
IllumilibLighting.SetKeyboardLighting(8, 2, 2, 2, 0, 1, 0);
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(5));
|
Thread.Sleep(TimeSpan.FromSeconds(5));
|
||||||
IllumilibLighting.SetKeyboardLighting(r: 0, g: 0, b: 0);
|
IllumilibLighting.SetKeyboardLighting(0, 0, 0);
|
||||||
|
|
||||||
Console.WriteLine("Doing a fun effect");
|
Console.WriteLine("Doing a fun effect");
|
||||||
for (var x = 0; x < IllumilibLighting.KeyboardWidth; x++) {
|
for (var x = 0; x < IllumilibLighting.KeyboardWidth; x++) {
|
||||||
IllumilibLighting.SetKeyboardLighting(x: x, y: 0, width: 1, height: IllumilibLighting.KeyboardHeight, r: 0, g: 0, b: 1);
|
IllumilibLighting.SetKeyboardLighting(x, 0, 1, IllumilibLighting.KeyboardHeight, 0, 0, 1);
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(0.25F));
|
Thread.Sleep(TimeSpan.FromSeconds(0.25F));
|
||||||
}
|
}
|
||||||
for (var x = IllumilibLighting.KeyboardWidth - 1; x >= 0; x--) {
|
for (var x = IllumilibLighting.KeyboardWidth - 1; x >= 0; x--) {
|
||||||
IllumilibLighting.SetKeyboardLighting(x: x, y: 0, width: 1, height: IllumilibLighting.KeyboardHeight, r: 0, g: 0, b: 0);
|
IllumilibLighting.SetKeyboardLighting(x, 0, 1, IllumilibLighting.KeyboardHeight, 0, 0, 0);
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(0.25F));
|
Thread.Sleep(TimeSpan.FromSeconds(0.25F));
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Going through the alphabet");
|
Console.WriteLine("Going through the alphabet");
|
||||||
for (var i = 65; i <= 90; i++) {
|
for (var i = 65; i <= 90; i++) {
|
||||||
var key = (KeyboardKeys) i;
|
var key = (KeyboardKeys) i;
|
||||||
IllumilibLighting.SetKeyboardLighting(key: key, r: 0, g: 1, b: 0);
|
IllumilibLighting.SetKeyboardLighting(key, 0, 1, 0);
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(0.25F));
|
Thread.Sleep(TimeSpan.FromSeconds(0.25F));
|
||||||
IllumilibLighting.SetKeyboardLighting(key: key, r: 0, g: 0, b: 0);
|
IllumilibLighting.SetKeyboardLighting(key, 0, 0, 0);
|
||||||
}
|
}
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(1));
|
Thread.Sleep(TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
Console.WriteLine("Pulsing");
|
Console.WriteLine("Pulsing");
|
||||||
for (var i = 0; i < 500; i++) {
|
for (var i = 0; i < 500; i++) {
|
||||||
var value = (MathF.Sin(i / 50F * MathF.PI) + 1) / 2;
|
var value = (MathF.Sin(i / 50F * MathF.PI) + 1) / 2;
|
||||||
IllumilibLighting.SetAllLighting(r: value, g: 0, b: value);
|
IllumilibLighting.SetAllLighting(value, 0, value);
|
||||||
Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
}
|
}
|
||||||
IllumilibLighting.SetAllLighting(r: 0, g: 0, b: 0);
|
IllumilibLighting.SetAllLighting(0, 0, 0);
|
||||||
|
|
||||||
Console.WriteLine("Setting all supported keys");
|
Console.WriteLine("Setting all supported keys");
|
||||||
foreach (var key in Enum.GetValues<KeyboardKeys>()) {
|
foreach (var key in Enum.GetValues<KeyboardKeys>()) {
|
||||||
IllumilibLighting.SetKeyboardLighting(key: key, r: 1, g: 0, b: 0);
|
IllumilibLighting.SetKeyboardLighting(key, 1, 0, 0);
|
||||||
Thread.Sleep(50);
|
Thread.Sleep(50);
|
||||||
}
|
}
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(15));
|
Thread.Sleep(TimeSpan.FromSeconds(15));
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace Illumilib {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A property that returns whether Illumilib is currently initialized
|
/// A property that returns whether Illumilib is currently initialized
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool Initialized => systems != null;
|
public static bool Initialized => IllumilibLighting.systems != null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes Illumilib, starting all of the supported lighting systems.
|
/// Initializes Illumilib, starting all of the supported lighting systems.
|
||||||
|
@ -31,25 +31,25 @@ namespace Illumilib {
|
||||||
/// <returns>Whether at least one lighting system was successfully initialized</returns>
|
/// <returns>Whether at least one lighting system was successfully initialized</returns>
|
||||||
/// <exception cref="InvalidOperationException">Thrown if Illumilib has already been <see cref="Initialized"/></exception>
|
/// <exception cref="InvalidOperationException">Thrown if Illumilib has already been <see cref="Initialized"/></exception>
|
||||||
public static bool Initialize() {
|
public static bool Initialize() {
|
||||||
if (Initialized)
|
if (IllumilibLighting.Initialized)
|
||||||
throw new InvalidOperationException("Illumilib has already been initialized");
|
throw new InvalidOperationException("Illumilib has already been initialized");
|
||||||
systems = new Dictionary<LightingType, LightingSystem>();
|
IllumilibLighting.systems = new Dictionary<LightingType, LightingSystem>();
|
||||||
foreach (var system in new LightingSystem[] {new LogitechLighting(), new RazerLighting(), new CorsairLighting()}) {
|
foreach (var system in new LightingSystem[] {new LogitechLighting(), new RazerLighting(), new CorsairLighting()}) {
|
||||||
if (system.Initialize())
|
if (system.Initialize())
|
||||||
systems.Add(system.Type, system);
|
IllumilibLighting.systems.Add(system.Type, system);
|
||||||
}
|
}
|
||||||
return systems.Count > 0;
|
return IllumilibLighting.systems.Count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disposes Illumilib, disposing all of the underlying lighting systems
|
/// Disposes Illumilib, disposing all of the underlying lighting systems
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Dispose() {
|
public static void Dispose() {
|
||||||
if (!Initialized)
|
if (!IllumilibLighting.Initialized)
|
||||||
return;
|
return;
|
||||||
foreach (var system in systems.Values)
|
foreach (var system in IllumilibLighting.systems.Values)
|
||||||
system.Dispose();
|
system.Dispose();
|
||||||
systems = null;
|
IllumilibLighting.systems = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -58,8 +58,8 @@ namespace Illumilib {
|
||||||
/// <param name="type">The <see cref="LightingType"/> to query.</param>
|
/// <param name="type">The <see cref="LightingType"/> to query.</param>
|
||||||
/// <returns>Whether the given <see cref="LightingType"/> has been initialized and is enabled.</returns>
|
/// <returns>Whether the given <see cref="LightingType"/> has been initialized and is enabled.</returns>
|
||||||
public static bool IsEnabled(LightingType type) {
|
public static bool IsEnabled(LightingType type) {
|
||||||
EnsureInitialized();
|
IllumilibLighting.EnsureInitialized();
|
||||||
return systems.ContainsKey(type);
|
return IllumilibLighting.systems.ContainsKey(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -69,8 +69,8 @@ namespace Illumilib {
|
||||||
/// <param name="g">The color's green value, between 0 and 1</param>
|
/// <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>
|
/// <param name="b">The color's blue value, between 0 and 1</param>
|
||||||
public static void SetAllLighting(float r, float g, float b) {
|
public static void SetAllLighting(float r, float g, float b) {
|
||||||
EnsureInitialized();
|
IllumilibLighting.EnsureInitialized();
|
||||||
foreach (var system in systems.Values)
|
foreach (var system in IllumilibLighting.systems.Values)
|
||||||
system.SetAllLighting(r, g, b);
|
system.SetAllLighting(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,8 +81,8 @@ namespace Illumilib {
|
||||||
/// <param name="g">The color's green value, between 0 and 1</param>
|
/// <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>
|
/// <param name="b">The color's blue value, between 0 and 1</param>
|
||||||
public static void SetKeyboardLighting(float r, float g, float b) {
|
public static void SetKeyboardLighting(float r, float g, float b) {
|
||||||
EnsureInitialized();
|
IllumilibLighting.EnsureInitialized();
|
||||||
foreach (var system in systems.Values)
|
foreach (var system in IllumilibLighting.systems.Values)
|
||||||
system.SetKeyboardLighting(r, g, b);
|
system.SetKeyboardLighting(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,12 +97,12 @@ namespace Illumilib {
|
||||||
/// <param name="b">The color's blue value, between 0 and 1</param>
|
/// <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>
|
/// <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) {
|
public static void SetKeyboardLighting(int x, int y, float r, float g, float b) {
|
||||||
EnsureInitialized();
|
IllumilibLighting.EnsureInitialized();
|
||||||
if (x < 0 || x >= KeyboardWidth)
|
if (x < 0 || x >= IllumilibLighting.KeyboardWidth)
|
||||||
throw new ArgumentOutOfRangeException(nameof(x));
|
throw new ArgumentOutOfRangeException(nameof(x));
|
||||||
if (y < 0 || y >= KeyboardHeight)
|
if (y < 0 || y >= IllumilibLighting.KeyboardHeight)
|
||||||
throw new ArgumentOutOfRangeException(nameof(y));
|
throw new ArgumentOutOfRangeException(nameof(y));
|
||||||
foreach (var system in systems.Values)
|
foreach (var system in IllumilibLighting.systems.Values)
|
||||||
system.SetKeyboardLighting(x, y, r, g, b);
|
system.SetKeyboardLighting(x, y, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,12 +120,12 @@ namespace Illumilib {
|
||||||
/// <param name="b">The color's blue value, between 0 and 1</param>
|
/// <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>
|
/// <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) {
|
public static void SetKeyboardLighting(int x, int y, int width, int height, float r, float g, float b) {
|
||||||
EnsureInitialized();
|
IllumilibLighting.EnsureInitialized();
|
||||||
if (x < 0 || x + width > KeyboardWidth)
|
if (x < 0 || x + width > IllumilibLighting.KeyboardWidth)
|
||||||
throw new ArgumentOutOfRangeException(nameof(x));
|
throw new ArgumentOutOfRangeException(nameof(x));
|
||||||
if (y < 0 || y + height > KeyboardHeight)
|
if (y < 0 || y + height > IllumilibLighting.KeyboardHeight)
|
||||||
throw new ArgumentOutOfRangeException(nameof(y));
|
throw new ArgumentOutOfRangeException(nameof(y));
|
||||||
foreach (var system in systems.Values)
|
foreach (var system in IllumilibLighting.systems.Values)
|
||||||
system.SetKeyboardLighting(x, y, width, height, r, g, b);
|
system.SetKeyboardLighting(x, y, width, height, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,8 +138,8 @@ namespace Illumilib {
|
||||||
/// <param name="g">The color's green value, between 0 and 1</param>
|
/// <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>
|
/// <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) {
|
public static void SetKeyboardLighting(KeyboardKeys key, float r, float g, float b) {
|
||||||
EnsureInitialized();
|
IllumilibLighting.EnsureInitialized();
|
||||||
foreach (var system in systems.Values)
|
foreach (var system in IllumilibLighting.systems.Values)
|
||||||
system.SetKeyboardLighting(key, r, g, b);
|
system.SetKeyboardLighting(key, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,13 +150,13 @@ namespace Illumilib {
|
||||||
/// <param name="g">The color's green value, between 0 and 1</param>
|
/// <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>
|
/// <param name="b">The color's blue value, between 0 and 1</param>
|
||||||
public static void SetMouseLighting(float r, float g, float b) {
|
public static void SetMouseLighting(float r, float g, float b) {
|
||||||
EnsureInitialized();
|
IllumilibLighting.EnsureInitialized();
|
||||||
foreach (var system in systems.Values)
|
foreach (var system in IllumilibLighting.systems.Values)
|
||||||
system.SetMouseLighting(r, g, b);
|
system.SetMouseLighting(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void EnsureInitialized() {
|
private static void EnsureInitialized() {
|
||||||
if (!Initialized)
|
if (!IllumilibLighting.Initialized)
|
||||||
throw new InvalidOperationException("Illumilib has not been initialized yet");
|
throw new InvalidOperationException("Illumilib has not been initialized yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,16 +138,16 @@ namespace Illumilib.Lib {
|
||||||
private const int LogiDevicetypeRgbOrd = 1;
|
private const int LogiDevicetypeRgbOrd = 1;
|
||||||
private const int LogiDevicetypePerkeyRgbOrd = 2;
|
private const int LogiDevicetypePerkeyRgbOrd = 2;
|
||||||
|
|
||||||
public const int LogiDevicetypeMonochrome = (1 << LogiDevicetypeMonochromeOrd);
|
public const int LogiDevicetypeMonochrome = 1 << LogitechGsdk.LogiDevicetypeMonochromeOrd;
|
||||||
public const int LogiDevicetypeRgb = (1 << LogiDevicetypeRgbOrd);
|
public const int LogiDevicetypeRgb = 1 << LogitechGsdk.LogiDevicetypeRgbOrd;
|
||||||
public const int LogiDevicetypePerkeyRgb = (1 << LogiDevicetypePerkeyRgbOrd);
|
public const int LogiDevicetypePerkeyRgb = 1 << LogitechGsdk.LogiDevicetypePerkeyRgbOrd;
|
||||||
public const int LogiDevicetypeAll = (LogiDevicetypeMonochrome | LogiDevicetypeRgb | LogiDevicetypePerkeyRgb);
|
public const int LogiDevicetypeAll = LogitechGsdk.LogiDevicetypeMonochrome | LogitechGsdk.LogiDevicetypeRgb | LogitechGsdk.LogiDevicetypePerkeyRgb;
|
||||||
|
|
||||||
public const int LogiLedBitmapWidth = 21;
|
public const int LogiLedBitmapWidth = 21;
|
||||||
public const int LogiLedBitmapHeight = 6;
|
public const int LogiLedBitmapHeight = 6;
|
||||||
public const int LogiLedBitmapBytesPerKey = 4;
|
public const int LogiLedBitmapBytesPerKey = 4;
|
||||||
|
|
||||||
public const int LogiLedBitmapSize = LogiLedBitmapWidth * LogiLedBitmapHeight * LogiLedBitmapBytesPerKey;
|
public const int LogiLedBitmapSize = LogitechGsdk.LogiLedBitmapWidth * LogitechGsdk.LogiLedBitmapHeight * LogitechGsdk.LogiLedBitmapBytesPerKey;
|
||||||
public const int LogiLedDurationInfinite = 0;
|
public const int LogiLedDurationInfinite = 0;
|
||||||
|
|
||||||
[DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace Illumilib.System {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetKeyboardLighting(KeyboardKeys key, float r, float g, float b) {
|
public override void SetKeyboardLighting(KeyboardKeys key, float r, float g, float b) {
|
||||||
var id = ConvertKey(key);
|
var id = CorsairLighting.ConvertKey(key);
|
||||||
foreach (var device in this.devices) {
|
foreach (var device in this.devices) {
|
||||||
if (!device.IsKeyboard())
|
if (!device.IsKeyboard())
|
||||||
continue;
|
continue;
|
||||||
|
@ -344,12 +344,12 @@ namespace Illumilib.System {
|
||||||
|
|
||||||
public void SetAllColors(float r, float g, float b) {
|
public void SetAllColors(float r, float g, float b) {
|
||||||
foreach (var color in this.colors)
|
foreach (var color in this.colors)
|
||||||
SetColor(color, r, g, b);
|
DeviceInfo.SetColor(color, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SetColorForId(CorsairLedId id, float r, float g, float b) {
|
public bool SetColorForId(CorsairLedId id, float r, float g, float b) {
|
||||||
if (this.ledIdToColorIndex.TryGetValue(id, out var index)) {
|
if (this.ledIdToColorIndex.TryGetValue(id, out var index)) {
|
||||||
SetColor(this.colors[index], r, g, b);
|
DeviceInfo.SetColor(this.colors[index], r, g, b);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace Illumilib.System {
|
||||||
|
|
||||||
public override void SetKeyboardLighting(KeyboardKeys key, float r, float g, float b) {
|
public override void SetKeyboardLighting(KeyboardKeys key, float r, float g, float b) {
|
||||||
this.ClearBitmap();
|
this.ClearBitmap();
|
||||||
LogitechGsdk.LogiLedSetLightingForKeyWithKeyName(ConvertKey(key), (int) (r * 100), (int) (g * 100), (int) (b * 100));
|
LogitechGsdk.LogiLedSetLightingForKeyWithKeyName(LogitechLighting.ConvertKey(key), (int) (r * 100), (int) (g * 100), (int) (b * 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetMouseLighting(float r, float g, float b) {
|
public override void SetMouseLighting(float r, float g, float b) {
|
||||||
|
|
|
@ -59,7 +59,7 @@ namespace Illumilib.System {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetKeyboardLighting(KeyboardKeys key, float r, float g, float b) {
|
public override void SetKeyboardLighting(KeyboardKeys key, float r, float g, float b) {
|
||||||
this.chroma.Keyboard?.SetKeyAsync(ConvertKey(key), new Color(r, g, b));
|
this.chroma.Keyboard?.SetKeyAsync(RazerLighting.ConvertKey(key), new Color(r, g, b));
|
||||||
this.effectOutdated = true;
|
this.effectOutdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue