Fixed warnings

This commit is contained in:
DarthAffe committed 2021-02-02 23:37:56 +01:00
1 parent 57dc9afb32
commit a0a1521658
118 files changed
+802 -1181

No files matched your search

@@ -22,7 +22,7 @@ namespace RGB.NET.Devices.Logitech
/// Gets or sets the update queue performing updates for this device.
/// </summary>
// ReSharper disable once MemberCanBePrivate.Global
protected UpdateQueue UpdateQueue { get; set; }
protected UpdateQueue? UpdateQueue { get; set; }
#endregion
@@ -34,16 +34,6 @@ namespace RGB.NET.Devices.Logitech
/// </summary>
public int Zones { get; }
/// <summary>
/// Gets the layout used to decide which images to load.
/// </summary>
internal string ImageLayout { get; }
/// <summary>
/// Gets the path/name of the layout-file.
/// </summary>
internal string LayoutPath { get; }
#endregion
#region Constructors
@@ -57,15 +47,12 @@ namespace RGB.NET.Devices.Logitech
/// <param name="zones">The amount of zones the device is able to control.</param>
/// <param name="imageLayout">The layout used to decide which images to load.</param>
/// <param name="layoutPath">The path/name of the layout-file.</param>
internal LogitechRGBDeviceInfo(RGBDeviceType deviceType, string model, LogitechDeviceCaps deviceCaps,
int zones, string imageLayout, string layoutPath)
internal LogitechRGBDeviceInfo(RGBDeviceType deviceType, string model, LogitechDeviceCaps deviceCaps, int zones)
{
this.DeviceType = deviceType;
this.Model = model;
this.DeviceCaps = deviceCaps;
this.Zones = zones;
this.ImageLayout = imageLayout;
this.LayoutPath = layoutPath;
DeviceName = $"{Manufacturer} {Model}";
}
+65 -69
View File
@@ -5,83 +5,81 @@ using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech.HID
{
//TODO DarthAffe 04.02.2017: Rewrite this once the SDK supports per-device lighting to get all the devices connected.
internal static class DeviceChecker
{
#region Constants
private const int VENDOR_ID = 0x046D;
//TODO DarthAffe 14.11.2017: Add devices
private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> PER_KEY_DEVICES
= new List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>
{
("G910", RGBDeviceType.Keyboard, 0xC32B, 0, "DE", @"Keyboards\G910\UK"), //TODO DarthAffe 15.11.2017: Somehow detect the current layout
("G910v2", RGBDeviceType.Keyboard, 0xC335, 0, "DE", @"Keyboards\G910\UK"),
("G915", RGBDeviceType.Keyboard, 0xC541, 0, "DE", @"Keyboards\G915\UK"),
("G810", RGBDeviceType.Keyboard, 0xC337, 0, "DE", @"Keyboards\G810\UK"),
("G810", RGBDeviceType.Keyboard, 0xC331, 0, "DE", @"Keyboards\G810\UK"),
("G610", RGBDeviceType.Keyboard, 0xC333, 0, "DE", @"Keyboards\G610\UK"),
("G512", RGBDeviceType.Keyboard, 0xC33C, 0, "DE", @"Keyboards\G512\UK"),
("G512 SE", RGBDeviceType.Keyboard, 0xC342, 0, "DE", @"Keyboards\G512SE\UK"),
("G410", RGBDeviceType.Keyboard, 0xC330, 0, "DE", @"Keyboards\G410\UK"),
("G213", RGBDeviceType.Keyboard, 0xC336, 0, "DE", @"Keyboards\G213\UK"),
("Pro", RGBDeviceType.Keyboard, 0xC339, 0, "DE", @"Keyboards\Pro\UK"),
("G915 TKL", RGBDeviceType.Keyboard, 0xC343, 0, "DE", @"Keyboards\G915TKL\UK"),
("Lightspeed Keyboard Dongle", RGBDeviceType.Keyboard, 0xC545, 0, "DE", @"Keyboards\G915\UK"),
};
private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones)> PER_KEY_DEVICES
= new()
{
("G910", RGBDeviceType.Keyboard, 0xC32B, 0),
("G910v2", RGBDeviceType.Keyboard, 0xC335, 0),
("G915", RGBDeviceType.Keyboard, 0xC541, 0),
("G810", RGBDeviceType.Keyboard, 0xC337, 0),
("G810", RGBDeviceType.Keyboard, 0xC331, 0),
("G610", RGBDeviceType.Keyboard, 0xC333, 0),
("G512", RGBDeviceType.Keyboard, 0xC33C, 0),
("G512 SE", RGBDeviceType.Keyboard, 0xC342, 0),
("G410", RGBDeviceType.Keyboard, 0xC330, 0),
("G213", RGBDeviceType.Keyboard, 0xC336, 0),
("Pro", RGBDeviceType.Keyboard, 0xC339, 0),
("G915 TKL", RGBDeviceType.Keyboard, 0xC343, 0),
("Lightspeed Keyboard Dongle", RGBDeviceType.Keyboard, 0xC545, 0),
};
private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> PER_DEVICE_DEVICES
= new List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>
{
("G19", RGBDeviceType.Keyboard, 0xC228, 0, "DE", @"Keyboards\G19\UK"),
("G19s", RGBDeviceType.Keyboard, 0xC229, 0, "DE", @"Keyboards\G19s\UK"),
("G600", RGBDeviceType.Mouse, 0xC24A, 0, "default", @"Mice\G600"),
("G300s", RGBDeviceType.Mouse, 0xC246, 0, "default", @"Mice\G300s"),
("G510", RGBDeviceType.Keyboard, 0xC22D, 0, "DE", @"Keyboards\G510\UK"),
("G510s", RGBDeviceType.Keyboard, 0xC22E, 0, "DE", @"Keyboards\G510s\UK"),
("G13", RGBDeviceType.Keypad, 0xC21C, 0, "DE", @"Keypads\G13\UK"),
("G110", RGBDeviceType.Keyboard, 0xC22B, 0, "DE", @"Keyboards\G110\UK"),
("G710+", RGBDeviceType.Keyboard, 0xC24D, 0, "DE", @"Keyboards\G710+\UK"),
("G105", RGBDeviceType.Keyboard, 0xC248, 0, "DE", @"Keyboards\G105\UK"),
("G15", RGBDeviceType.Keyboard, 0xC222, 0, "DE", @"Keyboards\G15\UK"),
("G11", RGBDeviceType.Keyboard, 0xC225, 0, "DE", @"Keyboards\G11\UK"),
};
private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones)> PER_DEVICE_DEVICES
= new()
{
("G19", RGBDeviceType.Keyboard, 0xC228, 0),
("G19s", RGBDeviceType.Keyboard, 0xC229, 0),
("G600", RGBDeviceType.Mouse, 0xC24A, 0),
("G300s", RGBDeviceType.Mouse, 0xC246, 0),
("G510", RGBDeviceType.Keyboard, 0xC22D, 0),
("G510s", RGBDeviceType.Keyboard, 0xC22E, 0),
("G13", RGBDeviceType.Keypad, 0xC21C, 0),
("G110", RGBDeviceType.Keyboard, 0xC22B, 0),
("G710+", RGBDeviceType.Keyboard, 0xC24D, 0),
("G105", RGBDeviceType.Keyboard, 0xC248, 0),
("G15", RGBDeviceType.Keyboard, 0xC222, 0),
("G11", RGBDeviceType.Keyboard, 0xC225, 0),
};
private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> ZONE_DEVICES
= new List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>
{
("G213", RGBDeviceType.Keyboard, 0xC336, 5, "default", @"Keyboards\G213"),
("G903", RGBDeviceType.Mouse, 0xC086, 2, "default", @"Mice\G903"),
("Lightspeed Mouse Dongle", RGBDeviceType.Mouse, 0xC539, 2, "default", @"Mice\G900"),
("G703", RGBDeviceType.Mouse, 0xC087, 2, "default", @"Mice\G703"),
("G502 HERO", RGBDeviceType.Mouse, 0xC08B, 2, "default", @"Mice\G502"),
("G502 Lightspeed", RGBDeviceType.Mouse, 0xC08D, 2, "default", @"Mice\G502"),
("G502", RGBDeviceType.Mouse, 0xC332, 2, "default", @"Mice\G502"),
("G403", RGBDeviceType.Mouse, 0xC083, 2, "default", @"Mice\G403"),
("G303", RGBDeviceType.Mouse, 0xC080, 2, "default", @"Mice\G303"),
("G203", RGBDeviceType.Mouse, 0xC084, 1, "default", @"Mice\G203"),
("G Pro", RGBDeviceType.Mouse, 0xC085, 1, "default", @"Mice\GPro"),
("G Pro Wireless", RGBDeviceType.Mouse, 0xC088, 2, "default", @"Mice\GProWireless"),
("G Pro Hero", RGBDeviceType.Mouse, 0xC08C, 1, "default", @"Mice\GProHero"),
("G633", RGBDeviceType.Headset, 0x0A5C, 2, "default", @"Headsets\G633"),
("G933", RGBDeviceType.Headset, 0x0A5B, 2, "default", @"Headsets\G933"),
("G935", RGBDeviceType.Headset, 0x0A87, 2, "default", @"Headsets\G935"),
("G560", RGBDeviceType.Speaker, 0x0A78, 4, "default", @"Speakers\G560"),
};
private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones)> ZONE_DEVICES
= new()
{
("G213", RGBDeviceType.Keyboard, 0xC336, 5),
("G903", RGBDeviceType.Mouse, 0xC086, 2),
("Lightspeed Mouse Dongle", RGBDeviceType.Mouse, 0xC539, 2),
("G703", RGBDeviceType.Mouse, 0xC087, 2),
("G502 HERO", RGBDeviceType.Mouse, 0xC08B, 2),
("G502 Lightspeed", RGBDeviceType.Mouse, 0xC08D, 2),
("G502", RGBDeviceType.Mouse, 0xC332, 2),
("G403", RGBDeviceType.Mouse, 0xC083, 2),
("G303", RGBDeviceType.Mouse, 0xC080, 2),
("G203", RGBDeviceType.Mouse, 0xC084, 1),
("G Pro", RGBDeviceType.Mouse, 0xC085, 1),
("G Pro Wireless", RGBDeviceType.Mouse, 0xC088, 2),
("G Pro Hero", RGBDeviceType.Mouse, 0xC08C, 1),
("G633", RGBDeviceType.Headset, 0x0A5C, 2),
("G933", RGBDeviceType.Headset, 0x0A5B, 2),
("G935", RGBDeviceType.Headset, 0x0A87, 2),
("G560", RGBDeviceType.Speaker, 0x0A78, 4),
};
#endregion
#region Properties & Fields
public static bool IsPerKeyDeviceConnected { get; private set; }
public static (string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath) PerKeyDeviceData { get; private set; }
public static (string model, RGBDeviceType deviceType, int id, int zones) PerKeyDeviceData { get; private set; }
public static bool IsPerDeviceDeviceConnected { get; private set; }
public static (string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath) PerDeviceDeviceData { get; private set; }
public static (string model, RGBDeviceType deviceType, int id, int zones) PerDeviceDeviceData { get; private set; }
public static bool IsZoneDeviceConnected { get; private set; }
public static IEnumerable<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> ZoneDeviceData { get; private set; }
public static IEnumerable<(string model, RGBDeviceType deviceType, int id, int zones)> ZoneDeviceData { get; private set; } = Enumerable.Empty<(string model, RGBDeviceType deviceType, int id, int zones)>();
#endregion
@@ -91,7 +89,7 @@ namespace RGB.NET.Devices.Logitech.HID
{
List<int> ids = DeviceList.Local.GetHidDevices(VENDOR_ID).Select(x => x.ProductID).Distinct().ToList();
foreach ((string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath) deviceData in PER_KEY_DEVICES)
foreach ((string model, RGBDeviceType deviceType, int id, int zones) deviceData in PER_KEY_DEVICES)
if (ids.Contains(deviceData.id))
{
IsPerKeyDeviceConnected = true;
@@ -99,7 +97,7 @@ namespace RGB.NET.Devices.Logitech.HID
break;
}
foreach ((string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath) deviceData in PER_DEVICE_DEVICES)
foreach ((string model, RGBDeviceType deviceType, int id, int zones) deviceData in PER_DEVICE_DEVICES)
if (ids.Contains(deviceData.id))
{
IsPerDeviceDeviceConnected = true;
@@ -107,21 +105,19 @@ namespace RGB.NET.Devices.Logitech.HID
break;
}
Dictionary<RGBDeviceType, List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>> connectedZoneDevices
= new Dictionary<RGBDeviceType, List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>>();
foreach ((string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath) deviceData in ZONE_DEVICES)
Dictionary<RGBDeviceType, List<(string model, RGBDeviceType deviceType, int id, int zones)>> connectedZoneDevices = new();
foreach ((string model, RGBDeviceType deviceType, int id, int zones) deviceData in ZONE_DEVICES)
{
if (ids.Contains(deviceData.id))
{
IsZoneDeviceConnected = true;
if (!connectedZoneDevices.TryGetValue(deviceData.deviceType, out List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> deviceList))
connectedZoneDevices.Add(deviceData.deviceType, deviceList = new List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>());
if (!connectedZoneDevices.TryGetValue(deviceData.deviceType, out List<(string model, RGBDeviceType deviceType, int id, int zones)>? deviceList))
connectedZoneDevices.Add(deviceData.deviceType, deviceList = new List<(string model, RGBDeviceType deviceType, int id, int zones)>());
deviceList.Add(deviceData);
}
}
List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> zoneDeviceData
= new List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>();
foreach (KeyValuePair<RGBDeviceType, List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>> connectedZoneDevice in connectedZoneDevices)
List<(string model, RGBDeviceType deviceType, int id, int zones)> zoneDeviceData = new();
foreach (KeyValuePair<RGBDeviceType, List<(string model, RGBDeviceType deviceType, int id, int zones)>> connectedZoneDevice in connectedZoneDevices)
{
int maxZones = connectedZoneDevice.Value.Max(x => x.zones);
zoneDeviceData.Add(connectedZoneDevice.Value.First(x => x.zones == maxZones));
@@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.HID;
using RGB.NET.Devices.Logitech.Native;
@@ -19,7 +19,7 @@ namespace RGB.NET.Devices.Logitech
{
#region Properties & Fields
private static LogitechDeviceProvider _instance;
private static LogitechDeviceProvider? _instance;
/// <summary>
/// Gets the singleton <see cref="LogitechDeviceProvider"/> instance.
/// </summary>
@@ -29,40 +29,27 @@ namespace RGB.NET.Devices.Logitech
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX86NativePaths { get; } = new List<string> { "x86/LogitechLedEnginesWrapper.dll" };
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/LogitechLedEnginesWrapper.dll" };
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX64NativePaths { get; } = new List<string> { "x64/LogitechLedEnginesWrapper.dll" };
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/LogitechLedEnginesWrapper.dll" };
/// <inheritdoc />
public bool IsInitialized { get; private set; }
/// <summary>
/// Gets the loaded architecture (x64/x86).
/// </summary>
public string LoadedArchitecture => _LogitechGSDK.LoadedArchitecture;
/// <inheritdoc />
public IEnumerable<IRGBDevice> Devices { get; private set; }
/// <inheritdoc />
public bool HasExclusiveAccess => false; // Exclusive access isn't possible for logitech devices.
/// <summary>
/// Gets or sets a function to get the culture for a specific device.
/// </summary>
public Func<CultureInfo> GetCulture { get; set; } = CultureHelper.GetCurrentCulture;
public IEnumerable<IRGBDevice> Devices { get; private set; } = Enumerable.Empty<IRGBDevice>();
/// <summary>
/// The <see cref="DeviceUpdateTrigger"/> used to trigger the updates for logitech devices.
/// </summary>
public DeviceUpdateTrigger UpdateTrigger { get; private set; }
public DeviceUpdateTrigger UpdateTrigger { get; }
// ReSharper disable once CollectionNeverQueried.Local - for now this is just to make sure they're never collected
private readonly Dictionary<RGBDeviceType, LogitechZoneUpdateQueue> _zoneUpdateQueues = new Dictionary<RGBDeviceType, LogitechZoneUpdateQueue>();
private readonly Dictionary<RGBDeviceType, LogitechZoneUpdateQueue> _zoneUpdateQueues = new();
private LogitechPerDeviceUpdateQueue _perDeviceUpdateQueue;
private LogitechPerKeyUpdateQueue _perKeyUpdateQueue;
@@ -102,7 +89,7 @@ namespace RGB.NET.Devices.Logitech
try
{
UpdateTrigger?.Stop();
UpdateTrigger.Stop();
_LogitechGSDK.Reload();
if (!_LogitechGSDK.LogiLedInit()) return false;
@@ -116,10 +103,10 @@ namespace RGB.NET.Devices.Logitech
{
if (DeviceChecker.IsPerKeyDeviceConnected)
{
(string model, RGBDeviceType deviceType, int _, int _, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData;
(string model, RGBDeviceType deviceType, int _, int _) = DeviceChecker.PerKeyDeviceData;
if (loadFilter.HasFlag(deviceType)) //TODO DarthAffe 07.12.2017: Check if it's worth to try another device if the one returned doesn't match the filter
{
ILogitechRGBDevice device = new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.PerKeyRGB, 0, imageLayout, layoutPath));
ILogitechRGBDevice device = new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.PerKeyRGB, 0));
device.Initialize(_perKeyUpdateQueue);
devices.Add(device);
}
@@ -131,10 +118,10 @@ namespace RGB.NET.Devices.Logitech
{
if (DeviceChecker.IsPerDeviceDeviceConnected)
{
(string model, RGBDeviceType deviceType, int _, int _, string imageLayout, string layoutPath) = DeviceChecker.PerDeviceDeviceData;
(string model, RGBDeviceType deviceType, int _, int _) = DeviceChecker.PerDeviceDeviceData;
if (loadFilter.HasFlag(deviceType)) //TODO DarthAffe 07.12.2017: Check if it's worth to try another device if the one returned doesn't match the filter
{
ILogitechRGBDevice device = new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, 0, imageLayout, layoutPath));
ILogitechRGBDevice device = new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, 0));
device.Initialize(_perDeviceUpdateQueue);
devices.Add(device);
}
@@ -146,13 +133,13 @@ namespace RGB.NET.Devices.Logitech
{
if (DeviceChecker.IsZoneDeviceConnected)
{
foreach ((string model, RGBDeviceType deviceType, int _, int zones, string imageLayout, string layoutPath) in DeviceChecker.ZoneDeviceData)
foreach ((string model, RGBDeviceType deviceType, int _, int zones) in DeviceChecker.ZoneDeviceData)
try
{
if (loadFilter.HasFlag(deviceType))
{
LogitechZoneUpdateQueue updateQueue = new LogitechZoneUpdateQueue(UpdateTrigger, deviceType);
ILogitechRGBDevice device = new LogitechZoneRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, zones, imageLayout, layoutPath));
LogitechZoneUpdateQueue updateQueue = new(UpdateTrigger, deviceType);
ILogitechRGBDevice device = new LogitechZoneRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, zones));
device.Initialize(updateQueue);
devices.Add(device);
_zoneUpdateQueues.Add(deviceType, updateQueue);
@@ -163,7 +150,7 @@ namespace RGB.NET.Devices.Logitech
}
catch { if (throwExceptions) throw; }
UpdateTrigger?.Start();
UpdateTrigger.Start();
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true;
@@ -17,12 +17,7 @@ namespace RGB.NET.Devices.Logitech.Native
#region Libary Management
private static IntPtr _dllHandle = IntPtr.Zero;
/// <summary>
/// Gets the loaded architecture (x64/x86).
/// </summary>
internal static string LoadedArchitecture { get; private set; }
/// <summary>
/// Reloads the SDK.
/// </summary>
@@ -38,7 +33,7 @@ namespace RGB.NET.Devices.Logitech.Native
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
List<string> possiblePathList = Environment.Is64BitProcess ? LogitechDeviceProvider.PossibleX64NativePaths : LogitechDeviceProvider.PossibleX86NativePaths;
string dllPath = possiblePathList.FirstOrDefault(File.Exists);
string? dllPath = possiblePathList.FirstOrDefault(File.Exists);
if (dllPath == null) throw new RGBDeviceException($"Can't find the Logitech-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
_dllHandle = LoadLibrary(dllPath);
@@ -81,16 +76,16 @@ namespace RGB.NET.Devices.Logitech.Native
#region Pointers
private static LogiLedInitPointer _logiLedInitPointer;
private static LogiLedShutdownPointer _logiLedShutdownPointer;
private static LogiLedSetTargetDevicePointer _logiLedSetTargetDevicePointer;
private static LogiLedGetSdkVersionPointer _logiLedGetSdkVersionPointer;
private static LogiLedSaveCurrentLightingPointer _lgiLedSaveCurrentLightingPointer;
private static LogiLedRestoreLightingPointer _logiLedRestoreLightingPointer;
private static LogiLedSetLightingPointer _logiLedSetLightingPointer;
private static LogiLedSetLightingForKeyWithKeyNamePointer _logiLedSetLightingForKeyWithKeyNamePointer;
private static LogiLedSetLightingFromBitmapPointer _logiLedSetLightingFromBitmapPointer;
private static LogiLedSetLightingForTargetZonePointer _logiLedSetLightingForTargetZonePointer;
private static LogiLedInitPointer? _logiLedInitPointer;
private static LogiLedShutdownPointer? _logiLedShutdownPointer;
private static LogiLedSetTargetDevicePointer? _logiLedSetTargetDevicePointer;
private static LogiLedGetSdkVersionPointer? _logiLedGetSdkVersionPointer;
private static LogiLedSaveCurrentLightingPointer? _lgiLedSaveCurrentLightingPointer;
private static LogiLedRestoreLightingPointer? _logiLedRestoreLightingPointer;
private static LogiLedSetLightingPointer? _logiLedSetLightingPointer;
private static LogiLedSetLightingForKeyWithKeyNamePointer? _logiLedSetLightingForKeyWithKeyNamePointer;
private static LogiLedSetLightingFromBitmapPointer? _logiLedSetLightingFromBitmapPointer;
private static LogiLedSetLightingForTargetZonePointer? _logiLedSetLightingForTargetZonePointer;
#endregion
@@ -130,11 +125,11 @@ namespace RGB.NET.Devices.Logitech.Native
// ReSharper disable EventExceptionNotDocumented
internal static bool LogiLedInit() => _logiLedInitPointer();
internal static bool LogiLedInit() => (_logiLedInitPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static void LogiLedShutdown() => _logiLedShutdownPointer();
internal static void LogiLedShutdown() => (_logiLedShutdownPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static bool LogiLedSetTargetDevice(LogitechDeviceCaps targetDevice) => _logiLedSetTargetDevicePointer((int)targetDevice);
internal static bool LogiLedSetTargetDevice(LogitechDeviceCaps targetDevice) => (_logiLedSetTargetDevicePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke((int)targetDevice);
internal static string LogiLedGetSdkVersion()
{
@@ -146,21 +141,23 @@ namespace RGB.NET.Devices.Logitech.Native
return $"{major}.{minor}.{build}";
}
internal static bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum) => _logiLedGetSdkVersionPointer(ref majorNum, ref minorNum, ref buildNum);
internal static bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum) =>
(_logiLedGetSdkVersionPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(ref majorNum, ref minorNum, ref buildNum);
internal static bool LogiLedSaveCurrentLighting() => _lgiLedSaveCurrentLightingPointer();
internal static bool LogiLedSaveCurrentLighting() => (_lgiLedSaveCurrentLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static bool LogiLedRestoreLighting() => _logiLedRestoreLightingPointer();
internal static bool LogiLedRestoreLighting() => (_logiLedRestoreLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage) => _logiLedSetLightingPointer(redPercentage, greenPercentage, bluePercentage);
internal static bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage) =>
(_logiLedSetLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(redPercentage, greenPercentage, bluePercentage);
internal static bool LogiLedSetLightingForKeyWithKeyName(int keyCode, int redPercentage, int greenPercentage, int bluePercentage)
=> _logiLedSetLightingForKeyWithKeyNamePointer(keyCode, redPercentage, greenPercentage, bluePercentage);
=> (_logiLedSetLightingForKeyWithKeyNamePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(keyCode, redPercentage, greenPercentage, bluePercentage);
internal static bool LogiLedSetLightingFromBitmap(byte[] bitmap) => _logiLedSetLightingFromBitmapPointer(bitmap);
internal static bool LogiLedSetLightingFromBitmap(byte[] bitmap) => (_logiLedSetLightingFromBitmapPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(bitmap);
internal static bool LogiLedSetLightingForTargetZone(LogitechDeviceType deviceType, int zone, int redPercentage, int greenPercentage, int bluePercentage)
=> _logiLedSetLightingForTargetZonePointer(deviceType, zone, redPercentage, greenPercentage, bluePercentage);
=> (_logiLedSetLightingForTargetZonePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(deviceType, zone, redPercentage, greenPercentage, bluePercentage);
// ReSharper restore EventExceptionNotDocumented
@@ -33,10 +33,10 @@ namespace RGB.NET.Devices.Logitech
AddLed(LedId.Custom1, new Point(0, 0), new Size(10, 10));
}
/// <inheritdoc />
protected override object? GetLedCustomData(LedId ledId) => (ledId, LogitechLedId.DEVICE);
protected override object GetLedCustomData(LedId ledId) => (ledId, LogitechLedId.DEVICE);
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0).Take(1));
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0).Take(1));
#endregion
}
@@ -14,8 +14,8 @@ namespace RGB.NET.Devices.Logitech
#region Properties & Fields
internal static Dictionary<LedId, int> BitmapOffset { get; } = new Dictionary<LedId, int>
{
internal static Dictionary<LedId, int> BitmapOffset { get; } = new()
{
{ LedId.Keyboard_Escape, 0 },
{ LedId.Keyboard_F1, 4 },
{ LedId.Keyboard_F2, 8 },
@@ -29,7 +29,7 @@ namespace RGB.NET.Devices.Logitech
protected override object? GetLedCustomData(LedId ledId) => (ledId, PerKeyIdMapping.DEFAULT.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : LogitechLedId.Invalid);
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
#endregion
}
@@ -5,8 +5,8 @@ namespace RGB.NET.Devices.Logitech
{
internal static class PerKeyIdMapping
{
internal static readonly Dictionary<LedId, LogitechLedId> DEFAULT = new Dictionary<LedId, LogitechLedId>
{
internal static readonly Dictionary<LedId, LogitechLedId> DEFAULT = new()
{
{ LedId.Invalid, LogitechLedId.Invalid },
{ LedId.Keyboard_Escape, LogitechLedId.ESC },
{ LedId.Keyboard_F1, LogitechLedId.F1 },
@@ -12,13 +12,13 @@ namespace RGB.NET.Devices.Logitech
{
#region Constants
private static readonly Dictionary<RGBDeviceType, LedId> BASE_LED_MAPPING = new Dictionary<RGBDeviceType, LedId>
private static readonly Dictionary<RGBDeviceType, LedId> BASE_LED_MAPPING = new()
{
{RGBDeviceType.Keyboard, LedId.Keyboard_Programmable1},
{RGBDeviceType.Mouse, LedId.Mouse1},
{RGBDeviceType.Headset, LedId.Headset1},
{RGBDeviceType.Mousepad, LedId.Mousepad1},
{RGBDeviceType.Speaker, LedId.Speaker1}
{ RGBDeviceType.Keyboard, LedId.Keyboard_Programmable1 },
{ RGBDeviceType.Mouse, LedId.Mouse1 },
{ RGBDeviceType.Headset, LedId.Headset1 },
{ RGBDeviceType.Mousepad, LedId.Mousepad1 },
{ RGBDeviceType.Speaker, LedId.Speaker1 }
};
#endregion
@@ -59,7 +59,7 @@ namespace RGB.NET.Devices.Logitech
protected override object? GetLedCustomData(LedId ledId) => (int)(ledId - _baseLedId);
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
#endregion
}
@@ -12,8 +12,8 @@ namespace RGB.NET.Devices.Logitech
{
#region Constants
private static readonly Dictionary<RGBDeviceType, LogitechDeviceType> DEVICE_TYPE_MAPPING = new Dictionary<RGBDeviceType, LogitechDeviceType>
{
private static readonly Dictionary<RGBDeviceType, LogitechDeviceType> DEVICE_TYPE_MAPPING = new()
{
{RGBDeviceType.Keyboard, LogitechDeviceType.Keyboard},
{RGBDeviceType.Mouse, LogitechDeviceType.Mouse},
{RGBDeviceType.Headset, LogitechDeviceType.Headset},