Merge pull request #227 from DarthAffe/CodeIssues

Preparing for first major release
This commit is contained in:
DarthAffe authored and GitHub committed 2021-08-07 17:52:20 +02:00
commit 1bae7fd3de
241 files changed
+2168 -794

No files matched your search

@@ -1,5 +1,10 @@
namespace RGB.NET.Devices.Logitech
#pragma warning disable 1591
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Contains list of available logitech device types.
/// </summary>
public enum LogitechDeviceType
{
Keyboard = 0x0,
@@ -1,4 +1,5 @@
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
// ReSharper disable InconsistentNaming
#pragma warning disable 1591
namespace RGB.NET.Devices.Logitech
{
@@ -2,8 +2,14 @@
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Contains mappings for <see cref="LedId"/> to <see cref="LogitechDeviceCaps"/>.
/// </summary>
public static class LedMappings
{
/// <summary>
/// Gets the mapping for per key devices.
/// </summary>
public static LedMapping<LogitechLedId> PerKey { get; } = new()
{
{ LedId.Keyboard_Escape, LogitechLedId.ESC },
@@ -131,11 +137,17 @@ namespace RGB.NET.Devices.Logitech
{ LedId.Keyboard_Custom1, LogitechLedId.G_BADGE },
};
/// <summary>
/// Gets the mapping for per device devices.
/// </summary>
public static LedMapping<int> Device { get; } = new()
{
{ LedId.Custom1, 0 }
};
/// <summary>
/// Gets the mapping for per zone keyboards.
/// </summary>
public static LedMapping<int> ZoneKeyboard { get; } = new()
{
{ LedId.Keyboard_Programmable1, 0 },
@@ -172,6 +184,9 @@ namespace RGB.NET.Devices.Logitech
{ LedId.Keyboard_Programmable32, 31 },
};
/// <summary>
/// Gets the mapping for per zone mice.
/// </summary>
public static LedMapping<int> ZoneMouse { get; } = new()
{
{ LedId.Mouse1, 0 },
@@ -208,6 +223,9 @@ namespace RGB.NET.Devices.Logitech
{ LedId.Mouse32, 31 },
};
/// <summary>
/// Gets the mapping for per zone headsets.
/// </summary>
public static LedMapping<int> ZoneHeadset { get; } = new()
{
{ LedId.Headset1, 0 },
@@ -244,6 +262,9 @@ namespace RGB.NET.Devices.Logitech
{ LedId.Headset32, 31 },
};
/// <summary>
/// Gets the mapping for per zone mousepads.
/// </summary>
public static LedMapping<int> ZoneMousepad { get; } = new()
{
{ LedId.Mousepad1, 0 },
@@ -280,6 +301,9 @@ namespace RGB.NET.Devices.Logitech
{ LedId.Mousepad32, 31 },
};
/// <summary>
/// Gets the mapping for per zone speakers.
/// </summary>
public static LedMapping<int> ZoneSpeaker { get; } = new()
{
{ LedId.Speaker1, 0 },
@@ -15,6 +15,7 @@ namespace RGB.NET.Devices.Logitech
/// Initializes a new instance of the <see cref="LogitechRGBDevice{TDeviceInfo}"/> class.
/// </summary>
/// <param name="info">The generic information provided by Logitech for the device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
protected LogitechRGBDevice(TDeviceInfo info, IUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
@@ -22,6 +22,7 @@ namespace RGB.NET.Devices.Logitech
/// <inheritdoc />
public string Model { get; }
/// <inheritdoc />
public object? LayoutMetadata { get; set; }
/// <summary>
@@ -45,8 +46,6 @@ namespace RGB.NET.Devices.Logitech
/// <param name="model">The represented device model.</param>
/// <param name="deviceCaps">The lighting-capabilities of the device.</param>
/// <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)
{
this.DeviceType = deviceType;
@@ -42,6 +42,9 @@ namespace RGB.NET.Devices.Logitech
private const int VENDOR_ID = 0x046D;
/// <summary>
/// Gets the HID-definitions for per-key-devices.
/// </summary>
public static HIDLoader<LogitechLedId, int> PerKeyDeviceDefinitions { get; } = new(VENDOR_ID)
{
{ 0xC32B, RGBDeviceType.Keyboard, "G910", LedMappings.PerKey, 0 },
@@ -60,6 +63,9 @@ namespace RGB.NET.Devices.Logitech
{ 0xC545, RGBDeviceType.Keyboard, "Lightspeed Keyboard Dongle", LedMappings.PerKey, 0 },
};
/// <summary>
/// Gets the HID-definitions for per-zone-devices.
/// </summary>
public static HIDLoader<int, (LogitechDeviceType deviceType, int zones)> PerZoneDeviceDefinitions { get; } = new(VENDOR_ID)
{
{ 0xC336, RGBDeviceType.Keyboard, "G213", LedMappings.ZoneKeyboard, (LogitechDeviceType.Keyboard, 2) },
@@ -82,6 +88,9 @@ namespace RGB.NET.Devices.Logitech
{ 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4) },
};
/// <summary>
/// Gets the HID-definitions for per-device-devices.
/// </summary>
public static HIDLoader<int, int> PerDeviceDeviceDefinitions { get; } = new(VENDOR_ID)
{
{ 0xC228, RGBDeviceType.Keyboard, "G19", LedMappings.Device, 0 },
@@ -117,6 +126,7 @@ namespace RGB.NET.Devices.Logitech
#region Methods
/// <inheritdoc />
protected override void InitializeSDK()
{
_perDeviceUpdateQueue = new LogitechPerDeviceUpdateQueue(GetUpdateTrigger());
@@ -128,6 +138,7 @@ namespace RGB.NET.Devices.Logitech
_LogitechGSDK.LogiLedSaveCurrentLighting();
}
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> GetLoadedDevices(RGBDeviceType loadFilter)
{
PerKeyDeviceDefinitions.LoadFilter = loadFilter;
@@ -136,14 +147,14 @@ namespace RGB.NET.Devices.Logitech
return base.GetLoadedDevices(loadFilter);
}
//TODO DarthAffe 04.03.2021: Rework device selection and configuration for HID-based providers
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> LoadDevices()
{
IEnumerable<(HIDDeviceDefinition<LogitechLedId, int> definition, HidDevice device)> perKeyDevices = PerKeyDeviceDefinitions.GetConnectedDevices();
if ((_perKeyUpdateQueue != null) && perKeyDevices.Any())
(HIDDeviceDefinition<LogitechLedId, int> definition, HidDevice device) perKeyDevice = PerKeyDeviceDefinitions.GetConnectedDevices().FirstOrDefault();
if ((_perKeyUpdateQueue != null) && (perKeyDevice != default))
{
(HIDDeviceDefinition<LogitechLedId, int> definition, _) = perKeyDevices.First();
(HIDDeviceDefinition<LogitechLedId, int> definition, _) = perKeyDevice;
yield return new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.PerKeyRGB, 0), _perKeyUpdateQueue, definition.LedMapping);
}
@@ -154,10 +165,10 @@ namespace RGB.NET.Devices.Logitech
yield return new LogitechZoneRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.DeviceRGB, definition.CustomData.zones), updateQueue, definition.LedMapping);
}
IEnumerable<(HIDDeviceDefinition<int, int> definition, HidDevice device)> perDeviceDevices = PerDeviceDeviceDefinitions.GetConnectedDevices();
if ((_perDeviceUpdateQueue != null) && perDeviceDevices.Any())
(HIDDeviceDefinition<int, int> definition, HidDevice device) perDeviceDevice = PerDeviceDeviceDefinitions.GetConnectedDevices().FirstOrDefault();
if ((_perDeviceUpdateQueue != null) && (perDeviceDevice != default))
{
(HIDDeviceDefinition<int, int> definition, _) = perDeviceDevices.First();
(HIDDeviceDefinition<int, int> definition, _) = perDeviceDevice;
yield return new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.DeviceRGB, 0), _perDeviceUpdateQueue, definition.LedMapping);
}
}
@@ -172,6 +183,8 @@ namespace RGB.NET.Devices.Logitech
try { _LogitechGSDK.UnloadLogitechGSDK(); }
catch { /* at least we tried */ }
GC.SuppressFinalize(this);
}
#endregion
@@ -1,4 +1,5 @@
// ReSharper disable UnusedMethodReturnValue.Global
#pragma warning disable IDE1006 // Naming Styles
// ReSharper disable UnusedMethodReturnValue.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable MemberCanBePrivate.Global
@@ -62,13 +63,13 @@ namespace RGB.NET.Devices.Logitech.Native
_dllHandle = IntPtr.Zero;
}
[DllImport("kernel32.dll")]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr dllHandle);
[DllImport("kernel32.dll")]
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
#endregion
@@ -15,11 +15,10 @@
<RootNamespace>RGB.NET.Devices.Logitech</RootNamespace>
<Description>Logitech-Device-Implementations of RGB.NET</Description>
<Summary>Logitech-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals</Summary>
<Copyright>Copyright © Darth Affe 2020</Copyright>
<PackageCopyright>Copyright © Darth Affe 2020</PackageCopyright>
<PackageIconUrl>http://lib.arge.be/icon.png</PackageIconUrl>
<Copyright>Copyright © Darth Affe 2021</Copyright>
<Icon>icon.png</Icon>
<PackageProjectUrl>https://github.com/DarthAffe/RGB.NET</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE</PackageLicenseUrl>
<License>LGPL-2.1-only</License>
<RepositoryType>Github</RepositoryType>
<RepositoryUrl>https://github.com/DarthAffe/RGB.NET</RepositoryUrl>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
@@ -34,22 +33,26 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSource>True</IncludeSource>
<IncludeSymbols>True</IncludeSymbols>
<DebugType>portable</DebugType>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DefineConstants>$(DefineConstants);TRACE;DEBUG</DefineConstants>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<NoWarn>$(NoWarn);CS1591;CS1572;CS1573</NoWarn>
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Content Include="..\Resources\icon.png" Link="icon.png" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" />
<ProjectReference Include="..\RGB.NET.HID\RGB.NET.HID.csproj" />
@@ -6,4 +6,5 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mouse/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=perdevice/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=perkey/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=zone/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=zone/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
@@ -40,7 +40,7 @@ namespace RGB.NET.Devices.Logitech
}
/// <inheritdoc />
protected override object? GetLedCustomData(LedId ledId) => _ledMapping[ledId];
protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId];
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate));